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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.github/workflows/verify.yml +1 -1
- data/examples/dump_secrets_from_sid.rb +207 -0
- data/examples/enum_domain_users.rb +75 -0
- data/examples/get_computer_info.rb +42 -0
- data/examples/query_service_status.rb +42 -4
- data/lib/ruby_smb/client.rb +3 -14
- data/lib/ruby_smb/dcerpc/bind.rb +28 -20
- data/lib/ruby_smb/dcerpc/bind_ack.rb +29 -28
- data/lib/ruby_smb/dcerpc/client.rb +542 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_bind_request.rb +24 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_bind_response.rb +26 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_crack_names_request.rb +57 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_crack_names_response.rb +76 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_domain_controller_info_request.rb +46 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_domain_controller_info_response.rb +168 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_extensions.rb +56 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_get_nc_changes_request.rb +121 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_get_nc_changes_response.rb +118 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_unbind_request.rb +24 -0
- data/lib/ruby_smb/dcerpc/drsr/drs_unbind_response.rb +26 -0
- data/lib/ruby_smb/dcerpc/drsr.rb +909 -0
- data/lib/ruby_smb/dcerpc/epm/epm_ept_map_request.rb +26 -0
- data/lib/ruby_smb/dcerpc/epm/epm_ept_map_response.rb +25 -0
- data/lib/ruby_smb/dcerpc/epm/epm_twrt.rb +211 -0
- data/lib/ruby_smb/dcerpc/epm.rb +75 -0
- data/lib/ruby_smb/dcerpc/error.rb +17 -0
- data/lib/ruby_smb/dcerpc/ndr.rb +1159 -297
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request.rb +3 -13
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_response.rb +3 -3
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request.rb +3 -13
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request.rb +3 -11
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/netlogon.rb +5 -4
- data/lib/ruby_smb/dcerpc/p_syntax_id_t.rb +4 -3
- data/lib/ruby_smb/dcerpc/pdu_header.rb +7 -7
- data/lib/ruby_smb/dcerpc/ptypes.rb +1 -0
- data/lib/ruby_smb/dcerpc/request.rb +79 -32
- data/lib/ruby_smb/dcerpc/response.rb +45 -10
- data/lib/ruby_smb/dcerpc/rpc_auth3.rb +28 -0
- data/lib/ruby_smb/dcerpc/rpc_security_attributes.rb +11 -11
- data/lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb +118 -0
- data/lib/ruby_smb/dcerpc/samr/rpc_sid.rb +150 -0
- data/lib/ruby_smb/dcerpc/samr/samr_close_handle_request.rb +23 -0
- data/lib/ruby_smb/dcerpc/samr/samr_close_handle_response.rb +24 -0
- data/lib/ruby_smb/dcerpc/samr/samr_connect_request.rb +32 -0
- data/lib/ruby_smb/dcerpc/samr/samr_connect_response.rb +23 -0
- data/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_request.rb +26 -0
- data/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_response.rb +55 -0
- data/lib/ruby_smb/dcerpc/samr/samr_get_alias_membership_request.rb +48 -0
- data/lib/ruby_smb/dcerpc/samr/samr_get_alias_membership_response.rb +38 -0
- data/lib/ruby_smb/dcerpc/samr/samr_get_groups_for_user_request.rb +23 -0
- data/lib/ruby_smb/dcerpc/samr/samr_get_groups_for_user_response.rb +48 -0
- data/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_request.rb +24 -0
- data/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_response.rb +25 -0
- data/lib/ruby_smb/dcerpc/samr/samr_open_domain_request.rb +27 -0
- data/lib/ruby_smb/dcerpc/samr/samr_open_domain_response.rb +24 -0
- data/lib/ruby_smb/dcerpc/samr/samr_open_user_request.rb +26 -0
- data/lib/ruby_smb/dcerpc/samr/samr_open_user_response.rb +24 -0
- data/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_request.rb +23 -0
- data/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_response.rb +23 -0
- data/lib/ruby_smb/dcerpc/samr.rb +613 -0
- data/lib/ruby_smb/dcerpc/sec_trailer.rb +26 -0
- data/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all.rb +56 -79
- data/lib/ruby_smb/dcerpc/srvsvc.rb +27 -4
- data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request.rb +13 -25
- data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response.rb +2 -2
- data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/svcctl/control_service_request.rb +1 -1
- data/lib/ruby_smb/dcerpc/svcctl/control_service_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request.rb +4 -14
- data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/svcctl/open_service_w_request.rb +3 -11
- data/lib/ruby_smb/dcerpc/svcctl/open_service_w_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request.rb +1 -1
- data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response.rb +12 -11
- data/lib/ruby_smb/dcerpc/svcctl/query_service_status_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/svcctl/service_status.rb +9 -8
- data/lib/ruby_smb/dcerpc/svcctl/start_service_w_request.rb +3 -3
- data/lib/ruby_smb/dcerpc/svcctl/start_service_w_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/svcctl.rb +1 -3
- data/lib/ruby_smb/dcerpc/uuid.rb +3 -0
- data/lib/ruby_smb/dcerpc/winreg/close_key_response.rb +2 -2
- data/lib/ruby_smb/dcerpc/winreg/create_key_request.rb +2 -13
- data/lib/ruby_smb/dcerpc/winreg/create_key_response.rb +3 -3
- data/lib/ruby_smb/dcerpc/winreg/enum_key_request.rb +3 -20
- data/lib/ruby_smb/dcerpc/winreg/enum_key_response.rb +3 -20
- data/lib/ruby_smb/dcerpc/winreg/enum_value_request.rb +5 -14
- data/lib/ruby_smb/dcerpc/winreg/enum_value_response.rb +5 -14
- data/lib/ruby_smb/dcerpc/winreg/open_key_request.rb +1 -9
- data/lib/ruby_smb/dcerpc/winreg/open_key_response.rb +4 -3
- data/lib/ruby_smb/dcerpc/winreg/open_root_key_request.rb +5 -6
- data/lib/ruby_smb/dcerpc/winreg/open_root_key_response.rb +2 -2
- data/lib/ruby_smb/dcerpc/winreg/query_info_key_response.rb +9 -18
- data/lib/ruby_smb/dcerpc/winreg/query_value_request.rb +4 -14
- data/lib/ruby_smb/dcerpc/winreg/query_value_response.rb +7 -15
- data/lib/ruby_smb/dcerpc/winreg/regsam.rb +3 -1
- data/lib/ruby_smb/dcerpc/winreg/save_key_request.rb +0 -9
- data/lib/ruby_smb/dcerpc/winreg/save_key_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/winreg.rb +10 -14
- data/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_request.rb +26 -0
- data/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_response.rb +88 -0
- data/lib/ruby_smb/dcerpc/wkssvc.rb +65 -0
- data/lib/ruby_smb/dcerpc.rb +41 -11
- data/lib/ruby_smb/field/file_time.rb +1 -1
- data/lib/ruby_smb/field/string16.rb +5 -1
- data/lib/ruby_smb/ntlm.rb +18 -2
- data/lib/ruby_smb/smb1/pipe.rb +4 -0
- data/lib/ruby_smb/smb2/pipe.rb +4 -0
- data/lib/ruby_smb/version.rb +1 -1
- data/spec/lib/ruby_smb/client_spec.rb +1 -2
- data/spec/lib/ruby_smb/dcerpc/bind_ack_spec.rb +69 -41
- data/spec/lib/ruby_smb/dcerpc/bind_spec.rb +75 -21
- data/spec/lib/ruby_smb/dcerpc/client_spec.rb +714 -0
- data/spec/lib/ruby_smb/dcerpc/drsr_spec.rb +2169 -0
- data/spec/lib/ruby_smb/dcerpc/ndr_spec.rb +3792 -1373
- data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request_spec.rb +4 -4
- data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request_spec.rb +4 -4
- data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/p_syntax_id_t_spec.rb +18 -4
- data/spec/lib/ruby_smb/dcerpc/pdu_header_spec.rb +27 -1
- data/spec/lib/ruby_smb/dcerpc/request_spec.rb +76 -11
- data/spec/lib/ruby_smb/dcerpc/response_spec.rb +99 -9
- data/spec/lib/ruby_smb/dcerpc/rpc_auth3_spec.rb +75 -0
- data/spec/lib/ruby_smb/dcerpc/rpc_security_attributes_spec.rb +29 -28
- data/spec/lib/ruby_smb/dcerpc/rrp_rpc_unicode_string_spec.rb +340 -0
- data/spec/lib/ruby_smb/dcerpc/samr/rpc_sid_spec.rb +116 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_close_handle_request_spec.rb +40 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_close_handle_response_spec.rb +48 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_connect_request_spec.rb +56 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_connect_response_spec.rb +47 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_request_spec.rb +63 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_response_spec.rb +265 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_request_spec.rb +52 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_lookup_domain_in_sam_server_response_spec.rb +36 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_open_domain_request_spec.rb +56 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_open_domain_response_spec.rb +48 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_request_spec.rb +48 -0
- data/spec/lib/ruby_smb/dcerpc/samr/samr_rid_to_sid_response_spec.rb +42 -0
- data/spec/lib/ruby_smb/dcerpc/samr_spec.rb +420 -0
- data/spec/lib/ruby_smb/dcerpc/sec_trailer_spec.rb +92 -0
- data/spec/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all_spec.rb +149 -110
- data/spec/lib/ruby_smb/dcerpc/srvsvc_spec.rb +21 -17
- data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request_spec.rb +56 -79
- data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response_spec.rb +4 -4
- data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_request_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request_spec.rb +19 -29
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_request_spec.rb +9 -15
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response_spec.rb +22 -22
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/svcctl/service_status_spec.rb +18 -14
- data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_request_spec.rb +5 -4
- data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/svcctl_spec.rb +1 -5
- data/spec/lib/ruby_smb/dcerpc/uuid_spec.rb +15 -23
- data/spec/lib/ruby_smb/dcerpc/winreg/close_key_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/winreg/create_key_request_spec.rb +4 -41
- data/spec/lib/ruby_smb/dcerpc/winreg/create_key_response_spec.rb +4 -4
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_request_spec.rb +4 -52
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_response_spec.rb +4 -56
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_request_spec.rb +10 -34
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_response_spec.rb +10 -34
- data/spec/lib/ruby_smb/dcerpc/winreg/open_key_request_spec.rb +2 -26
- data/spec/lib/ruby_smb/dcerpc/winreg/open_key_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_request_spec.rb +17 -25
- data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/winreg/query_info_key_response_spec.rb +20 -44
- data/spec/lib/ruby_smb/dcerpc/winreg/query_value_request_spec.rb +8 -32
- data/spec/lib/ruby_smb/dcerpc/winreg/query_value_response_spec.rb +10 -22
- data/spec/lib/ruby_smb/dcerpc/winreg/regsam_spec.rb +4 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/save_key_request_spec.rb +0 -12
- data/spec/lib/ruby_smb/dcerpc/winreg/save_key_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/winreg_spec.rb +18 -47
- data/spec/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_request_spec.rb +43 -0
- data/spec/lib/ruby_smb/dcerpc/wkssvc/netr_wksta_get_info_response_spec.rb +410 -0
- data/spec/lib/ruby_smb/dcerpc/wkssvc_spec.rb +70 -0
- data/spec/lib/ruby_smb/field/string16_spec.rb +22 -0
- data/spec/lib/ruby_smb/gss/provider/ntlm/os_version_spec.rb +1 -1
- data/spec/lib/ruby_smb/smb1/pipe_spec.rb +18 -37
- data/spec/lib/ruby_smb/smb2/pipe_spec.rb +18 -16
- data/spec/support/bin_helper.rb +9 -0
- data.tar.gz.sig +0 -0
- metadata +96 -5
- metadata.gz.sig +0 -0
- data/lib/ruby_smb/dcerpc/rrp_unicode_string.rb +0 -38
- 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://
|
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
|
-
|
8
|
-
|
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
|
-
|
12
|
+
ndr_wide_stringz_ptr :shi1_netname
|
13
|
+
ndr_uint32 :shi1_type
|
14
|
+
ndr_wide_stringz_ptr :shi1_remark
|
15
|
+
end
|
11
16
|
|
12
|
-
|
17
|
+
class ShareInfo1 < Ndr::NdrConfArray
|
18
|
+
default_parameters type: :share_info1_element
|
19
|
+
end
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
22
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
uint32 :pointer_to_array, initial_value: 0
|
29
|
+
ndr_uint32 :entries_read
|
30
|
+
lpshare_info1 :buffer
|
31
|
+
end
|
28
32
|
|
29
|
-
|
33
|
+
class LpshareInfo1Container < ShareInfo1Container
|
34
|
+
extend Ndr::PointerClassPlugin
|
35
|
+
end
|
30
36
|
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
83
|
-
raise RuntimeError, "Invalid DCERPC response: comment_offset != 0 (#{comment_offset})"
|
84
|
-
end
|
53
|
+
endian :little
|
85
54
|
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
60
|
+
def initialize_instance
|
61
|
+
super
|
62
|
+
@opnum = NET_SHARE_ENUM_ALL
|
63
|
+
end
|
64
|
+
end
|
91
65
|
|
92
|
-
|
66
|
+
class NetShareEnumAllResponse < BinData::Record
|
67
|
+
attr_reader :opnum
|
93
68
|
|
94
|
-
|
95
|
-
s_type = ['DISK', 'PRINTER', 'DEVICE', 'IPC', 'SPECIAL', 'TEMPORARY'][types[t]].gsub("\x00", "")
|
96
|
-
comment = comment.gsub("\x00", "")
|
69
|
+
endian :little
|
97
70
|
|
98
|
-
|
99
|
-
|
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
|
-
|
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::
|
18
|
-
|
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
|
-
|
21
|
-
|
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
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
@@ -2,7 +2,7 @@ module RubySMB
|
|
2
2
|
module Dcerpc
|
3
3
|
module Svcctl
|
4
4
|
|
5
|
-
class SvcctlHandleW < Ndr::
|
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
|
14
|
-
|
15
|
-
|
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
|
@@ -8,22 +8,14 @@ module RubySMB
|
|
8
8
|
|
9
9
|
endian :little
|
10
10
|
|
11
|
-
sc_rpc_handle
|
12
|
-
|
13
|
-
|
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
|
@@ -4,21 +4,22 @@ module RubySMB
|
|
4
4
|
module Dcerpc
|
5
5
|
module Svcctl
|
6
6
|
|
7
|
-
class LpBoundedDword8k <
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
34
|
+
ndr_uint32 :error_status
|
34
35
|
|
35
36
|
def initialize_instance
|
36
37
|
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 <
|
8
|
+
class ServiceStatus < Ndr::NdrStruct
|
9
|
+
default_parameter byte_align: 4
|
9
10
|
endian :little
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
@@ -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
|
-
|
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
|
data/lib/ruby_smb/dcerpc/uuid.rb
CHANGED
@@ -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]))
|
@@ -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
|
-
|
51
|
-
uint32 :dw_options
|
49
|
+
ndr_uint32 :dw_options
|
52
50
|
regsam :sam_desired
|
53
51
|
prpc_security_attributes :lp_security_attributes
|
54
|
-
|
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
|
@@ -12,33 +12,16 @@ module RubySMB
|
|
12
12
|
endian :little
|
13
13
|
|
14
14
|
rpc_hkey :hkey
|
15
|
-
|
16
|
-
rrp_unicode_string
|
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
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
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
|