ruby_smb 1.0.5 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.travis.yml +3 -2
  5. data/Gemfile +6 -2
  6. data/README.md +35 -47
  7. data/examples/anonymous_auth.rb +3 -3
  8. data/examples/append_file.rb +10 -8
  9. data/examples/authenticate.rb +9 -5
  10. data/examples/delete_file.rb +8 -6
  11. data/examples/enum_registry_key.rb +29 -0
  12. data/examples/enum_registry_values.rb +31 -0
  13. data/examples/list_directory.rb +8 -6
  14. data/examples/negotiate.rb +51 -8
  15. data/examples/negotiate_with_netbios_service.rb +9 -5
  16. data/examples/net_share_enum_all.rb +6 -4
  17. data/examples/pipes.rb +13 -13
  18. data/examples/query_service_status.rb +64 -0
  19. data/examples/read_file.rb +8 -6
  20. data/examples/read_file_encryption.rb +56 -0
  21. data/examples/read_registry_key_value.rb +33 -0
  22. data/examples/rename_file.rb +9 -7
  23. data/examples/tree_connect.rb +7 -5
  24. data/examples/write_file.rb +9 -7
  25. data/lib/ruby_smb.rb +4 -1
  26. data/lib/ruby_smb/client.rb +239 -21
  27. data/lib/ruby_smb/client/authentication.rb +27 -8
  28. data/lib/ruby_smb/client/encryption.rb +62 -0
  29. data/lib/ruby_smb/client/negotiation.rb +154 -12
  30. data/lib/ruby_smb/client/signing.rb +19 -0
  31. data/lib/ruby_smb/client/tree_connect.rb +4 -4
  32. data/lib/ruby_smb/client/utils.rb +8 -7
  33. data/lib/ruby_smb/client/winreg.rb +46 -0
  34. data/lib/ruby_smb/crypto.rb +30 -0
  35. data/lib/ruby_smb/dcerpc.rb +40 -0
  36. data/lib/ruby_smb/dcerpc/bind.rb +2 -2
  37. data/lib/ruby_smb/dcerpc/bind_ack.rb +2 -2
  38. data/lib/ruby_smb/dcerpc/error.rb +6 -0
  39. data/lib/ruby_smb/dcerpc/ndr.rb +260 -16
  40. data/lib/ruby_smb/dcerpc/pdu_header.rb +1 -1
  41. data/lib/ruby_smb/dcerpc/request.rb +41 -9
  42. data/lib/ruby_smb/dcerpc/rpc_security_attributes.rb +34 -0
  43. data/lib/ruby_smb/dcerpc/rrp_unicode_string.rb +38 -0
  44. data/lib/ruby_smb/dcerpc/srvsvc.rb +10 -0
  45. data/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all.rb +9 -0
  46. data/lib/ruby_smb/dcerpc/svcctl.rb +479 -0
  47. data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request.rb +48 -0
  48. data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response.rb +26 -0
  49. data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_request.rb +25 -0
  50. data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response.rb +26 -0
  51. data/lib/ruby_smb/dcerpc/svcctl/control_service_request.rb +26 -0
  52. data/lib/ruby_smb/dcerpc/svcctl/control_service_response.rb +26 -0
  53. data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request.rb +35 -0
  54. data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response.rb +23 -0
  55. data/lib/ruby_smb/dcerpc/svcctl/open_service_w_request.rb +31 -0
  56. data/lib/ruby_smb/dcerpc/svcctl/open_service_w_response.rb +23 -0
  57. data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request.rb +25 -0
  58. data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response.rb +44 -0
  59. data/lib/ruby_smb/dcerpc/svcctl/query_service_status_request.rb +23 -0
  60. data/lib/ruby_smb/dcerpc/svcctl/query_service_status_response.rb +27 -0
  61. data/lib/ruby_smb/dcerpc/svcctl/service_status.rb +25 -0
  62. data/lib/ruby_smb/dcerpc/svcctl/start_service_w_request.rb +27 -0
  63. data/lib/ruby_smb/dcerpc/svcctl/start_service_w_response.rb +25 -0
  64. data/lib/ruby_smb/dcerpc/winreg.rb +421 -0
  65. data/lib/ruby_smb/dcerpc/winreg/close_key_request.rb +24 -0
  66. data/lib/ruby_smb/dcerpc/winreg/close_key_response.rb +27 -0
  67. data/lib/ruby_smb/dcerpc/winreg/create_key_request.rb +73 -0
  68. data/lib/ruby_smb/dcerpc/winreg/create_key_response.rb +36 -0
  69. data/lib/ruby_smb/dcerpc/winreg/enum_key_request.rb +45 -0
  70. data/lib/ruby_smb/dcerpc/winreg/enum_key_response.rb +42 -0
  71. data/lib/ruby_smb/dcerpc/winreg/enum_value_request.rb +39 -0
  72. data/lib/ruby_smb/dcerpc/winreg/enum_value_response.rb +36 -0
  73. data/lib/ruby_smb/dcerpc/winreg/open_key_request.rb +34 -0
  74. data/lib/ruby_smb/dcerpc/winreg/open_key_response.rb +25 -0
  75. data/lib/ruby_smb/dcerpc/winreg/open_root_key_request.rb +43 -0
  76. data/lib/ruby_smb/dcerpc/winreg/open_root_key_response.rb +35 -0
  77. data/lib/ruby_smb/dcerpc/winreg/query_info_key_request.rb +27 -0
  78. data/lib/ruby_smb/dcerpc/winreg/query_info_key_response.rb +40 -0
  79. data/lib/ruby_smb/dcerpc/winreg/query_value_request.rb +40 -0
  80. data/lib/ruby_smb/dcerpc/winreg/query_value_response.rb +57 -0
  81. data/lib/ruby_smb/dcerpc/winreg/regsam.rb +40 -0
  82. data/lib/ruby_smb/dcerpc/winreg/save_key_request.rb +37 -0
  83. data/lib/ruby_smb/dcerpc/winreg/save_key_response.rb +23 -0
  84. data/lib/ruby_smb/dispatcher/base.rb +1 -1
  85. data/lib/ruby_smb/dispatcher/socket.rb +5 -4
  86. data/lib/ruby_smb/error.rb +28 -1
  87. data/lib/ruby_smb/field/stringz16.rb +17 -1
  88. data/lib/ruby_smb/nbss/session_header.rb +4 -4
  89. data/lib/ruby_smb/smb1/commands.rb +1 -1
  90. data/lib/ruby_smb/smb1/file.rb +8 -14
  91. data/lib/ruby_smb/smb1/packet/session_setup_legacy_request.rb +1 -1
  92. data/lib/ruby_smb/smb1/packet/session_setup_legacy_response.rb +2 -2
  93. data/lib/ruby_smb/smb1/packet/session_setup_request.rb +1 -1
  94. data/lib/ruby_smb/smb1/packet/session_setup_response.rb +2 -2
  95. data/lib/ruby_smb/smb1/packet/write_andx_request.rb +1 -1
  96. data/lib/ruby_smb/smb1/pipe.rb +81 -3
  97. data/lib/ruby_smb/smb1/tree.rb +12 -3
  98. data/lib/ruby_smb/smb2/bit_field/session_flags.rb +2 -1
  99. data/lib/ruby_smb/smb2/bit_field/share_flags.rb +6 -4
  100. data/lib/ruby_smb/smb2/file.rb +51 -61
  101. data/lib/ruby_smb/smb2/negotiate_context.rb +108 -0
  102. data/lib/ruby_smb/smb2/packet.rb +2 -0
  103. data/lib/ruby_smb/smb2/packet/compression_transform_header.rb +41 -0
  104. data/lib/ruby_smb/smb2/packet/error_packet.rb +2 -4
  105. data/lib/ruby_smb/smb2/packet/negotiate_request.rb +51 -14
  106. data/lib/ruby_smb/smb2/packet/negotiate_response.rb +50 -4
  107. data/lib/ruby_smb/smb2/packet/transform_header.rb +84 -0
  108. data/lib/ruby_smb/smb2/packet/tree_connect_request.rb +92 -6
  109. data/lib/ruby_smb/smb2/packet/tree_connect_response.rb +8 -26
  110. data/lib/ruby_smb/smb2/pipe.rb +80 -3
  111. data/lib/ruby_smb/smb2/smb2_header.rb +1 -1
  112. data/lib/ruby_smb/smb2/tree.rb +32 -20
  113. data/lib/ruby_smb/version.rb +1 -1
  114. data/ruby_smb.gemspec +5 -3
  115. data/spec/lib/ruby_smb/client_spec.rb +1583 -102
  116. data/spec/lib/ruby_smb/crypto_spec.rb +25 -0
  117. data/spec/lib/ruby_smb/dcerpc/bind_ack_spec.rb +2 -2
  118. data/spec/lib/ruby_smb/dcerpc/bind_spec.rb +2 -2
  119. data/spec/lib/ruby_smb/dcerpc/ndr_spec.rb +1729 -0
  120. data/spec/lib/ruby_smb/dcerpc/request_spec.rb +50 -7
  121. data/spec/lib/ruby_smb/dcerpc/rpc_security_attributes_spec.rb +161 -0
  122. data/spec/lib/ruby_smb/dcerpc/rrp_unicode_string_spec.rb +135 -0
  123. data/spec/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all_spec.rb +13 -0
  124. data/spec/lib/ruby_smb/dcerpc/srvsvc_spec.rb +60 -0
  125. data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request_spec.rb +191 -0
  126. data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response_spec.rb +38 -0
  127. data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_request_spec.rb +30 -0
  128. data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response_spec.rb +38 -0
  129. data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_request_spec.rb +39 -0
  130. data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_response_spec.rb +38 -0
  131. data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request_spec.rb +78 -0
  132. data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response_spec.rb +38 -0
  133. data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_request_spec.rb +59 -0
  134. data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_response_spec.rb +38 -0
  135. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request_spec.rb +38 -0
  136. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response_spec.rb +152 -0
  137. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_request_spec.rb +30 -0
  138. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_response_spec.rb +38 -0
  139. data/spec/lib/ruby_smb/dcerpc/svcctl/service_status_spec.rb +72 -0
  140. data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_request_spec.rb +46 -0
  141. data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_response_spec.rb +30 -0
  142. data/spec/lib/ruby_smb/dcerpc/svcctl_spec.rb +512 -0
  143. data/spec/lib/ruby_smb/dcerpc/winreg/close_key_request_spec.rb +28 -0
  144. data/spec/lib/ruby_smb/dcerpc/winreg/close_key_response_spec.rb +36 -0
  145. data/spec/lib/ruby_smb/dcerpc/winreg/create_key_request_spec.rb +110 -0
  146. data/spec/lib/ruby_smb/dcerpc/winreg/create_key_response_spec.rb +44 -0
  147. data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_request_spec.rb +104 -0
  148. data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_response_spec.rb +97 -0
  149. data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_request_spec.rb +94 -0
  150. data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_response_spec.rb +82 -0
  151. data/spec/lib/ruby_smb/dcerpc/winreg/open_key_request_spec.rb +74 -0
  152. data/spec/lib/ruby_smb/dcerpc/winreg/open_key_response_spec.rb +35 -0
  153. data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_request_spec.rb +95 -0
  154. data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_response_spec.rb +38 -0
  155. data/spec/lib/ruby_smb/dcerpc/winreg/query_info_key_request_spec.rb +35 -0
  156. data/spec/lib/ruby_smb/dcerpc/winreg/query_info_key_response_spec.rb +113 -0
  157. data/spec/lib/ruby_smb/dcerpc/winreg/query_value_request_spec.rb +88 -0
  158. data/spec/lib/ruby_smb/dcerpc/winreg/query_value_response_spec.rb +138 -0
  159. data/spec/lib/ruby_smb/dcerpc/winreg/regsam_spec.rb +32 -0
  160. data/spec/lib/ruby_smb/dcerpc/winreg/save_key_request_spec.rb +57 -0
  161. data/spec/lib/ruby_smb/dcerpc/winreg/save_key_response_spec.rb +22 -0
  162. data/spec/lib/ruby_smb/dcerpc/winreg_spec.rb +884 -0
  163. data/spec/lib/ruby_smb/dcerpc_spec.rb +81 -0
  164. data/spec/lib/ruby_smb/dispatcher/socket_spec.rb +12 -12
  165. data/spec/lib/ruby_smb/error_spec.rb +59 -0
  166. data/spec/lib/ruby_smb/field/stringz16_spec.rb +12 -0
  167. data/spec/lib/ruby_smb/nbss/session_header_spec.rb +4 -11
  168. data/spec/lib/ruby_smb/smb1/file_spec.rb +9 -1
  169. data/spec/lib/ruby_smb/smb1/packet/session_setup_legacy_request_spec.rb +2 -2
  170. data/spec/lib/ruby_smb/smb1/packet/session_setup_legacy_response_spec.rb +2 -2
  171. data/spec/lib/ruby_smb/smb1/packet/session_setup_request_spec.rb +2 -2
  172. data/spec/lib/ruby_smb/smb1/packet/session_setup_response_spec.rb +1 -1
  173. data/spec/lib/ruby_smb/smb1/pipe_spec.rb +216 -147
  174. data/spec/lib/ruby_smb/smb2/bit_field/session_flags_spec.rb +9 -0
  175. data/spec/lib/ruby_smb/smb2/bit_field/share_flags_spec.rb +27 -0
  176. data/spec/lib/ruby_smb/smb2/file_spec.rb +146 -68
  177. data/spec/lib/ruby_smb/smb2/negotiate_context_spec.rb +332 -0
  178. data/spec/lib/ruby_smb/smb2/packet/compression_transform_header_spec.rb +108 -0
  179. data/spec/lib/ruby_smb/smb2/packet/error_packet_spec.rb +3 -24
  180. data/spec/lib/ruby_smb/smb2/packet/negotiate_request_spec.rb +138 -3
  181. data/spec/lib/ruby_smb/smb2/packet/negotiate_response_spec.rb +120 -2
  182. data/spec/lib/ruby_smb/smb2/packet/transform_header_spec.rb +220 -0
  183. data/spec/lib/ruby_smb/smb2/packet/tree_connect_request_spec.rb +339 -9
  184. data/spec/lib/ruby_smb/smb2/packet/tree_connect_response_spec.rb +3 -30
  185. data/spec/lib/ruby_smb/smb2/pipe_spec.rb +226 -148
  186. data/spec/lib/ruby_smb/smb2/smb2_header_spec.rb +2 -2
  187. data/spec/lib/ruby_smb/smb2/tree_spec.rb +88 -9
  188. metadata +257 -81
  189. metadata.gz.sig +0 -0
  190. data/lib/ruby_smb/smb1/dcerpc.rb +0 -72
  191. data/lib/ruby_smb/smb2/dcerpc.rb +0 -75
@@ -7,18 +7,61 @@
7
7
  require 'bundler/setup'
8
8
  require 'ruby_smb'
9
9
 
10
- def run_negotiation(address, smb1, smb2)
10
+ def run_negotiation(address, smb1, smb2, smb3, opts = {})
11
11
  # Create our socket and add it to the dispatcher
12
12
  sock = TCPSocket.new address, 445
13
13
  dispatcher = RubySMB::Dispatcher::Socket.new(sock)
14
14
 
15
- client = RubySMB::Client.new(dispatcher, smb1: smb1, smb2: smb2, username: 'msfadmin', password: 'msfadmin')
15
+ client = RubySMB::Client.new(dispatcher, smb1: smb1, smb2: smb2, smb3: smb3, username: 'msfadmin', password: 'msfadmin')
16
16
  client.negotiate
17
17
  end
18
18
 
19
- # Negotiate with both SMB1 and SMB2 enabled on the client
20
- run_negotiation(ARGV[0], true, true)
21
- # Negotiate with only SMB1 enabled
22
- run_negotiation(ARGV[0], true, false)
23
- # Negotiate with only SMB2 enabled
24
- run_negotiation(ARGV[0], false, true)
19
+ begin
20
+ puts "Negotiate with only SMB1 enabled..."
21
+ puts " Negotiated version: #{run_negotiation(ARGV[0], true, false, false)}"
22
+ rescue RubySMB::Error::RubySMBError => e
23
+ puts "Error: #{e.message}"
24
+ end
25
+
26
+ begin
27
+ puts "Negotiate with only SMB2 enabled..."
28
+ puts " Negotiated version: #{run_negotiation(ARGV[0], false, true, false)}"
29
+ rescue RubySMB::Error::RubySMBError => e
30
+ puts "Error: #{e.message}"
31
+ end
32
+
33
+ begin
34
+ puts "Negotiate with only SMB3 enabled..."
35
+ puts " Negotiated version: #{run_negotiation(ARGV[0], false, false, true)}"
36
+ rescue RubySMB::Error::RubySMBError => e
37
+ puts "Error: #{e.message}"
38
+ end
39
+
40
+ begin
41
+ puts "Negotiate with both SMB1 and SMB2 enabled on the client..."
42
+ puts " Negotiated version: #{run_negotiation(ARGV[0], true, true, false)}"
43
+ rescue RubySMB::Error::RubySMBError => e
44
+ puts "Error: #{e.message}"
45
+ end
46
+
47
+ begin
48
+ puts "Negotiate with both SMB2 and SMB3 enabled on the client..."
49
+ puts " Negotiated version: #{run_negotiation(ARGV[0], false, true, true)}"
50
+ rescue RubySMB::Error::RubySMBError => e
51
+ puts "Error: #{e.message}"
52
+ end
53
+
54
+ begin
55
+ puts "Negotiate with both SMB1 and SMB3 enabled on the client..."
56
+ puts " Negotiated version: #{run_negotiation(ARGV[0], true, false, true)}"
57
+ rescue RubySMB::Error::RubySMBError => e
58
+ puts "Error: #{e.message}"
59
+ end
60
+
61
+ begin
62
+ puts "Negotiate with SMB1, SMB2 and SMB3 enabled on the client..."
63
+ puts " Negotiated version: #{run_negotiation(ARGV[0], true, true, true)}"
64
+ rescue RubySMB::Error::RubySMBError => e
65
+ puts "Error: #{e.message}"
66
+ end
67
+
@@ -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 = ARGV[0]
12
- username = ARGV[1]
13
- password = ARGV[2]
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: true, smb2: true, username: username, password: password)
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
 
@@ -10,30 +10,30 @@
10
10
  require 'bundler/setup'
11
11
  require 'ruby_smb'
12
12
 
13
- address = ARGV[0]
14
- pipename = ARGV[1]
15
- username = ARGV[2]
16
- password = ARGV[3]
17
- smbver = ARGV[4].to_i
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
- if smbver == 2
23
- client = RubySMB::Client.new(dispatcher, smb1: false, username: username, password: password)
24
- client.negotiate
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
35
34
  client.tree_connect("\\\\#{address}\\IPC$")
36
- pipe = client.create_pipe(pipename, nil)
35
+ client.create_pipe(pipename)
36
+ pipe = client.last_file
37
37
 
38
38
  puts "Available: #{pipe.peek_available}"
39
39
  puts "PipeState: #{pipe.peek_state}" # 3 == OK
@@ -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
+
@@ -9,17 +9,19 @@
9
9
  require 'bundler/setup'
10
10
  require 'ruby_smb'
11
11
 
12
- address = ARGV[0]
13
- username = ARGV[1]
14
- password = ARGV[2]
15
- share = ARGV[3]
16
- file = ARGV[4]
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: true, smb2: true, username: username, password: password)
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
 
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # This example script is used for testing the reading of a file.
4
+ # It will attempt to connect to a specific share and then read a specified file.
5
+ # Example usage: ruby read_file.rb 192.168.172.138 msfadmin msfadmin TEST_SHARE short.txt
6
+ # This will try to connect to \\192.168.172.138\TEST_SHARE with the msfadmin:msfadmin credentials
7
+ # and read the file short.txt
8
+
9
+ require 'bundler/setup'
10
+ require 'ruby_smb'
11
+
12
+ address = ARGV[0]
13
+ username = ARGV[1]
14
+ password = ARGV[2]
15
+ share = ARGV[3]
16
+ filename = ARGV[4]
17
+ path = "\\\\#{address}\\#{share}"
18
+
19
+ sock = TCPSocket.new address, 445
20
+ dispatcher = RubySMB::Dispatcher::Socket.new(sock)
21
+
22
+ # To require encryption on the server, run this in an elevated Powershell:
23
+ # C:\> Set-SmbServerConfiguration -EncryptData $true
24
+
25
+ # To enable per-share encryption on the server, run this in an elevated Powershell:
26
+ # C:\ Set-SmbServerConfiguration -EncryptData $false
27
+ # C:\ Set-SmbShare -Name <share name> -EncryptData 1
28
+
29
+ # For this encryption to work, it has to be SMBv3. By only setting smb3 to true,
30
+ # we make sure the server will negotiate this version, if it supports it
31
+ opts = {
32
+ smb1: false,
33
+ smb2: false,
34
+ smb3: true,
35
+ username: username,
36
+ password: password,
37
+ }
38
+
39
+ # By default, the client uses encryption even if it is not required by the server. Disable this by setting always_encrypt to false
40
+ #opts[:always_encrypt] = false
41
+
42
+ client = RubySMB::Client.new(dispatcher, opts)
43
+ protocol = client.negotiate
44
+ status = client.authenticate
45
+
46
+ begin
47
+ tree = client.tree_connect(path)
48
+ rescue StandardError => e
49
+ puts "Failed to connect to #{path}: #{e.message}"
50
+ end
51
+
52
+ file = tree.open_file(filename: filename)
53
+
54
+ data = file.read
55
+ puts data
56
+ file.close
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # This example script is used for testing the Winreg registry key value read functionality.
4
+ # It will attempt to connect to a host and reads the value of a specified registry key.
5
+ # Example usage: ruby enum_registry_key.rb 192.168.172.138 msfadmin msfadmin HKLM\\My\\Key ValueName
6
+ # This will try to connect to \\192.168.172.138 with the msfadmin:msfadmin credentialas and reads the ValueName data corresponding to the HKLM\\My\\Key registry key.
7
+
8
+ require 'bundler/setup'
9
+ require 'ruby_smb'
10
+
11
+ address = ARGV[0]
12
+ username = ARGV[1]
13
+ password = ARGV[2]
14
+ registry_key = ARGV[3]
15
+ value_name = ARGV[4]
16
+ smb_versions = ARGV[5]&.split(',') || ['1','2','3']
17
+
18
+ sock = TCPSocket.new address, 445
19
+ dispatcher = RubySMB::Dispatcher::Socket.new(sock, read_timeout: 60)
20
+
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)
22
+ protocol = client.negotiate
23
+ status = client.authenticate
24
+
25
+ puts "#{protocol}: #{status}"
26
+ puts "Key: #{registry_key}"
27
+ puts "Value: #{value_name}"
28
+
29
+ key_value = client.read_registry_key_value(address, registry_key, value_name)
30
+ puts key_value
31
+
32
+ client.disconnect!
33
+
@@ -9,18 +9,20 @@
9
9
  require 'bundler/setup'
10
10
  require 'ruby_smb'
11
11
 
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]
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: true, smb2: true, username: username, password: password)
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
@@ -8,16 +8,18 @@
8
8
  require 'bundler/setup'
9
9
  require 'ruby_smb'
10
10
 
11
- address = ARGV[0]
12
- username = ARGV[1]
13
- password = ARGV[2]
14
- share = ARGV[3]
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: true, smb2: true, username: username, password: password)
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
 
@@ -9,18 +9,20 @@
9
9
  require 'bundler/setup'
10
10
  require 'ruby_smb'
11
11
 
12
- address = ARGV[0]
13
- username = ARGV[1]
14
- password = ARGV[2]
15
- share = ARGV[3]
16
- file = ARGV[4]
17
- data = ARGV[5]
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
+
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: true, smb2: true, username: username, password: password)
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
 
@@ -1,6 +1,9 @@
1
1
  require 'bindata'
2
2
  require 'net/ntlm'
3
3
  require 'net/ntlm/client'
4
+ require 'openssl'
5
+ require 'openssl/ccm'
6
+ require 'openssl/cmac'
4
7
  require 'windows_error'
5
8
  require 'windows_error/nt_status'
6
9
  # A packet parsing and manipulation library for the SMB1 and SMB2 protocols
@@ -15,7 +18,6 @@ module RubySMB
15
18
  require 'ruby_smb/field'
16
19
  require 'ruby_smb/nbss'
17
20
  require 'ruby_smb/fscc'
18
- require 'ruby_smb/dcerpc'
19
21
  require 'ruby_smb/generic_packet'
20
22
  require 'ruby_smb/dispatcher'
21
23
  require 'ruby_smb/version'
@@ -23,4 +25,5 @@ module RubySMB
23
25
  require 'ruby_smb/smb2'
24
26
  require 'ruby_smb/smb1'
25
27
  require 'ruby_smb/client'
28
+ require 'ruby_smb/crypto'
26
29
  end