ruby_smb 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/ruby_smb/dcerpc.rb +3 -1
- data/lib/ruby_smb/dcerpc/ndr.rb +97 -0
- data/lib/ruby_smb/dcerpc/netlogon.rb +101 -0
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request.rb +28 -0
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_response.rb +26 -0
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request.rb +27 -0
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_response.rb +23 -0
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request.rb +25 -0
- data/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response.rb +24 -0
- data/lib/ruby_smb/dcerpc/request.rb +6 -0
- data/lib/ruby_smb/smb1/pipe.rb +4 -2
- data/lib/ruby_smb/smb2/pipe.rb +6 -4
- data/lib/ruby_smb/version.rb +1 -1
- data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request_spec.rb +69 -0
- data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_response_spec.rb +53 -0
- data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request_spec.rb +69 -0
- data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_response_spec.rb +37 -0
- data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request_spec.rb +45 -0
- data/spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response_spec.rb +37 -0
- metadata +21 -2
- metadata.gz.sig +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 896580b7c9baf63e5028f31462f29555a8db4e74e85d5e16b451f41336d3be62
|
4
|
+
data.tar.gz: 534d7f287cd36e68e1a385f5f639ade86a6f1b8b2ca308417ce8f5a66239743e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 656efd29de839b2eb6ef4cc79aa098ca2570d13795510987ccb9b30a6d0e5ec3d052626c17dcb9a879aab6ca9a9993e0361912dffde303a254f72c0c5e504abc
|
7
|
+
data.tar.gz: 9c88d2a160ed0dfa16ec3a953f3b91a74b380b4c132e3d681d36bcf2fbd4a6a78f8ac7aa5f29920e739f41dacb74b661b5cbf81750ea78359b893ec044139a80
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/ruby_smb/dcerpc.rb
CHANGED
@@ -13,14 +13,16 @@ module RubySMB
|
|
13
13
|
require 'ruby_smb/dcerpc/rpc_security_attributes'
|
14
14
|
require 'ruby_smb/dcerpc/pdu_header'
|
15
15
|
require 'ruby_smb/dcerpc/srvsvc'
|
16
|
-
require 'ruby_smb/dcerpc/winreg'
|
17
16
|
require 'ruby_smb/dcerpc/svcctl'
|
17
|
+
require 'ruby_smb/dcerpc/winreg'
|
18
|
+
require 'ruby_smb/dcerpc/netlogon'
|
18
19
|
require 'ruby_smb/dcerpc/request'
|
19
20
|
require 'ruby_smb/dcerpc/response'
|
20
21
|
require 'ruby_smb/dcerpc/bind'
|
21
22
|
require 'ruby_smb/dcerpc/bind_ack'
|
22
23
|
|
23
24
|
|
25
|
+
|
24
26
|
# Bind to the remote server interface endpoint.
|
25
27
|
#
|
26
28
|
# @param options [Hash] the options to pass to the Bind request packet. At least, :endpoint must but provided with an existing Dcerpc class
|
data/lib/ruby_smb/dcerpc/ndr.rb
CHANGED
@@ -7,6 +7,9 @@ module RubySMB
|
|
7
7
|
VER_MAJOR = 2
|
8
8
|
VER_MINOR = 0
|
9
9
|
|
10
|
+
# An NDR Enum type as defined in
|
11
|
+
# [Transfer Syntax NDR - Enumerated Types](https://pubs.opengroup.org/onlinepubs/9629399/chap14.htm#tagcjh_19_02_05_01)
|
12
|
+
class NdrEnum < BinData::Int16le; end
|
10
13
|
|
11
14
|
# An NDR Conformant and Varying String representation as defined in
|
12
15
|
# [Transfer Syntax NDR - Conformant and Varying Strings](http://pubs.opengroup.org/onlinepubs/9629399/chap14.htm#tagcjh_19_03_04_02)
|
@@ -92,6 +95,100 @@ module RubySMB
|
|
92
95
|
end
|
93
96
|
end
|
94
97
|
|
98
|
+
# An NDR Uni-dimensional Fixed Array of bytes representation as defined in:
|
99
|
+
# [Transfer Syntax NDR - NDR Constructed Types](https://pubs.opengroup.org/onlinepubs/9629399/chap14.htm#tagcjh_19_03_03_01)
|
100
|
+
class NdrFixedByteArray < BinData::BasePrimitive
|
101
|
+
optional_parameters :read_length, :length, :pad_byte, :pad_front
|
102
|
+
default_parameters pad_byte: 0
|
103
|
+
mutually_exclusive_parameters :length, :value
|
104
|
+
|
105
|
+
def initialize_shared_instance
|
106
|
+
if (has_parameter?(:value) || has_parameter?(:asserted_value)) && !has_parameter?(:read_length)
|
107
|
+
extend WarnNoReadLengthPlugin
|
108
|
+
end
|
109
|
+
super
|
110
|
+
end
|
111
|
+
|
112
|
+
def assign(val)
|
113
|
+
super(fixed_byte_array(val))
|
114
|
+
end
|
115
|
+
|
116
|
+
def snapshot
|
117
|
+
clamp_to_length(super)
|
118
|
+
end
|
119
|
+
|
120
|
+
class << self
|
121
|
+
def arg_processor
|
122
|
+
NdrFixedByteArrayArgProcessor.new
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
def clamp_to_length(val)
|
129
|
+
val = fixed_byte_array(val)
|
130
|
+
len = eval_parameter(:length) || val.length
|
131
|
+
if val.length > len
|
132
|
+
val = val.first(len)
|
133
|
+
elsif val.length < len
|
134
|
+
pad = eval_parameter(:pad_byte)
|
135
|
+
if get_parameter(:pad_front)
|
136
|
+
val = val.insert(0, *Array.new(len - val.length, pad))
|
137
|
+
else
|
138
|
+
val = val.fill(pad, val.length...len)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
val
|
143
|
+
end
|
144
|
+
|
145
|
+
def fixed_byte_array(val)
|
146
|
+
val = val.bytes if val.is_a? String
|
147
|
+
val.to_ary
|
148
|
+
end
|
149
|
+
|
150
|
+
def read_and_return_value(io)
|
151
|
+
len = eval_parameter(:read_length) || eval_parameter(:length) || 0
|
152
|
+
io.readbytes(len)
|
153
|
+
end
|
154
|
+
|
155
|
+
def sensible_default
|
156
|
+
[ ]
|
157
|
+
end
|
158
|
+
|
159
|
+
def value_to_binary_string(val)
|
160
|
+
clamp_to_length(val).pack('C*')
|
161
|
+
end
|
162
|
+
|
163
|
+
class NdrFixedByteArrayArgProcessor < BinData::BaseArgProcessor
|
164
|
+
def sanitize_parameters!(obj_class, obj_params)
|
165
|
+
obj_params.must_be_integer(:length, :pad_byte)
|
166
|
+
obj_params.sanitize(:pad_byte) { |byte| sanitized_pad_byte(byte) }
|
167
|
+
end
|
168
|
+
|
169
|
+
private
|
170
|
+
|
171
|
+
def sanitized_pad_byte(byte)
|
172
|
+
if byte.is_a?(String)
|
173
|
+
raise ArgumentError, ':pad_byte must not contain more than 1 byte' if byte.bytesize > 1
|
174
|
+
|
175
|
+
byte = byte.ord
|
176
|
+
end
|
177
|
+
raise ArgumentError, ':pad_byte must be within the range of 0 - 255' unless ((byte >= 0) && (byte <= 255))
|
178
|
+
|
179
|
+
byte
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# Warns when reading if :value && no :read_length
|
184
|
+
module WarnNoReadLengthPlugin
|
185
|
+
def read_and_return_value(io)
|
186
|
+
warn "#{debug_name} does not have a :read_length parameter - returning empty array"
|
187
|
+
""
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
95
192
|
# An NDR Context Handle representation as defined in
|
96
193
|
# [IDL Data Type Declarations - Basic Type Declarations](http://pubs.opengroup.org/onlinepubs/9629399/apdxn.htm#tagcjh_34_01)
|
97
194
|
class NdrContextHandle < BinData::Primitive
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module RubySMB
|
2
|
+
module Dcerpc
|
3
|
+
module Netlogon
|
4
|
+
|
5
|
+
# see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/592edbc8-f6f1-40c0-9ab3-fe6725ac6d7e
|
6
|
+
UUID = '12345678-1234-abcd-ef00-01234567cffb'
|
7
|
+
VER_MAJOR = 1
|
8
|
+
VER_MINOR = 0
|
9
|
+
|
10
|
+
# Operation numbers
|
11
|
+
NETR_SERVER_REQ_CHALLENGE = 4
|
12
|
+
NETR_SERVER_AUTHENTICATE3 = 26
|
13
|
+
NETR_SERVER_PASSWORD_SET2 = 30
|
14
|
+
|
15
|
+
# see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/3b224201-b531-43e2-8c79-b61f6dea8640
|
16
|
+
class LogonsrvHandle < Ndr::NdrLpStr; end
|
17
|
+
|
18
|
+
# see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/d55e2632-7163-4f6c-b662-4b870e8cc1cd
|
19
|
+
class NetlogonCredential < Ndr::NdrFixedByteArray
|
20
|
+
default_parameters length: 8
|
21
|
+
end
|
22
|
+
|
23
|
+
# see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/76c93227-942a-4687-ab9d-9d972ffabdab
|
24
|
+
class NetlogonAuthenticator < BinData::Record
|
25
|
+
endian :little
|
26
|
+
|
27
|
+
netlogon_credential :credential
|
28
|
+
uint32 :timestamp
|
29
|
+
end
|
30
|
+
|
31
|
+
# see: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/4d1235e3-2c96-4e9f-a147-3cb338a0d09f
|
32
|
+
class NetlogonSecureChannelType < Ndr::NdrEnum
|
33
|
+
# enum example from dmendel/bindata#38 https://github.com/dmendel/bindata/issues/38#issuecomment-46397163
|
34
|
+
ALL = {
|
35
|
+
0 => :NullSecureChannel,
|
36
|
+
1 => :MsvApSecureChannel,
|
37
|
+
2 => :WorkstationSecureChannel,
|
38
|
+
3 => :TrustedDnsDomainSecureChannel,
|
39
|
+
4 => :TrustedDomainSecureChannel,
|
40
|
+
5 => :UasServerSecureChannel,
|
41
|
+
6 => :ServerSecureChannel,
|
42
|
+
7 => :CdcServerSecureChannel
|
43
|
+
}
|
44
|
+
ALL.each_pair { |val,sym| const_set(sym.to_s.gsub(/([a-z])([A-Z])/, '\1_\2').upcase, val) }
|
45
|
+
default_parameter assert: -> { ALL.keys.include? value }
|
46
|
+
|
47
|
+
def as_enum
|
48
|
+
ALL[value]
|
49
|
+
end
|
50
|
+
|
51
|
+
def assign(val)
|
52
|
+
if val.is_a? Symbol
|
53
|
+
val = ALL.key(val)
|
54
|
+
raise ArgumentError, 'invalid value name' if val.nil?
|
55
|
+
end
|
56
|
+
|
57
|
+
super
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
require 'ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request'
|
62
|
+
require 'ruby_smb/dcerpc/netlogon/netr_server_authenticate3_response'
|
63
|
+
require 'ruby_smb/dcerpc/netlogon/netr_server_password_set2_request'
|
64
|
+
require 'ruby_smb/dcerpc/netlogon/netr_server_password_set2_response'
|
65
|
+
require 'ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request'
|
66
|
+
require 'ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response'
|
67
|
+
|
68
|
+
# Calculate the netlogon session key from the provided shared secret and
|
69
|
+
# challenges. The shared secret is an NTLM hash.
|
70
|
+
#
|
71
|
+
# @param shared_secret [String] the share secret between the client and the server
|
72
|
+
# @param client_challenge [String] the client challenge portion of the negotiation
|
73
|
+
# @param server_challenge [String] the server challenge portion of the negotiation
|
74
|
+
# @return [String] the session key for encryption
|
75
|
+
def self.calculate_session_key(shared_secret, client_challenge, server_challenge)
|
76
|
+
client_challenge = client_challenge.to_binary_s if client_challenge.is_a? NetlogonCredential
|
77
|
+
server_challenge = server_challenge.to_binary_s if server_challenge.is_a? NetlogonCredential
|
78
|
+
|
79
|
+
hmac = OpenSSL::HMAC.new(shared_secret, OpenSSL::Digest::SHA256.new)
|
80
|
+
hmac << client_challenge
|
81
|
+
hmac << server_challenge
|
82
|
+
hmac.digest.first(16)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Encrypt the input data using the specified session key. This is used for
|
86
|
+
# certain Netlogon service operations including the authentication
|
87
|
+
# process. Per the specification, this uses AES-128-CFB8 with an all zero
|
88
|
+
# initialization vector.
|
89
|
+
#
|
90
|
+
# @param session_key [String] the session key to use for encryption (must be 16 bytes long)
|
91
|
+
# @param input_data [String] the data to encrypt
|
92
|
+
# @return [String] the encrypted data
|
93
|
+
def self.encrypt_credential(session_key, input_data)
|
94
|
+
cipher = OpenSSL::Cipher.new('AES-128-CFB8').encrypt
|
95
|
+
cipher.iv = "\x00" * 16
|
96
|
+
cipher.key = session_key
|
97
|
+
cipher.update(input_data) + cipher.final
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'ruby_smb/dcerpc/ndr'
|
2
|
+
|
3
|
+
module RubySMB
|
4
|
+
module Dcerpc
|
5
|
+
module Netlogon
|
6
|
+
|
7
|
+
# [3.5.4.4.2 NetrServerAuthenticate3 (Opnum 26)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/3a9ed16f-8014-45ae-80af-c0ecb06e2db9)
|
8
|
+
class NetrServerAuthenticate3Request < BinData::Record
|
9
|
+
attr_reader :opnum
|
10
|
+
|
11
|
+
endian :little
|
12
|
+
|
13
|
+
logonsrv_handle :primary_name
|
14
|
+
ndr_string :account_name
|
15
|
+
netlogon_secure_channel_type :secure_channel_type
|
16
|
+
ndr_string :computer_name
|
17
|
+
netlogon_credential :client_credential
|
18
|
+
uint32 :flags
|
19
|
+
|
20
|
+
def initialize_instance
|
21
|
+
super
|
22
|
+
@opnum = NETR_SERVER_AUTHENTICATE3
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'ruby_smb/dcerpc/ndr'
|
2
|
+
|
3
|
+
module RubySMB
|
4
|
+
module Dcerpc
|
5
|
+
module Netlogon
|
6
|
+
|
7
|
+
# [3.5.4.4.2 NetrServerAuthenticate3 (Opnum 26)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/3a9ed16f-8014-45ae-80af-c0ecb06e2db9)
|
8
|
+
class NetrServerAuthenticate3Response < BinData::Record
|
9
|
+
attr_reader :opnum
|
10
|
+
|
11
|
+
endian :little
|
12
|
+
|
13
|
+
netlogon_credential :server_credential
|
14
|
+
uint32 :negotiate_flags
|
15
|
+
uint32 :account_rid
|
16
|
+
uint32 :error_status
|
17
|
+
|
18
|
+
def initialize_instance
|
19
|
+
super
|
20
|
+
@opnum = NETR_SERVER_AUTHENTICATE3
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ruby_smb/dcerpc/ndr'
|
2
|
+
|
3
|
+
module RubySMB
|
4
|
+
module Dcerpc
|
5
|
+
module Netlogon
|
6
|
+
|
7
|
+
# [3.5.4.4.5 NetrServerPasswordSet2 (Opnum 30)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/14b020a8-0bcf-4af5-ab72-cc92bc6b1d81)
|
8
|
+
class NetrServerPasswordSet2Request < BinData::Record
|
9
|
+
attr_reader :opnum
|
10
|
+
|
11
|
+
endian :little
|
12
|
+
|
13
|
+
logonsrv_handle :primary_name
|
14
|
+
ndr_string :account_name
|
15
|
+
netlogon_secure_channel_type :secure_channel_type
|
16
|
+
ndr_string :computer_name
|
17
|
+
netlogon_authenticator :authenticator
|
18
|
+
ndr_fixed_byte_array :clear_new_password, length: 516 # this is an encrypted NL_TRUST_PASSWORD
|
19
|
+
|
20
|
+
def initialize_instance
|
21
|
+
super
|
22
|
+
@opnum = Netlogon::NETR_SERVER_PASSWORD_SET2
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'ruby_smb/dcerpc/ndr'
|
2
|
+
|
3
|
+
module RubySMB
|
4
|
+
module Dcerpc
|
5
|
+
module Netlogon
|
6
|
+
|
7
|
+
# [3.5.4.4.5 NetrServerPasswordSet2 (Opnum 30)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/14b020a8-0bcf-4af5-ab72-cc92bc6b1d81)
|
8
|
+
class NetrServerPasswordSet2Response < BinData::Record
|
9
|
+
attr_reader :opnum
|
10
|
+
|
11
|
+
endian :little
|
12
|
+
|
13
|
+
netlogon_authenticator :return_authenticator
|
14
|
+
uint32 :error_status
|
15
|
+
|
16
|
+
def initialize_instance
|
17
|
+
super
|
18
|
+
@opnum = Netlogon::NETR_SERVER_PASSWORD_SET2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'ruby_smb/dcerpc/ndr'
|
2
|
+
|
3
|
+
module RubySMB
|
4
|
+
module Dcerpc
|
5
|
+
module Netlogon
|
6
|
+
|
7
|
+
# [3.5.4.4.1 NetrServerReqChallenge (Opnum 4)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/5ad9db9f-7441-4ce5-8c7b-7b771e243d32)
|
8
|
+
class NetrServerReqChallengeRequest < BinData::Record
|
9
|
+
attr_reader :opnum
|
10
|
+
|
11
|
+
endian :little
|
12
|
+
|
13
|
+
logonsrv_handle :primary_name
|
14
|
+
ndr_string :computer_name
|
15
|
+
netlogon_credential :client_challenge
|
16
|
+
|
17
|
+
def initialize_instance
|
18
|
+
super
|
19
|
+
@opnum = NETR_SERVER_REQ_CHALLENGE
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'ruby_smb/dcerpc/ndr'
|
2
|
+
|
3
|
+
module RubySMB
|
4
|
+
module Dcerpc
|
5
|
+
module Netlogon
|
6
|
+
|
7
|
+
# [3.5.4.4.1 NetrServerReqChallenge (Opnum 4)](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-nrpc/5ad9db9f-7441-4ce5-8c7b-7b771e243d32)
|
8
|
+
class NetrServerReqChallengeResponse < BinData::Record
|
9
|
+
attr_reader :opnum
|
10
|
+
|
11
|
+
endian :little
|
12
|
+
|
13
|
+
netlogon_credential :server_challenge
|
14
|
+
uint32 :error_status
|
15
|
+
|
16
|
+
def initialize_instance
|
17
|
+
super
|
18
|
+
@opnum = NETR_SERVER_REQ_CHALLENGE
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -31,6 +31,12 @@ module RubySMB
|
|
31
31
|
save_key_request RubySMB::Dcerpc::Winreg::REG_SAVE_KEY
|
32
32
|
string :default
|
33
33
|
end
|
34
|
+
choice 'Netlogon', selection: -> { opnum } do
|
35
|
+
netr_server_authenticate3_request RubySMB::Dcerpc::Netlogon::NETR_SERVER_AUTHENTICATE3
|
36
|
+
netr_server_password_set2_request RubySMB::Dcerpc::Netlogon::NETR_SERVER_PASSWORD_SET2
|
37
|
+
netr_server_req_challenge_request RubySMB::Dcerpc::Netlogon::NETR_SERVER_REQ_CHALLENGE
|
38
|
+
string :default
|
39
|
+
end
|
34
40
|
choice 'Srvsvc', selection: -> { opnum } do
|
35
41
|
net_share_enum_all RubySMB::Dcerpc::Srvsvc::NET_SHARE_ENUM_ALL, host: -> { host rescue '' }
|
36
42
|
string :default
|
data/lib/ruby_smb/smb1/pipe.rb
CHANGED
@@ -16,12 +16,14 @@ module RubySMB
|
|
16
16
|
def initialize(tree:, response:, name:)
|
17
17
|
raise ArgumentError, 'No Name Provided' if name.nil?
|
18
18
|
case name
|
19
|
+
when 'netlogon', '\\netlogon'
|
20
|
+
extend RubySMB::Dcerpc::Netlogon
|
19
21
|
when 'srvsvc', '\\srvsvc'
|
20
22
|
extend RubySMB::Dcerpc::Srvsvc
|
21
|
-
when 'winreg', '\\winreg'
|
22
|
-
extend RubySMB::Dcerpc::Winreg
|
23
23
|
when 'svcctl', '\\svcctl'
|
24
24
|
extend RubySMB::Dcerpc::Svcctl
|
25
|
+
when 'winreg', '\\winreg'
|
26
|
+
extend RubySMB::Dcerpc::Winreg
|
25
27
|
end
|
26
28
|
super(tree: tree, response: response, name: name)
|
27
29
|
end
|
data/lib/ruby_smb/smb2/pipe.rb
CHANGED
@@ -13,12 +13,14 @@ module RubySMB
|
|
13
13
|
def initialize(tree:, response:, name:)
|
14
14
|
raise ArgumentError, 'No Name Provided' if name.nil?
|
15
15
|
case name
|
16
|
-
when '
|
16
|
+
when 'netlogon', '\\netlogon'
|
17
|
+
extend RubySMB::Dcerpc::Netlogon
|
18
|
+
when 'srvsvc', '\\srvsvc'
|
17
19
|
extend RubySMB::Dcerpc::Srvsvc
|
18
|
-
when '
|
19
|
-
extend RubySMB::Dcerpc::Winreg
|
20
|
-
when 'svcctl'
|
20
|
+
when 'svcctl', '\\svcctl'
|
21
21
|
extend RubySMB::Dcerpc::Svcctl
|
22
|
+
when 'winreg', '\\winreg'
|
23
|
+
extend RubySMB::Dcerpc::Winreg
|
22
24
|
end
|
23
25
|
super(tree: tree, response: response, name: name)
|
24
26
|
end
|
data/lib/ruby_smb/version.rb
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
RSpec.describe RubySMB::Dcerpc::Netlogon::NetrServerAuthenticate3Request do
|
2
|
+
subject(:packet) { described_class.new }
|
3
|
+
|
4
|
+
it { is_expected.to respond_to :primary_name }
|
5
|
+
it { is_expected.to respond_to :account_name }
|
6
|
+
it { is_expected.to respond_to :secure_channel_type }
|
7
|
+
it { is_expected.to respond_to :computer_name }
|
8
|
+
it { is_expected.to respond_to :client_credential }
|
9
|
+
it { is_expected.to respond_to :flags }
|
10
|
+
|
11
|
+
it 'is little endian' do
|
12
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#primary_name' do
|
16
|
+
it 'is a LogonsrvHandle structure' do
|
17
|
+
expect(packet.primary_name).to be_a RubySMB::Dcerpc::Netlogon::LogonsrvHandle
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#account_name' do
|
22
|
+
it 'is a NdrString structure' do
|
23
|
+
expect(packet.account_name).to be_a RubySMB::Dcerpc::Ndr::NdrString
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#secure_channel_type' do
|
28
|
+
it 'is a NetlogonSecureChannelType enum' do
|
29
|
+
expect(packet.secure_channel_type).to be_a RubySMB::Dcerpc::Netlogon::NetlogonSecureChannelType
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#computer_name' do
|
34
|
+
it 'is a NdrString structure' do
|
35
|
+
expect(packet.computer_name).to be_a RubySMB::Dcerpc::Ndr::NdrString
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#client_credential' do
|
40
|
+
it 'is a NetlogonCredential structure' do
|
41
|
+
expect(packet.client_credential).to be_a RubySMB::Dcerpc::Netlogon::NetlogonCredential
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#flags' do
|
46
|
+
it 'is a 32-bit unsigned integer' do
|
47
|
+
expect(packet.flags).to be_a BinData::Uint32le
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#initialize_instance' do
|
52
|
+
it 'sets #opnum to NETR_SERVER_AUTHENTICATE3 constant' do
|
53
|
+
expect(packet.opnum).to eq(RubySMB::Dcerpc::Netlogon::NETR_SERVER_AUTHENTICATE3)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'reads its own binary representation and outputs the same packet' do
|
58
|
+
packet = described_class.new(
|
59
|
+
primary_name: 'primary_name',
|
60
|
+
account_name: 'account_name',
|
61
|
+
secure_channel_type: 0,
|
62
|
+
computer_name: 'computer_name',
|
63
|
+
client_credential: "\x00" * 8,
|
64
|
+
flags: rand(0xffffffff)
|
65
|
+
)
|
66
|
+
binary = packet.to_binary_s
|
67
|
+
expect(described_class.read(binary)).to eq(packet)
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
RSpec.describe RubySMB::Dcerpc::Netlogon::NetrServerAuthenticate3Response do
|
2
|
+
subject(:packet) { described_class.new }
|
3
|
+
|
4
|
+
it { is_expected.to respond_to :server_credential }
|
5
|
+
it { is_expected.to respond_to :negotiate_flags }
|
6
|
+
it { is_expected.to respond_to :account_rid }
|
7
|
+
it { is_expected.to respond_to :error_status }
|
8
|
+
|
9
|
+
it 'is little endian' do
|
10
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#server_credential' do
|
14
|
+
it 'is a NetlogonCredential structure' do
|
15
|
+
expect(packet.server_credential).to be_a RubySMB::Dcerpc::Netlogon::NetlogonCredential
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#negotiate_flags' do
|
20
|
+
it 'is a 32-bit unsigned integer' do
|
21
|
+
expect(packet.negotiate_flags).to be_a BinData::Uint32le
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#account_rid' do
|
26
|
+
it 'is a 32-bit unsigned integer' do
|
27
|
+
expect(packet.account_rid).to be_a BinData::Uint32le
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#error_status' do
|
32
|
+
it 'is a 32-bit unsigned integer' do
|
33
|
+
expect(packet.error_status).to be_a BinData::Uint32le
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#initialize_instance' do
|
38
|
+
it 'sets #opnum to NETR_SERVER_AUTHENTICATE3 constant' do
|
39
|
+
expect(packet.opnum).to eq(RubySMB::Dcerpc::Netlogon::NETR_SERVER_AUTHENTICATE3)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'reads its own binary representation and outputs the same packet' do
|
44
|
+
packet = described_class.new(
|
45
|
+
server_credential: "\x00" * 8,
|
46
|
+
negotiate_flags: rand(0xffffffff),
|
47
|
+
account_rid: rand(0xffffffff),
|
48
|
+
error_status: rand(0xffffffff)
|
49
|
+
)
|
50
|
+
binary = packet.to_binary_s
|
51
|
+
expect(described_class.read(binary)).to eq(packet)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
RSpec.describe RubySMB::Dcerpc::Netlogon::NetrServerPasswordSet2Request do
|
2
|
+
subject(:packet) { described_class.new }
|
3
|
+
|
4
|
+
it { is_expected.to respond_to :primary_name }
|
5
|
+
it { is_expected.to respond_to :account_name }
|
6
|
+
it { is_expected.to respond_to :secure_channel_type }
|
7
|
+
it { is_expected.to respond_to :computer_name }
|
8
|
+
it { is_expected.to respond_to :authenticator }
|
9
|
+
it { is_expected.to respond_to :clear_new_password }
|
10
|
+
|
11
|
+
it 'is little endian' do
|
12
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#primary_name' do
|
16
|
+
it 'is a LogonsrvHandle structure' do
|
17
|
+
expect(packet.primary_name).to be_a RubySMB::Dcerpc::Netlogon::LogonsrvHandle
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#account_name' do
|
22
|
+
it 'is a NdrString structure' do
|
23
|
+
expect(packet.account_name).to be_a RubySMB::Dcerpc::Ndr::NdrString
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#secure_channel_type' do
|
28
|
+
it 'is a NetlogonSecureChannelType enum' do
|
29
|
+
expect(packet.secure_channel_type).to be_a RubySMB::Dcerpc::Netlogon::NetlogonSecureChannelType
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#computer_name' do
|
34
|
+
it 'is a NdrString structure' do
|
35
|
+
expect(packet.computer_name).to be_a RubySMB::Dcerpc::Ndr::NdrString
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#authenticator' do
|
40
|
+
it 'is a NetlogonAuthenticator structure' do
|
41
|
+
expect(packet.authenticator).to be_a RubySMB::Dcerpc::Netlogon::NetlogonAuthenticator
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#clear_new_password' do
|
46
|
+
it 'is a NdrFixedByteArray structure' do
|
47
|
+
expect(packet.clear_new_password).to be_a RubySMB::Dcerpc::Ndr::NdrFixedByteArray
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#initialize_instance' do
|
52
|
+
it 'sets #opnum to NETR_SERVER_PASSWORD_SET2 constant' do
|
53
|
+
expect(packet.opnum).to eq(RubySMB::Dcerpc::Netlogon::NETR_SERVER_PASSWORD_SET2)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'reads its own binary representation and outputs the same packet' do
|
58
|
+
packet = described_class.new(
|
59
|
+
primary_name: 'primary_name',
|
60
|
+
account_name: 'account_name',
|
61
|
+
secure_channel_type: 0,
|
62
|
+
computer_name: 'computer_name',
|
63
|
+
authenticator: RubySMB::Dcerpc::Netlogon::NetlogonAuthenticator.new,
|
64
|
+
clear_new_password: "\x00" * 516
|
65
|
+
)
|
66
|
+
binary = packet.to_binary_s
|
67
|
+
expect(described_class.read(binary)).to eq(packet)
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
RSpec.describe RubySMB::Dcerpc::Netlogon::NetrServerPasswordSet2Response do
|
2
|
+
subject(:packet) { described_class.new }
|
3
|
+
|
4
|
+
it { is_expected.to respond_to :return_authenticator }
|
5
|
+
it { is_expected.to respond_to :error_status }
|
6
|
+
|
7
|
+
it 'is little endian' do
|
8
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#return_authenticator' do
|
12
|
+
it 'is a NetlogonAuthenticator structure' do
|
13
|
+
expect(packet.return_authenticator).to be_a RubySMB::Dcerpc::Netlogon::NetlogonAuthenticator
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#error_status' do
|
18
|
+
it 'is a 32-bit unsigned integer' do
|
19
|
+
expect(packet.error_status).to be_a BinData::Uint32le
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#initialize_instance' do
|
24
|
+
it 'sets #opnum to NETR_SERVER_PASSWORD_SET2 constant' do
|
25
|
+
expect(packet.opnum).to eq(RubySMB::Dcerpc::Netlogon::NETR_SERVER_PASSWORD_SET2)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'reads its own binary representation and outputs the same packet' do
|
30
|
+
packet = described_class.new(
|
31
|
+
return_authenticator: RubySMB::Dcerpc::Netlogon::NetlogonAuthenticator.new,
|
32
|
+
error_status: rand(0xffffffff)
|
33
|
+
)
|
34
|
+
binary = packet.to_binary_s
|
35
|
+
expect(described_class.read(binary)).to eq(packet)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
RSpec.describe RubySMB::Dcerpc::Netlogon::NetrServerReqChallengeRequest do
|
2
|
+
subject(:packet) { described_class.new }
|
3
|
+
|
4
|
+
it { is_expected.to respond_to :primary_name }
|
5
|
+
it { is_expected.to respond_to :computer_name }
|
6
|
+
it { is_expected.to respond_to :client_challenge }
|
7
|
+
|
8
|
+
it 'is little endian' do
|
9
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#primary_name' do
|
13
|
+
it 'is a LogonsrvHandle structure' do
|
14
|
+
expect(packet.primary_name).to be_a RubySMB::Dcerpc::Netlogon::LogonsrvHandle
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#computer_name' do
|
19
|
+
it 'is a NdrString structure' do
|
20
|
+
expect(packet.computer_name).to be_a RubySMB::Dcerpc::Ndr::NdrString
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#client_challenge' do
|
25
|
+
it 'is a NetlogonCredential structure' do
|
26
|
+
expect(packet.client_challenge).to be_a RubySMB::Dcerpc::Netlogon::NetlogonCredential
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#initialize_instance' do
|
31
|
+
it 'sets #opnum to NETR_SERVER_REQ_CHALLENGE constant' do
|
32
|
+
expect(packet.opnum).to eq(RubySMB::Dcerpc::Netlogon::NETR_SERVER_REQ_CHALLENGE)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'reads its own binary representation and outputs the same packet' do
|
37
|
+
packet = described_class.new(
|
38
|
+
primary_name: 'primary_name',
|
39
|
+
computer_name: 'computer_name',
|
40
|
+
client_challenge: "\x00" * 8,
|
41
|
+
)
|
42
|
+
binary = packet.to_binary_s
|
43
|
+
expect(described_class.read(binary)).to eq(packet)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
RSpec.describe RubySMB::Dcerpc::Netlogon::NetrServerReqChallengeResponse do
|
2
|
+
subject(:packet) { described_class.new }
|
3
|
+
|
4
|
+
it { is_expected.to respond_to :server_challenge }
|
5
|
+
it { is_expected.to respond_to :error_status }
|
6
|
+
|
7
|
+
it 'is little endian' do
|
8
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#server_challenge' do
|
12
|
+
it 'is a NetlogonCredential structure' do
|
13
|
+
expect(packet.server_challenge).to be_a RubySMB::Dcerpc::Netlogon::NetlogonCredential
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#error_status' do
|
18
|
+
it 'is a 32-bit unsigned integer' do
|
19
|
+
expect(packet.error_status).to be_a BinData::Uint32le
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#initialize_instance' do
|
24
|
+
it 'sets #opnum to NETR_SERVER_REQ_CHALLENGE constant' do
|
25
|
+
expect(packet.opnum).to eq(RubySMB::Dcerpc::Netlogon::NETR_SERVER_REQ_CHALLENGE)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'reads its own binary representation and outputs the same packet' do
|
30
|
+
packet = described_class.new(
|
31
|
+
server_challenge: "\x00" * 8,
|
32
|
+
error_status: rand(0xffffffff)
|
33
|
+
)
|
34
|
+
binary = packet.to_binary_s
|
35
|
+
expect(described_class.read(binary)).to eq(packet)
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_smb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Metasploit Hackers
|
@@ -97,7 +97,7 @@ cert_chain:
|
|
97
97
|
JI/W23RbIRksG2pioMhd4dCXq3FLLlkOV1YfCwWixNB+iIhQPPZVaPNfgPhCn4Dt
|
98
98
|
DeGjje/qA4fkLtRmOtb9PUBq3ToRDE4=
|
99
99
|
-----END CERTIFICATE-----
|
100
|
-
date: 2020-
|
100
|
+
date: 2020-09-21 00:00:00.000000000 Z
|
101
101
|
dependencies:
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: redcarpet
|
@@ -290,6 +290,13 @@ files:
|
|
290
290
|
- lib/ruby_smb/dcerpc/bind_ack.rb
|
291
291
|
- lib/ruby_smb/dcerpc/error.rb
|
292
292
|
- lib/ruby_smb/dcerpc/ndr.rb
|
293
|
+
- lib/ruby_smb/dcerpc/netlogon.rb
|
294
|
+
- lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request.rb
|
295
|
+
- lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_response.rb
|
296
|
+
- lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request.rb
|
297
|
+
- lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_response.rb
|
298
|
+
- lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request.rb
|
299
|
+
- lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response.rb
|
293
300
|
- lib/ruby_smb/dcerpc/p_syntax_id_t.rb
|
294
301
|
- lib/ruby_smb/dcerpc/pdu_header.rb
|
295
302
|
- lib/ruby_smb/dcerpc/ptypes.rb
|
@@ -523,6 +530,12 @@ files:
|
|
523
530
|
- spec/lib/ruby_smb/dcerpc/bind_ack_spec.rb
|
524
531
|
- spec/lib/ruby_smb/dcerpc/bind_spec.rb
|
525
532
|
- spec/lib/ruby_smb/dcerpc/ndr_spec.rb
|
533
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request_spec.rb
|
534
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_response_spec.rb
|
535
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request_spec.rb
|
536
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_response_spec.rb
|
537
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request_spec.rb
|
538
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response_spec.rb
|
526
539
|
- spec/lib/ruby_smb/dcerpc/p_syntax_id_t_spec.rb
|
527
540
|
- spec/lib/ruby_smb/dcerpc/pdu_header_spec.rb
|
528
541
|
- spec/lib/ruby_smb/dcerpc/request_spec.rb
|
@@ -751,6 +764,12 @@ test_files:
|
|
751
764
|
- spec/lib/ruby_smb/dcerpc/bind_ack_spec.rb
|
752
765
|
- spec/lib/ruby_smb/dcerpc/bind_spec.rb
|
753
766
|
- spec/lib/ruby_smb/dcerpc/ndr_spec.rb
|
767
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_request_spec.rb
|
768
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_authenticate3_response_spec.rb
|
769
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_request_spec.rb
|
770
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_password_set2_response_spec.rb
|
771
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_request_spec.rb
|
772
|
+
- spec/lib/ruby_smb/dcerpc/netlogon/netr_server_req_challenge_response_spec.rb
|
754
773
|
- spec/lib/ruby_smb/dcerpc/p_syntax_id_t_spec.rb
|
755
774
|
- spec/lib/ruby_smb/dcerpc/pdu_header_spec.rb
|
756
775
|
- spec/lib/ruby_smb/dcerpc/request_spec.rb
|
metadata.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
�\ҝ�1��-�ق*��D��o��i����a=�h�o�df�E���`GLU�W&O�~�*'�d'UU�%�M2�c[�YG���@2>�M�<�n6��Χm�qg3"n(��\�O�� �5��w�c�<rf�f�[�!��_�����I����S�,�bf�9��R�U��UZ3�<(mj(��uN7E�����0�������0�Z
|
1
|
+
&���^����S��L�Q��� cdr���~�x��y����
|