Class: RubySMB::Client
- Inherits:
-
Object
- Object
- RubySMB::Client
- Includes:
- Authentication, Echo, Encryption, Negotiation, Signing, TreeConnect, Utils, Winreg
- Defined in:
- lib/ruby_smb/client.rb,
lib/ruby_smb/client/echo.rb,
lib/ruby_smb/client/utils.rb,
lib/ruby_smb/client/winreg.rb,
lib/ruby_smb/client/signing.rb,
lib/ruby_smb/client/encryption.rb,
lib/ruby_smb/client/negotiation.rb,
lib/ruby_smb/client/tree_connect.rb,
lib/ruby_smb/client/authentication.rb
Overview
This module holds all of the methods backing the #open_file method
Defined Under Namespace
Modules: Authentication, Echo, Encryption, Negotiation, Signing, TreeConnect, Utils, Winreg
Constant Summary collapse
- SMB1_DIALECT_SMB1_DEFAULT =
The Default SMB1 Dialect string used in an SMB1 Negotiate Request
'NT LM 0.12'.freeze
- SMB1_DIALECT_SMB2_DEFAULT =
The Default SMB2 Dialect string used in an SMB1 Negotiate Request
'SMB 2.002'.freeze
- SMB1_DIALECT_SMB2_WILDCARD =
The SMB2 wildcard revision number Dialect string used in an SMB1 Negotiate Request It indicates that the server implements SMB 2.1 or future dialect revisions Note that this must be used for SMB3
'SMB 2.???'.freeze
- SMB2_DIALECT_DEFAULT =
Dialect values for SMB2
['0x0202', '0x0210']
- SMB3_DIALECT_DEFAULT =
Dialect values for SMB3
['0x0300', '0x0302', '0x0311']
- MAX_BUFFER_SIZE =
The default maximum size of a SMB message that the Client accepts (in bytes)
64512- SERVER_MAX_BUFFER_SIZE =
The default maximum size of a SMB message that the Server accepts (in bytes)
4356
Instance Attribute Summary collapse
- #client_encryption_key ⇒ String
- #default_domain ⇒ String
- #default_name ⇒ String
- #dialect ⇒ Integer
- #dispatcher ⇒ RubySMB::Dispatcher::Socket
- #dns_domain_name ⇒ String
- #dns_host_name ⇒ String
- #dns_tree_name ⇒ String
- #domain ⇒ String
- #encryption_algorithm ⇒ String
- #encryption_required ⇒ Boolean
- #local_workstation ⇒ String
- #max_buffer_size ⇒ Integer
-
#negotiated_smb_version ⇒ Integer
The negotiated SMB version.
- #ntlm_client ⇒ String
- #os_version ⇒ String
- #password ⇒ String
- #peer_native_lm ⇒ String
- #peer_native_os ⇒ String
- #preauth_integrity_hash_algorithm ⇒ String
- #preauth_integrity_hash_value ⇒ String
- #primary_domain ⇒ String
- #sequence_counter ⇒ Integer
-
#server_compression_algorithms ⇒ Array<Integer>
List of supported compression algorithms (constants defined in RubySMB::SMB2::CompressionCapabilities).
-
#server_encryption_algorithms ⇒ Array<Integer>
List of supported encryption algorithms (constants defined in RubySMB::SMB2::EncryptionCapabilities).
- #server_encryption_key ⇒ String
-
#server_max_buffer_size ⇒ Object
The maximum size SMB message that the Server accepts (in bytes) The default value is small by default.
- #server_max_read_size ⇒ Integer
- #server_max_transact_size ⇒ Integer
- #server_max_write_size ⇒ Integer
- #session_id ⇒ Integer
- #signing_enabled ⇒ Boolean
-
#signing_required ⇒ Object
Whether or not the Server requires signing.
- #smb1 ⇒ Boolean
- #smb2 ⇒ Boolean
- #smb2_message_id ⇒ Integer
- #smb3 ⇒ Boolean
- #user_id ⇒ String
- #username ⇒ String
Attributes included from Utils
#auth_user, #evasion_opts, #last_file_id, #native_lm, #native_os, #open_files, #send_lm, #send_ntlm, #spnopt, #tree_connects, #use_lanman_key, #use_ntlmv2, #usentlm2_session, #verify_signature
Attributes included from Signing
Instance Method Summary collapse
-
#can_be_encrypted?(packet) ⇒ Boolean
Check if the request packet can be encrypted.
-
#disconnect! ⇒ void
Logs off any currently open session on the server and closes the TCP socket connection.
-
#echo(count: 1, data: '') ⇒ WindowsError::ErrorCode
Sends an Echo request to the server and returns the NTStatus of the last response packet received.
-
#encryption_supported? ⇒ Boolean
Check if the current dialect support encryption.
-
#increment_smb_message_id(packet) ⇒ RubySMB::GenericPacket
Sets the message id field in an SMB2 packet's header to the one tracked by the client.
-
#initialize(dispatcher, smb1: true, smb2: true, smb3: true, username:, password:, domain: '.', local_workstation: 'WORKSTATION', always_encrypt: true) ⇒ Client
constructor
A new instance of Client.
-
#is_status_pending?(raw_response) ⇒ Boolean
Check if the response is an asynchronous operation with STATUS_PENDING status code.
-
#login(username: self.username, password: self.password, domain: self.domain, local_workstation: self.local_workstation) ⇒ Object
Performs protocol negotiation and session setup.
-
#logoff! ⇒ WindowsError::ErrorCode
Sends a LOGOFF command to the remote server to terminate the session.
-
#net_share_enum_all(host) ⇒ Array
Returns array of shares.
-
#recv_encrypt ⇒ String
Receives the raw response through the Dispatcher and decrypt the packet.
-
#send_encrypt(packet) ⇒ Object
Encrypt and send a packet.
-
#send_recv(packet, encrypt: false) ⇒ String
Sends a packet and receives the raw response through the Dispatcher.
-
#session_request(name = '*SMBSERVER') ⇒ TrueClass
Requests a NetBIOS Session Service using the provided name.
-
#session_request_packet(name = '*SMBSERVER') ⇒ RubySMB::Nbss::SessionRequest
Crafts the NetBIOS SessionRequest packet to be sent for session request operations.
- #session_setup(user, pass, domain, do_recv = true, local_workstation: self.local_workstation) ⇒ Object
-
#tree_connect(share) ⇒ RubySMB::SMB1::Tree, RubySMB::SMB2::Tree
Connects to the supplied share.
- #update_preauth_hash(data) ⇒ Object
-
#wipe_state! ⇒ void
Resets all of the session state on the client, setting it back to scratch.
Methods included from Encryption
Methods included from Winreg
#connect_to_winreg, #enum_registry_key, #enum_registry_values, #has_registry_key?, #read_registry_key_value
Methods included from Utils
#close, #create_pipe, #delete, #last_file, #last_tree, #last_tree_id, #open, #read, #tree_disconnect, #write
Methods included from Echo
Methods included from TreeConnect
#smb1_tree_connect, #smb1_tree_from_response, #smb2_tree_connect, #smb2_tree_from_response
Methods included from Signing
#smb1_sign, #smb2_sign, #smb3_sign
Methods included from Authentication
#authenticate, #extract_os_version, #smb1_anonymous_auth, #smb1_anonymous_auth_request, #smb1_anonymous_auth_response, #smb1_authenticate, #smb1_ntlmssp_auth_packet, #smb1_ntlmssp_authenticate, #smb1_ntlmssp_challenge_packet, #smb1_ntlmssp_final_packet, #smb1_ntlmssp_negotiate, #smb1_ntlmssp_negotiate_packet, #smb1_type2_message, #smb2_authenticate, #smb2_ntlmssp_auth_packet, #smb2_ntlmssp_authenticate, #smb2_ntlmssp_challenge_packet, #smb2_ntlmssp_final_packet, #smb2_ntlmssp_negotiate, #smb2_ntlmssp_negotiate_packet, #smb2_type2_message, #store_target_info
Methods included from Negotiation
#add_smb3_to_negotiate_request, #negotiate, #negotiate_request, #negotiate_response, #parse_negotiate_response, #parse_smb3_encryption_data, #smb1_negotiate_request, #smb2_3_negotiate_request
Constructor Details
#initialize(dispatcher, smb1: true, smb2: true, smb3: true, username:, password:, domain: '.', local_workstation: 'WORKSTATION', always_encrypt: true) ⇒ Client
Returns a new instance of Client.
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/ruby_smb/client.rb', line 246 def initialize(dispatcher, smb1: true, smb2: true, smb3: true, username:, password:, domain: '.', local_workstation: 'WORKSTATION', always_encrypt: true) raise ArgumentError, 'No Dispatcher provided' unless dispatcher.is_a? RubySMB::Dispatcher::Base if smb1 == false && smb2 == false && smb3 == false raise ArgumentError, 'You must enable at least one Protocol' end @dispatcher = dispatcher @domain = domain @local_workstation = local_workstation @password = password.encode('utf-8') || ''.encode('utf-8') @sequence_counter = 0 @session_id = 0x00 @session_key = '' @signing_required = false @smb1 = smb1 @smb2 = smb2 @smb3 = smb3 @username = username.encode('utf-8') || ''.encode('utf-8') @max_buffer_size = MAX_BUFFER_SIZE # These sizes will be modifed during negotiation @server_max_buffer_size = SERVER_MAX_BUFFER_SIZE @server_max_read_size = RubySMB::SMB2::File::MAX_PACKET_SIZE @server_max_write_size = RubySMB::SMB2::File::MAX_PACKET_SIZE @server_max_transact_size = RubySMB::SMB2::File::MAX_PACKET_SIZE # SMB 3.x options @encryption_required = always_encrypt negotiate_version_flag = 0x02000000 flags = Net::NTLM::Client::DEFAULT_FLAGS | Net::NTLM::FLAGS[:TARGET_INFO] | negotiate_version_flag @ntlm_client = Net::NTLM::Client.new( @username, @password, workstation: @local_workstation, domain: @domain, flags: flags ) @tree_connects = [] @open_files = {} @smb2_message_id = 0 end |
Instance Attribute Details
#client_encryption_key ⇒ String
212 213 214 |
# File 'lib/ruby_smb/client.rb', line 212 def client_encryption_key @client_encryption_key end |
#default_domain ⇒ String
92 93 94 |
# File 'lib/ruby_smb/client.rb', line 92 def default_domain @default_domain end |
#default_name ⇒ String
87 88 89 |
# File 'lib/ruby_smb/client.rb', line 87 def default_name @default_name end |
#dialect ⇒ Integer
117 118 119 |
# File 'lib/ruby_smb/client.rb', line 117 def dialect @dialect end |
#dispatcher ⇒ RubySMB::Dispatcher::Socket
43 44 45 |
# File 'lib/ruby_smb/client.rb', line 43 def dispatcher @dispatcher end |
#dns_domain_name ⇒ String
102 103 104 |
# File 'lib/ruby_smb/client.rb', line 102 def dns_domain_name @dns_domain_name end |
#dns_host_name ⇒ String
97 98 99 |
# File 'lib/ruby_smb/client.rb', line 97 def dns_host_name @dns_host_name end |
#dns_tree_name ⇒ String
107 108 109 |
# File 'lib/ruby_smb/client.rb', line 107 def dns_tree_name @dns_tree_name end |
#domain ⇒ String
48 49 50 |
# File 'lib/ruby_smb/client.rb', line 48 def domain @domain end |
#encryption_algorithm ⇒ String
207 208 209 |
# File 'lib/ruby_smb/client.rb', line 207 def encryption_algorithm @encryption_algorithm end |
#encryption_required ⇒ Boolean
222 223 224 |
# File 'lib/ruby_smb/client.rb', line 222 def encryption_required @encryption_required end |
#local_workstation ⇒ String
53 54 55 |
# File 'lib/ruby_smb/client.rb', line 53 def local_workstation @local_workstation end |
#max_buffer_size ⇒ Integer
170 171 172 |
# File 'lib/ruby_smb/client.rb', line 170 def max_buffer_size @max_buffer_size end |
#negotiated_smb_version ⇒ Integer
Returns the negotiated SMB version.
240 241 242 |
# File 'lib/ruby_smb/client.rb', line 240 def negotiated_smb_version @negotiated_smb_version end |
#ntlm_client ⇒ String
58 59 60 |
# File 'lib/ruby_smb/client.rb', line 58 def ntlm_client @ntlm_client end |
#os_version ⇒ String
112 113 114 |
# File 'lib/ruby_smb/client.rb', line 112 def os_version @os_version end |
#password ⇒ String
63 64 65 |
# File 'lib/ruby_smb/client.rb', line 63 def password @password end |
#peer_native_lm ⇒ String
75 76 77 |
# File 'lib/ruby_smb/client.rb', line 75 def peer_native_lm @peer_native_lm end |
#peer_native_os ⇒ String
69 70 71 |
# File 'lib/ruby_smb/client.rb', line 69 def peer_native_os @peer_native_os end |
#preauth_integrity_hash_algorithm ⇒ String
197 198 199 |
# File 'lib/ruby_smb/client.rb', line 197 def preauth_integrity_hash_algorithm @preauth_integrity_hash_algorithm end |
#preauth_integrity_hash_value ⇒ String
202 203 204 |
# File 'lib/ruby_smb/client.rb', line 202 def preauth_integrity_hash_value @preauth_integrity_hash_value end |
#primary_domain ⇒ String
82 83 84 |
# File 'lib/ruby_smb/client.rb', line 82 def primary_domain @primary_domain end |
#sequence_counter ⇒ Integer
124 125 126 |
# File 'lib/ruby_smb/client.rb', line 124 def sequence_counter @sequence_counter end |
#server_compression_algorithms ⇒ Array<Integer>
Returns list of supported compression algorithms (constants defined in RubySMB::SMB2::CompressionCapabilities).
234 235 236 |
# File 'lib/ruby_smb/client.rb', line 234 def server_compression_algorithms @server_compression_algorithms end |
#server_encryption_algorithms ⇒ Array<Integer>
Returns list of supported encryption algorithms (constants defined in RubySMB::SMB2::EncryptionCapabilities).
228 229 230 |
# File 'lib/ruby_smb/client.rb', line 228 def server_encryption_algorithms @server_encryption_algorithms end |
#server_encryption_key ⇒ String
217 218 219 |
# File 'lib/ruby_smb/client.rb', line 217 def server_encryption_key @server_encryption_key end |
#server_max_buffer_size ⇒ Object
The maximum size SMB message that the Server accepts (in bytes) The default value is small by default
176 177 178 |
# File 'lib/ruby_smb/client.rb', line 176 def server_max_buffer_size @server_max_buffer_size end |
#server_max_read_size ⇒ Integer
186 187 188 |
# File 'lib/ruby_smb/client.rb', line 186 def server_max_read_size @server_max_read_size end |
#server_max_transact_size ⇒ Integer
192 193 194 |
# File 'lib/ruby_smb/client.rb', line 192 def server_max_transact_size @server_max_transact_size end |
#server_max_write_size ⇒ Integer
181 182 183 |
# File 'lib/ruby_smb/client.rb', line 181 def server_max_write_size @server_max_write_size end |
#session_id ⇒ Integer
129 130 131 |
# File 'lib/ruby_smb/client.rb', line 129 def session_id @session_id end |
#signing_enabled ⇒ Boolean
134 |
# File 'lib/ruby_smb/client.rb', line 134 attr_accessor :signing_required |
#signing_required ⇒ Object
Whether or not the Server requires signing
134 135 136 |
# File 'lib/ruby_smb/client.rb', line 134 def signing_required @signing_required end |
#smb1 ⇒ Boolean
139 140 141 |
# File 'lib/ruby_smb/client.rb', line 139 def smb1 @smb1 end |
#smb2 ⇒ Boolean
144 145 146 |
# File 'lib/ruby_smb/client.rb', line 144 def smb2 @smb2 end |
#smb2_message_id ⇒ Integer
154 155 156 |
# File 'lib/ruby_smb/client.rb', line 154 def @smb2_message_id end |
#smb3 ⇒ Boolean
149 150 151 |
# File 'lib/ruby_smb/client.rb', line 149 def smb3 @smb3 end |
#user_id ⇒ String
164 165 166 |
# File 'lib/ruby_smb/client.rb', line 164 def user_id @user_id end |
#username ⇒ String
159 160 161 |
# File 'lib/ruby_smb/client.rb', line 159 def username @username end |
Instance Method Details
#can_be_encrypted?(packet) ⇒ Boolean
Check if the request packet can be encrypted. Per the SMB spec, SessionSetupRequest and NegotiateRequest must not be encrypted.
462 463 464 465 466 |
# File 'lib/ruby_smb/client.rb', line 462 def can_be_encrypted?(packet) [RubySMB::SMB2::Packet::SessionSetupRequest, RubySMB::SMB2::Packet::NegotiateRequest].none? do |klass| packet.is_a?(klass) end end |
#disconnect! ⇒ void
This method returns an undefined value.
Logs off any currently open session on the server and closes the TCP socket connection.
296 297 298 299 300 301 302 303 |
# File 'lib/ruby_smb/client.rb', line 296 def disconnect! begin logoff! rescue wipe_state! end dispatcher.tcp_socket.close end |
#echo(count: 1, data: '') ⇒ WindowsError::ErrorCode
Sends an Echo request to the server and returns the NTStatus of the last response packet received.
311 312 313 314 315 316 317 318 |
# File 'lib/ruby_smb/client.rb', line 311 def echo(count: 1, data: '') response = if smb2 || smb3 smb2_echo else smb1_echo(count: count, data: data) end response.status_code end |
#encryption_supported? ⇒ Boolean
Check if the current dialect support encryption.
471 472 473 |
# File 'lib/ruby_smb/client.rb', line 471 def encryption_supported? ['0x0300', '0x0302', '0x0311'].include?(@dialect) end |
#increment_smb_message_id(packet) ⇒ RubySMB::GenericPacket
Sets the message id field in an SMB2 packet's header to the one tracked by the client. It then increments the counter on the client.
326 327 328 329 330 |
# File 'lib/ruby_smb/client.rb', line 326 def (packet) packet.smb2_header. = self. += 1 packet end |
#is_status_pending?(raw_response) ⇒ Boolean
Check if the response is an asynchronous operation with STATUS_PENDING status code.
449 450 451 452 453 454 455 |
# File 'lib/ruby_smb/client.rb', line 449 def is_status_pending?(raw_response) smb2_header = RubySMB::SMB2::SMB2Header.read(raw_response) value = smb2_header.nt_status.value status_code = WindowsError::NTStatus.find_by_retval(value).first status_code == WindowsError::NTStatus::STATUS_PENDING && smb2_header.flags.async_command == 1 end |
#login(username: self.username, password: self.password, domain: self.domain, local_workstation: self.local_workstation) ⇒ Object
Performs protocol negotiation and session setup. It defaults to using the credentials supplied during initialization, but can take a new set of credentials if needed.
334 335 336 337 338 |
# File 'lib/ruby_smb/client.rb', line 334 def login(username: self.username, password: self.password, domain: self.domain, local_workstation: self.local_workstation) negotiate session_setup(username, password, domain, true, local_workstation: local_workstation) end |
#logoff! ⇒ WindowsError::ErrorCode
Sends a LOGOFF command to the remote server to terminate the session
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/ruby_smb/client.rb', line 367 def logoff! if smb2 || smb3 request = RubySMB::SMB2::Packet::LogoffRequest.new raw_response = send_recv(request) response = RubySMB::SMB2::Packet::LogoffResponse.read(raw_response) unless response.valid? raise RubySMB::Error::InvalidPacket.new( expected_proto: RubySMB::SMB2::SMB2_PROTOCOL_ID, expected_cmd: RubySMB::SMB2::Packet::LogoffResponse::COMMAND, received_proto: response.smb2_header.protocol, received_cmd: response.smb2_header.command ) end else request = RubySMB::SMB1::Packet::LogoffRequest.new raw_response = send_recv(request) response = RubySMB::SMB1::Packet::LogoffResponse.read(raw_response) unless response.valid? raise RubySMB::Error::InvalidPacket.new( expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID, expected_cmd: RubySMB::SMB1::Packet::LogoffResponse::COMMAND, received_proto: response.smb_header.protocol, received_cmd: response.smb_header.command ) end end wipe_state! response.status_code end |
#net_share_enum_all(host) ⇒ Array
Returns array of shares
521 522 523 524 525 |
# File 'lib/ruby_smb/client.rb', line 521 def net_share_enum_all(host) tree = tree_connect("\\\\#{host}\\IPC$") named_pipe = tree.open_file(filename: "srvsvc", write: true, read: true) named_pipe.net_share_enum_all(host) end |
#recv_encrypt ⇒ String
Receives the raw response through the Dispatcher and decrypt the packet.
488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/ruby_smb/client.rb', line 488 def recv_encrypt raw_response = dispatcher.recv_packet begin transform_response = RubySMB::SMB2::Packet::TransformHeader.read(raw_response) rescue IOError raise RubySMB::Error::InvalidPacket, 'Not a SMB2 TransformHeader packet' end begin smb3_decrypt(transform_response) rescue RubySMB::Error::RubySMBError => e raise RubySMB::Error::EncryptionError, "Error while decrypting #{transform_response.class.name} packet (SMB #@dialect}): #{e}" end end |
#send_encrypt(packet) ⇒ Object
Encrypt and send a packet
476 477 478 479 480 481 482 483 |
# File 'lib/ruby_smb/client.rb', line 476 def send_encrypt(packet) begin transform_request = smb3_encrypt(packet.to_binary_s) rescue RubySMB::Error::RubySMBError => e raise RubySMB::Error::EncryptionError, "Error while encrypting #{packet.class.name} packet (SMB #{@dialect}): #{e}" end dispatcher.send_packet(transform_request) end |
#send_recv(packet, encrypt: false) ⇒ String
Sends a packet and receives the raw response through the Dispatcher. It will also sign the packet if neccessary.
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/ruby_smb/client.rb', line 402 def send_recv(packet, encrypt: false) version = packet.packet_smb_version case version when 'SMB1' packet.smb_header.uid = user_id if user_id packet = smb1_sign(packet) when 'SMB2' packet = (packet) packet.smb2_header.session_id = session_id unless packet.is_a?(RubySMB::SMB2::Packet::SessionSetupRequest) if self.smb2 packet = smb2_sign(packet) elsif self.smb3 packet = smb3_sign(packet) end end else packet = packet end if can_be_encrypted?(packet) && encryption_supported? && (@encryption_required || encrypt) send_encrypt(packet) raw_response = recv_encrypt loop do break unless is_status_pending?(raw_response) sleep 1 raw_response = recv_encrypt end else dispatcher.send_packet(packet) raw_response = dispatcher.recv_packet loop do break unless is_status_pending?(raw_response) sleep 1 raw_response = dispatcher.recv_packet end unless version == 'SMB1' end self.sequence_counter += 1 if signing_required && !session_key.empty? raw_response end |
#session_request(name = '*SMBSERVER') ⇒ TrueClass
Requests a NetBIOS Session Service using the provided name.
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/ruby_smb/client.rb', line 548 def session_request(name = '*SMBSERVER') session_request = session_request_packet(name) dispatcher.send_packet(session_request, nbss_header: false) raw_response = dispatcher.recv_packet(full_response: true) begin session_header = RubySMB::Nbss::SessionHeader.read(raw_response) if session_header.session_packet_type == RubySMB::Nbss::NEGATIVE_SESSION_RESPONSE negative_session_response = RubySMB::Nbss::NegativeSessionResponse.read(raw_response) raise RubySMB::Error::NetBiosSessionService, "Session Request failed: #{negative_session_response.error_msg}" end rescue IOError raise RubySMB::Error::InvalidPacket, 'Not a NBSS packet' end return true end |
#session_request_packet(name = '*SMBSERVER') ⇒ RubySMB::Nbss::SessionRequest
Crafts the NetBIOS SessionRequest packet to be sent for session request operations.
569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/ruby_smb/client.rb', line 569 def session_request_packet(name = '*SMBSERVER') called_name = "#{name.upcase.ljust(15)}\x20" calling_name = "#{''.ljust(15)}\x00" session_request = RubySMB::Nbss::SessionRequest.new session_request.session_header.session_packet_type = RubySMB::Nbss::SESSION_REQUEST session_request.called_name = called_name session_request.calling_name = calling_name session_request.session_header.packet_length = session_request.num_bytes - session_request.session_header.num_bytes session_request end |
#session_setup(user, pass, domain, do_recv = true, local_workstation: self.local_workstation) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/ruby_smb/client.rb', line 340 def session_setup(user, pass, domain, do_recv=true, local_workstation: self.local_workstation) @domain = domain @local_workstation = local_workstation @password = pass.encode('utf-8') || ''.encode('utf-8') @username = user.encode('utf-8') || ''.encode('utf-8') negotiate_version_flag = 0x02000000 flags = Net::NTLM::Client::DEFAULT_FLAGS | Net::NTLM::FLAGS[:TARGET_INFO] | negotiate_version_flag @ntlm_client = Net::NTLM::Client.new( @username, @password, workstation: @local_workstation, domain: @domain, flags: flags ) authenticate end |
#tree_connect(share) ⇒ RubySMB::SMB1::Tree, RubySMB::SMB2::Tree
Connects to the supplied share
507 508 509 510 511 512 513 514 515 |
# File 'lib/ruby_smb/client.rb', line 507 def tree_connect(share) connected_tree = if smb2 || smb3 smb2_tree_connect(share) else smb1_tree_connect(share) end @tree_connects << connected_tree connected_tree end |
#update_preauth_hash(data) ⇒ Object
582 583 584 585 586 587 588 589 590 591 592 |
# File 'lib/ruby_smb/client.rb', line 582 def update_preauth_hash(data) unless @preauth_integrity_hash_algorithm raise RubySMB::Error::EncryptionError.new( 'Cannot compute the Preauth Integrity Hash value: Preauth Integrity Hash Algorithm is nil' ) end @preauth_integrity_hash_value = OpenSSL::Digest.digest( @preauth_integrity_hash_algorithm, @preauth_integrity_hash_value + data.to_binary_s ) end |
#wipe_state! ⇒ void
This method returns an undefined value.
Resets all of the session state on the client, setting it back to scratch. Should only be called when a session is no longer valid.
532 533 534 535 536 537 538 539 540 |
# File 'lib/ruby_smb/client.rb', line 532 def wipe_state! self.session_id = 0x00 self.user_id = 0x00 self.session_key = '' self.sequence_counter = 0 self. = 0 self.client_encryption_key = nil self.server_encryption_key = nil end |