SQLI LABS | Less-39 GET-Stacked Query Injection-Intiger Based

关注这个靶场的其它相关笔记:SQLI LABS ------ 靶场笔记合集-CSDN博客

0x01:过关流程

输入下面的链接进入靶场(如果你的地址和我不一样,按照你本地的环境来):

复制代码
 http://localhost/sqli-labs/Less-39/

本关是堆叠注入,先来看一下受害者原始数据(我们的目标就是篡改信息,或者删除信息?):

首先,用 BP 抓包,然后用时间盲注的字典去爆破后端 SQL 模板:

如下,是一个可以使用的 Payload 模板:

sql 复制代码
 1 and sleep(3)

通过上面的模板,我们可以推测出其后端的 SQL 模板为:

sql 复制代码
 select * from users where id=$_GET["id"];

我们可以使用如下 Payload 做一个测试,进行校验,看看我们上面的推测是否正确:

sql 复制代码
 1 and 1=1   => 若页面回显内容,则证明存在漏洞
 1 and 1=0   => 若页面回显为空,则证明存在漏洞

明确了漏洞存在,且知道 Payload 该怎么写后,就是收集数据库信息、收集数据表信息 。。。 这些笔者在这里节省时间就不说了,直接当作已知条件,下面直接开始上堆叠注入的 Payload:

sql 复制代码
 -- 修改 id = 1 的用户密码为 HACKER
 1;update users set password='HACKER' where id=1;#

如上,我们已经能够随意篡改用户密码了。至此,SQLI LABS Less-39 GET-Stacked Query Injection-Intiger Based 成功过关。

0x02:源码分析

下面是 SQLI LABS Less-39 GET-Stacked Query Injection-Intiger Based 后端的部分源码,以及笔者做的笔记:

php 复制代码
<?php
 // take the variables 
 if (isset($_GET['id'])) {
 $id = $_GET['id'];
 //logging the connection parameters to a file for analysis.
 $fp = fopen('result.txt', 'a');
 fwrite($fp, 'ID:' . $id . "\n");
 fclose($fp);
 ​
 // connectivity
 //mysql connections for stacked query examples.
 $con1 = mysqli_connect($host, $dbuser, $dbpass, $dbname);
 // Check connection
 if (mysqli_connect_errno($con1)) {
     echo "Failed to connect to MySQL: " . mysqli_connect_error();
 } else {
     @mysqli_select_db($con1, $dbname) or die("Unable to connect to the database: $dbname");
 }
 ​
 // 直接拼接进 SQL 模板中
 $sql = "SELECT * FROM users WHERE id=$id LIMIT 0,1";
 /* execute multi query */
 // mysqli_multi_query => 执行一个或多个针对数据库的查询,多个查询用分号进行分隔。 
 if (mysqli_multi_query($con1, $sql)) {
     /* store first result set */
     // mysqli_stroe_result => 转移将上一次查询返回的结果集(多个结果)
     if ($result = mysqli_store_result($con1)) {
         if ($row = mysqli_fetch_row($result)) {
             echo '<font size = "5" color= "#00FF00">';
             printf("Your Username is : %s", $row[1]);
             echo "<br>";
             printf("Your Password is : %s", $row[2]);
             echo "<br>";
             echo "</font>";
         }
         //            mysqli_free_result($result);
     }
     /* print divider */
     // mysqli_more_results => 如果当前执行的查询存在多个结果,返回 "真",否则返回 "假"
     if (mysqli_more_results($con1)) {
         //printf("-----------------\n");
     }
     //while (mysqli_next_result($con1));
 } else {
     echo '<font size="5" color= "#FFFF00">';
     print_r(mysqli_error($con1));
     echo "</font>";
 }
 /* close connection */
 mysqli_close($con1);
 } else {
 echo "Please input the ID as parameter with numeric value";
 }
 ?>
相关推荐
LuDvei1 小时前
CH9121T电路及配置详解
服务器·嵌入式硬件·物联网·网络协议·tcp/ip·网络安全·信号处理
程序员的世界你不懂1 小时前
adb 简介与常用命令
adb
EngZegNgi2 小时前
安卓应用启动崩溃的问题排查记录
android·crash·启动崩溃
火柴就是我2 小时前
每日见闻之Container Decoration
android·flutter
天枢破军2 小时前
【AOSP】解决repo拉取提示无法连接android.googlesource.com
android
whysqwhw2 小时前
OkHttp之AndroidPlatform类分析
android
XiaolongTu3 小时前
Kotlin Flow详述:从一个“卡顿”问题到线程切换的本质
android·面试
Kapaseker3 小时前
全网最详细的Compose Stable讲解,你一定要看
android
solo_993 小时前
使用Android Studio 聊微信
android
whysqwhw3 小时前
OkHttp PublicSuffix包的平台化设计分析
android