PHP SSRF

Support HackTricks

SSRF PHP functions

कुछ फ़ंक्शन जैसे file_get_contents(), fopen(), file(), md5_file() URL को इनपुट के रूप में स्वीकार करते हैं जिन्हें वे फॉलो करेंगे जिससे संभावित SSRF कमजोरियाँ बन सकती हैं यदि उपयोगकर्ता डेटा को नियंत्रित कर सकता है:

file_get_contents("http://127.0.0.1:8081");
fopen("http://127.0.0.1:8081", "r");
file("http://127.0.0.1:8081");
md5_file("http://127.0.0.1:8081");

Wordpress SSRF via DNS Rebinding

जैसा कि इस ब्लॉग पोस्ट में समझाया गया है, यहां तक कि Wordpress फ़ंक्शन wp_safe_remote_get DNS rebinding के प्रति संवेदनशील है, जिससे यह संभावित रूप से SSRF हमलों के लिए संवेदनशील हो जाता है। मुख्य सत्यापन जो यह कॉल करता है वह है wp_http_validate_url, जो यह जांचता है कि प्रोटोकॉल http:// या https:// है और कि पोर्ट 80, 443, और 8080 में से एक है, लेकिन यह DNS rebinding के प्रति संवेदनशील है

पोस्ट के अनुसार अन्य संवेदनशील फ़ंक्शन हैं:

  • wp_safe_remote_request()

  • wp_safe_remote_post()

  • wp_safe_remote_head()

  • WP_REST_URL_Details_Controller::get_remote_url()

  • download_url()

  • wp_remote_fopen()

  • WP_oEmbed::discover()

CRLF

इसके अलावा, कुछ मामलों में, पिछले फ़ंक्शनों में CRLF "कमजोरियों" के माध्यम से मनमाने हेडर भेजना भी संभव हो सकता है:

# The following will create a header called from with value Hi and
# an extra header "Injected: I HAVE IT"
ini_set("from", "Hi\r\nInjected: I HAVE IT");
file_get_contents("http://127.0.0.1:8081");

GET / HTTP/1.1
From: Hi
Injected: I HAVE IT
Host: 127.0.0.1:8081
Connection: close

# Any of the previously mentioned functions will send those headers

इस CRLF vuln के बारे में अधिक जानकारी के लिए, इस बग की जांच करें https://bugs.php.net/bug.php?id=81680&edit=1

ध्यान दें कि इन फ़ंक्शनों में अनुरोधों में मनमाने हेडर सेट करने के अन्य तरीके हो सकते हैं, जैसे:

$url = "";

$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n" .  // check function.stream-context-create on php.net
"User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad
)
);

$context = stream_context_create($options);
$file = file_get_contents($url, false, $context);
HackTricks का समर्थन करें

Last updated