Module: RubySMB::Client::Utils

Included in:
RubySMB::Client
Defined in:
lib/ruby_smb/client/utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auth_userObject

Returns the value of attribute auth_user.



11
12
13
# File 'lib/ruby_smb/client/utils.rb', line 11

def auth_user
  @auth_user
end

#evasion_optsObject

Returns the value of attribute evasion_opts.



9
10
11
# File 'lib/ruby_smb/client/utils.rb', line 9

def evasion_opts
  @evasion_opts
end

#last_file_idObject

Returns the value of attribute last_file_id.



13
14
15
# File 'lib/ruby_smb/client/utils.rb', line 13

def last_file_id
  @last_file_id
end

#native_lmObject

Returns the value of attribute native_lm.



11
12
13
# File 'lib/ruby_smb/client/utils.rb', line 11

def native_lm
  @native_lm
end

#native_osObject

Returns the value of attribute native_os.



11
12
13
# File 'lib/ruby_smb/client/utils.rb', line 11

def native_os
  @native_os
end

#open_filesObject

Returns the value of attribute open_files.



6
7
8
# File 'lib/ruby_smb/client/utils.rb', line 6

def open_files
  @open_files
end

#send_lmObject

Returns the value of attribute send_lm.



8
9
10
# File 'lib/ruby_smb/client/utils.rb', line 8

def send_lm
  @send_lm
end

#send_ntlmObject

Returns the value of attribute send_ntlm.



8
9
10
# File 'lib/ruby_smb/client/utils.rb', line 8

def send_ntlm
  @send_ntlm
end

#spnoptObject

Returns the value of attribute spnopt.



8
9
10
# File 'lib/ruby_smb/client/utils.rb', line 8

def spnopt
  @spnopt
end

#tree_connectsObject

Returns the value of attribute tree_connects.



5
6
7
# File 'lib/ruby_smb/client/utils.rb', line 5

def tree_connects
  @tree_connects
end

#use_lanman_keyObject

Returns the value of attribute use_lanman_key.



8
9
10
# File 'lib/ruby_smb/client/utils.rb', line 8

def use_lanman_key
  @use_lanman_key
end

#use_ntlmv2Object

Returns the value of attribute use_ntlmv2.



8
9
10
# File 'lib/ruby_smb/client/utils.rb', line 8

def use_ntlmv2
  @use_ntlmv2
end

#usentlm2_sessionObject

Returns the value of attribute usentlm2_session.



8
9
10
# File 'lib/ruby_smb/client/utils.rb', line 8

def usentlm2_session
  @usentlm2_session
end

#verify_signatureObject

Returns the value of attribute verify_signature.



11
12
13
# File 'lib/ruby_smb/client/utils.rb', line 11

def verify_signature
  @verify_signature
end

Instance Method Details

#close(file_id = last_file_id, tree_id = last_tree_id, do_recv = true) ⇒ Object



59
60
61
# File 'lib/ruby_smb/client/utils.rb', line 59

def close(file_id = last_file_id, tree_id = last_tree_id, do_recv = true)
 @open_files[file_id].close
end

#create_pipe(path, disposition = RubySMB::Dispositions::FILE_OPEN_IF) ⇒ Object



38
39
40
# File 'lib/ruby_smb/client/utils.rb', line 38

def create_pipe(path, disposition=RubySMB::Dispositions::FILE_OPEN_IF)
  open(path.gsub(/\\/, ''), disposition, write: true, read: true)
end

#delete(path, tree_id = last_tree_id, do_recv = true) ⇒ Object



52
53
54
55
56
57
# File 'lib/ruby_smb/client/utils.rb', line 52

def delete(path, tree_id = last_tree_id, do_recv = true)
  tree = @tree_connects.detect{ |tree| tree.id == tree_id }
  file = tree.open_file(filename: path.sub(/^\\/, ''), delete: true)
  file.delete
  file.close
end

#last_fileObject



19
20
21
# File 'lib/ruby_smb/client/utils.rb', line 19

def last_file
  @open_files[@last_file_id]
end

#last_treeObject



15
16
17
# File 'lib/ruby_smb/client/utils.rb', line 15

def last_tree
  @tree_connects.last
end

#last_tree_idObject



23
24
25
# File 'lib/ruby_smb/client/utils.rb', line 23

def last_tree_id
  last_tree.id
end

#open(path, disposition = RubySMB::Dispositions::FILE_OPEN, write: false, read: true) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/ruby_smb/client/utils.rb', line 27

def open(path, disposition=RubySMB::Dispositions::FILE_OPEN, write: false, read: true)
   file = last_tree.open_file(filename: path.sub(/^\\/, ''), write: write, read: read, disposition: disposition)
   @last_file_id = if file.respond_to?(:guid)
     file.guid.to_binary_s
   elsif file.respond_to?(:fid)
     file.fid.to_binary_s
   end
   @open_files[@last_file_id] = file
   @last_file_id
end

#read(file_id = last_file_id, offset = 0, length = last_file.size, do_recv = true) ⇒ Object



47
48
49
50
# File 'lib/ruby_smb/client/utils.rb', line 47

def read(file_id = last_file_id, offset = 0, length = last_file.size, do_recv = true)
  data = @open_files[file_id].send_recv_read(read_length: length, offset: offset)
  data.bytes
end

#tree_disconnect(tree_id = last_tree_id, do_recv = true) ⇒ Object



63
64
65
# File 'lib/ruby_smb/client/utils.rb', line 63

def tree_disconnect(tree_id = last_tree_id, do_recv = true)
 @tree_connects.detect{|tree| tree.id == tree_id }.disconnect!
end

#write(file_id = last_file_id, offset = 0, data = '', do_recv = true) ⇒ Object

Writes data to an open file handle



43
44
45
# File 'lib/ruby_smb/client/utils.rb', line 43

def write(file_id = last_file_id, offset = 0, data = '', do_recv = true)
  @open_files[file_id].send_recv_write(data: data, offset: offset)
end