ruby_smb 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/examples/anonymous_auth.rb +3 -3
- data/examples/append_file.rb +10 -8
- data/examples/authenticate.rb +9 -5
- data/examples/delete_file.rb +8 -6
- data/examples/enum_registry_key.rb +5 -4
- data/examples/enum_registry_values.rb +5 -4
- data/examples/list_directory.rb +8 -6
- data/examples/negotiate_with_netbios_service.rb +9 -5
- data/examples/net_share_enum_all.rb +6 -4
- data/examples/pipes.rb +11 -12
- data/examples/query_service_status.rb +64 -0
- data/examples/read_file.rb +8 -6
- data/examples/read_registry_key_value.rb +6 -5
- data/examples/rename_file.rb +9 -7
- data/examples/tree_connect.rb +7 -5
- data/examples/write_file.rb +9 -7
- data/lib/ruby_smb/client.rb +72 -43
- data/lib/ruby_smb/client/negotiation.rb +1 -0
- data/lib/ruby_smb/dcerpc.rb +2 -0
- data/lib/ruby_smb/dcerpc/error.rb +3 -0
- data/lib/ruby_smb/dcerpc/ndr.rb +209 -44
- data/lib/ruby_smb/dcerpc/request.rb +13 -0
- data/lib/ruby_smb/dcerpc/rpc_security_attributes.rb +34 -0
- data/lib/ruby_smb/dcerpc/rrp_unicode_string.rb +9 -6
- data/lib/ruby_smb/dcerpc/svcctl.rb +479 -0
- data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request.rb +48 -0
- data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response.rb +26 -0
- data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_request.rb +25 -0
- data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response.rb +26 -0
- data/lib/ruby_smb/dcerpc/svcctl/control_service_request.rb +26 -0
- data/lib/ruby_smb/dcerpc/svcctl/control_service_response.rb +26 -0
- data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request.rb +35 -0
- data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response.rb +23 -0
- data/lib/ruby_smb/dcerpc/svcctl/open_service_w_request.rb +31 -0
- data/lib/ruby_smb/dcerpc/svcctl/open_service_w_response.rb +23 -0
- data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request.rb +25 -0
- data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response.rb +44 -0
- data/lib/ruby_smb/dcerpc/svcctl/query_service_status_request.rb +23 -0
- data/lib/ruby_smb/dcerpc/svcctl/query_service_status_response.rb +27 -0
- data/lib/ruby_smb/dcerpc/svcctl/service_status.rb +25 -0
- data/lib/ruby_smb/dcerpc/svcctl/start_service_w_request.rb +27 -0
- data/lib/ruby_smb/dcerpc/svcctl/start_service_w_response.rb +25 -0
- data/lib/ruby_smb/dcerpc/winreg.rb +98 -17
- data/lib/ruby_smb/dcerpc/winreg/create_key_request.rb +73 -0
- data/lib/ruby_smb/dcerpc/winreg/create_key_response.rb +36 -0
- data/lib/ruby_smb/dcerpc/winreg/enum_key_request.rb +1 -1
- data/lib/ruby_smb/dcerpc/winreg/enum_value_request.rb +1 -1
- data/lib/ruby_smb/dcerpc/winreg/enum_value_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/winreg/open_root_key_request.rb +4 -4
- data/lib/ruby_smb/dcerpc/winreg/query_info_key_request.rb +1 -1
- data/lib/ruby_smb/dcerpc/winreg/query_value_request.rb +7 -6
- data/lib/ruby_smb/dcerpc/winreg/query_value_response.rb +10 -10
- data/lib/ruby_smb/dcerpc/winreg/save_key_request.rb +37 -0
- data/lib/ruby_smb/dcerpc/winreg/save_key_response.rb +23 -0
- data/lib/ruby_smb/dispatcher/base.rb +1 -1
- data/lib/ruby_smb/dispatcher/socket.rb +1 -1
- data/lib/ruby_smb/field/stringz16.rb +17 -1
- data/lib/ruby_smb/nbss/session_header.rb +4 -4
- data/lib/ruby_smb/smb1/file.rb +2 -10
- data/lib/ruby_smb/smb1/pipe.rb +2 -0
- data/lib/ruby_smb/smb2/file.rb +25 -17
- data/lib/ruby_smb/smb2/pipe.rb +3 -0
- data/lib/ruby_smb/smb2/tree.rb +9 -3
- data/lib/ruby_smb/version.rb +1 -1
- data/spec/lib/ruby_smb/client_spec.rb +161 -60
- data/spec/lib/ruby_smb/dcerpc/ndr_spec.rb +1396 -77
- data/spec/lib/ruby_smb/dcerpc/rpc_security_attributes_spec.rb +161 -0
- data/spec/lib/ruby_smb/dcerpc/rrp_unicode_string_spec.rb +49 -12
- data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request_spec.rb +191 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_request_spec.rb +30 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_request_spec.rb +39 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request_spec.rb +78 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_request_spec.rb +59 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response_spec.rb +152 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_request_spec.rb +30 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/service_status_spec.rb +72 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_request_spec.rb +46 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_response_spec.rb +30 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl_spec.rb +512 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/create_key_request_spec.rb +110 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/create_key_response_spec.rb +44 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_request_spec.rb +0 -4
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_request_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_request_spec.rb +9 -4
- data/spec/lib/ruby_smb/dcerpc/winreg/query_info_key_request_spec.rb +0 -4
- data/spec/lib/ruby_smb/dcerpc/winreg/query_value_request_spec.rb +17 -17
- data/spec/lib/ruby_smb/dcerpc/winreg/query_value_response_spec.rb +11 -23
- data/spec/lib/ruby_smb/dcerpc/winreg/save_key_request_spec.rb +57 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/save_key_response_spec.rb +22 -0
- data/spec/lib/ruby_smb/dcerpc/winreg_spec.rb +215 -41
- data/spec/lib/ruby_smb/dispatcher/socket_spec.rb +10 -10
- data/spec/lib/ruby_smb/field/stringz16_spec.rb +12 -0
- data/spec/lib/ruby_smb/nbss/session_header_spec.rb +4 -11
- data/spec/lib/ruby_smb/smb1/pipe_spec.rb +7 -0
- data/spec/lib/ruby_smb/smb2/file_spec.rb +60 -6
- data/spec/lib/ruby_smb/smb2/pipe_spec.rb +7 -0
- data/spec/lib/ruby_smb/smb2/tree_spec.rb +35 -1
- metadata +72 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cce717ed3175b8027db1e414fae576e984ff4c88a158568014b4c4eb06406f7
|
4
|
+
data.tar.gz: fb9223d4f15a3ed99aca553523dd957ceb3173cef87b4ba3d29a409ae4baffda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94319bee008719b00933ab82140fafd65c13344858f6677ecb26502cf22d087de0200c0feab9304959ac38df17fcac6540707e2b55457d8d92370484fbfbcd06
|
7
|
+
data.tar.gz: bf55746b294b17d9a4633e1344d976bfdc13df89e96c1ea5861c55999fdd0e1367d25b0e7e1ec455d4666a9fe0d41bfc7b943c84bc00606e2705f952319f4cb2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/examples/anonymous_auth.rb
CHANGED
@@ -6,12 +6,12 @@
|
|
6
6
|
require 'bundler/setup'
|
7
7
|
require 'ruby_smb'
|
8
8
|
|
9
|
-
def run_authentication(address, smb1, smb2, username, password)
|
9
|
+
def run_authentication(address, smb1, smb2, smb3, username, password)
|
10
10
|
# Create our socket and add it to the dispatcher
|
11
11
|
sock = TCPSocket.new address, 445
|
12
12
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
13
13
|
|
14
|
-
client = RubySMB::Client.new(dispatcher, smb1: smb1, smb2: smb2, username: username, password: password)
|
14
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb1, smb2: smb2, smb3: smb3, username: username, password: password)
|
15
15
|
protocol = client.negotiate
|
16
16
|
status = client.authenticate
|
17
17
|
puts "#{protocol} : #{status}"
|
@@ -27,4 +27,4 @@ username = ''
|
|
27
27
|
password = ''
|
28
28
|
|
29
29
|
# Negotiate with only SMB1 enabled
|
30
|
-
run_authentication(address, true, false, username, password)
|
30
|
+
run_authentication(address, true, false, false, username, password)
|
data/examples/append_file.rb
CHANGED
@@ -9,18 +9,20 @@
|
|
9
9
|
require 'bundler/setup'
|
10
10
|
require 'ruby_smb'
|
11
11
|
|
12
|
-
address
|
13
|
-
username
|
14
|
-
password
|
15
|
-
share
|
16
|
-
file
|
17
|
-
data
|
18
|
-
|
12
|
+
address = ARGV[0]
|
13
|
+
username = ARGV[1]
|
14
|
+
password = ARGV[2]
|
15
|
+
share = ARGV[3]
|
16
|
+
file = ARGV[4]
|
17
|
+
data = ARGV[5]
|
18
|
+
smb_versions = ARGV[6]&.split(',') || ['1','2','3']
|
19
|
+
|
20
|
+
path = "\\\\#{address}\\#{share}"
|
19
21
|
|
20
22
|
sock = TCPSocket.new address, 445
|
21
23
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
22
24
|
|
23
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
25
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
24
26
|
protocol = client.negotiate
|
25
27
|
status = client.authenticate
|
26
28
|
|
data/examples/authenticate.rb
CHANGED
@@ -6,12 +6,12 @@
|
|
6
6
|
require 'bundler/setup'
|
7
7
|
require 'ruby_smb'
|
8
8
|
|
9
|
-
def run_authentication(address, smb1, smb2, username, password)
|
9
|
+
def run_authentication(address, smb1, smb2, smb3, username, password)
|
10
10
|
# Create our socket and add it to the dispatcher
|
11
11
|
sock = TCPSocket.new address, 445
|
12
12
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
13
13
|
|
14
|
-
client = RubySMB::Client.new(dispatcher, smb1: smb1, smb2: smb2, username: username, password: password)
|
14
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb1, smb2: smb2, smb3: smb3, username: username, password: password)
|
15
15
|
protocol = client.negotiate
|
16
16
|
status = client.authenticate
|
17
17
|
puts "#{protocol} : #{status}"
|
@@ -32,9 +32,13 @@ address = ARGV[0]
|
|
32
32
|
username = ARGV[1]
|
33
33
|
password = ARGV[2]
|
34
34
|
|
35
|
+
# Negotiate with SMB1, SMB2 and SMB3 enabled on the client
|
36
|
+
run_authentication(address, true, true, true, username, password)
|
35
37
|
# Negotiate with both SMB1 and SMB2 enabled on the client
|
36
|
-
run_authentication(address, true, true, username, password)
|
38
|
+
run_authentication(address, true, true, false, username, password)
|
37
39
|
# Negotiate with only SMB1 enabled
|
38
|
-
run_authentication(address, true, false, username, password)
|
40
|
+
run_authentication(address, true, false, false, username, password)
|
39
41
|
# Negotiate with only SMB2 enabled
|
40
|
-
run_authentication(address, false, true, username, password)
|
42
|
+
run_authentication(address, false, true, false, username, password)
|
43
|
+
# Negotiate with only SMB3 enabled
|
44
|
+
run_authentication(address, false, false, true, username, password)
|
data/examples/delete_file.rb
CHANGED
@@ -9,17 +9,19 @@
|
|
9
9
|
require 'bundler/setup'
|
10
10
|
require 'ruby_smb'
|
11
11
|
|
12
|
-
address
|
13
|
-
username
|
14
|
-
password
|
15
|
-
share
|
16
|
-
file
|
12
|
+
address = ARGV[0]
|
13
|
+
username = ARGV[1]
|
14
|
+
password = ARGV[2]
|
15
|
+
share = ARGV[3]
|
16
|
+
file = ARGV[4]
|
17
|
+
smb_versions = ARGV[5]&.split(',') || ['1','2','3']
|
18
|
+
|
17
19
|
path = "\\\\#{address}\\#{share}"
|
18
20
|
|
19
21
|
sock = TCPSocket.new address, 445
|
20
22
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
21
23
|
|
22
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
24
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
23
25
|
|
24
26
|
protocol = client.negotiate
|
25
27
|
status = client.authenticate
|
@@ -8,15 +8,16 @@
|
|
8
8
|
require 'bundler/setup'
|
9
9
|
require 'ruby_smb'
|
10
10
|
|
11
|
-
address
|
12
|
-
username
|
13
|
-
password
|
11
|
+
address = ARGV[0]
|
12
|
+
username = ARGV[1]
|
13
|
+
password = ARGV[2]
|
14
14
|
registry_key = ARGV[3]
|
15
|
+
smb_versions = ARGV[4]&.split(',') || ['1','2','3']
|
15
16
|
|
16
17
|
sock = TCPSocket.new address, 445
|
17
18
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock, read_timeout: 60)
|
18
19
|
|
19
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
20
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
20
21
|
protocol = client.negotiate
|
21
22
|
status = client.authenticate
|
22
23
|
|
@@ -8,15 +8,16 @@
|
|
8
8
|
require 'bundler/setup'
|
9
9
|
require 'ruby_smb'
|
10
10
|
|
11
|
-
address
|
12
|
-
username
|
13
|
-
password
|
11
|
+
address = ARGV[0]
|
12
|
+
username = ARGV[1]
|
13
|
+
password = ARGV[2]
|
14
14
|
registry_key = ARGV[3]
|
15
|
+
smb_versions = ARGV[4]&.split(',') || ['1','2','3']
|
15
16
|
|
16
17
|
sock = TCPSocket.new address, 445
|
17
18
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock, read_timeout: 60)
|
18
19
|
|
19
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
20
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
20
21
|
protocol = client.negotiate
|
21
22
|
status = client.authenticate
|
22
23
|
|
data/examples/list_directory.rb
CHANGED
@@ -10,17 +10,19 @@
|
|
10
10
|
require 'bundler/setup'
|
11
11
|
require 'ruby_smb'
|
12
12
|
|
13
|
-
address
|
14
|
-
username
|
15
|
-
password
|
16
|
-
share
|
17
|
-
dir
|
13
|
+
address = ARGV[0]
|
14
|
+
username = ARGV[1]
|
15
|
+
password = ARGV[2]
|
16
|
+
share = ARGV[3]
|
17
|
+
dir = ARGV[4]
|
18
|
+
smb_versions = ARGV[5]&.split(',') || ['1','2','3']
|
19
|
+
|
18
20
|
path = "\\\\#{address}\\#{share}"
|
19
21
|
|
20
22
|
sock = TCPSocket.new address, 445
|
21
23
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
22
24
|
|
23
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
25
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
24
26
|
protocol = client.negotiate
|
25
27
|
status = client.authenticate
|
26
28
|
|
@@ -9,11 +9,11 @@
|
|
9
9
|
require 'bundler/setup'
|
10
10
|
require 'ruby_smb'
|
11
11
|
|
12
|
-
def run_negotiation(address, smb1, smb2, netbios_name)
|
12
|
+
def run_negotiation(address, smb1, smb2, smb3, netbios_name)
|
13
13
|
sock = TCPSocket.new address, 139
|
14
14
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
15
15
|
|
16
|
-
client = RubySMB::Client.new(dispatcher, smb1: smb1, smb2: smb2, username: 'msfadmin', password: 'msfadmin')
|
16
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb1, smb2: smb2, smb3: smb3, username: 'msfadmin', password: 'msfadmin')
|
17
17
|
begin
|
18
18
|
client.session_request(netbios_name)
|
19
19
|
rescue RubySMB::Error::NetBiosSessionService => e
|
@@ -28,9 +28,13 @@ end
|
|
28
28
|
address = ARGV[0]
|
29
29
|
netbios_name = ARGV[1] || '*SMBSERVER'
|
30
30
|
|
31
|
+
# Negotiate with SMB1, SMB2 and SMB3 enabled on the client
|
32
|
+
run_negotiation(ARGV[0], true, true, true, netbios_name)
|
31
33
|
# Negotiate with both SMB1 and SMB2 enabled on the client
|
32
|
-
run_negotiation(ARGV[0], true, true, netbios_name)
|
34
|
+
run_negotiation(ARGV[0], true, true, false, netbios_name)
|
33
35
|
# Negotiate with only SMB1 enabled
|
34
|
-
run_negotiation(ARGV[0], true, false, netbios_name)
|
36
|
+
run_negotiation(ARGV[0], true, false, false, netbios_name)
|
35
37
|
# Negotiate with only SMB2 enabled
|
36
|
-
run_negotiation(ARGV[0], false, true, netbios_name)
|
38
|
+
run_negotiation(ARGV[0], false, true, false, netbios_name)
|
39
|
+
# Negotiate with only SMB3 enabled
|
40
|
+
run_negotiation(ARGV[0], false, false, true, netbios_name)
|
@@ -8,15 +8,17 @@
|
|
8
8
|
require 'bundler/setup'
|
9
9
|
require 'ruby_smb'
|
10
10
|
|
11
|
-
address
|
12
|
-
username
|
13
|
-
password
|
11
|
+
address = ARGV[0]
|
12
|
+
username = ARGV[1]
|
13
|
+
password = ARGV[2]
|
14
|
+
smb_versions = ARGV[3]&.split(',') || ['1','2','3']
|
15
|
+
|
14
16
|
path = "\\\\#{address}\\IPC$"
|
15
17
|
|
16
18
|
sock = TCPSocket.new address, 445
|
17
19
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock, read_timeout: 60)
|
18
20
|
|
19
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
21
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
20
22
|
protocol = client.negotiate
|
21
23
|
status = client.authenticate
|
22
24
|
|
data/examples/pipes.rb
CHANGED
@@ -10,25 +10,24 @@
|
|
10
10
|
require 'bundler/setup'
|
11
11
|
require 'ruby_smb'
|
12
12
|
|
13
|
-
address
|
14
|
-
pipename
|
15
|
-
username
|
16
|
-
password
|
17
|
-
|
13
|
+
address = ARGV[0]
|
14
|
+
pipename = ARGV[1]
|
15
|
+
username = ARGV[2]
|
16
|
+
password = ARGV[3]
|
17
|
+
smb_versions = ARGV[4]&.split(',') || ['1','2','3']
|
18
18
|
|
19
19
|
sock = TCPSocket.new(address, 445)
|
20
20
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
23
|
+
smbver = client.negotiate
|
24
|
+
|
25
|
+
if smbver == 'SMB1'
|
26
|
+
puts "ServerMaxBuffer: #{client.server_max_buffer_size}"
|
27
|
+
else
|
25
28
|
puts "ServerMaxRead: #{client.server_max_read_size}"
|
26
29
|
puts "ServerMaxWrite: #{client.server_max_write_size}"
|
27
30
|
puts "ServerMaxTrans: #{client.server_max_transact_size}"
|
28
|
-
elsif smbver == 1
|
29
|
-
client = RubySMB::Client.new(dispatcher, smb2: false, username: username, password: password)
|
30
|
-
client.negotiate
|
31
|
-
puts "ServerMaxBuffer: #{client.server_max_buffer_size}"
|
32
31
|
end
|
33
32
|
|
34
33
|
client.authenticate
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# This example script is used for testing remote service status and start type query.
|
4
|
+
# It will attempt to connect to a host and query the status and start type of the provided service.
|
5
|
+
# Example usage: ruby query_service_status.rb 192.168.172.138 msfadmin msfadmin "RemoteRegistry"
|
6
|
+
# This will try to connect to \\192.168.172.138 with the msfadmin:msfadmin credentialas and get the status and start type of the "RemoteRegistry" service.
|
7
|
+
|
8
|
+
require 'bundler/setup'
|
9
|
+
require 'ruby_smb'
|
10
|
+
|
11
|
+
address = ARGV[0]
|
12
|
+
username = ARGV[1]
|
13
|
+
password = ARGV[2]
|
14
|
+
service = ARGV[3]
|
15
|
+
smb_versions = ARGV[4]&.split(',') || ['1','2','3']
|
16
|
+
|
17
|
+
sock = TCPSocket.new address, 445
|
18
|
+
dispatcher = RubySMB::Dispatcher::Socket.new(sock, read_timeout: 60)
|
19
|
+
|
20
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
21
|
+
protocol = client.negotiate
|
22
|
+
status = client.authenticate
|
23
|
+
|
24
|
+
puts "#{protocol} : #{status}"
|
25
|
+
|
26
|
+
tree = client.tree_connect("\\\\#{address}\\IPC$")
|
27
|
+
svcctl = tree.open_file(filename: 'svcctl', write: true, read: true)
|
28
|
+
|
29
|
+
puts('Binding to \\svcctl...')
|
30
|
+
svcctl.bind(endpoint: RubySMB::Dcerpc::Svcctl)
|
31
|
+
puts('Bound to \\svcctl')
|
32
|
+
|
33
|
+
puts('Opening Service Control Manager')
|
34
|
+
scm_handle = svcctl.open_sc_manager_w(address)
|
35
|
+
|
36
|
+
svc_handle = svcctl.open_service_w(scm_handle, service)
|
37
|
+
svc_status = svcctl.query_service_status(svc_handle)
|
38
|
+
|
39
|
+
case svc_status.dw_current_state
|
40
|
+
when RubySMB::Dcerpc::Svcctl::SERVICE_RUNNING
|
41
|
+
puts("Service #{service} is running")
|
42
|
+
when RubySMB::Dcerpc::Svcctl::SERVICE_STOPPED
|
43
|
+
puts("Service #{service} is in stopped state")
|
44
|
+
end
|
45
|
+
|
46
|
+
svc_config = svcctl.query_service_config(svc_handle)
|
47
|
+
case svc_config.dw_start_type
|
48
|
+
when RubySMB::Dcerpc::Svcctl::SERVICE_DISABLED
|
49
|
+
puts("Service #{service} is disabled")
|
50
|
+
when RubySMB::Dcerpc::Svcctl::SERVICE_BOOT_START, RubySMB::Dcerpc::Svcctl::SERVICE_SYSTEM_START
|
51
|
+
puts("Service #{service} starts when the system boots up (driver)")
|
52
|
+
when RubySMB::Dcerpc::Svcctl::SERVICE_AUTO_START
|
53
|
+
puts("Service #{service} starts automatically during system startup")
|
54
|
+
when RubySMB::Dcerpc::Svcctl::SERVICE_DEMAND_START
|
55
|
+
puts("Service #{service} starts manually")
|
56
|
+
end
|
57
|
+
|
58
|
+
if svcctl
|
59
|
+
svcctl.close_service_handle(svc_handle) if svc_handle
|
60
|
+
svcctl.close_service_handle(scm_handle) if scm_handle
|
61
|
+
svcctl.close
|
62
|
+
end
|
63
|
+
client.disconnect!
|
64
|
+
|
data/examples/read_file.rb
CHANGED
@@ -9,17 +9,19 @@
|
|
9
9
|
require 'bundler/setup'
|
10
10
|
require 'ruby_smb'
|
11
11
|
|
12
|
-
address
|
13
|
-
username
|
14
|
-
password
|
15
|
-
share
|
16
|
-
file
|
12
|
+
address = ARGV[0]
|
13
|
+
username = ARGV[1]
|
14
|
+
password = ARGV[2]
|
15
|
+
share = ARGV[3]
|
16
|
+
file = ARGV[4]
|
17
|
+
smb_versions = ARGV[5]&.split(',') || ['1','2','3']
|
18
|
+
|
17
19
|
path = "\\\\#{address}\\#{share}"
|
18
20
|
|
19
21
|
sock = TCPSocket.new address, 445
|
20
22
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
21
23
|
|
22
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
24
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
23
25
|
protocol = client.negotiate
|
24
26
|
status = client.authenticate
|
25
27
|
|
@@ -8,16 +8,17 @@
|
|
8
8
|
require 'bundler/setup'
|
9
9
|
require 'ruby_smb'
|
10
10
|
|
11
|
-
address
|
12
|
-
username
|
13
|
-
password
|
11
|
+
address = ARGV[0]
|
12
|
+
username = ARGV[1]
|
13
|
+
password = ARGV[2]
|
14
14
|
registry_key = ARGV[3]
|
15
|
-
value_name
|
15
|
+
value_name = ARGV[4]
|
16
|
+
smb_versions = ARGV[5]&.split(',') || ['1','2','3']
|
16
17
|
|
17
18
|
sock = TCPSocket.new address, 445
|
18
19
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock, read_timeout: 60)
|
19
20
|
|
20
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
21
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
21
22
|
protocol = client.negotiate
|
22
23
|
status = client.authenticate
|
23
24
|
|
data/examples/rename_file.rb
CHANGED
@@ -9,18 +9,20 @@
|
|
9
9
|
require 'bundler/setup'
|
10
10
|
require 'ruby_smb'
|
11
11
|
|
12
|
-
address
|
13
|
-
username
|
14
|
-
password
|
15
|
-
share
|
16
|
-
file
|
17
|
-
new_name
|
12
|
+
address = ARGV[0]
|
13
|
+
username = ARGV[1]
|
14
|
+
password = ARGV[2]
|
15
|
+
share = ARGV[3]
|
16
|
+
file = ARGV[4]
|
17
|
+
new_name = ARGV[5]
|
18
|
+
smb_versions = ARGV[6]&.split(',') || ['1','2','3']
|
19
|
+
|
18
20
|
path = "\\\\#{address}\\#{share}"
|
19
21
|
|
20
22
|
sock = TCPSocket.new address, 445
|
21
23
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
22
24
|
|
23
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
25
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
24
26
|
|
25
27
|
protocol = client.negotiate
|
26
28
|
status = client.authenticate
|
data/examples/tree_connect.rb
CHANGED
@@ -8,16 +8,18 @@
|
|
8
8
|
require 'bundler/setup'
|
9
9
|
require 'ruby_smb'
|
10
10
|
|
11
|
-
address
|
12
|
-
username
|
13
|
-
password
|
14
|
-
share
|
11
|
+
address = ARGV[0]
|
12
|
+
username = ARGV[1]
|
13
|
+
password = ARGV[2]
|
14
|
+
share = ARGV[3]
|
15
|
+
smb_versions = ARGV[4]&.split(',') || ['1','2','3']
|
16
|
+
|
15
17
|
path = "\\\\#{address}\\#{share}"
|
16
18
|
|
17
19
|
sock = TCPSocket.new address, 445
|
18
20
|
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
|
19
21
|
|
20
|
-
client = RubySMB::Client.new(dispatcher, smb1:
|
22
|
+
client = RubySMB::Client.new(dispatcher, smb1: smb_versions.include?('1'), smb2: smb_versions.include?('2'), smb3: smb_versions.include?('3'), username: username, password: password)
|
21
23
|
protocol = client.negotiate
|
22
24
|
status = client.authenticate
|
23
25
|
|