ruby_smb 2.0.10 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.github/workflows/verify.yml +5 -16
  4. data/examples/auth_capture.rb +71 -0
  5. data/examples/dump_secrets_from_sid.rb +207 -0
  6. data/examples/enum_domain_users.rb +75 -0
  7. data/examples/get_computer_info.rb +42 -0
  8. data/examples/query_service_status.rb +42 -4
  9. data/lib/ruby_smb/client/negotiation.rb +1 -1
  10. data/lib/ruby_smb/client.rb +10 -20
  11. data/lib/ruby_smb/dcerpc/bind.rb +28 -20
  12. data/lib/ruby_smb/dcerpc/bind_ack.rb +29 -28
  13. data/lib/ruby_smb/dcerpc/client.rb +542 -0
  14. data/lib/ruby_smb/dcerpc/drsr/drs_bind_request.rb +24 -0
  15. data/lib/ruby_smb/dcerpc/drsr/drs_bind_response.rb +26 -0
  16. data/lib/ruby_smb/dcerpc/drsr/drs_crack_names_request.rb +57 -0
  17. data/lib/ruby_smb/dcerpc/drsr/drs_crack_names_response.rb +76 -0
  18. data/lib/ruby_smb/dcerpc/drsr/drs_domain_controller_info_request.rb +46 -0
  19. data/lib/ruby_smb/dcerpc/drsr/drs_domain_controller_info_response.rb +168 -0
  20. data/lib/ruby_smb/dcerpc/drsr/drs_extensions.rb +56 -0
  21. data/lib/ruby_smb/dcerpc/drsr/drs_get_nc_changes_request.rb +121 -0
  22. data/lib/ruby_smb/dcerpc/drsr/drs_get_nc_changes_response.rb +118 -0
  23. data/lib/ruby_smb/dcerpc/drsr/drs_unbind_request.rb +24 -0
  24. data/lib/ruby_smb/dcerpc/drsr/drs_unbind_response.rb +26 -0
  25. data/lib/ruby_smb/dcerpc/drsr.rb +909 -0
  26. data/lib/ruby_smb/dcerpc/epm/epm_ept_map_request.rb +26 -0
  27. data/lib/ruby_smb/dcerpc/epm/epm_ept_map_response.rb +25 -0
  28. data/lib/ruby_smb/dcerpc/epm/epm_twrt.rb +211 -0
  29. data/lib/ruby_smb/dcerpc/epm.rb +75 -0
  30. data/lib/ruby_smb/dcerpc/error.rb +17 -0
  31. data/lib/ruby_smb/dcerpc/ndr.rb +1159 -297
  32. data/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request.rb +3 -13
  33. data/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_response.rb +3 -3
  34. data/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request.rb +3 -13
  35. data/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_response.rb +1 -1
  36. data/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request.rb +3 -11
  37. data/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response.rb +1 -1
  38. data/lib/ruby_smb/dcerpc/netlogon.rb +5 -4
  39. data/lib/ruby_smb/dcerpc/p_syntax_id_t.rb +4 -3
  40. data/lib/ruby_smb/dcerpc/pdu_header.rb +7 -7
  41. data/lib/ruby_smb/dcerpc/ptypes.rb +1 -0
  42. data/lib/ruby_smb/dcerpc/request.rb +79 -32
  43. data/lib/ruby_smb/dcerpc/response.rb +45 -10
  44. data/lib/ruby_smb/dcerpc/rpc_auth3.rb +28 -0
  45. data/lib/ruby_smb/dcerpc/rpc_security_attributes.rb +11 -11
  46. data/lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb +118 -0
  47. data/lib/ruby_smb/dcerpc/samr/rpc_sid.rb +150 -0
  48. data/lib/ruby_smb/dcerpc/samr/samr_close_handle_request.rb +23 -0
  49. data/lib/ruby_smb/dcerpc/samr/samr_close_handle_response.rb +24 -0
  50. data/lib/ruby_smb/dcerpc/samr/samr_connect_request.rb +32 -0
  51. data/lib/ruby_smb/dcerpc/samr/samr_connect_response.rb +23 -0
  52. data/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_request.rb +26 -0
  53. data/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_response.rb +55 -0
  54. data/lib/ruby_smb/dcerpc/samr/samr_get_alias_membership_request.rb +48 -0
  55. data/lib/ruby_smb/dcerpc/samr/samr_get_alias_membership_response.rb +38 -0
  56. data/lib/ruby_smb/dcerpc/samr/samr_get_groups_for_user_request.rb +23 -0
  57. data/lib/ruby_smb/dcerpc/samr/samr_get_groups_for_user_response.rb +48 -0
  58. data/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_request.rb +24 -0
  59. data/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_response.rb +25 -0
  60. data/lib/ruby_smb/dcerpc/samr/samr_open_domain_request.rb +27 -0
  61. data/lib/ruby_smb/dcerpc/samr/samr_open_domain_response.rb +24 -0
  62. data/lib/ruby_smb/dcerpc/samr/samr_open_user_request.rb +26 -0
  63. data/lib/ruby_smb/dcerpc/samr/samr_open_user_response.rb +24 -0
  64. data/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_request.rb +23 -0
  65. data/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_response.rb +23 -0
  66. data/lib/ruby_smb/dcerpc/samr.rb +613 -0
  67. data/lib/ruby_smb/dcerpc/sec_trailer.rb +26 -0
  68. data/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all.rb +56 -79
  69. data/lib/ruby_smb/dcerpc/srvsvc.rb +27 -4
  70. data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request.rb +13 -25
  71. data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response.rb +2 -2
  72. data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response.rb +1 -1
  73. data/lib/ruby_smb/dcerpc/svcctl/control_service_request.rb +1 -1
  74. data/lib/ruby_smb/dcerpc/svcctl/control_service_response.rb +1 -1
  75. data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request.rb +4 -14
  76. data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response.rb +1 -1
  77. data/lib/ruby_smb/dcerpc/svcctl/open_service_w_request.rb +3 -11
  78. data/lib/ruby_smb/dcerpc/svcctl/open_service_w_response.rb +1 -1
  79. data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request.rb +1 -1
  80. data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response.rb +12 -11
  81. data/lib/ruby_smb/dcerpc/svcctl/query_service_status_response.rb +1 -1
  82. data/lib/ruby_smb/dcerpc/svcctl/service_status.rb +9 -8
  83. data/lib/ruby_smb/dcerpc/svcctl/start_service_w_request.rb +3 -3
  84. data/lib/ruby_smb/dcerpc/svcctl/start_service_w_response.rb +1 -1
  85. data/lib/ruby_smb/dcerpc/svcctl.rb +1 -3
  86. data/lib/ruby_smb/dcerpc/uuid.rb +3 -0
  87. data/lib/ruby_smb/dcerpc/winreg/close_key_response.rb +2 -2
  88. data/lib/ruby_smb/dcerpc/winreg/create_key_request.rb +2 -13
  89. data/lib/ruby_smb/dcerpc/winreg/create_key_response.rb +3 -3
  90. data/lib/ruby_smb/dcerpc/winreg/enum_key_request.rb +3 -20
  91. data/lib/ruby_smb/dcerpc/winreg/enum_key_response.rb +3 -20
  92. data/lib/ruby_smb/dcerpc/winreg/enum_value_request.rb +5 -14
  93. data/lib/ruby_smb/dcerpc/winreg/enum_value_response.rb +5 -14
  94. data/lib/ruby_smb/dcerpc/winreg/open_key_request.rb +1 -9
  95. data/lib/ruby_smb/dcerpc/winreg/open_key_response.rb +4 -3
  96. data/lib/ruby_smb/dcerpc/winreg/open_root_key_request.rb +5 -6
  97. data/lib/ruby_smb/dcerpc/winreg/open_root_key_response.rb +2 -2
  98. data/lib/ruby_smb/dcerpc/winreg/query_info_key_response.rb +9 -18
  99. data/lib/ruby_smb/dcerpc/winreg/query_value_request.rb +4 -14
  100. data/lib/ruby_smb/dcerpc/winreg/query_value_response.rb +7 -15
  101. data/lib/ruby_smb/dcerpc/winreg/regsam.rb +3 -1
  102. data/lib/ruby_smb/dcerpc/winreg/save_key_request.rb +0 -9
  103. data/lib/ruby_smb/dcerpc/winreg/save_key_response.rb +1 -1
  104. data/lib/ruby_smb/dcerpc/winreg.rb +10 -14
  105. data/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_request.rb +26 -0
  106. data/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_response.rb +88 -0
  107. data/lib/ruby_smb/dcerpc/wkssvc.rb +65 -0
  108. data/lib/ruby_smb/dcerpc.rb +41 -11
  109. data/lib/ruby_smb/dialect.rb +45 -0
  110. data/lib/ruby_smb/dispatcher/base.rb +1 -1
  111. data/lib/ruby_smb/field/file_time.rb +1 -1
  112. data/lib/ruby_smb/field/string16.rb +5 -1
  113. data/lib/ruby_smb/gss/provider/authenticator.rb +42 -0
  114. data/lib/ruby_smb/gss/provider/ntlm.rb +303 -0
  115. data/lib/ruby_smb/gss/provider.rb +35 -0
  116. data/lib/ruby_smb/gss.rb +56 -63
  117. data/lib/ruby_smb/ntlm.rb +61 -0
  118. data/lib/ruby_smb/server/server_client/negotiation.rb +156 -0
  119. data/lib/ruby_smb/server/server_client/session_setup.rb +82 -0
  120. data/lib/ruby_smb/server/server_client.rb +162 -0
  121. data/lib/ruby_smb/server.rb +54 -0
  122. data/lib/ruby_smb/signing.rb +59 -0
  123. data/lib/ruby_smb/smb1/packet/negotiate_response.rb +11 -11
  124. data/lib/ruby_smb/smb1/packet/negotiate_response_extended.rb +1 -1
  125. data/lib/ruby_smb/smb1/packet/session_setup_request.rb +1 -1
  126. data/lib/ruby_smb/smb1/pipe.rb +4 -0
  127. data/lib/ruby_smb/smb2/negotiate_context.rb +18 -2
  128. data/lib/ruby_smb/smb2/packet/negotiate_request.rb +9 -0
  129. data/lib/ruby_smb/smb2/packet/negotiate_response.rb +0 -1
  130. data/lib/ruby_smb/smb2/packet/session_setup_response.rb +2 -2
  131. data/lib/ruby_smb/smb2/packet/tree_connect_request.rb +1 -1
  132. data/lib/ruby_smb/smb2/pipe.rb +4 -0
  133. data/lib/ruby_smb/smb2.rb +3 -1
  134. data/lib/ruby_smb/version.rb +1 -1
  135. data/lib/ruby_smb.rb +2 -1
  136. data/spec/lib/ruby_smb/client_spec.rb +8 -11
  137. data/spec/lib/ruby_smb/dcerpc/bind_ack_spec.rb +69 -41
  138. data/spec/lib/ruby_smb/dcerpc/bind_spec.rb +75 -21
  139. data/spec/lib/ruby_smb/dcerpc/client_spec.rb +714 -0
  140. data/spec/lib/ruby_smb/dcerpc/drsr_spec.rb +2169 -0
  141. data/spec/lib/ruby_smb/dcerpc/ndr_spec.rb +3792 -1373
  142. data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request_spec.rb +4 -4
  143. data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request_spec.rb +4 -4
  144. data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request_spec.rb +2 -2
  145. data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response_spec.rb +2 -2
  146. data/spec/lib/ruby_smb/dcerpc/p_syntax_id_t_spec.rb +18 -4
  147. data/spec/lib/ruby_smb/dcerpc/pdu_header_spec.rb +27 -1
  148. data/spec/lib/ruby_smb/dcerpc/request_spec.rb +76 -11
  149. data/spec/lib/ruby_smb/dcerpc/response_spec.rb +99 -9
  150. data/spec/lib/ruby_smb/dcerpc/rpc_auth3_spec.rb +75 -0
  151. data/spec/lib/ruby_smb/dcerpc/rpc_security_attributes_spec.rb +29 -28
  152. data/spec/lib/ruby_smb/dcerpc/rrp_rpc_unicode_string_spec.rb +340 -0
  153. data/spec/lib/ruby_smb/dcerpc/samr/rpc_sid_spec.rb +116 -0
  154. data/spec/lib/ruby_smb/dcerpc/samr/samr_close_handle_request_spec.rb +40 -0
  155. data/spec/lib/ruby_smb/dcerpc/samr/samr_close_handle_response_spec.rb +48 -0
  156. data/spec/lib/ruby_smb/dcerpc/samr/samr_connect_request_spec.rb +56 -0
  157. data/spec/lib/ruby_smb/dcerpc/samr/samr_connect_response_spec.rb +47 -0
  158. data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_request_spec.rb +63 -0
  159. data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_response_spec.rb +265 -0
  160. data/spec/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_request_spec.rb +52 -0
  161. data/spec/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_response_spec.rb +36 -0
  162. data/spec/lib/ruby_smb/dcerpc/samr/samr_open_domain_request_spec.rb +56 -0
  163. data/spec/lib/ruby_smb/dcerpc/samr/samr_open_domain_response_spec.rb +48 -0
  164. data/spec/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_request_spec.rb +48 -0
  165. data/spec/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_response_spec.rb +42 -0
  166. data/spec/lib/ruby_smb/dcerpc/samr_spec.rb +420 -0
  167. data/spec/lib/ruby_smb/dcerpc/sec_trailer_spec.rb +92 -0
  168. data/spec/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all_spec.rb +149 -110
  169. data/spec/lib/ruby_smb/dcerpc/srvsvc_spec.rb +21 -17
  170. data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request_spec.rb +56 -79
  171. data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response_spec.rb +4 -4
  172. data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response_spec.rb +2 -2
  173. data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_request_spec.rb +2 -2
  174. data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_response_spec.rb +2 -2
  175. data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request_spec.rb +19 -29
  176. data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response_spec.rb +2 -2
  177. data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_request_spec.rb +9 -15
  178. data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_response_spec.rb +2 -2
  179. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request_spec.rb +2 -2
  180. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response_spec.rb +22 -22
  181. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_response_spec.rb +2 -2
  182. data/spec/lib/ruby_smb/dcerpc/svcctl/service_status_spec.rb +18 -14
  183. data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_request_spec.rb +5 -4
  184. data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_response_spec.rb +2 -2
  185. data/spec/lib/ruby_smb/dcerpc/svcctl_spec.rb +1 -5
  186. data/spec/lib/ruby_smb/dcerpc/uuid_spec.rb +15 -23
  187. data/spec/lib/ruby_smb/dcerpc/winreg/close_key_response_spec.rb +2 -2
  188. data/spec/lib/ruby_smb/dcerpc/winreg/create_key_request_spec.rb +4 -41
  189. data/spec/lib/ruby_smb/dcerpc/winreg/create_key_response_spec.rb +4 -4
  190. data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_request_spec.rb +4 -52
  191. data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_response_spec.rb +4 -56
  192. data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_request_spec.rb +10 -34
  193. data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_response_spec.rb +10 -34
  194. data/spec/lib/ruby_smb/dcerpc/winreg/open_key_request_spec.rb +2 -26
  195. data/spec/lib/ruby_smb/dcerpc/winreg/open_key_response_spec.rb +2 -2
  196. data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_request_spec.rb +17 -25
  197. data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_response_spec.rb +2 -2
  198. data/spec/lib/ruby_smb/dcerpc/winreg/query_info_key_response_spec.rb +20 -44
  199. data/spec/lib/ruby_smb/dcerpc/winreg/query_value_request_spec.rb +8 -32
  200. data/spec/lib/ruby_smb/dcerpc/winreg/query_value_response_spec.rb +10 -22
  201. data/spec/lib/ruby_smb/dcerpc/winreg/regsam_spec.rb +4 -0
  202. data/spec/lib/ruby_smb/dcerpc/winreg/save_key_request_spec.rb +0 -12
  203. data/spec/lib/ruby_smb/dcerpc/winreg/save_key_response_spec.rb +2 -2
  204. data/spec/lib/ruby_smb/dcerpc/winreg_spec.rb +18 -47
  205. data/spec/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_request_spec.rb +43 -0
  206. data/spec/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_response_spec.rb +410 -0
  207. data/spec/lib/ruby_smb/dcerpc/wkssvc_spec.rb +70 -0
  208. data/spec/lib/ruby_smb/field/string16_spec.rb +22 -0
  209. data/spec/lib/ruby_smb/gss/provider/ntlm/account_spec.rb +32 -0
  210. data/spec/lib/ruby_smb/gss/provider/ntlm/authenticator_spec.rb +101 -0
  211. data/spec/lib/ruby_smb/gss/provider/ntlm/os_version_spec.rb +32 -0
  212. data/spec/lib/ruby_smb/gss/provider/ntlm_spec.rb +113 -0
  213. data/spec/lib/ruby_smb/server/server_client_spec.rb +156 -0
  214. data/spec/lib/ruby_smb/server_spec.rb +32 -0
  215. data/spec/lib/ruby_smb/smb1/pipe_spec.rb +18 -37
  216. data/spec/lib/ruby_smb/smb2/negotiate_context_spec.rb +2 -2
  217. data/spec/lib/ruby_smb/smb2/pipe_spec.rb +18 -16
  218. data/spec/support/bin_helper.rb +9 -0
  219. data.tar.gz.sig +0 -0
  220. metadata +119 -6
  221. metadata.gz.sig +0 -0
  222. data/lib/ruby_smb/client/signing.rb +0 -64
  223. data/lib/ruby_smb/dcerpc/rrp_unicode_string.rb +0 -38
  224. data/spec/lib/ruby_smb/dcerpc/rrp_unicode_string_spec.rb +0 -135
@@ -0,0 +1,340 @@
1
+ RSpec.describe RubySMB::Dcerpc::RrpUnicodeString do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :buffer_length }
5
+ it { is_expected.to respond_to :maximum_length }
6
+ it { is_expected.to respond_to :buffer }
7
+
8
+ it 'is little endian' do
9
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
10
+ end
11
+
12
+ it 'has :byte_align parameter set to the expected value' do
13
+ expect(described_class.default_parameters[:byte_align]).to eq(4)
14
+ end
15
+
16
+ describe '#buffer_length' do
17
+ it 'should be a NdrUint16' do
18
+ expect(packet.buffer_length).to be_a RubySMB::Dcerpc::Ndr::NdrUint16
19
+ end
20
+ it 'is 0 by default' do
21
+ expect(packet.buffer_length).to eq(0)
22
+ end
23
+ end
24
+
25
+ describe '#maximum_length' do
26
+ it 'should be a NdrUint16' do
27
+ expect(packet.maximum_length).to be_a RubySMB::Dcerpc::Ndr::NdrUint16
28
+ end
29
+ it 'is 0 by default' do
30
+ expect(packet.maximum_length).to eq(0)
31
+ end
32
+ end
33
+
34
+ describe '#buffer' do
35
+ it 'should be a NdrWideStringzPtr' do
36
+ expect(packet.buffer).to be_a RubySMB::Dcerpc::Ndr::NdrWideStringzPtr
37
+ end
38
+ it 'is :null by default' do
39
+ expect(packet.buffer).to eq(:null)
40
+ end
41
+ end
42
+
43
+ describe '#assign' do
44
+ context 'with a string' do
45
+ before :example do
46
+ packet.assign('spec_test')
47
+ end
48
+
49
+ [BinData::Stringz, BinData::String, String].each do |klass|
50
+ context "with a #{klass}" do
51
+ it 'sets #buffer to the expected value' do
52
+ expect(packet.buffer).to eq(RubySMB::Dcerpc::Ndr::NdrWideStringPtr.new(klass.new('spec_test')))
53
+ end
54
+
55
+ it 'sets #buffer_length to the expected value' do
56
+ expect(packet.buffer_length).to eq(('spec_test'.size + 1) * 2)
57
+ end
58
+
59
+ it 'sets #maximum_length to the expected value' do
60
+ expect(packet.maximum_length).to eq(('spec_test'.size + 1) * 2)
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'with a :null pointer' do
67
+ before :example do
68
+ packet.assign(:null)
69
+ end
70
+ it 'sets #buffer to :null' do
71
+ expect(packet.buffer).to eq(:null)
72
+ end
73
+
74
+ it 'sets #buffer_length to 0' do
75
+ expect(packet.buffer_length).to eq(0)
76
+ end
77
+
78
+ it 'sets #maximum_length to 0' do
79
+ expect(packet.maximum_length).to eq(0)
80
+ end
81
+ end
82
+ end
83
+
84
+ describe '#read' do
85
+ context 'with a null pointer' do
86
+ it 'reads its own binary representation' do
87
+ raw = packet.to_binary_s
88
+ expect(described_class.read(raw)).to eq(packet)
89
+ expect(described_class.read(raw).to_binary_s).to eq(raw)
90
+ end
91
+ end
92
+
93
+ context 'with a normal string' do
94
+ it 'reads its own binary representation' do
95
+ packet.assign('my_test')
96
+ raw = packet.to_binary_s
97
+ expect(described_class.read(raw)).to eq(packet)
98
+ expect(described_class.read(raw).to_binary_s).to eq(raw)
99
+ end
100
+ end
101
+ end
102
+
103
+ describe '#set_max_buffer_size' do
104
+ it 'sets buffer.max_count to the expected value' do
105
+ packet.set_max_buffer_size(4)
106
+ expect(packet.buffer.max_count).to eq(4 / 2)
107
+ end
108
+
109
+ it 'sets #maximum_length to the expected value' do
110
+ packet.set_max_buffer_size(4)
111
+ expect(packet.maximum_length).to eq(4)
112
+ end
113
+
114
+ it 'instantiates `buffer` if it is a null pointer' do
115
+ expect(packet.buffer).to eq(:null)
116
+ packet.set_max_buffer_size(4)
117
+ expect(packet.buffer).to eq('')
118
+ end
119
+ end
120
+
121
+ describe '#to_s' do
122
+ it 'returns a unicode string' do
123
+ packet.assign('Test')
124
+ expect(packet.to_s).to eq('Test'.encode('utf-16le'))
125
+ end
126
+
127
+ it 'returns a unicode encoded empty string if `buffer` is a null pointer' do
128
+ expect(packet.buffer).to eq(:null)
129
+ expect(packet.to_s).to eq(''.encode('utf-16le'))
130
+ end
131
+ end
132
+ end
133
+
134
+ RSpec.describe RubySMB::Dcerpc::PrrpUnicodeString do
135
+ it 'is RrpUnicodeString subclass' do
136
+ expect(described_class).to be < RubySMB::Dcerpc::RrpUnicodeString
137
+ end
138
+
139
+ subject(:packet) { described_class.new }
140
+
141
+ it 'is a NDR pointer' do
142
+ expect(subject).to be_a RubySMB::Dcerpc::Ndr::PointerPlugin
143
+ end
144
+
145
+ it { is_expected.to respond_to :ref_id }
146
+
147
+ it 'is :null if #ref_id is zero' do
148
+ packet.ref_id = 0
149
+ expect(packet).to eq(:null)
150
+ end
151
+
152
+ describe '#read' do
153
+ context 'with a null pointer' do
154
+ it 'reads its own binary representation' do
155
+ raw = packet.to_binary_s
156
+ expect(described_class.read(raw)).to eq(packet)
157
+ expect(described_class.read(raw).to_binary_s).to eq(raw)
158
+ end
159
+ end
160
+
161
+ context 'with a normal string' do
162
+ it 'reads its own binary representation' do
163
+ packet.assign('my_test')
164
+ raw = packet.to_binary_s
165
+ expect(described_class.read(raw)).to eq(packet)
166
+ expect(described_class.read(raw).to_binary_s).to eq(raw)
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ RSpec.describe RubySMB::Dcerpc::RpcUnicodeString do
173
+ subject(:packet) { described_class.new }
174
+
175
+ it { is_expected.to respond_to :buffer_length }
176
+ it { is_expected.to respond_to :maximum_length }
177
+ it { is_expected.to respond_to :buffer }
178
+
179
+ it 'is little endian' do
180
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
181
+ end
182
+
183
+ it 'has :byte_align parameter set to the expected value' do
184
+ expect(described_class.default_parameters[:byte_align]).to eq(4)
185
+ end
186
+
187
+ describe '#buffer_length' do
188
+ it 'should be a NdrUint16' do
189
+ expect(packet.buffer_length).to be_a RubySMB::Dcerpc::Ndr::NdrUint16
190
+ end
191
+ it 'is 0 by default' do
192
+ expect(packet.buffer_length).to eq(0)
193
+ end
194
+ end
195
+
196
+ describe '#maximum_length' do
197
+ it 'should be a NdrUint16' do
198
+ expect(packet.maximum_length).to be_a RubySMB::Dcerpc::Ndr::NdrUint16
199
+ end
200
+ it 'is 0 by default' do
201
+ expect(packet.maximum_length).to eq(0)
202
+ end
203
+ end
204
+
205
+ describe '#buffer' do
206
+ it 'should be a NdrWideStringPtr' do
207
+ expect(packet.buffer).to be_a RubySMB::Dcerpc::Ndr::NdrWideStringPtr
208
+ end
209
+ it 'is :null by default' do
210
+ expect(packet.buffer).to eq(:null)
211
+ end
212
+ end
213
+
214
+ describe '#assign' do
215
+ context 'with a string' do
216
+ before :example do
217
+ packet.assign('spec_test')
218
+ end
219
+
220
+ [BinData::Stringz, BinData::String, String].each do |klass|
221
+ context "with a #{klass}" do
222
+ it 'sets #buffer to the expected value' do
223
+ expect(packet.buffer).to eq(RubySMB::Dcerpc::Ndr::NdrWideStringPtr.new('spec_test'))
224
+ end
225
+
226
+ it 'sets #buffer_length to the expected value' do
227
+ expect(packet.buffer_length).to eq(('spec_test'.size) * 2)
228
+ end
229
+
230
+ it 'sets #maximum_length to the expected value' do
231
+ expect(packet.maximum_length).to eq(('spec_test'.size) * 2)
232
+ end
233
+ end
234
+ end
235
+ end
236
+ context 'with a :null pointer' do
237
+ before :example do
238
+ packet.assign(:null)
239
+ end
240
+ it 'sets #buffer to :null' do
241
+ expect(packet.buffer).to eq(:null)
242
+ end
243
+
244
+ it 'sets #buffer_length to 0' do
245
+ expect(packet.buffer_length).to eq(0)
246
+ end
247
+
248
+ it 'sets #maximum_length to 0' do
249
+ expect(packet.maximum_length).to eq(0)
250
+ end
251
+ end
252
+ end
253
+
254
+ describe '#read' do
255
+ context 'with a null pointer' do
256
+ it 'reads its own binary representation' do
257
+ raw = packet.to_binary_s
258
+ expect(described_class.read(raw)).to eq(packet)
259
+ expect(described_class.read(raw).to_binary_s).to eq(raw)
260
+ end
261
+ end
262
+
263
+ context 'with a normal string' do
264
+ it 'reads its own binary representation' do
265
+ packet.assign('my_test')
266
+ raw = packet.to_binary_s
267
+ expect(described_class.read(raw)).to eq(packet)
268
+ expect(described_class.read(raw).to_binary_s).to eq(raw)
269
+ end
270
+ end
271
+ end
272
+
273
+ describe '#set_max_buffer_size' do
274
+ it 'sets buffer.max_count to the expected value' do
275
+ packet.set_max_buffer_size(4)
276
+ expect(packet.buffer.max_count).to eq(4 / 2)
277
+ end
278
+
279
+ it 'sets #maximum_length to the expected value' do
280
+ packet.set_max_buffer_size(4)
281
+ expect(packet.maximum_length).to eq(4)
282
+ end
283
+
284
+ it 'instantiates `buffer` if it is a null pointer' do
285
+ expect(packet.buffer).to eq(:null)
286
+ packet.set_max_buffer_size(4)
287
+ expect(packet.buffer).to eq('')
288
+ end
289
+ end
290
+
291
+ describe '#to_s' do
292
+ it 'returns a unicode string' do
293
+ packet.assign('Test')
294
+ expect(packet.to_s).to eq('Test'.encode('utf-16le'))
295
+ end
296
+
297
+ it 'returns a unicode encoded empty string if `buffer` is a null pointer' do
298
+ expect(packet.buffer).to eq(:null)
299
+ expect(packet.to_s).to eq(''.encode('utf-16le'))
300
+ end
301
+ end
302
+ end
303
+
304
+ RSpec.describe RubySMB::Dcerpc::PrpcUnicodeString do
305
+ it 'is RpcUnicodeString subclass' do
306
+ expect(described_class).to be < RubySMB::Dcerpc::RpcUnicodeString
307
+ end
308
+
309
+ subject(:packet) { described_class.new }
310
+
311
+ it 'is a NDR pointer' do
312
+ expect(subject).to be_a RubySMB::Dcerpc::Ndr::PointerPlugin
313
+ end
314
+
315
+ it { is_expected.to respond_to :ref_id }
316
+
317
+ it 'is :null if #ref_id is zero' do
318
+ packet.ref_id = 0
319
+ expect(packet).to eq(:null)
320
+ end
321
+
322
+ describe '#read' do
323
+ context 'with a null pointer' do
324
+ it 'reads its own binary representation' do
325
+ raw = packet.to_binary_s
326
+ expect(described_class.read(raw)).to eq(packet)
327
+ expect(described_class.read(raw).to_binary_s).to eq(raw)
328
+ end
329
+ end
330
+
331
+ context 'with a normal string' do
332
+ it 'reads its own binary representation' do
333
+ packet.assign('my_test')
334
+ raw = packet.to_binary_s
335
+ expect(described_class.read(raw)).to eq(packet)
336
+ expect(described_class.read(raw).to_binary_s).to eq(raw)
337
+ end
338
+ end
339
+ end
340
+ end
@@ -0,0 +1,116 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::RpcSidIdentifierAuthority do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it 'is a Ndr::NdrFixArray' do
5
+ expect(packet).to be_a(RubySMB::Dcerpc::Ndr::NdrFixArray)
6
+ end
7
+ it 'has element of type :ndr_uint8' do
8
+ expect(packet[0]).to be_a(RubySMB::Dcerpc::Ndr::NdrUint8)
9
+ end
10
+ it 'has 6 elements by default' do
11
+ expect(packet.size).to eq(6)
12
+ end
13
+ it 'is one-byte aligned' do
14
+ expect(packet.eval_parameter(:byte_align)).to eq(1)
15
+ end
16
+ it 'reads itself' do
17
+ expect(packet.read(described_class.new([1, 2, 3, 4, 5, 6]).to_binary_s)).to eq([1, 2, 3, 4, 5, 6])
18
+ end
19
+ end
20
+
21
+ RSpec.describe RubySMB::Dcerpc::Samr::RpcSid do
22
+ subject(:packet) { described_class.new }
23
+
24
+ it { is_expected.to respond_to :revision }
25
+ it { is_expected.to respond_to :sub_authority_count }
26
+ it { is_expected.to respond_to :identifier_authority }
27
+ it { is_expected.to respond_to :sub_authority }
28
+
29
+ it 'is little endian' do
30
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
31
+ end
32
+ it 'is a Ndr::NdrStruct' do
33
+ expect(packet).to be_a(RubySMB::Dcerpc::Ndr::NdrStruct)
34
+ end
35
+ it 'is four-byte aligned' do
36
+ expect(packet.eval_parameter(:byte_align)).to eq(4)
37
+ end
38
+ describe '#revision' do
39
+ it 'is a NdrUint8 structure' do
40
+ expect(packet.revision).to be_a RubySMB::Dcerpc::Ndr::NdrUint8
41
+ end
42
+ end
43
+ describe '#sub_authority_count' do
44
+ it 'is a NdrUint8 structure' do
45
+ expect(packet.sub_authority_count).to be_a RubySMB::Dcerpc::Ndr::NdrUint8
46
+ end
47
+ it 'is set the the number of #sub_authority elements by default' do
48
+ packet.sub_authority = [21, 419547006, 9459028, 4093171872, 500]
49
+ expect(packet.sub_authority_count).to eq(5)
50
+ end
51
+ end
52
+ describe '#identifier_authority' do
53
+ it 'is a RpcSidIdentifierAuthority structure' do
54
+ expect(packet.identifier_authority).to be_a RubySMB::Dcerpc::Samr::RpcSidIdentifierAuthority
55
+ end
56
+ end
57
+ describe '#sub_authority' do
58
+ it 'is a NdrConfArray structure' do
59
+ expect(packet.sub_authority).to be_a RubySMB::Dcerpc::Ndr::NdrConfArray
60
+ end
61
+ it 'has element of type :ndr_uint32' do
62
+ packet.sub_authority << 1
63
+ expect(packet.sub_authority[0]).to be_a(RubySMB::Dcerpc::Ndr::NdrUint32)
64
+ end
65
+ end
66
+ describe '#snapshot' do
67
+ it 'outputs the expected SID' do
68
+ packet.revision = 1
69
+ packet.identifier_authority = [0, 0, 0, 0, 0, 5]
70
+ packet.sub_authority = [21, 419547006, 9459028, 4093171872, 500]
71
+ expect(packet.snapshot).to eq('S-1-5-21-419547006-9459028-4093171872-500')
72
+ end
73
+ end
74
+ describe '#assign' do
75
+ it 'assign the correct fields from a String' do
76
+ packet.assign('S-1-5-21-419547006-9459028-4093171872-500')
77
+ expect(packet.revision).to eq(1)
78
+ expect(packet.sub_authority_count).to eq(5)
79
+ expect(packet.identifier_authority).to eq([0, 0, 0, 0, 0, 5])
80
+ expect(packet.sub_authority).to eq([21, 419547006, 9459028, 4093171872, 500])
81
+ end
82
+ it 'assign the correct fields from another RpcSid object' do
83
+ packet2 = described_class.new
84
+ packet2.revision = 1
85
+ packet2.identifier_authority = [0, 0, 0, 0, 0, 5]
86
+ packet2.sub_authority = [21, 419547006, 9459028, 4093171872, 500]
87
+ packet.assign(packet2)
88
+ expect(packet.revision).to eq(1)
89
+ expect(packet.sub_authority_count).to eq(5)
90
+ expect(packet.identifier_authority).to eq([0, 0, 0, 0, 0, 5])
91
+ expect(packet.sub_authority).to eq([21, 419547006, 9459028, 4093171872, 500])
92
+ expect(packet.snapshot).to eq('S-1-5-21-419547006-9459028-4093171872-500')
93
+ end
94
+ end
95
+ it 'reads itself' do
96
+ expect(packet.read(described_class.new('S-1-5-21-419547006-9459028-4093171872-500').to_binary_s)).to eq('S-1-5-21-419547006-9459028-4093171872-500')
97
+ end
98
+ end
99
+
100
+ RSpec.describe RubySMB::Dcerpc::Samr::PrpcSid do
101
+ subject(:packet) { described_class.new }
102
+
103
+ it 'is a RpcSid' do
104
+ expect(packet).to be_a(RubySMB::Dcerpc::Samr::RpcSid)
105
+ end
106
+ it 'is a NdrPointer' do
107
+ expect(described_class).to be_a(RubySMB::Dcerpc::Ndr::PointerClassPlugin)
108
+ expect(packet).to be_a(RubySMB::Dcerpc::Ndr::PointerPlugin)
109
+ end
110
+ it 'is four-byte aligned' do
111
+ expect(packet.eval_parameter(:byte_align)).to eq(4)
112
+ end
113
+ it 'reads itself' do
114
+ expect(packet.read(described_class.new('S-1-5-21-419547006-9459028-4093171872-500').to_binary_s)).to eq('S-1-5-21-419547006-9459028-4093171872-500')
115
+ end
116
+ end
@@ -0,0 +1,40 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrCloseHandleRequest do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :sam_handle }
5
+ it { is_expected.to respond_to :opnum }
6
+
7
+ it 'is little endian' do
8
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
9
+ end
10
+ it 'is a BinData::Record' do
11
+ expect(packet).to be_a(BinData::Record)
12
+ end
13
+ describe '#sam_handle' do
14
+ it 'is a SamprHandle structure' do
15
+ expect(packet.sam_handle).to be_a RubySMB::Dcerpc::Samr::SamprHandle
16
+ end
17
+ end
18
+ describe '#initialize_instance' do
19
+ it 'sets #opnum to SAMR_CLOSE_HANDLE constant' do
20
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_CLOSE_HANDLE)
21
+ end
22
+ end
23
+ it 'reads itself' do
24
+ new_packet = described_class.new({
25
+ sam_handle: {
26
+ context_handle_attributes: 0,
27
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
28
+ }
29
+ })
30
+ expected_output = {
31
+ sam_handle: {
32
+ context_handle_attributes: 0,
33
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
34
+ }
35
+ }
36
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
37
+ end
38
+ end
39
+
40
+
@@ -0,0 +1,48 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrCloseHandleResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :sam_handle }
5
+ it { is_expected.to respond_to :error_status }
6
+ it { is_expected.to respond_to :opnum }
7
+
8
+ it 'is little endian' do
9
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
10
+ end
11
+ it 'is a BinData::Record' do
12
+ expect(packet).to be_a(BinData::Record)
13
+ end
14
+ describe '#sam_handle' do
15
+ it 'is a SamprHandle structure' do
16
+ expect(packet.sam_handle).to be_a RubySMB::Dcerpc::Samr::SamprHandle
17
+ end
18
+ end
19
+ describe '#error_status' do
20
+ it 'is a NdrUint32 structure' do
21
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
22
+ end
23
+ end
24
+ describe '#initialize_instance' do
25
+ it 'sets #opnum to SAMR_CLOSE_HANDLE constant' do
26
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_CLOSE_HANDLE)
27
+ end
28
+ end
29
+ it 'reads itself' do
30
+ new_packet = described_class.new({
31
+ sam_handle: {
32
+ context_handle_attributes: 0,
33
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
34
+ },
35
+ error_status: 4
36
+ })
37
+ expected_output = {
38
+ sam_handle: {
39
+ context_handle_attributes: 0,
40
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
41
+ },
42
+ error_status: 4
43
+ }
44
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
45
+ end
46
+ end
47
+
48
+
@@ -0,0 +1,56 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::PsamprServerName do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it 'is a RubySMB::Field::Stringz16' do
5
+ expect(packet).to be_a(RubySMB::Field::Stringz16)
6
+ end
7
+ it 'is a NdrPointer' do
8
+ expect(described_class).to be_a(RubySMB::Dcerpc::Ndr::PointerClassPlugin)
9
+ expect(packet).to be_a(RubySMB::Dcerpc::Ndr::PointerPlugin)
10
+ end
11
+ it 'is four-bytes aligned' do
12
+ expect(packet.eval_parameter(:byte_align)).to eq(4)
13
+ end
14
+ it 'has a referent which is two-bytes aligned' do
15
+ expect(packet.eval_parameter(:referent_byte_align)).to eq(2)
16
+ end
17
+ it 'reads itself' do
18
+ expect(packet.read(described_class.new('TestString!!').to_binary_s)).to eq('TestString!!'.encode('utf-16le'))
19
+ end
20
+ end
21
+
22
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrConnectRequest do
23
+ subject(:packet) { described_class.new }
24
+
25
+ it { is_expected.to respond_to :server_name }
26
+ it { is_expected.to respond_to :desired_access }
27
+ it { is_expected.to respond_to :opnum }
28
+
29
+ it 'is little endian' do
30
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
31
+ end
32
+ it 'is a BinData::Record' do
33
+ expect(packet).to be_a(BinData::Record)
34
+ end
35
+ describe '#server_name' do
36
+ it 'is a PsamprServerName structure' do
37
+ expect(packet.server_name).to be_a RubySMB::Dcerpc::Samr::PsamprServerName
38
+ end
39
+ end
40
+ describe '#desired_access' do
41
+ it 'is a NdrUint32 structure' do
42
+ expect(packet.desired_access).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
43
+ end
44
+ end
45
+ describe '#initialize_instance' do
46
+ it 'sets #opnum to SAMR_CONNECT constant' do
47
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_CONNECT)
48
+ end
49
+ end
50
+ it 'reads itself' do
51
+ new_class = described_class.new(server_name: 'TestServer', desired_access: 555)
52
+ expect(packet.read(new_class.to_binary_s)).to eq(
53
+ {server_name: 'TestServer'.encode('utf-16le'), desired_access: 555}
54
+ )
55
+ end
56
+ end
@@ -0,0 +1,47 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrConnectResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :server_handle }
5
+ it { is_expected.to respond_to :error_status }
6
+ it { is_expected.to respond_to :opnum }
7
+
8
+ it 'is little endian' do
9
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
10
+ end
11
+ it 'is a BinData::Record' do
12
+ expect(packet).to be_a(BinData::Record)
13
+ end
14
+ describe '#server_handle' do
15
+ it 'is a SamprHandle structure' do
16
+ expect(packet.server_handle).to be_a RubySMB::Dcerpc::Samr::SamprHandle
17
+ end
18
+ end
19
+ describe '#error_status' do
20
+ it 'is a NdrUint32 structure' do
21
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
22
+ end
23
+ end
24
+ describe '#initialize_instance' do
25
+ it 'sets #opnum to SAMR_CONNECT constant' do
26
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_CONNECT)
27
+ end
28
+ end
29
+ it 'reads itself' do
30
+ new_class = described_class.new(
31
+ server_handle: {
32
+ context_handle_attributes: 0,
33
+ context_handle_uuid: '2ef54a87-e29e-4d24-90e9-9da49b94449e'
34
+ },
35
+ error_status: 2
36
+ )
37
+ expect(packet.read(new_class.to_binary_s)).to eq(
38
+ {
39
+ server_handle: {
40
+ context_handle_attributes: 0,
41
+ context_handle_uuid: '2ef54a87-e29e-4d24-90e9-9da49b94449e'
42
+ },
43
+ error_status: 2
44
+ }
45
+ )
46
+ end
47
+ end