-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
haiti
executable file
·87 lines (77 loc) · 2.91 KB
/
haiti
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env ruby
# frozen_string_literal: true
# Ruby internal
# Project internal
require 'haiti'
# External
require 'docopt'
require 'paint'
doc = <<~DOCOPT
#{Paint['HAITI (HAsh IdenTifIer)', '#FF69B4']} v#{Paint[HashIdentifier::VERSION, :bold]}
#{Paint['Usage:', '#00FFFF']}
haiti [options] <hash>
haiti samples (<ref> | <name>)
haiti --ascii-art
haiti -h | --help
haiti --version
#{Paint['Commands:', '#00FFFF']}
samples Display hash samples for the given type
#{Paint['Parameters:', '#00FFFF']}
<hash> Hash string to identify, read from STDIN if equal to "-"
<ref> hashcat or john the ripper reference
<name> Hash type name
#{Paint['Options:', '#00FFFF']}
--no-color Disable colorized output (NO_COLOR environment variable is respected too)
-e, --extended List all possible hash algorithms including ones using salt
--short Display in a short format: do not display hashcat and john the ripper references
--hashcat-only Show only hashcat references
--john-only Show only john the ripper references
--ascii-art Display the logo in colored ascii-art
--debug Display arguments
-h, --help Show this screen
--version Show version
#{Paint['Examples:', '#00FFFF']}
haiti -e d41d8cd98f00b204e9800998ecf8427e
haiti --no-color --short d41d8cd98f00b204e9800998ecf8427e
b2sum /etc/os-release | awk '{print $1}' | haiti -
haiti samples crc32
#{Paint['Project:', '#00FFFF']}
#{Paint['author', :underline]} (https://pwn.by/noraj / https://twitter.com/noraj_rawsec)
#{Paint['source', :underline]} (https://github.com/noraj/haiti)
#{Paint['documentation', :underline]} (https://noraj.github.io/haiti)
DOCOPT
begin
args = Docopt.docopt(doc, version: HashIdentifier::VERSION)
Paint.mode = 0 if args['--no-color']
puts args if args['--debug']
# use case 1, using the tool
if args['<hash>']
args['<hash>'] = $stdin.read.chomp if args['<hash>'] == '-'
hi = HashIdentifier.new(args['<hash>'])
if hi.type.empty?
puts 'Unknown hash type'
exit(0)
end
hi.type.each do |type|
next if type.extended && !args['--extended']
print Paint[type.name, :bold]
unless type.hashcat.nil? || args['--short'] || args['--john-only']
print Paint[" [HC: #{type.hashcat}]", '#00FFFF']
end
print Paint[" [JtR: #{type.john}]", '#FF69B4'] unless type.john.nil? || args['--short'] || args['--hashcat-only']
puts
end
elsif args['samples']
input = args['<ref>'] || args['<name>']
samples = HashIdentifier.samples(input)
samples.each do |sample|
puts sample
end
elsif args['--ascii-art']
puts File.read(File.join(__dir__, '../docs/_media/logo.ascii'))
end
# use case 2, help: already handled by docopt
# use case 3, version: already handled by docopt
rescue Docopt::Exit => e
puts e.message
end