Class: Msf::Sessions::CommandShellUnix

Inherits:
CommandShell show all
Defined in:
lib/msf/base/sessions/command_shell_unix.rb

Instance Attribute Summary

Attributes inherited from CommandShell

#arch, #banner, #max_threads, #platform

Attributes included from Msf::Session::Interactive

#rstream

Attributes included from Rex::Ui::Interactive

#completed, #interacting, #next_session, #on_command_proc, #on_print_proc, #on_run_command_error_proc, #orig_suspend, #orig_usr1, #orig_winch

Attributes included from Rex::Ui::Subscriber::Input

#user_input

Attributes included from Rex::Ui::Subscriber::Output

#user_output

Attributes included from Msf::Session

#alive, #db_record, #exploit, #exploit_datastore, #exploit_task, #exploit_uuid, #framework, #info, #machine_id, #payload_uuid, #routes, #sid, #sname, #target_host, #target_port, #username, #uuid, #via, #workspace

Attributes included from Framework::Offspring

#framework

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandShell

#_file_transfer, _glue_cmdline_escape, #_interact, #_interact_stream, #abort_foreground_supported, binary_exists, #binary_exists, #bootstrap, can_cleanup_files, #cleanup, #cmd_background, #cmd_background_help, #cmd_download, #cmd_download_help, #cmd_help, #cmd_help_help, #cmd_irb, #cmd_irb_help, #cmd_pry, #cmd_pry_help, #cmd_resource, #cmd_resource_help, #cmd_sessions, #cmd_sessions_help, #cmd_shell, #cmd_shell_help, #cmd_source, #cmd_source_help, #cmd_upload, #cmd_upload_help, #commands, #desc, #docs_dir, #execute_file, #process_autoruns, #run_builtin_cmd, #run_single, #shell_close, #shell_command, #shell_init, #shell_read, #shell_write, type, #type

Methods included from Rex::Ui::Text::Resource

#load_resource

Methods included from Scriptable

#execute_file, #execute_script, included, #legacy_script_to_post_module

Methods included from Msf::Session::Provider::SingleCommandShell

#command_termination, #set_is_echo_shell, #shell_close, #shell_command_token_base, #shell_command_token_unix, #shell_command_token_win32, #shell_init, #shell_read, #shell_read_until_token, #shell_write

Methods included from Msf::Session::Basic

#_interact, #desc, #type

Methods included from Msf::Session::Interactive

#_interact, #_interact_complete, #_interrupt, #_suspend, #_usr1, #abort_foreground, #abort_foreground_supported, #cleanup, #comm_channel, #interactive?, #kill, #run_cmd, #tunnel_local, #tunnel_peer, #user_want_abort?

Methods included from Rex::Ui::Interactive

#_interact, #_interact_complete, #_interrupt, #_local_fd, #_remote_fd, #_stream_read_local_write_remote, #_stream_read_remote_write_local, #_suspend, #_winch, #detach, #handle_suspend, #handle_usr1, #handle_winch, #interact, #interact_stream, #prompt, #prompt_yesno, #restore_suspend, #restore_usr1, #restore_winch

Methods included from Rex::Ui::Subscriber

#copy_ui, #init_ui, #reset_ui

Methods included from Rex::Ui::Subscriber::Input

#gets

Methods included from Rex::Ui::Subscriber::Output

#flush, #print, #print_blank_line, #print_error, #print_good, #print_line, #print_status, #print_warning

Methods included from Msf::Session

#alive?, #cleanup, #comm_channel, #dead?, #desc, #inspect, #interactive?, #kill, #log_file_name, #log_source, #name, #name=, #register?, #session_host, #session_host=, #session_port, #session_port=, #session_type, #set_from_exploit, #set_via, #tunnel_local, #tunnel_peer, #tunnel_to_s, type, #type, #via_exploit, #via_payload

Constructor Details

#initialize(*args) ⇒ CommandShellUnix

Returns a new instance of CommandShellUnix.



4
5
6
7
# File 'lib/msf/base/sessions/command_shell_unix.rb', line 4

def initialize(*args)
  self.platform = "unix"
  super
end

Class Method Details

.escape_arg(arg) ⇒ Object

Escape an individual argument per Unix shell rules

Parameters:

  • arg (String)

    Shell argument



37
38
39
40
41
42
43
44
45
# File 'lib/msf/base/sessions/command_shell_unix.rb', line 37

def self.escape_arg(arg)
  quote_requiring = ['\\', '`', '(', ')', '<', '>', '&', '|', ' ', '@', '"', '$', ';']
  result = CommandShell._glue_cmdline_escape(arg, quote_requiring, "'", "\\'", "'")
  if result == ''
    result = "''"
  end

  result
end

.to_cmd(cmd_and_args) ⇒ Object

Convert the executable and argument array to a command that can be run in this command shell

Parameters:

  • cmd_and_args (Array<String>)

    The process path and the arguments to the process



27
28
29
30
31
32
33
# File 'lib/msf/base/sessions/command_shell_unix.rb', line 27

def self.to_cmd(cmd_and_args)
  escaped = cmd_and_args.map do |arg|
    escape_arg(arg)
  end

  escaped.join(' ')
end

Instance Method Details

#escape_arg(arg) ⇒ Object

Escape an individual argument per Unix shell rules

Parameters:

  • arg (String)

    Shell argument



21
22
23
# File 'lib/msf/base/sessions/command_shell_unix.rb', line 21

def escape_arg(arg)
  self.class.escape_arg(arg)
end

#shell_command_token(cmd, timeout = 10) ⇒ Object



9
10
11
# File 'lib/msf/base/sessions/command_shell_unix.rb', line 9

def shell_command_token(cmd,timeout = 10)
  shell_command_token_unix(cmd,timeout)
end

#to_cmd(cmd_and_args) ⇒ Object

Convert the executable and argument array to a command that can be run in this command shell

Parameters:

  • cmd_and_args (Array<String>)

    The process path and the arguments to the process



15
16
17
# File 'lib/msf/base/sessions/command_shell_unix.rb', line 15

def to_cmd(cmd_and_args)
  self.class.to_cmd(cmd_and_args)
end