rubyntlm 0.5.1 → 0.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0f0a253f64eaf9c8dc94df34a8f2ca3e92cc43f
4
- data.tar.gz: 85e3ac2289f6ed8cd265429280e2be7c1187d05d
3
+ metadata.gz: 2103fa846f443b850a3fbdd0890e8b491b7acd10
4
+ data.tar.gz: 9bbe755137b115b92f9ca70ce6b62299a36df823
5
5
  SHA512:
6
- metadata.gz: 9a87594be04e9d3cd5630e0ad3ed19f8d069daf4c39c78b33f5c19487fdc97960e40bc2f62b689c5f4004895befc5cb1ab38d4a781d630bcda4b50aa098d1112
7
- data.tar.gz: 7697d3619ceef486dcde7461eabc8ba9f0a7e60f9315088e01f23285b029e506b80c6f509f3aa3964fb593b6a3842a6669e96e115ad11b69d47f3c988bddea12
6
+ metadata.gz: fac19845cd742849e9771a8a90e7037c58d3c35255d8f5b30ceb217358a2f4a540b5f700ec181dcb2895a859799a326ee48cf85e30dd8c6d0783127b2f9e08b4
7
+ data.tar.gz: b294daa239f3652aa9903de8689e24b833adc30b18ba2a80cf20c968984bac61640af158a0801cccb3d541730d1e1fab7b1338dae9a8a72aa7defd1aaf2ab0ce
@@ -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 workstaiton to authenticate to
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
- ntlmhash = ntlm_hash(password, opt)
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)
@@ -4,7 +4,7 @@ module Net
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 5
7
- TINY = 1
7
+ TINY = 2
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
10
10
  end
@@ -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
  {
@@ -1,4 +1,6 @@
1
1
  require 'simplecov'
2
+ require 'pathname'
3
+
2
4
  SimpleCov.start do
3
5
  add_filter '/spec/'
4
6
  add_filter '/config/'
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.1
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-06-23 00:00:00.000000000 Z
12
+ date: 2015-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry