mirror of
https://github.com/hashcat/hashcat.git
synced 2024-12-22 06:38:11 +00:00
Add XML support for keepass keyfile and improve performance by not using chdir()
This commit is contained in:
parent
fd5700a607
commit
e363bf787e
65
tools/recursivefiles2sha256sum.pl
Normal file → Executable file
65
tools/recursivefiles2sha256sum.pl
Normal file → Executable file
@ -3,7 +3,7 @@
|
||||
##
|
||||
## This script was created to be used in conjunction with Hashcat mode 29700 (Keepass in keyfile only mode).
|
||||
## This can be useful if you have a partition and forgot which of the files was used as the keyfile.
|
||||
##
|
||||
##
|
||||
## Example use (if your target drive is mounted to /mnt/sda1 and (optionally) another one to /mnt/sda2):
|
||||
##
|
||||
## $ perl recursivefiles2sha256sum /mnt/sda1 /mnt/sda2 > wordlist.dict
|
||||
@ -16,30 +16,77 @@ use strict;
|
||||
use warnings;
|
||||
use File::Find;
|
||||
use Digest::SHA;
|
||||
use XML::Simple;
|
||||
|
||||
my $sha = Digest::SHA->new ("sha256");
|
||||
|
||||
my @folders = @ARGV;
|
||||
|
||||
if (scalar @folders == 0)
|
||||
if (scalar @folders == 0)
|
||||
{
|
||||
die ("use: $0 folder1 folder2...\n");
|
||||
}
|
||||
|
||||
find (\&handlefile, @folders);
|
||||
my $conf =
|
||||
{
|
||||
wanted => \&handlefile,
|
||||
no_chdir => 1,
|
||||
};
|
||||
|
||||
sub handlefile
|
||||
find ($conf, @folders);
|
||||
|
||||
sub handlefile
|
||||
{
|
||||
my $file = $_;
|
||||
|
||||
return unless -f $file;
|
||||
return unless -r $file;
|
||||
|
||||
my $sha_copy = $sha->clone;
|
||||
|
||||
$sha_copy->addfile ($file);
|
||||
open (my $fh, $file) or return;
|
||||
|
||||
my $digest = $sha_copy->hexdigest;
|
||||
binmode $fh;
|
||||
|
||||
print "$digest\n";
|
||||
my $nread = read ($fh, my $data, 5);
|
||||
|
||||
close ($fh);
|
||||
|
||||
my $xmlhash;
|
||||
|
||||
if (($nread == 5) && ($data eq "<?xml"))
|
||||
{
|
||||
my $xml = eval { XMLin ($file) or die };
|
||||
|
||||
if ($@)
|
||||
{
|
||||
# not interesting
|
||||
}
|
||||
else
|
||||
{
|
||||
if (exists $xml->{"Key"} && exists $xml->{"Key"}->{"Data"})
|
||||
{
|
||||
chomp $xml->{"Key"}->{"Data"};
|
||||
|
||||
$xmlhash = $xml->{"Key"}->{"Data"};
|
||||
}
|
||||
else
|
||||
{
|
||||
# not interesting
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defined $xmlhash)
|
||||
{
|
||||
print "$xmlhash\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
my $sha_copy = $sha->clone;
|
||||
|
||||
$sha_copy->addfile ($file);
|
||||
|
||||
my $digest = $sha_copy->hexdigest;
|
||||
|
||||
print "$digest\n";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user