rubyntlm 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/net/ntlm.rb +27 -2
- data/lib/net/ntlm/version.rb +1 -1
- data/spec/lib/net/ntlm_spec.rb +8 -0
- data/spec/spec_helper.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2103fa846f443b850a3fbdd0890e8b491b7acd10
|
4
|
+
data.tar.gz: 9bbe755137b115b92f9ca70ce6b62299a36df823
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fac19845cd742849e9771a8a90e7037c58d3c35255d8f5b30ceb217358a2f4a540b5f700ec181dcb2895a859799a326ee48cf85e30dd8c6d0783127b2f9e08b4
|
7
|
+
data.tar.gz: b294daa239f3652aa9903de8689e24b833adc30b18ba2a80cf20c968984bac61640af158a0801cccb3d541730d1e1fab7b1338dae9a8a72aa7defd1aaf2ab0ce
|
data/lib/net/ntlm.rb
CHANGED
@@ -71,6 +71,26 @@ module Net
|
|
71
71
|
|
72
72
|
class << self
|
73
73
|
|
74
|
+
# Valid format for LAN Manager hex digest portion: 32 hexadecimal characters.
|
75
|
+
LAN_MANAGER_HEX_DIGEST_REGEXP = /[0-9a-f]{32}/i
|
76
|
+
# Valid format for NT LAN Manager hex digest portion: 32 hexadecimal characters.
|
77
|
+
NT_LAN_MANAGER_HEX_DIGEST_REGEXP = /[0-9a-f]{32}/i
|
78
|
+
# Valid format for an NTLM hash composed of `'<LAN Manager hex digest>:<NT LAN Manager hex digest>'`.
|
79
|
+
DATA_REGEXP = /\A#{LAN_MANAGER_HEX_DIGEST_REGEXP}:#{NT_LAN_MANAGER_HEX_DIGEST_REGEXP}\z/
|
80
|
+
|
81
|
+
# Takes a string and determines whether it is a valid NTLM Hash
|
82
|
+
# @param [String] the string to validate
|
83
|
+
# @return [Boolean] whether or not the string is a valid NTLM hash
|
84
|
+
def is_ntlm_hash?(data)
|
85
|
+
decoded_data = data.dup
|
86
|
+
decoded_data = EncodeUtil.decode_utf16le(decoded_data)
|
87
|
+
if DATA_REGEXP.match(decoded_data)
|
88
|
+
true
|
89
|
+
else
|
90
|
+
false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
74
94
|
# Conver the value to a 64-Bit Little Endian Int
|
75
95
|
# @param [String] val The string to convert
|
76
96
|
def pack_int64le(val)
|
@@ -129,10 +149,15 @@ module Net
|
|
129
149
|
# Generate a NTLMv2 Hash
|
130
150
|
# @param [String] user The username
|
131
151
|
# @param [String] password The password
|
132
|
-
# @param [String] target The domain or
|
152
|
+
# @param [String] target The domain or workstation to authenticate to
|
133
153
|
# @option opt :unicode (false) Unicode encode the domain
|
134
154
|
def ntlmv2_hash(user, password, target, opt={})
|
135
|
-
|
155
|
+
if is_ntlm_hash? password
|
156
|
+
decoded_password = EncodeUtil.decode_utf16le(password)
|
157
|
+
ntlmhash = [decoded_password.upcase[33,65]].pack('H32')
|
158
|
+
else
|
159
|
+
ntlmhash = ntlm_hash(password, opt)
|
160
|
+
end
|
136
161
|
userdomain = user.upcase + target
|
137
162
|
unless opt[:unicode]
|
138
163
|
userdomain = EncodeUtil.encode_utf16le(userdomain)
|
data/lib/net/ntlm/version.rb
CHANGED
data/spec/lib/net/ntlm_spec.rb
CHANGED
@@ -51,6 +51,14 @@ describe Net::NTLM do
|
|
51
51
|
expect(Net::NTLM::ntlmv2_hash(user, passwd, domain)).to eq(["04b8e0ba74289cc540826bab1dee63ae"].pack("H*"))
|
52
52
|
end
|
53
53
|
|
54
|
+
context 'when a user passes an NTLM hash for pass-the-hash' do
|
55
|
+
let(:passwd) { Net::NTLM::EncodeUtil.encode_utf16le('ff3750bcc2b22412c2265b23734e0dac:cd06ca7c7e10c99b1d33b7485a2ed808') }
|
56
|
+
|
57
|
+
it 'should return the correct ntlmv2 hash' do
|
58
|
+
expect(Net::NTLM::ntlmv2_hash(user, passwd, domain)).to eq(["04b8e0ba74289cc540826bab1dee63ae"].pack("H*"))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
54
62
|
it 'should generate an lm_response' do
|
55
63
|
expect(Net::NTLM::lm_response(
|
56
64
|
{
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyntlm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Kajimoto
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|