Class: Msf::Sessions::SMB

Inherits:
Object
  • Object
show all
Includes:
Msf::Session::Basic, Scriptable
Defined in:
lib/msf/base/sessions/smb.rb

Instance Attribute Summary collapse

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, #info, #machine_id, #payload_uuid, #routes, #sid, #sname, #target_host, #target_port, #username, #uuid, #via, #workspace

Class Method Summary collapse

Instance Method Summary collapse

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

#copy_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?, #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

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :client (RubySMB::Client)


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

#archObject

Returns the value of attribute arch.



18
19
20
# File 'lib/msf/base/sessions/smb.rb', line 18

def arch
  @arch
end

#clientRubySMB::Client

Returns The SMB client.

Returns:

  • (RubySMB::Client)

    The SMB client



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

def client
  @client
end

#consoleRex::Post::SMB::Ui::Console

Returns The interactive console.

Returns:



13
14
15
# File 'lib/msf/base/sessions/smb.rb', line 13

def console
  @console
end

#frameworkObject (readonly)

Returns the value of attribute framework.



19
20
21
# File 'lib/msf/base/sessions/smb.rb', line 19

def framework
  @framework
end

#platformObject

Returns the value of attribute platform.



18
19
20
# File 'lib/msf/base/sessions/smb.rb', line 18

def platform
  @platform
end

#simple_clientRex::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_filesObject



66
67
68
# File 'lib/msf/base/sessions/smb.rb', line 66

def self.can_cleanup_files
  false
end

.typeObject

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

#_interactObject

: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_streamObject

:category: Msf::Session::Interactive implementors

Raises:

  • (EOFError)


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

#addressObject



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

#descObject

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

#exitObject



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

#portObject



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_uiObject

: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

#typeObject



56
57
58
# File 'lib/msf/base/sessions/smb.rb', line 56

def type
  self.class.type
end