smbhash 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.travis.yml +1 -1
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/README.md +8 -7
- data/Rakefile +3 -7
- data/lib/smbhash.rb +5 -7
- data/smbhash.gemspec +2 -1
- data/spec/smbhash/smbhash_spec.rb +39 -0
- data/spec/spec_helper.rb +7 -0
- metadata +22 -6
- data/test/test_samba_encrypt.rb +0 -39
data/.gitignore
ADDED
data/.travis.yml
CHANGED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.2.5)
|
5
|
+
rake (10.2.2)
|
6
|
+
rspec (2.14.1)
|
7
|
+
rspec-core (~> 2.14.0)
|
8
|
+
rspec-expectations (~> 2.14.0)
|
9
|
+
rspec-mocks (~> 2.14.0)
|
10
|
+
rspec-core (2.14.8)
|
11
|
+
rspec-expectations (2.14.5)
|
12
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
13
|
+
rspec-mocks (2.14.6)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
rake
|
20
|
+
rspec (~> 2.14)
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# ruby-smbhash
|
2
2
|
[![Build Status](https://travis-ci.org/krissi/ruby-smbhash.svg?branch=master)](https://travis-ci.org/krissi/ruby-smbhash)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/smbhash.svg)](http://badge.fury.io/rb/smbhash)
|
3
4
|
|
4
5
|
## Description
|
5
6
|
ruby-smbhash is a implementation of lanman and nt md4 hash functions for use in Samba style smbpasswd entries. It was stripped from ActiveSambaLDAP (http://asl.rubyforge.org/activesambaldap/)
|
@@ -12,16 +13,16 @@ ruby-smbhash is a implementation of lanman and nt md4 hash functions for use in
|
|
12
13
|
* MRI 2.1.1
|
13
14
|
|
14
15
|
## Usage
|
15
|
-
require '
|
16
|
+
require 'smbhash'
|
16
17
|
|
17
|
-
|
18
|
-
=> "E52CAC67419A9A224A3B108F3FA6CB6D"
|
18
|
+
Smbhash.lm_hash "password"
|
19
|
+
# => "E52CAC67419A9A224A3B108F3FA6CB6D"
|
19
20
|
|
20
|
-
|
21
|
-
=> "8846F7EAEE8FB117AD06BDD830B7586C"
|
21
|
+
Smbhash.ntlm_hash "password"
|
22
|
+
# => "8846F7EAEE8FB117AD06BDD830B7586C"
|
22
23
|
|
23
|
-
|
24
|
-
=> ["E52CAC67419A9A224A3B108F3FA6CB6D", "8846F7EAEE8FB117AD06BDD830B7586C"]
|
24
|
+
Smbhash.ntlmgen "password"
|
25
|
+
# => ["E52CAC67419A9A224A3B108F3FA6CB6D", "8846F7EAEE8FB117AD06BDD830B7586C"]
|
25
26
|
|
26
27
|
## Credits
|
27
28
|
* ActiveSambaLDAP project for sharing the code
|
data/Rakefile
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rspec/core/rake_task'
|
5
5
|
|
6
|
-
|
7
|
-
t.libs << "test"
|
8
|
-
t.test_files = FileList['test/test_*.rb']
|
9
|
-
t.verbose = false
|
10
|
-
end
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
11
7
|
|
data/lib/smbhash.rb
CHANGED
@@ -6,10 +6,8 @@ module Smbhash
|
|
6
6
|
dos_password = Private.convert_encoding("ISO-8859-1",
|
7
7
|
encoding || "UTF-8",
|
8
8
|
password.upcase)
|
9
|
-
if dos_password.size > 14
|
10
|
-
|
11
|
-
dos_password = dos_password[0, 14]
|
12
|
-
end
|
9
|
+
fail ArgumentError, 'Password must be > 14 characters in ISO-8859-1' if dos_password.size > 14
|
10
|
+
|
13
11
|
Private.encrypt_14characters(dos_password).unpack("C*").collect do |char|
|
14
12
|
"%02X" % char
|
15
13
|
end.join
|
@@ -19,9 +17,9 @@ module Smbhash
|
|
19
17
|
ucs2_password = Private.convert_encoding("UTF-16LE",
|
20
18
|
encoding || "UTF-8",
|
21
19
|
password)
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
|
21
|
+
fail ArgumentError, 'Password must be > 255 characters in UTF-16LE' if ucs2_password.size > 255
|
22
|
+
|
25
23
|
hex = OpenSSL::Digest::MD4.new(ucs2_password).hexdigest.upcase
|
26
24
|
hex
|
27
25
|
end
|
data/smbhash.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.platform = Gem::Platform::RUBY
|
3
3
|
s.name = 'smbhash'
|
4
|
-
s.version = '1.0.
|
4
|
+
s.version = '1.0.1'
|
5
5
|
s.license = 'MIT'
|
6
6
|
s.summary = "Lanman/NT hash generator"
|
7
7
|
s.description = "An implementation of lanman and nt md4 hash functions for use in Samba style smbpasswd entries"
|
@@ -16,4 +16,5 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.required_ruby_version = '>= 1.8.7'
|
17
17
|
|
18
18
|
s.add_development_dependency "rake"
|
19
|
+
s.add_development_dependency "rspec"
|
19
20
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'smbhash'
|
3
|
+
|
4
|
+
describe Smbhash do
|
5
|
+
describe '.lm_hash' do
|
6
|
+
it 'returns a valid lanman hash' do
|
7
|
+
expect(Smbhash.lm_hash("password")).to eq("E52CAC67419A9A224A3B108F3FA6CB6D")
|
8
|
+
expect(Smbhash.lm_hash("paSSWOrd")).to eq("E52CAC67419A9A224A3B108F3FA6CB6D")
|
9
|
+
expect(Smbhash.lm_hash("abcdefgabcdefg")).to eq("E0C510199CC66ABDE0C510199CC66ABD")
|
10
|
+
expect(Smbhash.lm_hash("SecREt01")).to eq("FF3750BCC2B22412C2265B23734E0DAC")
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when more than 14 chars are given as password' do
|
14
|
+
it 'raises an ArgumentError' do
|
15
|
+
expect { Smbhash.lm_hash('X' * 15) }.to raise_error(ArgumentError, /14 characters/)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.ntlm_hash' do
|
21
|
+
it 'returns a valid ntlm hash' do
|
22
|
+
expect(Smbhash.ntlm_hash("password")).to eq("8846F7EAEE8FB117AD06BDD830B7586C")
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when more than 255 chars are given as password' do
|
26
|
+
it 'raises an ArgumentError' do
|
27
|
+
expect { Smbhash.ntlm_hash('X' * 256) }.to raise_error(ArgumentError, /255 characters/)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.ntlmgen' do
|
33
|
+
it 'returns the output of .lm_hash and .htlm_hash as array' do
|
34
|
+
expect(Smbhash).to receive(:lm_hash).with("password", anything())
|
35
|
+
expect(Smbhash).to receive(:ntlm_hash).with("password", anything())
|
36
|
+
Smbhash.ntlmgen("password")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smbhash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &12201080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,18 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *12201080
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &12200140 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *12200140
|
25
36
|
description: An implementation of lanman and nt md4 hash functions for use in Samba
|
26
37
|
style smbpasswd entries
|
27
38
|
email:
|
@@ -29,14 +40,18 @@ executables: []
|
|
29
40
|
extensions: []
|
30
41
|
extra_rdoc_files: []
|
31
42
|
files:
|
43
|
+
- .gitignore
|
32
44
|
- .travis.yml
|
45
|
+
- Gemfile
|
46
|
+
- Gemfile.lock
|
33
47
|
- README.md
|
34
48
|
- Rakefile
|
35
49
|
- lib/smbhash.rb
|
36
50
|
- lib/smbhash/methods18.rb
|
37
51
|
- lib/smbhash/methods19.rb
|
38
52
|
- smbhash.gemspec
|
39
|
-
-
|
53
|
+
- spec/smbhash/smbhash_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
40
55
|
homepage: https://github.com/krissi/ruby-smbhash
|
41
56
|
licenses:
|
42
57
|
- MIT
|
@@ -63,4 +78,5 @@ signing_key:
|
|
63
78
|
specification_version: 3
|
64
79
|
summary: Lanman/NT hash generator
|
65
80
|
test_files:
|
66
|
-
-
|
81
|
+
- spec/smbhash/smbhash_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
data/test/test_samba_encrypt.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stringio'
|
3
|
-
require 'smbhash'
|
4
|
-
|
5
|
-
class SambaEncryptTest < Test::Unit::TestCase
|
6
|
-
def test_lm_hash
|
7
|
-
assert_equal("E52CAC67419A9A224A3B108F3FA6CB6D",
|
8
|
-
Smbhash.lm_hash("password"))
|
9
|
-
assert_equal("E52CAC67419A9A224A3B108F3FA6CB6D",
|
10
|
-
Smbhash.lm_hash("paSSWOrd"))
|
11
|
-
assert_equal("E0C510199CC66ABDE0C510199CC66ABD",
|
12
|
-
Smbhash.lm_hash("abcdefgabcdefg"))
|
13
|
-
assert_equal("FF3750BCC2B22412C2265B23734E0DAC",
|
14
|
-
Smbhash.lm_hash("SecREt01"))
|
15
|
-
begin
|
16
|
-
stderr = $stderr
|
17
|
-
$stderr = StringIO.new
|
18
|
-
assert_equal("E0C510199CC66ABDE0C510199CC66ABD",
|
19
|
-
Smbhash.lm_hash("abcdefgabcdefg" + "X"))
|
20
|
-
assert_equal("E0C510199CC66ABDE0C510199CC66ABD",
|
21
|
-
Smbhash.lm_hash("abcdefgabcdefg" + "X" * 100))
|
22
|
-
assert_equal("password is truncated to 14 characters\n" * 2,
|
23
|
-
$stderr.string)
|
24
|
-
ensure
|
25
|
-
$stderr = stderr
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_ntlm_hash
|
30
|
-
assert_equal("8846F7EAEE8FB117AD06BDD830B7586C",
|
31
|
-
Smbhash.ntlm_hash("password"))
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_ntlmgen
|
35
|
-
assert_equal(["E52CAC67419A9A224A3B108F3FA6CB6D", "8846F7EAEE8FB117AD06BDD830B7586C"],
|
36
|
-
Smbhash.ntlmgen("password"))
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|