Replace simpleclient's client with ruby_smb client
parent
0c7003e40c
commit
a9019585fe
|
@ -14,6 +14,7 @@ require 'rex/proto/smb/utils'
|
||||||
require 'rex/proto/smb/client'
|
require 'rex/proto/smb/client'
|
||||||
require 'rex/proto/smb/simpleclient/open_file'
|
require 'rex/proto/smb/simpleclient/open_file'
|
||||||
require 'rex/proto/smb/simpleclient/open_pipe'
|
require 'rex/proto/smb/simpleclient/open_pipe'
|
||||||
|
require 'ruby_smb'
|
||||||
|
|
||||||
# Some short-hand class aliases
|
# Some short-hand class aliases
|
||||||
CONST = Rex::Proto::SMB::Constants
|
CONST = Rex::Proto::SMB::Constants
|
||||||
|
@ -32,7 +33,13 @@ attr_accessor :socket, :client, :direct, :shares, :last_share
|
||||||
def initialize(socket, direct = false)
|
def initialize(socket, direct = false)
|
||||||
self.socket = socket
|
self.socket = socket
|
||||||
self.direct = direct
|
self.direct = direct
|
||||||
self.client = Rex::Proto::SMB::Client.new(socket)
|
|
||||||
|
self.client = RubySMB::Client.new(RubySMB::Dispatcher::Socket.new(self.socket, read_timeout: 60),
|
||||||
|
username: '',
|
||||||
|
password: '')#Rex::Proto::SMB::Client.new(socket)
|
||||||
|
self.client.class.module_eval { attr_accessor :evasion_opts}
|
||||||
|
self.client.evasion_opts = {}
|
||||||
|
|
||||||
self.shares = { }
|
self.shares = { }
|
||||||
self.server_max_buffer_size = 1024 # 4356 (workstation) or 16644 (server) expected
|
self.server_max_buffer_size = 1024 # 4356 (workstation) or 16644 (server) expected
|
||||||
end
|
end
|
||||||
|
@ -135,7 +142,13 @@ attr_accessor :socket, :client, :direct, :shares, :last_share
|
||||||
|
|
||||||
def connect(share)
|
def connect(share)
|
||||||
ok = self.client.tree_connect(share)
|
ok = self.client.tree_connect(share)
|
||||||
tree_id = ok['Payload']['SMB'].v['TreeID']
|
|
||||||
|
if ok.respond_to?(:id)
|
||||||
|
tree_id = ok.id
|
||||||
|
else
|
||||||
|
tree_id = ok['Payload']['SMB'].v['TreeID']
|
||||||
|
end
|
||||||
|
|
||||||
self.shares[share] = tree_id
|
self.shares[share] = tree_id
|
||||||
self.last_share = share
|
self.last_share = share
|
||||||
end
|
end
|
||||||
|
@ -168,7 +181,13 @@ attr_accessor :socket, :client, :direct, :shares, :last_share
|
||||||
def create_pipe(path, perm = 'c')
|
def create_pipe(path, perm = 'c')
|
||||||
disposition = UTILS.create_mode_to_disposition(perm)
|
disposition = UTILS.create_mode_to_disposition(perm)
|
||||||
ok = self.client.create_pipe(path, disposition)
|
ok = self.client.create_pipe(path, disposition)
|
||||||
file_id = ok['Payload'].v['FileID']
|
if ok.respond_to? :guid
|
||||||
|
file_id = ok.guid
|
||||||
|
elsif ok.respond_to? :fid
|
||||||
|
file_id = ok.fid
|
||||||
|
else
|
||||||
|
file_id = ok['Payload'].v['FileID']
|
||||||
|
end
|
||||||
fh = OpenPipe.new(self.client, path, self.client.last_tree_id, file_id)
|
fh = OpenPipe.new(self.client, path, self.client.last_tree_id, file_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -61,10 +61,14 @@ class OpenFile
|
||||||
return data
|
return data
|
||||||
else
|
else
|
||||||
ok = self.client.read(self.file_id, offset, length)
|
ok = self.client.read(self.file_id, offset, length)
|
||||||
data = ok.to_s.slice(
|
data = if ok.is_a? Array
|
||||||
ok['Payload'].v['DataOffset'] + 4,
|
ok.pack('C*')
|
||||||
ok['Payload'].v['DataLenLow']
|
else
|
||||||
)
|
ok.to_s.slice(
|
||||||
|
ok['Payload'].v['DataOffset'] + 4,
|
||||||
|
ok['Payload'].v['DataLenLow']
|
||||||
|
)
|
||||||
|
end
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -87,7 +91,11 @@ class OpenFile
|
||||||
# Keep writing data until we run out
|
# Keep writing data until we run out
|
||||||
while (chunk.length > 0)
|
while (chunk.length > 0)
|
||||||
ok = self.client.write(self.file_id, fptr, chunk)
|
ok = self.client.write(self.file_id, fptr, chunk)
|
||||||
cl = ok['Payload'].v['CountLow']
|
if ok.is_a? Integer
|
||||||
|
cl = ok
|
||||||
|
else
|
||||||
|
cl = ok['Payload'].v['CountLow']
|
||||||
|
end
|
||||||
|
|
||||||
# Partial write, push the failed data back into the queue
|
# Partial write, push the failed data back into the queue
|
||||||
if (cl != chunk.length)
|
if (cl != chunk.length)
|
||||||
|
|
Loading…
Reference in New Issue