Class: Msf::Sessions::SMB
- Inherits:
-
Object
- Object
- Msf::Sessions::SMB
- Includes:
- Msf::Session::Basic, Scriptable
- Defined in:
- lib/msf/base/sessions/smb.rb
Instance Attribute Summary collapse
-
#arch ⇒ Object
Returns the value of attribute arch.
-
#client ⇒ RubySMB::Client
The SMB client.
-
#console ⇒ Rex::Post::SMB::Ui::Console
The interactive console.
-
#framework ⇒ Object
readonly
Returns the value of attribute framework.
-
#platform ⇒ Object
Returns the value of attribute platform.
- #simple_client ⇒ Rex::Proto::SMB::SimpleClient
Attributes included from Msf::Session::Interactive
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
Attributes included from Rex::Ui::Subscriber::Output
Attributes included from Msf::Session
#alive, #db_record, #exploit, #exploit_datastore, #exploit_task, #exploit_uuid, #info, #machine_id, #payload_uuid, #routes, #sid, #sname, #target_host, #target_port, #username, #uuid, #via, #workspace
Class Method Summary collapse
- .can_cleanup_files ⇒ Object
-
.type ⇒ Object
Returns the type of session.
Instance Method Summary collapse
-
#_interact ⇒ Object
:category: Msf::Session::Interactive implementors.
-
#_interact_stream ⇒ Object
:category: Msf::Session::Interactive implementors.
- #address ⇒ Object
- #bootstrap(datastore = {}, handler = nil) ⇒ Object
-
#desc ⇒ Object
Returns the session description.
- #execute_file(full_path, args) ⇒ Object
- #exit ⇒ Object
-
#init_ui(input, output) ⇒ Object
:category: Msf::Session::Interactive implementors.
-
#initialize(rstream, opts = {}) ⇒ SMB
constructor
@param rstream.
- #port ⇒ Object
- #process_autoruns(datastore) ⇒ Object
-
#reset_ui ⇒ Object
:category: Msf::Session::Interactive implementors.
- #type ⇒ Object
Methods included from Scriptable
#execute_script, included, #legacy_script_to_post_module
Methods included from Msf::Session::Interactive
#_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_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
Methods included from Rex::Ui::Subscriber::Input
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?, #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, #via_exploit, #via_payload
Constructor Details
#initialize(rstream, opts = {}) ⇒ SMB
@param rstream
24 25 26 27 28 29 |
# File 'lib/msf/base/sessions/smb.rb', line 24 def initialize(rstream, opts = {}) @client = opts.fetch(:client) @simple_client = ::Rex::Proto::SMB::SimpleClient.new(client.dispatcher.tcp_socket, client: client) self.console = Rex::Post::SMB::Ui::Console.new(self) super(rstream, opts) end |
Instance Attribute Details
#arch ⇒ Object
Returns the value of attribute arch.
18 19 20 |
# File 'lib/msf/base/sessions/smb.rb', line 18 def arch @arch end |
#client ⇒ RubySMB::Client
Returns The SMB client.
15 16 17 |
# File 'lib/msf/base/sessions/smb.rb', line 15 def client @client end |
#console ⇒ Rex::Post::SMB::Ui::Console
Returns The interactive console.
13 14 15 |
# File 'lib/msf/base/sessions/smb.rb', line 13 def console @console end |
#framework ⇒ Object (readonly)
Returns the value of attribute framework.
19 20 21 |
# File 'lib/msf/base/sessions/smb.rb', line 19 def framework @framework end |
#platform ⇒ Object
Returns the value of attribute platform.
18 19 20 |
# File 'lib/msf/base/sessions/smb.rb', line 18 def platform @platform end |
#simple_client ⇒ Rex::Proto::SMB::SimpleClient
17 18 19 |
# File 'lib/msf/base/sessions/smb.rb', line 17 def simple_client @simple_client end |
Class Method Details
.can_cleanup_files ⇒ Object
66 67 68 |
# File 'lib/msf/base/sessions/smb.rb', line 66 def self.can_cleanup_files false end |
.type ⇒ Object
Returns the type of session.
62 63 64 |
# File 'lib/msf/base/sessions/smb.rb', line 62 def self.type 'smb' end |
Instance Method Details
#_interact ⇒ Object
:category: Msf::Session::Interactive implementors
Override the basic session interaction to use shell_read and shell_write instead of operating on rstream directly.
118 119 120 121 122 123 |
# File 'lib/msf/base/sessions/smb.rb', line 118 def _interact framework.events.on_session_interact(self) framework.history_manager.with_context(name: type.to_sym) do _interact_stream end end |
#_interact_stream ⇒ Object
:category: Msf::Session::Interactive implementors
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/msf/base/sessions/smb.rb', line 128 def _interact_stream framework.events.on_session_interact(self) console.framework = framework # Call the console interaction of the smb client and # pass it a block that returns whether or not we should still be # interacting. This will allow the shell to abort if interaction is # canceled. console.interact { interacting != true } console.framework = nil # If the stop flag has been set, then that means the user exited. Raise # the EOFError so we can drop this handle like a bad habit. raise EOFError if (console.stopped? == true) end |
#address ⇒ Object
77 78 79 |
# File 'lib/msf/base/sessions/smb.rb', line 77 def address @address ||= simple_client.peerhost end |
#bootstrap(datastore = {}, handler = nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/msf/base/sessions/smb.rb', line 31 def bootstrap(datastore = {}, handler = nil) session = self session.init_ui(user_input, user_output) @info = "SMB #{datastore['USERNAME']} @ #{@peer_info}" end |
#desc ⇒ Object
Returns the session description.
73 74 75 |
# File 'lib/msf/base/sessions/smb.rb', line 73 def desc 'SMB' end |
#execute_file(full_path, args) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/msf/base/sessions/smb.rb', line 38 def execute_file(full_path, args) if File.extname(full_path) == '.rb' Rex::Script::Shell.new(self, full_path).run(args) else console.load_resource(full_path) end end |
#exit ⇒ Object
109 110 111 |
# File 'lib/msf/base/sessions/smb.rb', line 109 def exit console.stop end |
#init_ui(input, output) ⇒ Object
:category: Msf::Session::Interactive implementors
Initializes the console’s I/O handles.
90 91 92 93 94 95 96 97 |
# File 'lib/msf/base/sessions/smb.rb', line 90 def init_ui(input, output) self.user_input = input self.user_output = output console.init_ui(input, output) console.set_log_source(log_source) super end |
#port ⇒ Object
81 82 83 |
# File 'lib/msf/base/sessions/smb.rb', line 81 def port @port ||= simple_client.peerport end |
#process_autoruns(datastore) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/msf/base/sessions/smb.rb', line 46 def process_autoruns(datastore) ['InitialAutoRunScript', 'AutoRunScript'].each do |key| next if datastore[key].nil? || datastore[key].empty? args = Shellwords.shellwords(datastore[key]) print_status("Session ID #{sid} (#{tunnel_to_s}) processing #{key} '#{datastore[key]}'") execute_script(args.shift, *args) end end |
#reset_ui ⇒ Object
:category: Msf::Session::Interactive implementors
Resets the console’s I/O handles.
104 105 106 107 |
# File 'lib/msf/base/sessions/smb.rb', line 104 def reset_ui console.unset_log_source console.reset_ui end |
#type ⇒ Object
56 57 58 |
# File 'lib/msf/base/sessions/smb.rb', line 56 def type self.class.type end |