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/lib/msf/base/sessions/command_shell_unix.rb
Views: 11623
1
module Msf::Sessions
2
3
class CommandShellUnix < CommandShell
4
def initialize(*args)
5
self.platform = "unix"
6
super
7
end
8
9
def shell_command_token(cmd,timeout = 10)
10
shell_command_token_unix(cmd,timeout)
11
end
12
13
# Convert the executable and argument array to a command that can be run in this command shell
14
# @param cmd_and_args [Array<String>] The process path and the arguments to the process
15
def to_cmd(cmd_and_args)
16
self.class.to_cmd(cmd_and_args)
17
end
18
19
# Escape an individual argument per Unix shell rules
20
# @param arg [String] Shell argument
21
def escape_arg(arg)
22
self.class.escape_arg(arg)
23
end
24
25
# Convert the executable and argument array to a command that can be run in this command shell
26
# @param cmd_and_args [Array<String>] The process path and the arguments to the process
27
def self.to_cmd(cmd_and_args)
28
escaped = cmd_and_args.map do |arg|
29
escape_arg(arg)
30
end
31
32
escaped.join(' ')
33
end
34
35
# Escape an individual argument per Unix shell rules
36
# @param arg [String] Shell argument
37
def self.escape_arg(arg)
38
quote_requiring = ['\\', '`', '(', ')', '<', '>', '&', '|', ' ', '@', '"', '$', ';']
39
result = CommandShell._glue_cmdline_escape(arg, quote_requiring, "'", "\\'", "'")
40
if result == ''
41
result = "''"
42
end
43
44
result
45
end
46
end
47
48
end
49
50