[RoarCTF 2019]Online Proxy

[RoarCTF 2019]Online Proxy

考点

  • 盲注

  • 二次注入

wp

直接输入参数 ?url=https://baidu.com/ 在请求包发现注释的 Current Ip 在HTTP header加上X-Forwarded-For: 127.0.1.23发现这个IP写入了 Current Ip

<?php
$last_ip = "";
$result = query("select current_ip, last_ip from ip_log where uu");
if(count($result) > 0) {
    if($ip !== $result[0]['current_ip']) {
        $last_ip = $result[0]['current_ip'];

        query("delete from ip_log where uu");
    } else {
        $last_ip = $result[0]['last_ip'];
    }
}

query("insert into ip_log values ('".addslashes($uuid)."', '".addslashes($ip)."', '$last_ip');");
die("\n<!-- Debug Info: \n Duration: $time s \n Current Ip: $ip ".($last_ip !== "" ? "\nLast Ip: ".$last_ip : "")." -->");

这里是一个二次注入,下面给出详细分析

根据已知信息,不难判断数据库中存在三个字段,分别是 current_ip,last_ip和uuid 在初始情况下,last_ip是空的

此时修改HTTP请求头为X-Forwarded-For: testtest,由于新输入的IP和数据库中保存的当前IP不同,所以会删除已存储的,然后经过addslashes()函数转义新的IP,再将新的IP和last_ip插入 如果相同,就会将数据库中存储的last_ip赋值给变量,然后再转义进行插入。根据代码此时的ip应为testtest,last_ip为174.0.0.2 插入语句顺序如下

假设输入为 X-Forwarded-For: 1' or '1,因为和已存储的current_ip不同,所以会删除以前的内容,然后经过addslashes()函数转义,再存入数据库,存入数据库的内容为 1' or '1 ,根据代码此时的ip应为1' or '1,last_ip为testtest

然后输入X-Forwarded-For: 123456,因为和已存储的current_ip不同,会把last_ip赋值为1' or '1 然后删除,再插入。如下语句,很明显构成了注入,'1' or '1' 的结果为 1,所以最后结果为 1,但是这是插入之后last_ip的值,根据代码,此时的ip应为123456,last_ip为1' or '1

再输入X-Forwarded-For: 123456时,才会看到经过SQL运算之后的值

脚本如下

最后更新于