Class: HashIdentifier

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

Overview

The global Hash Identifier class

Defined Under Namespace

Classes: Chf

Constant Summary collapse

PROTOTYPES =

Constants

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

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



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

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)



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

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



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

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



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

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



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

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



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

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