kh2hc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 55b4188b8e1e718687f18b3f45b120f1d04da27c6c906bf9c6c7c89e005282f8
4
+ data.tar.gz: 92b9439b9d9492bb58e38cc67788f54c256999c5fa119aa3d0f4f8ae0514cb1d
5
+ SHA512:
6
+ metadata.gz: 53b67dcd4e5e51f41f0a709dd37092da8734ae0794814ff670e7b35cc0aa824159219c5b49f630a09549d75c5592027d85ce76f43d44d946bf79bbf0d0ac4283
7
+ data.tar.gz: be057f802bca5560e4862cc3dd04f1edb4172216da83694008a58c62e559318857ab2d90afd0b5386eb7f93c6eda50e689022506f1aeb6d2aee424d6943bbc64
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Alexandre ZANNI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/bin/kh2hc ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Ruby internal
5
+ # Project internal
6
+ require 'kh2hc'
7
+ require 'kh2hc/cli'
8
+ # External
9
+
10
+ Kh2hc::CLI
data/lib/kh2hc/cli.rb ADDED
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ruby internal
4
+ # Project internal
5
+ # External
6
+ require 'docopt'
7
+
8
+ module Kh2hc
9
+ # module use for the CLI binary only, not required by the library
10
+ module CLI
11
+ doc = <<~DOCOPT
12
+ kh2hc v#{Kh2hc::VERSION}
13
+
14
+ Usage:
15
+ kh2hc <know_hosts> [<hashcat>] [--no-color --debug]
16
+ kh2hc -h | --help
17
+ kh2hc --version
18
+
19
+ Parameters:
20
+ <know_hosts> OpenSSH known_hosts file hashed with HashKnownHosts
21
+ <hashcat> Output file containing hash crackable by Hashcat
22
+
23
+ Options:
24
+ --no-color Disable colorized output
25
+ --debug Display arguments
26
+ -h, --help Show this screen
27
+ --version Show version
28
+ DOCOPT
29
+
30
+ begin
31
+ args = Docopt.docopt(doc, version: Kh2hc::VERSION)
32
+ Paint.mode = 0 if args['--no-color']
33
+ puts args if args['--debug']
34
+ if args['<know_hosts>']
35
+ if Kh2hc.hashed?(args['<know_hosts>'])
36
+ hc = Kh2hc.convert1(args['<know_hosts>'])
37
+ if args['<hashcat>']
38
+ File.write(args['<hashcat>'], hc)
39
+ else
40
+ puts hc
41
+ end
42
+ else
43
+ puts 'Good news, the hosts file is not hashed'
44
+ end
45
+ end
46
+ rescue Docopt::Exit => e
47
+ puts e.message
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kh2hc
4
+ # Version of Kh2hc library and app
5
+ VERSION = '0.0.1'
6
+ end
data/lib/kh2hc.rb ADDED
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ruby internal
4
+ # Project internal
5
+ require 'kh2hc/version'
6
+ # External
7
+ require 'ctf_party'
8
+
9
+ # known_hosts to Hashcat
10
+ module Kh2hc
11
+ # Convert OpenSSH known_hosts file hashed with HashKnownHosts to an array of hashes crackable by Hashcat.
12
+ # @param khfile [String] OpenSSH known_hosts file
13
+ # @return [Array<Hash>] An array of Hash. Each Hash has two keys: the `:hash` of the host hash,
14
+ # the `:salt` of the host hash
15
+ def self.convert(khfile)
16
+ hosts = []
17
+ data = File.read(khfile)
18
+ # |<Magic string>|<salt>|<hash> <key algorithm> <public key sig.>
19
+ data.scan(/^\|1\|([^|]+)\|([^|].+) .+ .+$/).each do |host|
20
+ # hash:salt
21
+ hosts << { hash: host[1].from_b64.to_hex, salt: host[0].from_b64.to_hex }
22
+ end
23
+ hosts
24
+ end
25
+
26
+ # Convert OpenSSH known_hosts file hashed with HashKnownHosts to a hash file crackable by Hashcat.
27
+ # @param khfile [String] OpenSSH known_hosts file
28
+ # @return [String] hash file in Hashcat format
29
+ def self.convert1(khfile)
30
+ hc_out = []
31
+ convert(khfile).each do |host|
32
+ hc_out << "#{host[:hash]}:#{host[:salt]}"
33
+ end
34
+ hc_out.join("\n")
35
+ end
36
+
37
+ # Check if OpenSSH known_hosts is hashed with HashKnownHosts option or not.
38
+ # @param khfile [String] OpenSSH known_hosts file
39
+ # @return [Boolean] `true` is hashed
40
+ def self.hashed?(khfile)
41
+ File.open(khfile) do |f|
42
+ return f.read(3) == '|1|'
43
+ end
44
+ # Resources friendly version of:
45
+ # data = File.read(khfile)
46
+ # /\A\|1\|/.match?(data)
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kh2hc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre ZANNI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ctf-party
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: docopt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ description: Convert OpenSSH known_hosts file hashed with HashKnownHosts to hashes
42
+ crackable by Hashcat.
43
+ email: alexandre.zanni@europe.com
44
+ executables:
45
+ - kh2hc
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE
50
+ - bin/kh2hc
51
+ - lib/kh2hc.rb
52
+ - lib/kh2hc/cli.rb
53
+ - lib/kh2hc/version.rb
54
+ homepage: https://noraj.github.io/kh2hc/
55
+ licenses:
56
+ - MIT
57
+ metadata:
58
+ yard.run: yard
59
+ bug_tracker_uri: https://github.com/noraj/kh2hc/issues
60
+ changelog_uri: https://github.com/noraj/kh2hc/blob/master/docs/CHANGELOG.md
61
+ documentation_uri: https://noraj.github.io/kh2hc/
62
+ homepage_uri: https://noraj.github.io/kh2hc/
63
+ source_code_uri: https://github.com/noraj/kh2hc/
64
+ rubygems_mfa_required: 'true'
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 3.0.0
74
+ - - "<"
75
+ - !ruby/object:Gem::Version
76
+ version: '4.0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.4.6
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Convert OpenSSH known_hosts file hashed with HashKnownHosts to hashes crackable
87
+ by Hashcat.
88
+ test_files: []