Class: Rex::Proto::SMB::SimpleClient

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/smb/simpleclient.rb,
lib/rex/proto/smb/simpleclient/open_file.rb,
lib/rex/proto/smb/simpleclient/open_pipe.rb

Defined Under Namespace

Classes: OpenFile, OpenPipe

Constant Summary collapse

CONST =

Some short-hand class aliases

Rex::Proto::SMB::Constants
CRYPT =
Rex::Proto::SMB::Crypt
UTILS =
Rex::Proto::SMB::Utils
XCEPT =
Rex::Proto::SMB::Exceptions
EVADE =
Rex::Proto::SMB::Evasions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket, direct = false) ⇒ SimpleClient

Pass the socket object and a boolean indicating whether the socket is netbios or cifs



32
33
34
35
36
37
# File 'lib/rex/proto/smb/simpleclient.rb', line 32

def initialize(socket, direct = false)
  self.socket = socket
  self.direct = direct
  self.client = Rex::Proto::SMB::Client.new(socket)
  self.shares = { }
end

Instance Attribute Details

#clientObject

Private accessors



29
30
31
# File 'lib/rex/proto/smb/simpleclient.rb', line 29

def client
  @client
end

#directObject

Private accessors



29
30
31
# File 'lib/rex/proto/smb/simpleclient.rb', line 29

def direct
  @direct
end

#last_errorObject

Public accessors



26
27
28
# File 'lib/rex/proto/smb/simpleclient.rb', line 26

def last_error
  @last_error
end

#last_shareObject

Private accessors



29
30
31
# File 'lib/rex/proto/smb/simpleclient.rb', line 29

def last_share
  @last_share
end

#sharesObject

Private accessors



29
30
31
# File 'lib/rex/proto/smb/simpleclient.rb', line 29

def shares
  @shares
end

#socketObject

Private accessors



29
30
31
# File 'lib/rex/proto/smb/simpleclient.rb', line 29

def socket
  @socket
end

Instance Method Details

#connect(share) ⇒ Object



134
135
136
137
138
139
# File 'lib/rex/proto/smb/simpleclient.rb', line 134

def connect(share)
  ok = self.client.tree_connect(share)
  tree_id = ok['Payload']['SMB'].v['TreeID']
  self.shares[share] = tree_id
  self.last_share = share
end

#create_pipe(path, perm = 'c') ⇒ Object



162
163
164
165
166
167
# File 'lib/rex/proto/smb/simpleclient.rb', line 162

def create_pipe(path, perm = 'c')
  disposition = UTILS.create_mode_to_disposition(perm)
  ok = self.client.create_pipe(path, disposition)
  file_id = ok['Payload'].v['FileID']
  fh = OpenPipe.new(self.client, path, self.client.last_tree_id, file_id)
end

#delete(*args) ⇒ Object



158
159
160
# File 'lib/rex/proto/smb/simpleclient.rb', line 158

def delete(*args)
  self.client.delete(*args)
end

#disconnect(share) ⇒ Object



141
142
143
144
# File 'lib/rex/proto/smb/simpleclient.rb', line 141

def disconnect(share)
  ok = self.client.tree_disconnect(self.shares[share])
  self.shares.delete(share)
end

#login(name = '', user = '', pass = '', domain = '', verify_signature = false, usentlmv2 = false, usentlm2_session = true, send_lm = true, use_lanman_key = false, send_ntlm = true, native_os = 'Windows 2000 2195', native_lm = 'Windows 2000 5.0', spnopt = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
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
# File 'lib/rex/proto/smb/simpleclient.rb', line 39

def (name = '', user = '', pass = '', domain = '',
    verify_signature = false, usentlmv2 = false, usentlm2_session = true,
    send_lm = true, use_lanman_key = false, send_ntlm = true,
    native_os = 'Windows 2000 2195', native_lm = 'Windows 2000 5.0', spnopt = {})

  begin

    if (self.direct != true)
      self.client.session_request(name)
    end
    self.client.native_os = native_os
    self.client.native_lm = native_lm
    self.client.verify_signature = verify_signature
    self.client.use_ntlmv2 = usentlmv2
    self.client.usentlm2_session = usentlm2_session
    self.client.send_lm = send_lm
    self.client.use_lanman_key =  use_lanman_key
    self.client.send_ntlm = send_ntlm

    self.client.negotiate

    # Disable NTLMv2 Session for Windows 2000 (breaks authentication on some systems)
    # XXX: This in turn breaks SMB auth for Windows 2000 configured to enforce NTLMv2
    # XXX: Tracked by ticket #4785#4785
    if self.client.native_lm =~ /Windows 2000 5\.0/ and usentlm2_session
    #	self.client.usentlm2_session = false
    end

    self.client.spnopt = spnopt

    # In case the user unsets the password option, we make sure this is
    # always a string
    pass ||= ''

    ok = self.client.session_setup(user, pass, domain)
  rescue ::Interrupt
    raise $!
  rescue ::Exception => e
    n = XCEPT::LoginError.new
    n.source = e
    if(e.respond_to?('error_code'))
      n.error_code   = e.error_code
      n.error_reason = e.get_error(e.error_code)
    end
    raise n
  end

  return true
end

#login_split_next_ntlm1(user, domain, hash_lm, hash_nt) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/rex/proto/smb/simpleclient.rb', line 116

def (user, domain, hash_lm, hash_nt)
  begin
    ok = self.client.session_setup_no_ntlmssp_prehash(user, domain, hash_lm, hash_nt)
  rescue ::Interrupt
    raise $!
  rescue ::Exception => e
    n = XCEPT::LoginError.new
    n.source = e
    if(e.respond_to?('error_code'))
      n.error_code   = e.error_code
      n.error_reason = e.get_error(e.error_code)
    end
    raise n
  end

  return true
end

#login_split_start_ntlm1(name = '') ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rex/proto/smb/simpleclient.rb', line 90

def (name = '')

  begin

    if (self.direct != true)
      self.client.session_request(name)
    end

    # Disable extended security
    self.client.negotiate(false)
  rescue ::Interrupt
    raise $!
  rescue ::Exception => e
    n = XCEPT::LoginError.new
    n.source = e
    if(e.respond_to?('error_code'))
      n.error_code   = e.error_code
      n.error_reason = e.get_error(e.error_code)
    end
    raise n
  end

  return true
end

#open(path, perm, chunk_size = 48000) ⇒ Object



147
148
149
150
151
152
153
154
155
156
# File 'lib/rex/proto/smb/simpleclient.rb', line 147

def open(path, perm, chunk_size = 48000)
  mode   = UTILS.open_mode_to_mode(perm)
  access = UTILS.open_mode_to_access(perm)

  ok = self.client.open(path, mode, access)
  file_id = ok['Payload'].v['FileID']
  fh = OpenFile.new(self.client, path, self.client.last_tree_id, file_id)
  fh.chunk_size = chunk_size
  fh
end

#trans_pipe(fid, data, no_response = nil) ⇒ Object



169
170
171
# File 'lib/rex/proto/smb/simpleclient.rb', line 169

def trans_pipe(fid, data, no_response = nil)
  client.trans_named_pipe(fid, data, no_response)
end