Class: Thieve

Inherits:
Object
  • Object
show all
Defined in:
lib/thieve.rb

Defined Under Namespace

Classes: Error, KeyInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(colorize = false) ⇒ Thieve

Returns a new instance of Thieve.



101
102
103
104
# File 'lib/thieve.rb', line 101

def initialize(colorize = false)
    @colorize = colorize
    @loot = Hash.new
end

Instance Attribute Details

#lootObject

Returns the value of attribute loot.



7
8
9
# File 'lib/thieve.rb', line 7

def loot
  @loot
end

Instance Method Details

#export_loot(dir) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/thieve.rb', line 15

def export_loot(dir)
    exported = Hash.new
    @loot.each do |type, keys|
        keys.each do |key|
            key.export(dir)
            exported[key.type] ||= Hash.new
            exported[key.type]["#{key.fingerprint}.#{key.ext}"] =
                key.to_json
        end
    end
    File.open("#{dir}/loot.json", "w") do |f|
        f.write(JSON.pretty_generate(exported))
    end
end

#find_matchesObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/thieve.rb', line 85

def find_matches
    @loot["CERTIFICATE"].each do |cert|
        next if (cert.openssl.nil?)
        @loot.each do |type, keys|
            next if (type == "CERTIFICATE")
            keys.each do |key|
                next if (key.openssl.nil?)
                if (cert.openssl.check_private_key(key.openssl))
                    cert.match = "#{key.fingerprint}.#{key.ext}"
                    key.match = "#{cert.fingerprint}.#{cert.ext}"
                end
            end
        end
    end
end

#steal_from(filename) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/thieve.rb', line 106

def steal_from(filename)
    file = Pathname.new(filename).expand_path

    if (file.directory?)
        files = Dir[File.join(file, "**", "*")].reject do |f|
            Pathname.new(f).directory? || Pathname.new(f).symlink?
        end

        files.each do |f|
            extract_from(Pathname.new(f).expand_path)
        end
    else
        extract_from(file)
    end

    return @loot
end

#to_sObject



137
138
139
# File 'lib/thieve.rb', line 137

def to_s
    return summarize_loot
end