Class: HashIdentifier

Inherits:
Object
  • Object
show all
Includes:
Version
Defined in:
lib/haiti.rb,
lib/haiti/hash.rb

Overview

The global Hash Identifier class

Defined Under Namespace

Classes: Chf

Constant Summary collapse

PROTOTYPES =
JSON.parse(File.read(File.join(__dir__, '../data/prototypes.json')))
COMMONS =
JSON.parse(File.read(File.join(__dir__, '../data/commons.json')))

Constants included from Version

Version::VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HashIdentifier

A new instance of hash identifier

Parameters:

  • hash (String)

    the hash to identify



27
28
29
30
31
# File 'lib/haiti.rb', line 27

def initialize(hash)
  @hash = hash
  @type = identify(hash)
  sort_commons
end

Instance Attribute Details

#hashString (readonly)

Returns the hash (as provided).

Examples:

'5f4dcc3b5aa765d61d8327deb882cf99'

Returns:

  • (String)

    the hash (as provided)



19
20
21
# File 'lib/haiti.rb', line 19

def hash
  @hash
end

#typeArray<Chf> (readonly)

Returns list of Chf objects, representing the identified hashes.

Returns:

  • (Array<Chf>)

    list of Chf objects, representing the identified hashes



23
24
25
# File 'lib/haiti.rb', line 23

def type
  @type
end

Class Method Details

.listArray<String>

List names of all hash types available

Examples:

HashIdentifier.list
# => ["CRC-16", "CRC-16-CCITT", "FCS-16", "Adler-32", "CRC-32B", "FCS-32", ...]

Returns:

  • (Array<String>)

    a list of hash types name



59
60
61
# File 'lib/haiti.rb', line 59

def list
  (PROTOTYPES.flat_map { |d| d['modes'].map { |m| m['name'] } }).sort { |a, b| a.downcase <=> b.downcase }.uniq
end

.object_listArray<Chf>

List all hash types available as <Chf> object

Returns:

  • (Array<Chf>)

    a list of hash types object



65
66
67
68
69
70
71
# File 'lib/haiti.rb', line 65

def object_list
  (PROTOTYPES.flat_map do |d|
     d['modes'].map do |m|
       Chf.new(m)
     end
   end).sort { |a, b| a.name.downcase <=> b.name.downcase }.uniq
end

.samples(input) ⇒ Array<String>

Find hash samples for a given hash type (by name or hashcat/john the ripper reference)

Examples:

HashIdentifier.samples('crc32')
# => ["c762de4a:00000000", "$crc32$00000000.fa455f6b", "$crc32$4ff4f23f.ce6eb863", "5e23d60f:00000000"]

Parameters:

  • input (String|Integer)

    hash type name, hashcat reference, john the ripper reference

Returns:

  • (Array<String>)

    a list of samples



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/haiti.rb', line 40

def samples(input)
  samples = []
  PROTOTYPES.each do |prototype|
    prototype['modes'].each do |mode|
      if [mode['name'].downcase, mode['hashcat'].to_s,
          mode['john'].nil? ? mode['john'] : mode['john'].downcase].include?(input.to_s.downcase)
        samples << Chf.new(mode).samples
      end
    end
  end
  samples.delete(nil)
  samples.flatten.uniq
end