Module: Msf::Exploit::Remote::SMB::Server

Includes:
LogAdapter, Msf::Exploit::Remote::SocketServer
Included in:
Share
Defined in:
lib/msf/core/exploit/remote/smb/server.rb,
lib/msf/core/exploit/remote/smb/server/share.rb

Overview

This mixin provides a minimal SMB server

Defined Under Namespace

Modules: HashCapture, ServiceMixin, Share

Instance Attribute Summary

Attributes included from Msf::Exploit::Remote::SocketServer

#service

Instance Method Summary collapse

Methods included from Msf::Exploit::Remote::SocketServer

#_determine_server_comm, #bindhost, #bindport, #cleanup, #exploit, #on_client_data, #primer, #regenerate_payload, #srvhost, #srvport, #via_string

Instance Method Details

#cleanup_serviceObject


94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/msf/core/exploit/remote/smb/server.rb', line 94

def cleanup_service
  if service
    begin
      self.service.stop
      self.service.wait
      true
    rescue ::Exception => e
      print_error(e.message)
      false
    end
  end
end

#initialize(info = {}) ⇒ Object


42
43
44
45
46
47
48
49
# File 'lib/msf/core/exploit/remote/smb/server.rb', line 42

def initialize(info = {})
  super

  register_options(
    [
      OptPort.new('SRVPORT', [ true, 'The local port to listen on.', 445 ])
    ], self.class)
end

#on_client_connect(client) ⇒ Object


90
91
92
# File 'lib/msf/core/exploit/remote/smb/server.rb', line 90

def on_client_connect(client)
  vprint_status("Received SMB connection from #{client.peerhost}")
end

#start_service(opts = {}) ⇒ Object


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/msf/core/exploit/remote/smb/server.rb', line 51

def start_service(opts = {})
  @rsock = Rex::Socket::Tcp.create(
    'LocalHost' => bindhost,
    'LocalPort' => bindport,
    'Comm' => _determine_server_comm(bindhost),
    'Server' => true,
    'Context' =>
      {
        'Msf' => framework,
        'MsfExploit' => self
      }
  )

  unless opts[:logger]
    log_device = LogAdapter::LogDevice::Framework.new(framework)
    opts[:logger] = LogAdapter::Logger.new(self, log_device)
  end

  thread_factory = Proc.new do |server_client, &block|
    Rex::ThreadFactory.spawn("SMBServerClient(#{server_client.peerhost}->#{server_client.dispatcher.tcp_socket.localhost})", false, &block)
  end

  server = RubySMB::Server.new(
    server_sock: @rsock,
    gss_provider: opts[:gss_provider],
    logger: opts[:logger],
    thread_factory: thread_factory
  )

  server.extend(ServiceMixin)
  server.on_client_connect_proc = Proc.new { |client|
    on_client_connect(client)
  }
  self.service = server
  self.service.start

  print_status("Server is running. Listening on #{bindhost}:#{bindport}")
end