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,26 @@
1
+ module RubySMB
2
+ module Dcerpc
3
+ module Epm
4
+
5
+ # [2.2.1.2.5 ept_map Method](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rpce/ab744583-430e-4055-8901-3c6bc007e791)
6
+ # [https://pubs.opengroup.org/onlinepubs/9629399/apdxo.htm](https://pubs.opengroup.org/onlinepubs/9629399/apdxo.htm)
7
+ class EpmEptMapRequest < BinData::Record
8
+ attr_reader :opnum
9
+
10
+ endian :little
11
+
12
+ uuid_ptr :obj
13
+ epm_twrpt :map_tower
14
+ ndr_context_handle :entry_handle
15
+ ndr_uint32 :max_towers
16
+
17
+ def initialize_instance
18
+ super
19
+ @opnum = EPT_MAP
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,25 @@
1
+ module RubySMB
2
+ module Dcerpc
3
+ module Epm
4
+
5
+ # [2.2.1.2.5 ept_map Method](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rpce/ab744583-430e-4055-8901-3c6bc007e791)
6
+ class EpmEptMapResponse < BinData::Record
7
+ attr_reader :opnum
8
+
9
+ endian :little
10
+
11
+ ndr_context_handle :entry_handle
12
+ ndr_uint32 :num_towers
13
+ ndr_conf_var_array :towers, type: :epm_twrpt
14
+ ndr_uint32 :error_status
15
+
16
+ def initialize_instance
17
+ super
18
+ @opnum = EPT_MAP
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,211 @@
1
+ module RubySMB
2
+ module Dcerpc
3
+ module Epm
4
+
5
+ # [Protocol Tower Encoding](https://pubs.opengroup.org/onlinepubs/9629399/apdxl.htm)
6
+ # [Protocol Identifiers](https://pubs.opengroup.org/onlinepubs/9629399/apdxi.htm#tagcjh_28)
7
+
8
+ class EpmFloorInterfaceOrDataIdentifier < Ndr::NdrStruct
9
+ default_parameters byte_align: 1
10
+ endian :little
11
+
12
+ uint16 :lhs_bytecount, byte_align: 1, initial_value: -> {identifier.num_bytes + interface.num_bytes + major_version.num_bytes}
13
+ uint8 :identifier, byte_align: 1, initial_value: 0x0d
14
+ choice :interface, selection: :identifier, byte_align: 1 do
15
+ # TODO
16
+ #oid 0
17
+ uuid :default
18
+ end
19
+ uint16 :major_version, byte_align: 1
20
+ uint16 :rhs_bytecount, byte_align: 1, initial_value: 2
21
+ uint16 :minor_version, byte_align: 1
22
+ end
23
+
24
+ class EpmFloorProtocolIdentifier < Ndr::NdrStruct
25
+ default_parameters byte_align: 1
26
+ endian :little
27
+
28
+ uint16 :lhs_bytecount, byte_align: 1, initial_value: -> {prot_identifier.num_bytes}
29
+ # Protocol Identifiers:
30
+ # 0x00: "OSI Object Identifier [OID]"
31
+ # 0x02: "DNA Session Control Phase 4"
32
+ # 0x03: "DNA Session Control V3 Phase 5"
33
+ # 0x04: "DNA NSP Transport"
34
+ # 0x05: "OSI TP4 [T-Selector]"
35
+ # 0x06: "OSI CLNS [NSAP]"
36
+ # 0x07: "DOD TCP port"
37
+ # 0x08: "DOD UDP port"
38
+ # 0x09: "DOD IP v4 big-endian"
39
+ # 0x0a: "RPC Connectionless v4"
40
+ # 0x0b: "RPC Connection-oriented v5"
41
+ # 0x0c: "MS Named Pipes"
42
+ # 0x0d: "UUID"
43
+ # 0x0e: "ncadg_ipx"
44
+ # 0x0f: "NetBIOS Named Pipes"
45
+ # 0x10: "MS Named Pipe Name" or "Local InterProcess Communication (LRPC)")
46
+ # 0x11: "MS NetBIOS"
47
+ # 0x12: "MS NetBEUI"
48
+ # 0x13: "Netware SPX"
49
+ # 0x14: "Netware IPX"
50
+ # 0x15: "NMP_TOWER_ID"
51
+ # 0x16: "Appletalk Stream [endpoint]"
52
+ # 0x17: "Appletalk Datagram [endpoint]"
53
+ # 0x18: "Appletalk [NBP-style Name]"
54
+ # 0x19: "NetBIOS [CL on all protocols]"
55
+ # 0x1a: "VINES SPP"
56
+ # 0x1b: "VINES IPC"
57
+ # 0x1c: "StreetTalk [name]"
58
+ # 0x1d: "MSMQ"
59
+ # 0x1f: "MS IIS (http)"
60
+ # 0x20: "Unix Domain socket [pathname]"
61
+ # 0x21: "null"
62
+ # 0x22: "NetBIOS name"
63
+ uint8 :prot_identifier, byte_align: 1, initial_value: 0x0b
64
+ uint16 :rhs_bytecount, byte_align: 1, initial_value: 2
65
+ uint16 :minor_version, byte_align: 1
66
+ end
67
+
68
+ class EpmFloorPipeOrHost < Ndr::NdrStruct
69
+ default_parameters byte_align: 1
70
+ endian :little
71
+
72
+ uint16 :lhs_bytecount, byte_align: 1, initial_value: -> {identifier.num_bytes}
73
+ # :identifier defines what :name is
74
+ # 0x10: MS Named pipe name
75
+ # 0x0c: ncalrpc pipe name (local interprocess communication)
76
+ # 0x0f: NetBIOS pipe name
77
+ # default: Host name
78
+ uint8 :identifier, byte_align: 1
79
+ uint16 :rhs_bytecount, byte_align: 1, initial_value: -> { name.length }
80
+ ndr_fixed_byte_array :name, initial_length: :rhs_bytecount
81
+ end
82
+
83
+ class EpmFloorPipeOrPort < Ndr::NdrStruct
84
+ default_parameters byte_align: 1
85
+ endian :little
86
+
87
+ uint16 :lhs_bytecount, byte_align: 1, initial_value: -> {identifier.num_bytes}
88
+ # :identifier defines what :pipe_or_port is
89
+ # 0x10: MS Named pipe name
90
+ # 0x0c: ncalrpc pipe name (local interprocess communication)
91
+ # 0x0f: NetBIOS pipe name
92
+ # 0x07: DOD TCP port
93
+ # 0x08: DOD UCP port
94
+ # 0x13: Netware SPX port
95
+ # 0x14: Netware IPX port
96
+ # 0x1a: VINES SPP port
97
+ # 0x1b: VINES IPC port
98
+ # 0x1f: Default port
99
+ # default: Default port
100
+ uint8 :identifier, byte_align: 1, initial_value: 0x07
101
+ uint16 :rhs_bytecount, byte_align: 1, initial_value: -> { pipe_or_port.num_bytes }
102
+ choice :pipe_or_port, selection: :identifier, byte_align: 1 do
103
+ ndr_fixed_byte_array 0x10, initial_length: :rhs_bytecount
104
+ ndr_fixed_byte_array 0x0c, initial_length: :rhs_bytecount
105
+ ndr_fixed_byte_array 0x0f, initial_length: :rhs_bytecount
106
+ uint16be 0x07
107
+ uint16be 0x08
108
+ uint16be 0x13
109
+ uint16be 0x14
110
+ uint16be 0x1a
111
+ uint16be 0x1b
112
+ uint16be 0x1f
113
+ ndr_fixed_byte_array :default, initial_length: :rhs_bytecount
114
+ end
115
+ end
116
+
117
+ class EpmIpv4Address < BinData::Uint32be
118
+ default_parameters byte_align: 1
119
+ end
120
+
121
+ class EpmIpxSpxAddress < Ndr::NdrStruct
122
+ default_parameters byte_align: 1
123
+ endian :little
124
+
125
+ int32 :net, byte_align: 1
126
+ int48 :node, byte_align: 1
127
+ end
128
+
129
+ class EpmFloorHostOrAddr < Ndr::NdrStruct
130
+ default_parameters byte_align: 1
131
+ endian :little
132
+
133
+ uint16 :lhs_bytecount, byte_align: 1, initial_value: -> {identifier.num_bytes}
134
+ # :identifier defines what :host_or_addr is
135
+ # 0x11: MS NetBIOS host name
136
+ # 0x12: MS NetBEUI host name
137
+ # 0x22: NetBIOS name
138
+ # 0x09: DOD IP v4 address (big-endian)
139
+ # 0x13: Netware SPX address
140
+ # 0x14: Netware IPX address
141
+ # 0x00: IP v6 address
142
+ # default: Default address
143
+ uint8 :identifier, byte_align: 1, initial_value: 0x09
144
+ uint16 :rhs_bytecount, byte_align: 1, initial_value: -> { host_or_addr.num_bytes }
145
+ choice :host_or_addr, selection: :identifier, byte_align: 1 do
146
+ ndr_fixed_byte_array 0x11, initial_length: :rhs_bytecount
147
+ ndr_fixed_byte_array 0x12, initial_length: :rhs_bytecount
148
+ ndr_fixed_byte_array 0x22, initial_length: :rhs_bytecount
149
+ epm_ipv4_address 0x09
150
+ epm_ipx_spx_address 0x13
151
+ epm_ipx_spx_address 0x14
152
+ choice 0x00, selection: -> {rhs_bytecount.num_bytes} do
153
+ ndr_fixed_byte_array 16, initial_length: 16
154
+ ndr_fixed_byte_array :default, initial_length: :rhs_bytecount
155
+ end
156
+ ndr_fixed_byte_array :default, initial_length: :rhs_bytecount
157
+ end
158
+ end
159
+
160
+ class EpmDecodedTowerOctetString < Ndr::NdrStruct
161
+ default_parameters byte_align: 1
162
+ endian :little
163
+
164
+ uint16 :floor_count, byte_align: 1, initial_value: 5
165
+ epm_floor_interface_or_data_identifier :interface_identifier
166
+ epm_floor_interface_or_data_identifier :data_representation
167
+ epm_floor_protocol_identifier :protocol_identifier
168
+ epm_floor_pipe_or_host :pipe_or_host, onlyif: -> {self.floor_count == 4}
169
+ epm_floor_pipe_or_port :pipe_or_port, onlyif: -> {self.floor_count == 5}
170
+ epm_floor_host_or_addr :host_or_addr, onlyif: -> {self.floor_count == 5}
171
+ # TODO:
172
+ #epm_floor4_decnet :session_ctrl, only_if: -> {self.floor_count == 6}
173
+ #epm_floor5_decnet :nsp_transport, only_if: -> {self.floor_count == 6}
174
+ #epm_floor6_decnet :nsap_routing, only_if: -> {self.floor_count == 6}
175
+ end
176
+
177
+ class EpmTowerOctetString < Ndr::NdrConfArray
178
+ default_parameters type: :ndr_uint8
179
+ end
180
+
181
+ # [2.2.1.2.2 twr_t Type](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rpce/7888714d-0c2a-48a0-b39a-6062ee3fd1d7)
182
+ class EpmTwrt < Ndr::NdrStruct
183
+ default_parameters byte_align: 4
184
+ endian :little
185
+
186
+ ndr_uint32 :tower_length, initial_value: -> { self.tower_octet_string.num_bytes }
187
+ epm_tower_octet_string :tower_octet_string
188
+
189
+ def assign(val)
190
+ case val
191
+ when String
192
+ self.tower_octet_string.assign(val.bytes)
193
+ when Array
194
+ self.tower_octet_string.assign(val.to_ary)
195
+ when EpmDecodedTowerOctetString
196
+ self.tower_octet_string.assign(val.to_binary_s.bytes)
197
+ else
198
+ super
199
+ end
200
+ end
201
+ end
202
+
203
+ class EpmTwrpt < EpmTwrt
204
+ default_parameters referent_byte_align: 4
205
+ extend Ndr::PointerClassPlugin
206
+ end
207
+
208
+ end
209
+ end
210
+ end
211
+
@@ -0,0 +1,75 @@
1
+ module RubySMB
2
+ module Dcerpc
3
+ module Epm
4
+
5
+ UUID = 'E1AF8308-5D1F-11C9-91A4-08002B14A0FA'
6
+ VER_MAJOR = 3
7
+ VER_MINOR = 0
8
+
9
+ # Operation numbers
10
+ EPT_MAP = 0x0003
11
+
12
+ require 'ruby_smb/dcerpc/epm/epm_twrt'
13
+ require 'ruby_smb/dcerpc/epm/epm_ept_map_request'
14
+ require 'ruby_smb/dcerpc/epm/epm_ept_map_response'
15
+
16
+ # Retrieve the service port number given a DCERPC interface UUID
17
+ # See:
18
+ # [2.2.1.2.5 ept_map Method](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rpce/ab744583-430e-4055-8901-3c6bc007e791)
19
+ # [https://pubs.opengroup.org/onlinepubs/9629399/apdxo.htm](https://pubs.opengroup.org/onlinepubs/9629399/apdxo.htm)
20
+ #
21
+ # @param uuid [String] The interface UUID
22
+ # @param maj_ver [Integer] The interface Major version
23
+ # @param min_ver [Integer] The interface Minor version
24
+ # @param max_towers [Integer] The maximum number of elements to be returned
25
+ # @return [Hash] A hash with the host and port
26
+ # @raise [RubySMB::Dcerpc::Error::InvalidPacket] if the response is not a
27
+ # EpmEptMap packet
28
+ # @raise [RubySMB::Dcerpc::Error::EpmError] if the response error status
29
+ # is not STATUS_SUCCESS
30
+ def get_host_port_from_ept_mapper(uuid:, maj_ver:, min_ver:, max_towers: 1)
31
+ decoded_tower = EpmDecodedTowerOctetString.new(
32
+ interface_identifier: {
33
+ interface: uuid,
34
+ major_version: maj_ver,
35
+ minor_version: min_ver
36
+ },
37
+ data_representation: {
38
+ interface: Ndr::UUID,
39
+ major_version: Ndr::VER_MAJOR,
40
+ minor_version: Ndr::VER_MINOR
41
+ }
42
+ )
43
+ tower = EpmTwrt.new(decoded_tower)
44
+ ept_map_request = EpmEptMapRequest.new(
45
+ obj: Uuid.new,
46
+ map_tower: tower,
47
+ entry_handle: Ndr::NdrContextHandle.new,
48
+ max_towers: max_towers
49
+ )
50
+ response = dcerpc_request(ept_map_request)
51
+ begin
52
+ ept_map_response = EpmEptMapResponse.read(response)
53
+ rescue IOError
54
+ raise RubySMB::Dcerpc::Error::InvalidPacket, 'Error reading EptMapResponse'
55
+ end
56
+ unless ept_map_response.error_status == WindowsError::NTStatus::STATUS_SUCCESS
57
+ raise RubySMB::Dcerpc::Error::EpmError,
58
+ "Error returned with ept_map: "\
59
+ "#{WindowsError::NTStatus.find_by_retval(ept_map_response.error_status.value).join(',')}"
60
+ end
61
+ tower_binary = ept_map_response.towers[0].tower_octet_string.to_binary_s
62
+ begin
63
+ decoded_tower = EpmDecodedTowerOctetString.read(tower_binary)
64
+ rescue IOError
65
+ raise RubySMB::Dcerpc::Error::InvalidPacket, 'Error reading EpmDecodedTowerOctetString'
66
+ end
67
+ {
68
+ port: decoded_tower.pipe_or_port.pipe_or_port.to_i,
69
+ host: decoded_tower.host_or_addr.host_or_addr.to_i
70
+ }
71
+ end
72
+ end
73
+ end
74
+ end
75
+
@@ -1,3 +1,5 @@
1
+ require 'ruby_smb/error'
2
+
1
3
  module RubySMB
2
4
  # Contains all the DCERPC specific Error classes.
3
5
  module Dcerpc
@@ -16,6 +18,21 @@ module RubySMB
16
18
 
17
19
  # Raised when an error is returned during a Svcctl operation
18
20
  class SvcctlError < DcerpcError; end
21
+
22
+ # Raised when an error is returned during a Samr operation
23
+ class SamrError < DcerpcError; end
24
+
25
+ # Raised when an error is returned during a Wkssvc operation
26
+ class WkssvcError < DcerpcError; end
27
+
28
+ # Raised when an error is returned during a Drsr operation
29
+ class DrsrError < DcerpcError; end
30
+
31
+ # Raised when an error occurs with the underlying socket.
32
+ class CommunicationError < DcerpcError; end
33
+
34
+ # Raised when an error is returned during a Epm operation
35
+ class EpmError < DcerpcError; end
19
36
  end
20
37
  end
21
38
  end