ruby_smb 2.0.12 → 2.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.github/workflows/verify.yml +1 -1
  4. data/examples/dump_secrets_from_sid.rb +207 -0
  5. data/examples/enum_domain_users.rb +75 -0
  6. data/examples/get_computer_info.rb +42 -0
  7. data/examples/query_service_status.rb +42 -4
  8. data/lib/ruby_smb/client.rb +3 -14
  9. data/lib/ruby_smb/dcerpc/bind.rb +28 -20
  10. data/lib/ruby_smb/dcerpc/bind_ack.rb +29 -28
  11. data/lib/ruby_smb/dcerpc/client.rb +542 -0
  12. data/lib/ruby_smb/dcerpc/drsr/drs_bind_request.rb +24 -0
  13. data/lib/ruby_smb/dcerpc/drsr/drs_bind_response.rb +26 -0
  14. data/lib/ruby_smb/dcerpc/drsr/drs_crack_names_request.rb +57 -0
  15. data/lib/ruby_smb/dcerpc/drsr/drs_crack_names_response.rb +76 -0
  16. data/lib/ruby_smb/dcerpc/drsr/drs_domain_controller_info_request.rb +46 -0
  17. data/lib/ruby_smb/dcerpc/drsr/drs_domain_controller_info_response.rb +168 -0
  18. data/lib/ruby_smb/dcerpc/drsr/drs_extensions.rb +56 -0
  19. data/lib/ruby_smb/dcerpc/drsr/drs_get_nc_changes_request.rb +121 -0
  20. data/lib/ruby_smb/dcerpc/drsr/drs_get_nc_changes_response.rb +118 -0
  21. data/lib/ruby_smb/dcerpc/drsr/drs_unbind_request.rb +24 -0
  22. data/lib/ruby_smb/dcerpc/drsr/drs_unbind_response.rb +26 -0
  23. data/lib/ruby_smb/dcerpc/drsr.rb +909 -0
  24. data/lib/ruby_smb/dcerpc/epm/epm_ept_map_request.rb +26 -0
  25. data/lib/ruby_smb/dcerpc/epm/epm_ept_map_response.rb +25 -0
  26. data/lib/ruby_smb/dcerpc/epm/epm_twrt.rb +211 -0
  27. data/lib/ruby_smb/dcerpc/epm.rb +75 -0
  28. data/lib/ruby_smb/dcerpc/error.rb +17 -0
  29. data/lib/ruby_smb/dcerpc/ndr.rb +1159 -297
  30. data/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request.rb +3 -13
  31. data/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_response.rb +3 -3
  32. data/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request.rb +3 -13
  33. data/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_response.rb +1 -1
  34. data/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request.rb +3 -11
  35. data/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response.rb +1 -1
  36. data/lib/ruby_smb/dcerpc/netlogon.rb +5 -4
  37. data/lib/ruby_smb/dcerpc/p_syntax_id_t.rb +4 -3
  38. data/lib/ruby_smb/dcerpc/pdu_header.rb +7 -7
  39. data/lib/ruby_smb/dcerpc/ptypes.rb +1 -0
  40. data/lib/ruby_smb/dcerpc/request.rb +79 -32
  41. data/lib/ruby_smb/dcerpc/response.rb +45 -10
  42. data/lib/ruby_smb/dcerpc/rpc_auth3.rb +28 -0
  43. data/lib/ruby_smb/dcerpc/rpc_security_attributes.rb +11 -11
  44. data/lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb +118 -0
  45. data/lib/ruby_smb/dcerpc/samr/rpc_sid.rb +150 -0
  46. data/lib/ruby_smb/dcerpc/samr/samr_close_handle_request.rb +23 -0
  47. data/lib/ruby_smb/dcerpc/samr/samr_close_handle_response.rb +24 -0
  48. data/lib/ruby_smb/dcerpc/samr/samr_connect_request.rb +32 -0
  49. data/lib/ruby_smb/dcerpc/samr/samr_connect_response.rb +23 -0
  50. data/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_request.rb +26 -0
  51. data/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_response.rb +55 -0
  52. data/lib/ruby_smb/dcerpc/samr/samr_get_alias_membership_request.rb +48 -0
  53. data/lib/ruby_smb/dcerpc/samr/samr_get_alias_membership_response.rb +38 -0
  54. data/lib/ruby_smb/dcerpc/samr/samr_get_groups_for_user_request.rb +23 -0
  55. data/lib/ruby_smb/dcerpc/samr/samr_get_groups_for_user_response.rb +48 -0
  56. data/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_request.rb +24 -0
  57. data/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_response.rb +25 -0
  58. data/lib/ruby_smb/dcerpc/samr/samr_open_domain_request.rb +27 -0
  59. data/lib/ruby_smb/dcerpc/samr/samr_open_domain_response.rb +24 -0
  60. data/lib/ruby_smb/dcerpc/samr/samr_open_user_request.rb +26 -0
  61. data/lib/ruby_smb/dcerpc/samr/samr_open_user_response.rb +24 -0
  62. data/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_request.rb +23 -0
  63. data/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_response.rb +23 -0
  64. data/lib/ruby_smb/dcerpc/samr.rb +613 -0
  65. data/lib/ruby_smb/dcerpc/sec_trailer.rb +26 -0
  66. data/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all.rb +56 -79
  67. data/lib/ruby_smb/dcerpc/srvsvc.rb +27 -4
  68. data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request.rb +13 -25
  69. data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response.rb +2 -2
  70. data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response.rb +1 -1
  71. data/lib/ruby_smb/dcerpc/svcctl/control_service_request.rb +1 -1
  72. data/lib/ruby_smb/dcerpc/svcctl/control_service_response.rb +1 -1
  73. data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request.rb +4 -14
  74. data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response.rb +1 -1
  75. data/lib/ruby_smb/dcerpc/svcctl/open_service_w_request.rb +3 -11
  76. data/lib/ruby_smb/dcerpc/svcctl/open_service_w_response.rb +1 -1
  77. data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request.rb +1 -1
  78. data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response.rb +12 -11
  79. data/lib/ruby_smb/dcerpc/svcctl/query_service_status_response.rb +1 -1
  80. data/lib/ruby_smb/dcerpc/svcctl/service_status.rb +9 -8
  81. data/lib/ruby_smb/dcerpc/svcctl/start_service_w_request.rb +3 -3
  82. data/lib/ruby_smb/dcerpc/svcctl/start_service_w_response.rb +1 -1
  83. data/lib/ruby_smb/dcerpc/svcctl.rb +1 -3
  84. data/lib/ruby_smb/dcerpc/uuid.rb +3 -0
  85. data/lib/ruby_smb/dcerpc/winreg/close_key_response.rb +2 -2
  86. data/lib/ruby_smb/dcerpc/winreg/create_key_request.rb +2 -13
  87. data/lib/ruby_smb/dcerpc/winreg/create_key_response.rb +3 -3
  88. data/lib/ruby_smb/dcerpc/winreg/enum_key_request.rb +3 -20
  89. data/lib/ruby_smb/dcerpc/winreg/enum_key_response.rb +3 -20
  90. data/lib/ruby_smb/dcerpc/winreg/enum_value_request.rb +5 -14
  91. data/lib/ruby_smb/dcerpc/winreg/enum_value_response.rb +5 -14
  92. data/lib/ruby_smb/dcerpc/winreg/open_key_request.rb +1 -9
  93. data/lib/ruby_smb/dcerpc/winreg/open_key_response.rb +4 -3
  94. data/lib/ruby_smb/dcerpc/winreg/open_root_key_request.rb +5 -6
  95. data/lib/ruby_smb/dcerpc/winreg/open_root_key_response.rb +2 -2
  96. data/lib/ruby_smb/dcerpc/winreg/query_info_key_response.rb +9 -18
  97. data/lib/ruby_smb/dcerpc/winreg/query_value_request.rb +4 -14
  98. data/lib/ruby_smb/dcerpc/winreg/query_value_response.rb +7 -15
  99. data/lib/ruby_smb/dcerpc/winreg/regsam.rb +3 -1
  100. data/lib/ruby_smb/dcerpc/winreg/save_key_request.rb +0 -9
  101. data/lib/ruby_smb/dcerpc/winreg/save_key_response.rb +1 -1
  102. data/lib/ruby_smb/dcerpc/winreg.rb +10 -14
  103. data/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_request.rb +26 -0
  104. data/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_response.rb +88 -0
  105. data/lib/ruby_smb/dcerpc/wkssvc.rb +65 -0
  106. data/lib/ruby_smb/dcerpc.rb +41 -11
  107. data/lib/ruby_smb/field/file_time.rb +1 -1
  108. data/lib/ruby_smb/field/string16.rb +5 -1
  109. data/lib/ruby_smb/ntlm.rb +18 -2
  110. data/lib/ruby_smb/smb1/pipe.rb +4 -0
  111. data/lib/ruby_smb/smb2/pipe.rb +4 -0
  112. data/lib/ruby_smb/version.rb +1 -1
  113. data/spec/lib/ruby_smb/client_spec.rb +1 -2
  114. data/spec/lib/ruby_smb/dcerpc/bind_ack_spec.rb +69 -41
  115. data/spec/lib/ruby_smb/dcerpc/bind_spec.rb +75 -21
  116. data/spec/lib/ruby_smb/dcerpc/client_spec.rb +714 -0
  117. data/spec/lib/ruby_smb/dcerpc/drsr_spec.rb +2169 -0
  118. data/spec/lib/ruby_smb/dcerpc/ndr_spec.rb +3792 -1373
  119. data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request_spec.rb +4 -4
  120. data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request_spec.rb +4 -4
  121. data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request_spec.rb +2 -2
  122. data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response_spec.rb +2 -2
  123. data/spec/lib/ruby_smb/dcerpc/p_syntax_id_t_spec.rb +18 -4
  124. data/spec/lib/ruby_smb/dcerpc/pdu_header_spec.rb +27 -1
  125. data/spec/lib/ruby_smb/dcerpc/request_spec.rb +76 -11
  126. data/spec/lib/ruby_smb/dcerpc/response_spec.rb +99 -9
  127. data/spec/lib/ruby_smb/dcerpc/rpc_auth3_spec.rb +75 -0
  128. data/spec/lib/ruby_smb/dcerpc/rpc_security_attributes_spec.rb +29 -28
  129. data/spec/lib/ruby_smb/dcerpc/rrp_rpc_unicode_string_spec.rb +340 -0
  130. data/spec/lib/ruby_smb/dcerpc/samr/rpc_sid_spec.rb +116 -0
  131. data/spec/lib/ruby_smb/dcerpc/samr/samr_close_handle_request_spec.rb +40 -0
  132. data/spec/lib/ruby_smb/dcerpc/samr/samr_close_handle_response_spec.rb +48 -0
  133. data/spec/lib/ruby_smb/dcerpc/samr/samr_connect_request_spec.rb +56 -0
  134. data/spec/lib/ruby_smb/dcerpc/samr/samr_connect_response_spec.rb +47 -0
  135. data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_request_spec.rb +63 -0
  136. data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_response_spec.rb +265 -0
  137. data/spec/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_request_spec.rb +52 -0
  138. data/spec/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_response_spec.rb +36 -0
  139. data/spec/lib/ruby_smb/dcerpc/samr/samr_open_domain_request_spec.rb +56 -0
  140. data/spec/lib/ruby_smb/dcerpc/samr/samr_open_domain_response_spec.rb +48 -0
  141. data/spec/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_request_spec.rb +48 -0
  142. data/spec/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_response_spec.rb +42 -0
  143. data/spec/lib/ruby_smb/dcerpc/samr_spec.rb +420 -0
  144. data/spec/lib/ruby_smb/dcerpc/sec_trailer_spec.rb +92 -0
  145. data/spec/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all_spec.rb +149 -110
  146. data/spec/lib/ruby_smb/dcerpc/srvsvc_spec.rb +21 -17
  147. data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request_spec.rb +56 -79
  148. data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response_spec.rb +4 -4
  149. data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response_spec.rb +2 -2
  150. data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_request_spec.rb +2 -2
  151. data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_response_spec.rb +2 -2
  152. data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request_spec.rb +19 -29
  153. data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response_spec.rb +2 -2
  154. data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_request_spec.rb +9 -15
  155. data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_response_spec.rb +2 -2
  156. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request_spec.rb +2 -2
  157. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response_spec.rb +22 -22
  158. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_response_spec.rb +2 -2
  159. data/spec/lib/ruby_smb/dcerpc/svcctl/service_status_spec.rb +18 -14
  160. data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_request_spec.rb +5 -4
  161. data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_response_spec.rb +2 -2
  162. data/spec/lib/ruby_smb/dcerpc/svcctl_spec.rb +1 -5
  163. data/spec/lib/ruby_smb/dcerpc/uuid_spec.rb +15 -23
  164. data/spec/lib/ruby_smb/dcerpc/winreg/close_key_response_spec.rb +2 -2
  165. data/spec/lib/ruby_smb/dcerpc/winreg/create_key_request_spec.rb +4 -41
  166. data/spec/lib/ruby_smb/dcerpc/winreg/create_key_response_spec.rb +4 -4
  167. data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_request_spec.rb +4 -52
  168. data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_response_spec.rb +4 -56
  169. data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_request_spec.rb +10 -34
  170. data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_response_spec.rb +10 -34
  171. data/spec/lib/ruby_smb/dcerpc/winreg/open_key_request_spec.rb +2 -26
  172. data/spec/lib/ruby_smb/dcerpc/winreg/open_key_response_spec.rb +2 -2
  173. data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_request_spec.rb +17 -25
  174. data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_response_spec.rb +2 -2
  175. data/spec/lib/ruby_smb/dcerpc/winreg/query_info_key_response_spec.rb +20 -44
  176. data/spec/lib/ruby_smb/dcerpc/winreg/query_value_request_spec.rb +8 -32
  177. data/spec/lib/ruby_smb/dcerpc/winreg/query_value_response_spec.rb +10 -22
  178. data/spec/lib/ruby_smb/dcerpc/winreg/regsam_spec.rb +4 -0
  179. data/spec/lib/ruby_smb/dcerpc/winreg/save_key_request_spec.rb +0 -12
  180. data/spec/lib/ruby_smb/dcerpc/winreg/save_key_response_spec.rb +2 -2
  181. data/spec/lib/ruby_smb/dcerpc/winreg_spec.rb +18 -47
  182. data/spec/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_request_spec.rb +43 -0
  183. data/spec/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_response_spec.rb +410 -0
  184. data/spec/lib/ruby_smb/dcerpc/wkssvc_spec.rb +70 -0
  185. data/spec/lib/ruby_smb/field/string16_spec.rb +22 -0
  186. data/spec/lib/ruby_smb/gss/provider/ntlm/os_version_spec.rb +1 -1
  187. data/spec/lib/ruby_smb/smb1/pipe_spec.rb +18 -37
  188. data/spec/lib/ruby_smb/smb2/pipe_spec.rb +18 -16
  189. data/spec/support/bin_helper.rb +9 -0
  190. data.tar.gz.sig +0 -0
  191. metadata +96 -5
  192. metadata.gz.sig +0 -0
  193. data/lib/ruby_smb/dcerpc/rrp_unicode_string.rb +0 -38
  194. data/spec/lib/ruby_smb/dcerpc/rrp_unicode_string_spec.rb +0 -135
@@ -2,103 +2,80 @@ module RubySMB
2
2
  module Dcerpc
3
3
  module Srvsvc
4
4
 
5
- #https://msdn.microsoft.com/en-us/library/cc247293.aspx
5
+ # [2.2.1.1 SRVSVC_HANDLE](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-srvs/5f8329ee-1965-4ea1-ad35-3b29fbb63232)
6
+ class SrvsvcHandle < Ndr::NdrWideStringzPtr; end
6
7
 
7
- class NetShareEnumAll < BinData::Record
8
- attr_reader :opnum
8
+ # [2.2.4.23 SHARE_INFO_1](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-srvs/fc69f110-998d-4c16-9667-514e22fdd80b)
9
+ class ShareInfo1Element < Ndr::NdrStruct
10
+ default_parameters byte_align: 4
9
11
 
10
- mandatory_parameter :host
12
+ ndr_wide_stringz_ptr :shi1_netname
13
+ ndr_uint32 :shi1_type
14
+ ndr_wide_stringz_ptr :shi1_remark
15
+ end
11
16
 
12
- endian :little
17
+ class ShareInfo1 < Ndr::NdrConfArray
18
+ default_parameters type: :share_info1_element
19
+ end
13
20
 
14
- uint32 :referent_id, initial_value: 0x00000001
15
- uint32 :max_count, initial_value: -> { server_unc.do_num_bytes / 2 }
16
- uint32 :offset, initial_value: 0
17
- uint32 :actual_count, initial_value: -> {max_count}
18
- stringz16 :server_unc, pad_front: false, read_length: -> { actual_count * 2 },
19
- initial_value: -> {"\\\\#{host.encode('utf-8')}".encode('utf-16le')}
21
+ class LpshareInfo1 < ShareInfo1
22
+ extend Ndr::PointerClassPlugin
23
+ end
20
24
 
21
- string :pad, length: lambda { pad_length }
22
- uint32 :level, initial_value: 1
25
+ # [2.2.4.33 SHARE_INFO_1_CONTAINER](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-srvs/919abd5d-87d9-4ffa-b4b1-632a66053bc6)
26
+ class ShareInfo1Container < Ndr::NdrStruct
27
+ default_parameters byte_align: 4
23
28
 
24
- uint32 :ctr, initial_value: 1
25
- uint32 :ctr_referent_id, initial_value: 0x00000001
26
- uint32 :ctr_count, initial_value: 0
27
- uint32 :pointer_to_array, initial_value: 0
29
+ ndr_uint32 :entries_read
30
+ lpshare_info1 :buffer
31
+ end
28
32
 
29
- uint32 :max_buffer, initial_value: 4294967295
33
+ class LpshareInfo1Container < ShareInfo1Container
34
+ extend Ndr::PointerClassPlugin
35
+ end
30
36
 
31
- uint32 :resume_referent_id, initial_value: 0x00000001
32
- uint32 :resume_handle, initial_value: 0
37
+ # [2.2.4.38 SHARE_ENUM_STRUCT](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-srvs/79ee052e-e16b-4ec5-b4b7-e99777c26eca)
38
+ class LpshareEnumStruct < Ndr::NdrStruct
39
+ hide :switch_value
40
+ default_parameters byte_align: 4
33
41
 
34
- def initialize_instance
35
- super
36
- @opnum = NET_SHARE_ENUM_ALL
37
- end
38
-
39
- def pad_length
40
- offset = (server_unc.abs_offset + server_unc.to_binary_s.length) % 4
41
- (4 - offset) % 4
42
+ ndr_uint32 :level, initial_value: 1
43
+ ndr_uint32 :switch_value, initial_value: :level
44
+ choice :share_info, selection: :level, byte_align: 4 do
45
+ lpshare_info1_container 1, initial_value: { entries_read: 0, buffer: :null }
42
46
  end
47
+ end
43
48
 
44
- def self.parse_response(response)
45
-
46
- shares = []
47
-
48
- res = response.dup
49
- win_error = res.slice!(-4, 4).unpack("V")[0]
50
-
51
- if win_error != 0
52
- raise RuntimeError, "Invalid DCERPC response: win_error = #{win_error}"
53
- end
54
-
55
- # Remove unused data
56
- res.slice!(0, 12) # level, CTR header, Reference ID of CTR
57
- share_count = res.slice!(0, 4).unpack("V")[0]
58
- res.slice!(0, 4) # Reference ID of CTR1
59
- share_max_count = res.slice!(0, 4).unpack("V")[0]
60
-
61
- if share_max_count != share_count
62
- raise RuntimeError, "Invalid DCERPC response: count != count max (#{share_count}/#{share_max_count})"
63
- end
64
-
65
- # ReferenceID / Type / ReferenceID of Comment
66
- types = res.slice!(0, share_count * 12).scan(/.{12}/n).map { |a| a[4, 2].unpack("v")[0] }
67
-
68
- share_count.times do |t|
69
- length, offset, max_length = res.slice!(0, 12).unpack("VVV")
70
- if offset != 0
71
- raise RuntimeError, "Invalid DCERPC response: offset != 0 (#{offset})"
72
- end
73
-
74
- if length != max_length
75
- raise RuntimeError, "Invalid DCERPC response: length !=max_length (#{length}/#{max_length})"
76
- end
77
- name = res.slice!(0, 2 * length).gsub('\x00', '')
78
- res.slice!(0, 2) if length % 2 == 1 # pad
79
-
80
- comment_length, comment_offset, comment_max_length = res.slice!(0, 12).unpack("VVV")
49
+ # [3.1.4.8 NetrShareEnum (Opnum 15)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-srvs/c4a98e7b-d416-439c-97bd-4d9f52f8ba52)
50
+ class NetShareEnumAllRequest < BinData::Record
51
+ attr_reader :opnum
81
52
 
82
- if comment_offset != 0
83
- raise RuntimeError, "Invalid DCERPC response: comment_offset != 0 (#{comment_offset})"
84
- end
53
+ endian :little
85
54
 
86
- if comment_length != comment_max_length
87
- raise RuntimeError, "Invalid DCERPC response: comment_length != comment_max_length (#{comment_length}/#{comment_max_length})"
88
- end
55
+ srvsvc_handle :server_name
56
+ lpshare_enum_struct :info_struct
57
+ ndr_uint32 :prefered_maximum_length, initial_value: 0xFFFFFFFF
58
+ ndr_uint32_ptr :resume_handle, initial_value: 0
89
59
 
90
- comment = res.slice!(0, 2 * comment_length)
60
+ def initialize_instance
61
+ super
62
+ @opnum = NET_SHARE_ENUM_ALL
63
+ end
64
+ end
91
65
 
92
- res.slice!(0, 2) if comment_length % 2 == 1 # pad
66
+ class NetShareEnumAllResponse < BinData::Record
67
+ attr_reader :opnum
93
68
 
94
- name = name.gsub("\x00", "")
95
- s_type = ['DISK', 'PRINTER', 'DEVICE', 'IPC', 'SPECIAL', 'TEMPORARY'][types[t]].gsub("\x00", "")
96
- comment = comment.gsub("\x00", "")
69
+ endian :little
97
70
 
98
- shares << [name, s_type, comment]
99
- end
71
+ lpshare_enum_struct :info_struct
72
+ ndr_uint32 :total_entries
73
+ ndr_uint32_ptr :resume_handle
74
+ ndr_uint32 :error_status
100
75
 
101
- shares
76
+ def initialize_instance
77
+ super
78
+ @opnum = NET_SHARE_ENUM_ALL
102
79
  end
103
80
  end
104
81
  end
@@ -9,16 +9,39 @@ module RubySMB
9
9
  # Operation numbers
10
10
  NET_SHARE_ENUM_ALL = 0xF
11
11
 
12
+ # [2.2.2.4 Share Types](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-srvs/6069f8c0-c93f-43a0-a5b4-7ed447eb4b84)
13
+ SHARE_TYPES = {
14
+ 0x00000000 => 'DISK',
15
+ 0x00000001 => 'PRINTER',
16
+ 0x00000002 => 'DEVICE',
17
+ 0x00000003 => 'IPC',
18
+ 0x02000000 => 'CLUSTER_FS',
19
+ 0x04000000 => 'CLUSTER_SOFS',
20
+ 0x08000000 => 'CLUSTER_DFS'
21
+ }
22
+ STYPE_SPECIAL = 0x80000000
23
+ STYPE_TEMPORARY = 0x40000000
24
+
12
25
  require 'ruby_smb/dcerpc/srvsvc/net_share_enum_all'
13
26
 
14
27
  def net_share_enum_all(host)
28
+ host = "\\\\#{host}" unless host.start_with?('\\\\')
15
29
  bind(endpoint: RubySMB::Dcerpc::Srvsvc)
16
30
 
17
- net_share_enum_all_request_packet = RubySMB::Dcerpc::Srvsvc::NetShareEnumAll.new(host: host)
18
- response = dcerpc_request(net_share_enum_all_request_packet)
31
+ net_share_enum_all_request_packet = RubySMB::Dcerpc::Srvsvc::NetShareEnumAllRequest.new(server_name: host)
32
+ raw_response = dcerpc_request(net_share_enum_all_request_packet)
19
33
 
20
- shares = RubySMB::Dcerpc::Srvsvc::NetShareEnumAll.parse_response(response)
21
- shares.map{|s|{name: s[0], type: s[1], comment: s[2]}}
34
+ response = RubySMB::Dcerpc::Srvsvc::NetShareEnumAllResponse.read(raw_response)
35
+ response.info_struct.share_info.buffer.map do |share|
36
+ type = [SHARE_TYPES[share.shi1_type & 0x0FFFFFFF]]
37
+ type << 'SPECIAL' unless share.shi1_type & STYPE_SPECIAL == 0
38
+ type << 'TEMPORARY' unless share.shi1_type & STYPE_TEMPORARY == 0
39
+ {
40
+ name: share.shi1_netname.encode('UTF-8'),
41
+ type: type.join('|'),
42
+ comment: share.shi1_remark.encode('UTF-8')
43
+ }
44
+ end
22
45
  end
23
46
  end
24
47
  end
@@ -10,36 +10,24 @@ module RubySMB
10
10
 
11
11
  endian :little
12
12
 
13
- sc_rpc_handle :h_service
14
- uint32 :dw_service_type
15
- uint32 :dw_start_type
16
- uint32 :dw_error_control
17
- ndr_lp_str :lp_binary_path_name
18
- string :pad1, length: -> { pad_length(self.lp_binary_path_name) }
19
- ndr_lp_str :lp_load_order_group
20
- string :pad2, length: -> { pad_length(self.lp_load_order_group) }
21
- ndr_lp_dword :dw_tag_id
22
- ndr_lp_byte :lp_dependencies
23
- string :pad3, length: -> { pad_length(self.lp_dependencies) }
24
- uint32 :dw_depend_size, value: -> { self.lp_dependencies.max_count }
25
- ndr_lp_str :lp_service_start_name
26
- string :pad4, length: -> { pad_length(self.lp_service_start_name) }
27
- ndr_lp_byte :lp_password
28
- string :pad5, length: -> { pad_length(self.lp_password) }
29
- uint32 :dw_pw_size, value: -> { self.lp_password.max_count }
30
- ndr_lp_str :lp_display_name
13
+ sc_rpc_handle :h_service
14
+ ndr_uint32 :dw_service_type
15
+ ndr_uint32 :dw_start_type
16
+ ndr_uint32 :dw_error_control
17
+ ndr_wide_string_ptr :lp_binary_path_name
18
+ ndr_wide_string_ptr :lp_load_order_group
19
+ ndr_uint32_ptr :dw_tag_id
20
+ ndr_conf_array :lp_dependencies, type: :ndr_uint8
21
+ ndr_uint32 :dw_depend_size, value: -> { self.lp_dependencies.size }
22
+ ndr_wide_string_ptr :lp_service_start_name
23
+ ndr_conf_array :lp_password, type: :ndr_uint8
24
+ ndr_uint32 :dw_pw_size, value: -> { self.lp_password.size }
25
+ ndr_wide_string_ptr :lp_display_name
31
26
 
32
27
  def initialize_instance
33
28
  super
34
29
  @opnum = CHANGE_SERVICE_CONFIG_W
35
30
  end
36
-
37
- # Determines the correct length for the padding, so that the next
38
- # field is 4-byte aligned.
39
- def pad_length(prev_element)
40
- offset = (prev_element.abs_offset + prev_element.to_binary_s.length) % 4
41
- (4 - offset) % 4
42
- end
43
31
  end
44
32
 
45
33
  end
@@ -10,8 +10,8 @@ module RubySMB
10
10
 
11
11
  endian :little
12
12
 
13
- ndr_lp_dword :dw_tag_id
14
- uint32 :error_status
13
+ ndr_uint32_ptr :dw_tag_id
14
+ ndr_uint32 :error_status
15
15
 
16
16
  def initialize_instance
17
17
  super
@@ -11,7 +11,7 @@ module RubySMB
11
11
  endian :little
12
12
 
13
13
  sc_rpc_handle :h_sc_object
14
- uint32 :error_status
14
+ ndr_uint32 :error_status
15
15
 
16
16
  def initialize_instance
17
17
  super
@@ -11,7 +11,7 @@ module RubySMB
11
11
  endian :little
12
12
 
13
13
  sc_rpc_handle :h_service
14
- uint32 :dw_control
14
+ ndr_uint32 :dw_control
15
15
 
16
16
  def initialize_instance
17
17
  super
@@ -11,7 +11,7 @@ module RubySMB
11
11
  endian :little
12
12
 
13
13
  service_status :lp_service_status
14
- uint32 :error_status
14
+ ndr_uint32 :error_status
15
15
 
16
16
  def initialize_instance
17
17
  super
@@ -2,7 +2,7 @@ module RubySMB
2
2
  module Dcerpc
3
3
  module Svcctl
4
4
 
5
- class SvcctlHandleW < Ndr::NdrLpStr; end
5
+ class SvcctlHandleW < Ndr::NdrWideStringzPtr; end
6
6
 
7
7
  # [3.1.4.15 ROpenSCManagerW (Opnum 15)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/dc84adb3-d51d-48eb-820d-ba1c6ca5faf2)
8
8
  class OpenSCManagerWRequest < BinData::Record
@@ -10,24 +10,14 @@ module RubySMB
10
10
 
11
11
  endian :little
12
12
 
13
- svcctl_handle_w :lp_machine_name
14
- string :pad1, length: -> { pad_length(self.lp_machine_name) }
15
- ndr_lp_str :lp_database_name
16
- string :pad2, length: -> { pad_length(self.lp_database_name) }
17
- uint32 :dw_desired_access
13
+ svcctl_handle_w :lp_machine_name
14
+ ndr_wide_stringz_ptr :lp_database_name
15
+ ndr_uint32 :dw_desired_access
18
16
 
19
17
  def initialize_instance
20
18
  super
21
19
  @opnum = OPEN_SC_MANAGER_W
22
20
  end
23
-
24
- # Determines the correct length for the padding, so that the next
25
- # field is 4-byte aligned.
26
- def pad_length(prev_element)
27
- offset = (prev_element.abs_offset + prev_element.to_binary_s.length) % 4
28
- (4 - offset) % 4
29
- end
30
-
31
21
  end
32
22
 
33
23
  end
@@ -9,7 +9,7 @@ module RubySMB
9
9
  endian :little
10
10
 
11
11
  sc_rpc_handle :lp_sc_handle
12
- uint32 :error_status
12
+ ndr_uint32 :error_status
13
13
 
14
14
  def initialize_instance
15
15
  super
@@ -8,22 +8,14 @@ module RubySMB
8
8
 
9
9
  endian :little
10
10
 
11
- sc_rpc_handle :lp_sc_handle
12
- ndr_string :lp_service_name
13
- string :pad, length: -> { pad_length(self.lp_service_name) }
14
- uint32 :dw_desired_access
11
+ sc_rpc_handle :lp_sc_handle
12
+ ndr_conf_var_wide_stringz :lp_service_name
13
+ ndr_uint32 :dw_desired_access
15
14
 
16
15
  def initialize_instance
17
16
  super
18
17
  @opnum = OPEN_SERVICE_W
19
18
  end
20
-
21
- # Determines the correct length for the padding, so that the next
22
- # field is 4-byte aligned.
23
- def pad_length(prev_element)
24
- offset = (prev_element.abs_offset + prev_element.to_binary_s.length) % 4
25
- (4 - offset) % 4
26
- end
27
19
  end
28
20
 
29
21
  end
@@ -9,7 +9,7 @@ module RubySMB
9
9
  endian :little
10
10
 
11
11
  sc_rpc_handle :lp_sc_handle
12
- uint32 :error_status
12
+ ndr_uint32 :error_status
13
13
 
14
14
  def initialize_instance
15
15
  super
@@ -9,7 +9,7 @@ module RubySMB
9
9
  endian :little
10
10
 
11
11
  sc_rpc_handle :h_service
12
- uint32 :cb_buf_size
12
+ ndr_uint32 :cb_buf_size
13
13
 
14
14
  def initialize_instance
15
15
  super
@@ -4,21 +4,22 @@ module RubySMB
4
4
  module Dcerpc
5
5
  module Svcctl
6
6
 
7
- class LpBoundedDword8k < BinData::Uint32le; end
7
+ class LpBoundedDword8k < RubySMB::Dcerpc::Ndr::NdrUint32; end
8
8
 
9
9
  # [2.2.15 QUERY_SERVICE_CONFIGW](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/97200665-5631-42ea-9917-6f9b41f02391)
10
10
  class QueryServiceConfigW < RubySMB::Dcerpc::Ndr::NdrStruct
11
+ default_parameters byte_align: 4
11
12
  endian :little
12
13
 
13
- uint32 :dw_service_type
14
- uint32 :dw_start_type
15
- uint32 :dw_error_control
16
- ndr_lp_str :lp_binary_path_name
17
- ndr_lp_str :lp_load_order_group
18
- uint32 :dw_tag_id
19
- ndr_lp_str :lp_dependencies
20
- ndr_lp_str :lp_service_start_name
21
- ndr_lp_str :lp_display_name
14
+ ndr_uint32 :dw_service_type
15
+ ndr_uint32 :dw_start_type
16
+ ndr_uint32 :dw_error_control
17
+ ndr_wide_string_ptr :lp_binary_path_name
18
+ ndr_wide_string_ptr :lp_load_order_group
19
+ ndr_uint32 :dw_tag_id
20
+ ndr_wide_string_ptr :lp_dependencies
21
+ ndr_wide_string_ptr :lp_service_start_name
22
+ ndr_wide_string_ptr :lp_display_name
22
23
 
23
24
  end
24
25
 
@@ -30,7 +31,7 @@ module RubySMB
30
31
 
31
32
  query_service_config_w :lp_service_config
32
33
  lp_bounded_dword8k :pcb_bytes_needed
33
- uint32 :error_status
34
+ ndr_uint32 :error_status
34
35
 
35
36
  def initialize_instance
36
37
  super
@@ -11,7 +11,7 @@ module RubySMB
11
11
  endian :little
12
12
 
13
13
  service_status :lp_service_status
14
- uint32 :error_status
14
+ ndr_uint32 :error_status
15
15
 
16
16
  def initialize_instance
17
17
  super
@@ -5,16 +5,17 @@ module RubySMB
5
5
  module Svcctl
6
6
 
7
7
  # [2.2.47 SERVICE_STATUS](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-scmr/4e91ff36-ab5f-49ed-a43d-a308e72b0b3c)
8
- class ServiceStatus < BinData::Record
8
+ class ServiceStatus < Ndr::NdrStruct
9
+ default_parameter byte_align: 4
9
10
  endian :little
10
11
 
11
- uint32 :dw_service_type
12
- uint32 :dw_current_state
13
- uint32 :dw_controls_accepted
14
- uint32 :dw_win32_exit_code
15
- uint32 :dw_service_specific_exit_code
16
- uint32 :dw_check_point
17
- uint32 :dw_wait_hint
12
+ ndr_uint32 :dw_service_type
13
+ ndr_uint32 :dw_current_state
14
+ ndr_uint32 :dw_controls_accepted
15
+ ndr_uint32 :dw_win32_exit_code
16
+ ndr_uint32 :dw_service_specific_exit_code
17
+ ndr_uint32 :dw_check_point
18
+ ndr_uint32 :dw_wait_hint
18
19
  end
19
20
 
20
21
  end
@@ -10,9 +10,9 @@ module RubySMB
10
10
 
11
11
  endian :little
12
12
 
13
- sc_rpc_handle :h_service
14
- uint32 :argc
15
- ndr_lp_string_ptrsw :argv
13
+ sc_rpc_handle :h_service
14
+ ndr_uint32 :argc
15
+ ndr_conf_array :argv, type: :ndr_wide_string_ptr
16
16
 
17
17
  def initialize_instance
18
18
  super
@@ -10,7 +10,7 @@ module RubySMB
10
10
 
11
11
  endian :little
12
12
 
13
- uint32 :error_status
13
+ ndr_uint32 :error_status
14
14
 
15
15
  def initialize_instance
16
16
  super
@@ -417,9 +417,7 @@ module RubySMB
417
417
  ss_request = StartServiceWRequest.new(h_service: svc_handle)
418
418
  unless argv.empty?
419
419
  ss_request.argc = argv.size
420
- ndr_string_ptrsw = RubySMB::Dcerpc::Ndr::NdrStringPtrsw.new
421
- ndr_string_ptrsw.elements = argv
422
- ss_request.argv = ndr_string_ptrsw
420
+ ss_request.argv = argv
423
421
  end
424
422
  response = dcerpc_request(ss_request)
425
423
  begin
@@ -3,6 +3,7 @@ module RubySMB
3
3
 
4
4
  # [Universal Unique Identifier](http://pubs.opengroup.org/onlinepubs/9629399/apdxa.htm)
5
5
  class Uuid < BinData::Primitive
6
+ default_parameter byte_align: 4
6
7
  endian :little
7
8
  uint32 :time_low, label: 'Low field of the timestamp'
8
9
  uint16 :time_mid, label: 'Middle field of the timestamp'
@@ -21,6 +22,8 @@ module RubySMB
21
22
  end
22
23
 
23
24
  def set(uuid_string)
25
+ uuid_string.delete_suffix!('}')
26
+ uuid_string.delete_prefix!('{')
24
27
  components = uuid_string.split('-')
25
28
  self.time_low.read(to_binary_le(components[0]))
26
29
  self.time_mid.read(to_binary_le(components[1]))
@@ -11,8 +11,8 @@ module RubySMB
11
11
 
12
12
  endian :little
13
13
 
14
- rpc_hkey :hkey
15
- uint32 :error_status
14
+ rpc_hkey :hkey
15
+ ndr_uint32 :error_status
16
16
 
17
17
  def initialize_instance
18
18
  super
@@ -45,28 +45,17 @@ module RubySMB
45
45
 
46
46
  rpc_hkey :hkey
47
47
  rrp_unicode_string :lp_sub_key
48
- string :pad1, length: -> { pad_length(self.lp_sub_key) }
49
48
  rrp_unicode_string :lp_class
50
- string :pad2, length: -> { pad_length(self.lp_class) }
51
- uint32 :dw_options
49
+ ndr_uint32 :dw_options
52
50
  regsam :sam_desired
53
51
  prpc_security_attributes :lp_security_attributes
54
- string :pad3, length: -> { pad_length(self.lp_security_attributes) }
55
- ndr_lp_dword :lpdw_disposition
52
+ ndr_uint32_ptr :lpdw_disposition
56
53
 
57
54
  def initialize_instance
58
55
  super
59
56
  @opnum = REG_CREATE_KEY
60
57
  end
61
-
62
- # Determines the correct length for the padding, so that the next
63
- # field is 4-byte aligned.
64
- def pad_length(prev_element)
65
- offset = (prev_element.abs_offset + prev_element.to_binary_s.length) % 4
66
- (4 - offset) % 4
67
- end
68
58
  end
69
-
70
59
  end
71
60
  end
72
61
  end
@@ -17,9 +17,9 @@ module RubySMB
17
17
 
18
18
  endian :little
19
19
 
20
- prpc_hkey :hkey
21
- ndr_lp_dword :lpdw_disposition
22
- uint32 :error_status
20
+ prpc_hkey :hkey
21
+ ndr_uint32_ptr :lpdw_disposition
22
+ ndr_uint32 :error_status
23
23
 
24
24
  def initialize_instance
25
25
  super
@@ -12,33 +12,16 @@ module RubySMB
12
12
  endian :little
13
13
 
14
14
  rpc_hkey :hkey
15
- uint32 :dw_index
16
- rrp_unicode_string :lp_name
17
- string :pad1, length: -> { pad_length1 }
15
+ ndr_uint32 :dw_index
16
+ rrp_unicode_string :lp_name
18
17
  prrp_unicode_string :lp_class
19
- string :pad2, length: -> { pad_length2 }
20
- ndr_lp_file_time :lpft_last_write_time
18
+ ndr_file_time_ptr :lpft_last_write_time
21
19
 
22
20
  def initialize_instance
23
21
  super
24
22
  @opnum = REG_ENUM_KEY
25
23
  end
26
-
27
- # Determines the correct length for the padding in front of
28
- # #lp_class. It should always force a 4-byte alignment.
29
- def pad_length1
30
- offset = (lp_name.abs_offset + lp_name.to_binary_s.length) % 4
31
- (4 - offset) % 4
32
- end
33
-
34
- # Determines the correct length for the padding in front of
35
- # #lpft_last_write_time. It should always force a 4-byte alignment.
36
- def pad_length2
37
- offset = (lp_class.abs_offset + lp_class.to_binary_s.length) % 4
38
- (4 - offset) % 4
39
- end
40
24
  end
41
-
42
25
  end
43
26
  end
44
27
  end
@@ -10,32 +10,15 @@ module RubySMB
10
10
  endian :little
11
11
 
12
12
  rrp_unicode_string :lp_name
13
- string :pad1, length: -> { pad_length1 }
14
- prrp_unicode_string :lp_class, initial_value: 0
15
- string :pad2, length: -> { pad_length2 }
16
- ndr_lp_file_time :lpft_last_write_time
17
- uint32 :error_status
13
+ prrp_unicode_string :lp_class
14
+ ndr_file_time_ptr :lpft_last_write_time
15
+ ndr_uint32 :error_status
18
16
 
19
17
  def initialize_instance
20
18
  super
21
19
  @opnum = REG_ENUM_KEY
22
20
  end
23
-
24
- # Determines the correct length for the padding in front of
25
- # #lp_class. It should always force a 4-byte alignment.
26
- def pad_length1
27
- offset = (lp_name.abs_offset + lp_name.to_binary_s.length) % 4
28
- (4 - offset) % 4
29
- end
30
-
31
- # Determines the correct length for the padding in front of
32
- # #lpft_last_write_time. It should always force a 4-byte alignment.
33
- def pad_length2
34
- offset = (lp_class.abs_offset + lp_class.to_binary_s.length) % 4
35
- (4 - offset) % 4
36
- end
37
21
  end
38
-
39
22
  end
40
23
  end
41
24
  end