SQLI LABS | Less-37 POST-Bypass mysql_real_escape_string
关注这个靶场的其它相关笔记:SQLI LABS —— 靶场笔记合集-CSDN博客
0x01:过关流程
输入下面的链接进入靶场(如果你的地址和我不一样,按照你本地的环境来):
http://localhost/sqli-labs/Less-37/
是一个登录框,我们可以随便输点数据后通过 BurpSuite 进行抓包,然后对 Username 字段进行时间盲注(可以预先准备一个字典,直接跑就好):
如下,是一个使用时间盲注成功爆破出来的可用模板,该模板只有通过 BurpSuite 的 Repeater 模块进行利用,因为如果你从网页端输入,会发现 %
会被二次 URL 编码,从而失去其原本的含义:
1%df'%20%26%20sleep(3)%23--%20%2f%2a
笔者嫌使用 sleep(3)
进行时间盲注太慢了,所以替换其 Payload 为报错盲注,如下,可以直接获取目标后端数据库信息:
-- 获取目标后端当前正在使用的数据库信息1%df'%20%26%20updatexml(1,concat(0x7e,database(),0x7e),1)%23--%20%2f%2a
可以看到,我们已经成功获取了当前站点使用的后端数据库的信息。至此,SQLI LABS Less-37 POST-Bypass mysql_real_escape_string 成功过关。
0x02:源码分析
下面是 SQLI LABS Less-37 POST-Bypass mysql_real_escape_string 后端的部分源码,以及笔者做的笔记:
<?php//including the Mysql connect parameters.include("../sql-connections/sqli-connect.php");// take the variablesif (isset($_POST['uname']) && isset($_POST['passwd'])) {// 接收 uname 与 passwd$uname1 = $_POST['uname'];$passwd1 = $_POST['passwd'];//echo "username before addslashes is :".$uname1 ."<br>";//echo "Input password before addslashes is : ".$passwd1. "<br>";//logging the connection parameters to a file for analysis.$fp = fopen('result.txt', 'a');fwrite($fp, 'User Name:' . $uname1);fwrite($fp, 'Password:' . $passwd1 . "\n");fclose($fp);// 对接收到的 uname 与 passwd 进行转义$uname = mysqli_real_escape_string($con1, $uname1);$passwd = mysqli_real_escape_string($con1, $passwd1);//echo "username after addslashes is :".$uname ."<br>";//echo "Input password after addslashes is : ".$passwd; // connectivity // 设置数据库连接的字符集为 gbk => 宽字节注入,前面的转义没用了mysqli_query($con1, "SET NAMES gbk");@$sql = "SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";$result = mysqli_query($con1, $sql);$row = mysqli_fetch_array($result, MYSQLI_BOTH);if ($row) {//echo '<font color= "#0000ff">'; echo "<br>";echo '<font color= "#FFFF00" font size = 4>';//echo " You Have successfully logged in\n\n " ;echo '<font size="3" color="#0000ff">';echo "<br>";echo 'Your Login name:' . $row['username'];echo "<br>";echo 'Your Password:' . $row['password'];echo "<br>";echo "</font>";echo "<br>";echo "<br>";echo '<img src="../images/flag.jpg" />';echo "</font>";} else {echo '<font color= "#0000ff" font size="3">';// 它人还怪好的,把 try again looser 给注释了,感觉少了点动力//echo "Try again looser";print_r(mysqli_error($con1));echo "</br>";echo "</br>";echo "</br>";echo '<img src="../images/slap.jpg" />';echo "</font>";}}?>