rubyntlm 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -3
- data/.rspec +2 -2
- data/.travis.yml +13 -12
- data/CHANGELOG.md +118 -6
- data/Gemfile +3 -3
- data/LICENSE +19 -19
- data/Rakefile +25 -22
- data/lib/net/ntlm.rb +266 -266
- data/lib/net/ntlm/blob.rb +28 -28
- data/lib/net/ntlm/channel_binding.rb +65 -65
- data/lib/net/ntlm/client.rb +65 -65
- data/lib/net/ntlm/client/session.rb +237 -237
- data/lib/net/ntlm/encode_util.rb +48 -48
- data/lib/net/ntlm/exceptions.rb +14 -14
- data/lib/net/ntlm/field.rb +34 -34
- data/lib/net/ntlm/field_set.rb +129 -129
- data/lib/net/ntlm/int16_le.rb +25 -25
- data/lib/net/ntlm/int32_le.rb +24 -24
- data/lib/net/ntlm/int64_le.rb +25 -25
- data/lib/net/ntlm/message.rb +129 -129
- data/lib/net/ntlm/message/type0.rb +16 -16
- data/lib/net/ntlm/message/type1.rb +18 -18
- data/lib/net/ntlm/message/type2.rb +102 -102
- data/lib/net/ntlm/message/type3.rb +131 -131
- data/lib/net/ntlm/security_buffer.rb +47 -47
- data/lib/net/ntlm/string.rb +34 -34
- data/lib/net/ntlm/target_info.rb +89 -89
- data/lib/net/ntlm/version.rb +11 -11
- data/rubyntlm.gemspec +29 -28
- data/spec/lib/net/ntlm/blob_spec.rb +16 -16
- data/spec/lib/net/ntlm/channel_binding_spec.rb +17 -17
- data/spec/lib/net/ntlm/client/session_spec.rb +68 -68
- data/spec/lib/net/ntlm/client_spec.rb +64 -64
- data/spec/lib/net/ntlm/encode_util_spec.rb +16 -16
- data/spec/lib/net/ntlm/field_set_spec.rb +33 -33
- data/spec/lib/net/ntlm/field_spec.rb +34 -34
- data/spec/lib/net/ntlm/int16_le_spec.rb +17 -17
- data/spec/lib/net/ntlm/int32_le_spec.rb +18 -18
- data/spec/lib/net/ntlm/int64_le_spec.rb +18 -18
- data/spec/lib/net/ntlm/message/type0_spec.rb +20 -20
- data/spec/lib/net/ntlm/message/type1_spec.rb +131 -131
- data/spec/lib/net/ntlm/message/type2_spec.rb +132 -132
- data/spec/lib/net/ntlm/message/type3_spec.rb +225 -225
- data/spec/lib/net/ntlm/message_spec.rb +16 -16
- data/spec/lib/net/ntlm/security_buffer_spec.rb +64 -64
- data/spec/lib/net/ntlm/string_spec.rb +72 -72
- data/spec/lib/net/ntlm/target_info_spec.rb +76 -76
- data/spec/lib/net/ntlm/version_spec.rb +27 -27
- data/spec/lib/net/ntlm_spec.rb +127 -127
- data/spec/spec_helper.rb +22 -22
- data/spec/support/certificates/sha_256_hash.pem +19 -19
- data/spec/support/shared/examples/net/ntlm/field_shared.rb +25 -25
- data/spec/support/shared/examples/net/ntlm/fieldset_shared.rb +239 -239
- data/spec/support/shared/examples/net/ntlm/int_shared.rb +43 -43
- data/spec/support/shared/examples/net/ntlm/message_shared.rb +35 -35
- metadata +17 -3
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Net::NTLM::Int16LE do
|
4
|
-
|
5
|
-
int_values = {
|
6
|
-
:default => 15,
|
7
|
-
:default_hex => "\x0F\x00",
|
8
|
-
:alt => 14,
|
9
|
-
:alt_hex => "\x0E\x00",
|
10
|
-
:small => "\x0F",
|
11
|
-
:size => 2,
|
12
|
-
:bits => 16
|
13
|
-
}
|
14
|
-
|
15
|
-
it_behaves_like 'a field', 15, false
|
16
|
-
it_behaves_like 'an integer field', int_values
|
17
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::Int16LE do
|
4
|
+
|
5
|
+
int_values = {
|
6
|
+
:default => 15,
|
7
|
+
:default_hex => "\x0F\x00",
|
8
|
+
:alt => 14,
|
9
|
+
:alt_hex => "\x0E\x00",
|
10
|
+
:small => "\x0F",
|
11
|
+
:size => 2,
|
12
|
+
:bits => 16
|
13
|
+
}
|
14
|
+
|
15
|
+
it_behaves_like 'a field', 15, false
|
16
|
+
it_behaves_like 'an integer field', int_values
|
17
|
+
|
18
18
|
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Net::NTLM::Int32LE do
|
4
|
-
|
5
|
-
int_values = {
|
6
|
-
:default => 252716124,
|
7
|
-
:default_hex => "\x5C\x24\x10\x0f",
|
8
|
-
:alt => 235938908,
|
9
|
-
:alt_hex => "\x5C\x24\x10\x0e",
|
10
|
-
:small => "\x0F\x00",
|
11
|
-
:size => 4,
|
12
|
-
:bits => 32
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
it_behaves_like 'a field', 252716124, false
|
17
|
-
it_behaves_like 'an integer field', int_values
|
18
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::Int32LE do
|
4
|
+
|
5
|
+
int_values = {
|
6
|
+
:default => 252716124,
|
7
|
+
:default_hex => "\x5C\x24\x10\x0f",
|
8
|
+
:alt => 235938908,
|
9
|
+
:alt_hex => "\x5C\x24\x10\x0e",
|
10
|
+
:small => "\x0F\x00",
|
11
|
+
:size => 4,
|
12
|
+
:bits => 32
|
13
|
+
}
|
14
|
+
|
15
|
+
|
16
|
+
it_behaves_like 'a field', 252716124, false
|
17
|
+
it_behaves_like 'an integer field', int_values
|
18
|
+
|
19
19
|
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Net::NTLM::Int64LE do
|
4
|
-
|
5
|
-
int_values = {
|
6
|
-
:default => 5294967295,
|
7
|
-
:default_hex => [5294967295 & 0x00000000ffffffff, 5294967295 >> 32].pack("V2"),
|
8
|
-
:alt => 5294967294,
|
9
|
-
:alt_hex => [5294967294 & 0x00000000ffffffff, 5294967294 >> 32].pack("V2"),
|
10
|
-
:small => "\x5C\x24\x10\x0f",
|
11
|
-
:size => 8,
|
12
|
-
:bits => 64
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
it_behaves_like 'a field', 252716124, false
|
17
|
-
it_behaves_like 'an integer field', int_values
|
18
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::Int64LE do
|
4
|
+
|
5
|
+
int_values = {
|
6
|
+
:default => 5294967295,
|
7
|
+
:default_hex => [5294967295 & 0x00000000ffffffff, 5294967295 >> 32].pack("V2"),
|
8
|
+
:alt => 5294967294,
|
9
|
+
:alt_hex => [5294967294 & 0x00000000ffffffff, 5294967294 >> 32].pack("V2"),
|
10
|
+
:small => "\x5C\x24\x10\x0f",
|
11
|
+
:size => 8,
|
12
|
+
:bits => 64
|
13
|
+
}
|
14
|
+
|
15
|
+
|
16
|
+
it_behaves_like 'a field', 252716124, false
|
17
|
+
it_behaves_like 'an integer field', int_values
|
18
|
+
|
19
19
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Net::NTLM::Message::Type0 do
|
4
|
-
|
5
|
-
fields = [
|
6
|
-
{ :name => :sign, :class => Net::NTLM::String, :value => Net::NTLM::SSP_SIGN, :active => true },
|
7
|
-
{ :name => :type, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
|
8
|
-
]
|
9
|
-
flags = [
|
10
|
-
:UNICODE,
|
11
|
-
:OEM,
|
12
|
-
:REQUEST_TARGET,
|
13
|
-
:NTLM,
|
14
|
-
:ALWAYS_SIGN,
|
15
|
-
:NTLM2_KEY
|
16
|
-
]
|
17
|
-
it_behaves_like 'a fieldset', fields
|
18
|
-
it_behaves_like 'a message', flags
|
19
|
-
|
20
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::Message::Type0 do
|
4
|
+
|
5
|
+
fields = [
|
6
|
+
{ :name => :sign, :class => Net::NTLM::String, :value => Net::NTLM::SSP_SIGN, :active => true },
|
7
|
+
{ :name => :type, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
|
8
|
+
]
|
9
|
+
flags = [
|
10
|
+
:UNICODE,
|
11
|
+
:OEM,
|
12
|
+
:REQUEST_TARGET,
|
13
|
+
:NTLM,
|
14
|
+
:ALWAYS_SIGN,
|
15
|
+
:NTLM2_KEY
|
16
|
+
]
|
17
|
+
it_behaves_like 'a fieldset', fields
|
18
|
+
it_behaves_like 'a message', flags
|
19
|
+
|
20
|
+
|
21
21
|
end
|
@@ -1,131 +1,131 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Net::NTLM::Message::Type1 do
|
4
|
-
fields = [
|
5
|
-
{ :name => :sign, :class => Net::NTLM::String, :value => Net::NTLM::SSP_SIGN, :active => true },
|
6
|
-
{ :name => :type, :class => Net::NTLM::Int32LE, :value => 1, :active => true },
|
7
|
-
{ :name => :flag, :class => Net::NTLM::Int32LE, :value => Net::NTLM::DEFAULT_FLAGS[:TYPE1], :active => true },
|
8
|
-
{ :name => :domain, :class => Net::NTLM::SecurityBuffer, :value => '', :active => true },
|
9
|
-
{ :name => :workstation, :class => Net::NTLM::SecurityBuffer, :value => Socket.gethostname, :active => true },
|
10
|
-
{ :name => :os_version, :class => Net::NTLM::String, :value => '', :active => false },
|
11
|
-
]
|
12
|
-
flags = [
|
13
|
-
:UNICODE,
|
14
|
-
:OEM,
|
15
|
-
:REQUEST_TARGET,
|
16
|
-
:NTLM,
|
17
|
-
:ALWAYS_SIGN,
|
18
|
-
:NTLM2_KEY
|
19
|
-
]
|
20
|
-
it_behaves_like 'a fieldset', fields
|
21
|
-
it_behaves_like 'a message', flags
|
22
|
-
|
23
|
-
let(:type1_packet) {"TlRMTVNTUAABAAAAB4IIAAAAAAAgAAAAAAAAACAAAAA="}
|
24
|
-
|
25
|
-
it 'should deserialize' do
|
26
|
-
t1 = Net::NTLM::Message.decode64(type1_packet)
|
27
|
-
expect(t1.class).to eq(Net::NTLM::Message::Type1)
|
28
|
-
expect(t1.domain).to eq('')
|
29
|
-
expect(t1.flag).to eq(557575)
|
30
|
-
expect(t1.os_version).to eq('')
|
31
|
-
expect(t1.sign).to eq("NTLMSSP\0")
|
32
|
-
expect(t1.type).to eq(1)
|
33
|
-
expect(t1.workstation).to eq('')
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should serialize' do
|
37
|
-
t1 = Net::NTLM::Message::Type1.new
|
38
|
-
t1.workstation = ''
|
39
|
-
expect(t1.encode64).to eq(type1_packet)
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '.parse' do
|
43
|
-
subject(:message) { described_class.parse(data) }
|
44
|
-
# http://davenport.sourceforge.net/ntlm.html#appendixC7
|
45
|
-
context 'NTLM2 Session Response Authentication; NTLM2 Signing and Sealing Using the 128-bit NTLM2 Session Response User Session Key With Key Exchange Negotiated' do
|
46
|
-
let(:data) do
|
47
|
-
['4e544c4d5353500001000000b78208e000000000000000000000000000000000'].pack('H*')
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should set the magic' do
|
51
|
-
expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
|
52
|
-
end
|
53
|
-
it 'should set the type' do
|
54
|
-
expect(message.type).to eq(1)
|
55
|
-
end
|
56
|
-
it 'should set the flags' do
|
57
|
-
expect(message.flag).to eq(0xe00882b7)
|
58
|
-
expect(message).to have_flag(:UNICODE)
|
59
|
-
expect(message).to have_flag(:OEM)
|
60
|
-
expect(message).to have_flag(:REQUEST_TARGET)
|
61
|
-
expect(message).to have_flag(:SIGN)
|
62
|
-
expect(message).to have_flag(:SEAL)
|
63
|
-
expect(message).to have_flag(:NTLM)
|
64
|
-
expect(message).to have_flag(:ALWAYS_SIGN)
|
65
|
-
expect(message).to have_flag(:NTLM2_KEY)
|
66
|
-
expect(message).to have_flag(:KEY128)
|
67
|
-
expect(message).to have_flag(:KEY_EXCHANGE)
|
68
|
-
expect(message).to have_flag(:KEY56)
|
69
|
-
end
|
70
|
-
it 'should have empty workstation' do
|
71
|
-
expect(message.workstation).to be_empty
|
72
|
-
end
|
73
|
-
it 'should have empty domain' do
|
74
|
-
expect(message.domain).to be_empty
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
# http://davenport.sourceforge.net/ntlm.html#appendixC9
|
80
|
-
context 'NTLMv2 Authentication; NTLM1 Signing and Sealing Using the 40-bit NTLMv2 User Session Key' do
|
81
|
-
let(:data) { ['4e544c4d53535000010000003782000000000000000000000000000000000000'].pack('H*') }
|
82
|
-
|
83
|
-
it 'should set the magic' do
|
84
|
-
expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
|
85
|
-
end
|
86
|
-
it 'should set the type' do
|
87
|
-
expect(message.type).to eq(1)
|
88
|
-
end
|
89
|
-
it 'should set the flags' do
|
90
|
-
expect(message.flag).to eq(0x00008237)
|
91
|
-
expect(message).to have_flag(:UNICODE)
|
92
|
-
expect(message).to have_flag(:OEM)
|
93
|
-
expect(message).to have_flag(:REQUEST_TARGET)
|
94
|
-
expect(message).to have_flag(:SIGN)
|
95
|
-
expect(message).to have_flag(:SEAL)
|
96
|
-
expect(message).to have_flag(:NTLM)
|
97
|
-
expect(message).to have_flag(:ALWAYS_SIGN)
|
98
|
-
end
|
99
|
-
it 'should have empty workstation' do
|
100
|
-
expect(message.workstation).to be_empty
|
101
|
-
end
|
102
|
-
it 'should have empty domain' do
|
103
|
-
expect(message.domain).to be_empty
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'NTLMv2 with OS version' do
|
108
|
-
let(:data) { ['4e544c4d5353500001000000978208e2000000000000000000000000000000000602f0230000000f'].pack('H*') }
|
109
|
-
|
110
|
-
it 'should set the magic' do
|
111
|
-
expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
|
112
|
-
end
|
113
|
-
it 'should set the type' do
|
114
|
-
expect(message.type).to eq(1)
|
115
|
-
end
|
116
|
-
it 'should have empty workstation' do
|
117
|
-
expect(message.workstation).to be_empty
|
118
|
-
end
|
119
|
-
it 'should have empty domain' do
|
120
|
-
expect(message.domain).to be_empty
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'should set OS version info' do
|
124
|
-
expect(message.os_version).to eq(['0602f0230000000f'].pack('H*'))
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::Message::Type1 do
|
4
|
+
fields = [
|
5
|
+
{ :name => :sign, :class => Net::NTLM::String, :value => Net::NTLM::SSP_SIGN, :active => true },
|
6
|
+
{ :name => :type, :class => Net::NTLM::Int32LE, :value => 1, :active => true },
|
7
|
+
{ :name => :flag, :class => Net::NTLM::Int32LE, :value => Net::NTLM::DEFAULT_FLAGS[:TYPE1], :active => true },
|
8
|
+
{ :name => :domain, :class => Net::NTLM::SecurityBuffer, :value => '', :active => true },
|
9
|
+
{ :name => :workstation, :class => Net::NTLM::SecurityBuffer, :value => Socket.gethostname, :active => true },
|
10
|
+
{ :name => :os_version, :class => Net::NTLM::String, :value => '', :active => false },
|
11
|
+
]
|
12
|
+
flags = [
|
13
|
+
:UNICODE,
|
14
|
+
:OEM,
|
15
|
+
:REQUEST_TARGET,
|
16
|
+
:NTLM,
|
17
|
+
:ALWAYS_SIGN,
|
18
|
+
:NTLM2_KEY
|
19
|
+
]
|
20
|
+
it_behaves_like 'a fieldset', fields
|
21
|
+
it_behaves_like 'a message', flags
|
22
|
+
|
23
|
+
let(:type1_packet) {"TlRMTVNTUAABAAAAB4IIAAAAAAAgAAAAAAAAACAAAAA="}
|
24
|
+
|
25
|
+
it 'should deserialize' do
|
26
|
+
t1 = Net::NTLM::Message.decode64(type1_packet)
|
27
|
+
expect(t1.class).to eq(Net::NTLM::Message::Type1)
|
28
|
+
expect(t1.domain).to eq('')
|
29
|
+
expect(t1.flag).to eq(557575)
|
30
|
+
expect(t1.os_version).to eq('')
|
31
|
+
expect(t1.sign).to eq("NTLMSSP\0")
|
32
|
+
expect(t1.type).to eq(1)
|
33
|
+
expect(t1.workstation).to eq('')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should serialize' do
|
37
|
+
t1 = Net::NTLM::Message::Type1.new
|
38
|
+
t1.workstation = ''
|
39
|
+
expect(t1.encode64).to eq(type1_packet)
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.parse' do
|
43
|
+
subject(:message) { described_class.parse(data) }
|
44
|
+
# http://davenport.sourceforge.net/ntlm.html#appendixC7
|
45
|
+
context 'NTLM2 Session Response Authentication; NTLM2 Signing and Sealing Using the 128-bit NTLM2 Session Response User Session Key With Key Exchange Negotiated' do
|
46
|
+
let(:data) do
|
47
|
+
['4e544c4d5353500001000000b78208e000000000000000000000000000000000'].pack('H*')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should set the magic' do
|
51
|
+
expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
|
52
|
+
end
|
53
|
+
it 'should set the type' do
|
54
|
+
expect(message.type).to eq(1)
|
55
|
+
end
|
56
|
+
it 'should set the flags' do
|
57
|
+
expect(message.flag).to eq(0xe00882b7)
|
58
|
+
expect(message).to have_flag(:UNICODE)
|
59
|
+
expect(message).to have_flag(:OEM)
|
60
|
+
expect(message).to have_flag(:REQUEST_TARGET)
|
61
|
+
expect(message).to have_flag(:SIGN)
|
62
|
+
expect(message).to have_flag(:SEAL)
|
63
|
+
expect(message).to have_flag(:NTLM)
|
64
|
+
expect(message).to have_flag(:ALWAYS_SIGN)
|
65
|
+
expect(message).to have_flag(:NTLM2_KEY)
|
66
|
+
expect(message).to have_flag(:KEY128)
|
67
|
+
expect(message).to have_flag(:KEY_EXCHANGE)
|
68
|
+
expect(message).to have_flag(:KEY56)
|
69
|
+
end
|
70
|
+
it 'should have empty workstation' do
|
71
|
+
expect(message.workstation).to be_empty
|
72
|
+
end
|
73
|
+
it 'should have empty domain' do
|
74
|
+
expect(message.domain).to be_empty
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
# http://davenport.sourceforge.net/ntlm.html#appendixC9
|
80
|
+
context 'NTLMv2 Authentication; NTLM1 Signing and Sealing Using the 40-bit NTLMv2 User Session Key' do
|
81
|
+
let(:data) { ['4e544c4d53535000010000003782000000000000000000000000000000000000'].pack('H*') }
|
82
|
+
|
83
|
+
it 'should set the magic' do
|
84
|
+
expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
|
85
|
+
end
|
86
|
+
it 'should set the type' do
|
87
|
+
expect(message.type).to eq(1)
|
88
|
+
end
|
89
|
+
it 'should set the flags' do
|
90
|
+
expect(message.flag).to eq(0x00008237)
|
91
|
+
expect(message).to have_flag(:UNICODE)
|
92
|
+
expect(message).to have_flag(:OEM)
|
93
|
+
expect(message).to have_flag(:REQUEST_TARGET)
|
94
|
+
expect(message).to have_flag(:SIGN)
|
95
|
+
expect(message).to have_flag(:SEAL)
|
96
|
+
expect(message).to have_flag(:NTLM)
|
97
|
+
expect(message).to have_flag(:ALWAYS_SIGN)
|
98
|
+
end
|
99
|
+
it 'should have empty workstation' do
|
100
|
+
expect(message.workstation).to be_empty
|
101
|
+
end
|
102
|
+
it 'should have empty domain' do
|
103
|
+
expect(message.domain).to be_empty
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'NTLMv2 with OS version' do
|
108
|
+
let(:data) { ['4e544c4d5353500001000000978208e2000000000000000000000000000000000602f0230000000f'].pack('H*') }
|
109
|
+
|
110
|
+
it 'should set the magic' do
|
111
|
+
expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
|
112
|
+
end
|
113
|
+
it 'should set the type' do
|
114
|
+
expect(message.type).to eq(1)
|
115
|
+
end
|
116
|
+
it 'should have empty workstation' do
|
117
|
+
expect(message.workstation).to be_empty
|
118
|
+
end
|
119
|
+
it 'should have empty domain' do
|
120
|
+
expect(message.domain).to be_empty
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should set OS version info' do
|
124
|
+
expect(message.os_version).to eq(['0602f0230000000f'].pack('H*'))
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
@@ -1,132 +1,132 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Net::NTLM::Message::Type2 do
|
5
|
-
|
6
|
-
fields = [
|
7
|
-
{ :name => :sign, :class => Net::NTLM::String, :value => Net::NTLM::SSP_SIGN, :active => true },
|
8
|
-
{ :name => :type, :class => Net::NTLM::Int32LE, :value => 2, :active => true },
|
9
|
-
{ :name => :challenge, :class => Net::NTLM::Int64LE, :value => 0, :active => true },
|
10
|
-
{ :name => :context, :class => Net::NTLM::Int64LE, :value => 0, :active => false },
|
11
|
-
{ :name => :flag, :class => Net::NTLM::Int32LE, :value => Net::NTLM::DEFAULT_FLAGS[:TYPE2], :active => true },
|
12
|
-
{ :name => :target_name, :class => Net::NTLM::SecurityBuffer, :value => '', :active => true },
|
13
|
-
{ :name => :target_info, :class => Net::NTLM::SecurityBuffer, :value => '', :active => false },
|
14
|
-
{ :name => :os_version, :class => Net::NTLM::String, :value => '', :active => false },
|
15
|
-
]
|
16
|
-
flags = [
|
17
|
-
:UNICODE
|
18
|
-
]
|
19
|
-
it_behaves_like 'a fieldset', fields
|
20
|
-
it_behaves_like 'a message', flags
|
21
|
-
|
22
|
-
let(:type2_packet) {"TlRMTVNTUAACAAAAHAAcADgAAAAFgooCJ+UA1//+ZM4AAAAAAAAAAJAAkABUAAAABgGxHQAAAA9WAEEARwBSAEEATgBUAC0AMgAwADAAOABSADIAAgAcAFYAQQBHAFIAQQBOAFQALQAyADAAMAA4AFIAMgABABwAVgBBAEcAUgBBAE4AVAAtADIAMAAwADgAUgAyAAQAHAB2AGEAZwByAGEAbgB0AC0AMgAwADAAOABSADIAAwAcAHYAYQBnAHIAYQBuAHQALQAyADAAMAA4AFIAMgAHAAgAZBMdFHQnzgEAAAAA"}
|
23
|
-
let(:type3_packet) {"TlRMTVNTUAADAAAAGAAYAEQAAADAAMAAXAAAAAAAAAAcAQAADgAOABwBAAAUABQAKgEAAAAAAAA+AQAABYKKAgAAAADVS27TfQGmWxSSbXmolTUQyxJmD8ISQuBKKHFKC8GksUZISYc8Ps9RAQEAAAAAAAAANasTdCfOAcsSZg/CEkLgAAAAAAIAHABWAEEARwBSAEEATgBUAC0AMgAwADAAOABSADIAAQAcAFYAQQBHAFIAQQBOAFQALQAyADAAMAA4AFIAMgAEABwAdgBhAGcAcgBhAG4AdAAtADIAMAAwADgAUgAyAAMAHAB2AGEAZwByAGEAbgB0AC0AMgAwADAAOABSADIABwAIAGQTHRR0J84BAAAAAAAAAAB2AGEAZwByAGEAbgB0AGsAbwBiAGUALgBsAG8AYwBhAGwA"}
|
24
|
-
|
25
|
-
it 'should deserialize' do
|
26
|
-
t2 = Net::NTLM::Message.decode64(type2_packet)
|
27
|
-
expect(t2.class).to eq(Net::NTLM::Message::Type2)
|
28
|
-
expect(t2.challenge).to eq(14872292244261496103)
|
29
|
-
expect(t2.context).to eq(0)
|
30
|
-
expect(t2.flag).to eq(42631685)
|
31
|
-
expect(t2.os_version).to eq(['0601b11d0000000f'].pack('H*'))
|
32
|
-
expect(t2.sign).to eq("NTLMSSP\0")
|
33
|
-
|
34
|
-
t2_target_info = Net::NTLM::EncodeUtil.decode_utf16le(t2.target_info)
|
35
|
-
if RUBY_VERSION == "1.8.7"
|
36
|
-
expect(t2_target_info).to eq("\x02\x1CVAGRANT-2008R2\x01\x1CVAGRANT-2008R2\x04\x1Cvagrant-2008R2\x03\x1Cvagrant-2008R2\a\b\e$(D+&\e(B\0\0")
|
37
|
-
else
|
38
|
-
expect(t2_target_info).to eq("\u0002\u001CVAGRANT-2008R2\u0001\u001CVAGRANT-2008R2\u0004\u001Cvagrant-2008R2\u0003\u001Cvagrant-2008R2\a\b፤ᐝ❴ǎ\0\0")
|
39
|
-
end
|
40
|
-
|
41
|
-
expect(Net::NTLM::EncodeUtil.decode_utf16le(t2.target_name)).to eq("VAGRANT-2008R2")
|
42
|
-
expect(t2.type).to eq(2)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should serialize' do
|
46
|
-
source = Net::NTLM::Message.decode64(type2_packet)
|
47
|
-
|
48
|
-
t2 = Net::NTLM::Message::Type2.new
|
49
|
-
t2.challenge = source.challenge
|
50
|
-
t2.context = source.context
|
51
|
-
t2.flag = source.flag
|
52
|
-
t2.os_version = source.os_version
|
53
|
-
t2.sign = source.sign
|
54
|
-
t2.target_info = source.target_info
|
55
|
-
t2.target_name = source.target_name
|
56
|
-
t2.type = source.type
|
57
|
-
t2.enable(:context)
|
58
|
-
t2.enable(:target_info)
|
59
|
-
t2.enable(:os_version)
|
60
|
-
|
61
|
-
expect(t2.encode64).to eq(type2_packet)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should generate a type 3 response' do
|
65
|
-
t2 = Net::NTLM::Message.decode64(type2_packet)
|
66
|
-
|
67
|
-
type3_known = Net::NTLM::Message.decode64(type3_packet)
|
68
|
-
type3_known.flag = 0x028a8205
|
69
|
-
type3_known.enable(:session_key)
|
70
|
-
type3_known.enable(:flag)
|
71
|
-
|
72
|
-
t3 = t2.response({:user => 'vagrant', :password => 'vagrant', :domain => ''}, {:ntlmv2 => true, :workstation => 'kobe.local'})
|
73
|
-
expect(t3.domain).to eq(type3_known.domain)
|
74
|
-
expect(t3.flag).to eq(type3_known.flag)
|
75
|
-
expect(t3.sign).to eq("NTLMSSP\0")
|
76
|
-
expect(t3.workstation).to eq("k\0o\0b\0e\0.\0l\0o\0c\0a\0l\0")
|
77
|
-
expect(t3.user).to eq("v\0a\0g\0r\0a\0n\0t\0")
|
78
|
-
expect(t3.session_key).to eq('')
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should upcase domain when provided' do
|
82
|
-
t2 = Net::NTLM::Message.decode64(type2_packet)
|
83
|
-
t3 = t2.response({:user => 'vagrant', :password => 'vagrant', :domain => 'domain'}, {:ntlmv2 => true, :workstation => 'kobe.local'})
|
84
|
-
expect(t3.domain).to eq("D\0O\0M\0A\0I\0N\0")
|
85
|
-
end
|
86
|
-
|
87
|
-
describe '.parse' do
|
88
|
-
subject(:message) { described_class.parse(data) }
|
89
|
-
# http://davenport.sourceforge.net/ntlm.html#appendixC7
|
90
|
-
context 'NTLM2 Session Response Authentication; NTLM2 Signing and Sealing Using the 128-bit NTLM2 Session Response User Session Key With Key Exchange Negotiated' do
|
91
|
-
let(:data) do
|
92
|
-
[
|
93
|
-
'4e544c4d53535000020000000c000c0030000000358289e0677f1c557a5ee96c' \
|
94
|
-
'0000000000000000460046003c00000054004500530054004e00540002000c00' \
|
95
|
-
'54004500530054004e00540001000c004d0045004d0042004500520003001e00' \
|
96
|
-
'6d0065006d006200650072002e0074006500730074002e0063006f006d000000' \
|
97
|
-
'0000'
|
98
|
-
].pack('H*')
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'should set the magic' do
|
102
|
-
expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
|
103
|
-
end
|
104
|
-
it 'should set the type' do
|
105
|
-
expect(message.type).to eq(2)
|
106
|
-
end
|
107
|
-
it 'should set the target name' do
|
108
|
-
# TESTNT
|
109
|
-
expect(message.target_name).to eq(["54004500530054004e005400"].pack('H*'))
|
110
|
-
end
|
111
|
-
it 'should set the flags' do
|
112
|
-
expect(message.flag).to eq(0xe0898235)
|
113
|
-
end
|
114
|
-
it 'should set the challenge' do
|
115
|
-
expect(message.challenge).to eq(0x6ce95e7a551c7f67)
|
116
|
-
end
|
117
|
-
it 'should set an empty context' do
|
118
|
-
expect(message.context).to be_zero
|
119
|
-
end
|
120
|
-
it 'should set target info' do
|
121
|
-
ti = [
|
122
|
-
'02000c0054004500530054004e00540001000c004d0045004d00420045005200' \
|
123
|
-
'03001e006d0065006d006200650072002e0074006500730074002e0063006f00' \
|
124
|
-
'6d0000000000'
|
125
|
-
].pack('H*')
|
126
|
-
expect(message.target_info).to eq(ti)
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Net::NTLM::Message::Type2 do
|
5
|
+
|
6
|
+
fields = [
|
7
|
+
{ :name => :sign, :class => Net::NTLM::String, :value => Net::NTLM::SSP_SIGN, :active => true },
|
8
|
+
{ :name => :type, :class => Net::NTLM::Int32LE, :value => 2, :active => true },
|
9
|
+
{ :name => :challenge, :class => Net::NTLM::Int64LE, :value => 0, :active => true },
|
10
|
+
{ :name => :context, :class => Net::NTLM::Int64LE, :value => 0, :active => false },
|
11
|
+
{ :name => :flag, :class => Net::NTLM::Int32LE, :value => Net::NTLM::DEFAULT_FLAGS[:TYPE2], :active => true },
|
12
|
+
{ :name => :target_name, :class => Net::NTLM::SecurityBuffer, :value => '', :active => true },
|
13
|
+
{ :name => :target_info, :class => Net::NTLM::SecurityBuffer, :value => '', :active => false },
|
14
|
+
{ :name => :os_version, :class => Net::NTLM::String, :value => '', :active => false },
|
15
|
+
]
|
16
|
+
flags = [
|
17
|
+
:UNICODE
|
18
|
+
]
|
19
|
+
it_behaves_like 'a fieldset', fields
|
20
|
+
it_behaves_like 'a message', flags
|
21
|
+
|
22
|
+
let(:type2_packet) {"TlRMTVNTUAACAAAAHAAcADgAAAAFgooCJ+UA1//+ZM4AAAAAAAAAAJAAkABUAAAABgGxHQAAAA9WAEEARwBSAEEATgBUAC0AMgAwADAAOABSADIAAgAcAFYAQQBHAFIAQQBOAFQALQAyADAAMAA4AFIAMgABABwAVgBBAEcAUgBBAE4AVAAtADIAMAAwADgAUgAyAAQAHAB2AGEAZwByAGEAbgB0AC0AMgAwADAAOABSADIAAwAcAHYAYQBnAHIAYQBuAHQALQAyADAAMAA4AFIAMgAHAAgAZBMdFHQnzgEAAAAA"}
|
23
|
+
let(:type3_packet) {"TlRMTVNTUAADAAAAGAAYAEQAAADAAMAAXAAAAAAAAAAcAQAADgAOABwBAAAUABQAKgEAAAAAAAA+AQAABYKKAgAAAADVS27TfQGmWxSSbXmolTUQyxJmD8ISQuBKKHFKC8GksUZISYc8Ps9RAQEAAAAAAAAANasTdCfOAcsSZg/CEkLgAAAAAAIAHABWAEEARwBSAEEATgBUAC0AMgAwADAAOABSADIAAQAcAFYAQQBHAFIAQQBOAFQALQAyADAAMAA4AFIAMgAEABwAdgBhAGcAcgBhAG4AdAAtADIAMAAwADgAUgAyAAMAHAB2AGEAZwByAGEAbgB0AC0AMgAwADAAOABSADIABwAIAGQTHRR0J84BAAAAAAAAAAB2AGEAZwByAGEAbgB0AGsAbwBiAGUALgBsAG8AYwBhAGwA"}
|
24
|
+
|
25
|
+
it 'should deserialize' do
|
26
|
+
t2 = Net::NTLM::Message.decode64(type2_packet)
|
27
|
+
expect(t2.class).to eq(Net::NTLM::Message::Type2)
|
28
|
+
expect(t2.challenge).to eq(14872292244261496103)
|
29
|
+
expect(t2.context).to eq(0)
|
30
|
+
expect(t2.flag).to eq(42631685)
|
31
|
+
expect(t2.os_version).to eq(['0601b11d0000000f'].pack('H*'))
|
32
|
+
expect(t2.sign).to eq("NTLMSSP\0")
|
33
|
+
|
34
|
+
t2_target_info = Net::NTLM::EncodeUtil.decode_utf16le(t2.target_info)
|
35
|
+
if RUBY_VERSION == "1.8.7"
|
36
|
+
expect(t2_target_info).to eq("\x02\x1CVAGRANT-2008R2\x01\x1CVAGRANT-2008R2\x04\x1Cvagrant-2008R2\x03\x1Cvagrant-2008R2\a\b\e$(D+&\e(B\0\0")
|
37
|
+
else
|
38
|
+
expect(t2_target_info).to eq("\u0002\u001CVAGRANT-2008R2\u0001\u001CVAGRANT-2008R2\u0004\u001Cvagrant-2008R2\u0003\u001Cvagrant-2008R2\a\b፤ᐝ❴ǎ\0\0")
|
39
|
+
end
|
40
|
+
|
41
|
+
expect(Net::NTLM::EncodeUtil.decode_utf16le(t2.target_name)).to eq("VAGRANT-2008R2")
|
42
|
+
expect(t2.type).to eq(2)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should serialize' do
|
46
|
+
source = Net::NTLM::Message.decode64(type2_packet)
|
47
|
+
|
48
|
+
t2 = Net::NTLM::Message::Type2.new
|
49
|
+
t2.challenge = source.challenge
|
50
|
+
t2.context = source.context
|
51
|
+
t2.flag = source.flag
|
52
|
+
t2.os_version = source.os_version
|
53
|
+
t2.sign = source.sign
|
54
|
+
t2.target_info = source.target_info
|
55
|
+
t2.target_name = source.target_name
|
56
|
+
t2.type = source.type
|
57
|
+
t2.enable(:context)
|
58
|
+
t2.enable(:target_info)
|
59
|
+
t2.enable(:os_version)
|
60
|
+
|
61
|
+
expect(t2.encode64).to eq(type2_packet)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should generate a type 3 response' do
|
65
|
+
t2 = Net::NTLM::Message.decode64(type2_packet)
|
66
|
+
|
67
|
+
type3_known = Net::NTLM::Message.decode64(type3_packet)
|
68
|
+
type3_known.flag = 0x028a8205
|
69
|
+
type3_known.enable(:session_key)
|
70
|
+
type3_known.enable(:flag)
|
71
|
+
|
72
|
+
t3 = t2.response({:user => 'vagrant', :password => 'vagrant', :domain => ''}, {:ntlmv2 => true, :workstation => 'kobe.local'})
|
73
|
+
expect(t3.domain).to eq(type3_known.domain)
|
74
|
+
expect(t3.flag).to eq(type3_known.flag)
|
75
|
+
expect(t3.sign).to eq("NTLMSSP\0")
|
76
|
+
expect(t3.workstation).to eq("k\0o\0b\0e\0.\0l\0o\0c\0a\0l\0")
|
77
|
+
expect(t3.user).to eq("v\0a\0g\0r\0a\0n\0t\0")
|
78
|
+
expect(t3.session_key).to eq('')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should upcase domain when provided' do
|
82
|
+
t2 = Net::NTLM::Message.decode64(type2_packet)
|
83
|
+
t3 = t2.response({:user => 'vagrant', :password => 'vagrant', :domain => 'domain'}, {:ntlmv2 => true, :workstation => 'kobe.local'})
|
84
|
+
expect(t3.domain).to eq("D\0O\0M\0A\0I\0N\0")
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '.parse' do
|
88
|
+
subject(:message) { described_class.parse(data) }
|
89
|
+
# http://davenport.sourceforge.net/ntlm.html#appendixC7
|
90
|
+
context 'NTLM2 Session Response Authentication; NTLM2 Signing and Sealing Using the 128-bit NTLM2 Session Response User Session Key With Key Exchange Negotiated' do
|
91
|
+
let(:data) do
|
92
|
+
[
|
93
|
+
'4e544c4d53535000020000000c000c0030000000358289e0677f1c557a5ee96c' \
|
94
|
+
'0000000000000000460046003c00000054004500530054004e00540002000c00' \
|
95
|
+
'54004500530054004e00540001000c004d0045004d0042004500520003001e00' \
|
96
|
+
'6d0065006d006200650072002e0074006500730074002e0063006f006d000000' \
|
97
|
+
'0000'
|
98
|
+
].pack('H*')
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should set the magic' do
|
102
|
+
expect(message.sign).to eql(Net::NTLM::SSP_SIGN)
|
103
|
+
end
|
104
|
+
it 'should set the type' do
|
105
|
+
expect(message.type).to eq(2)
|
106
|
+
end
|
107
|
+
it 'should set the target name' do
|
108
|
+
# TESTNT
|
109
|
+
expect(message.target_name).to eq(["54004500530054004e005400"].pack('H*'))
|
110
|
+
end
|
111
|
+
it 'should set the flags' do
|
112
|
+
expect(message.flag).to eq(0xe0898235)
|
113
|
+
end
|
114
|
+
it 'should set the challenge' do
|
115
|
+
expect(message.challenge).to eq(0x6ce95e7a551c7f67)
|
116
|
+
end
|
117
|
+
it 'should set an empty context' do
|
118
|
+
expect(message.context).to be_zero
|
119
|
+
end
|
120
|
+
it 'should set target info' do
|
121
|
+
ti = [
|
122
|
+
'02000c0054004500530054004e00540001000c004d0045004d00420045005200' \
|
123
|
+
'03001e006d0065006d006200650072002e0074006500730074002e0063006f00' \
|
124
|
+
'6d0000000000'
|
125
|
+
].pack('H*')
|
126
|
+
expect(message.target_info).to eq(ti)
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|