2022-08-24 12:33:57 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
##
|
|
|
|
## 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.
|
2022-08-25 18:33:10 +00:00
|
|
|
##
|
2022-08-24 12:33:57 +00:00
|
|
|
## 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
|
|
|
|
## $ ./hashcat kdbxdb.hash wordlist.dict
|
|
|
|
##
|
|
|
|
## Note that the redirection operator > also works on Windows cmd.exe.
|
|
|
|
## To run perl in Windows use strawberry perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use File::Find;
|
|
|
|
use Digest::SHA;
|
2022-08-25 18:33:10 +00:00
|
|
|
use XML::Simple;
|
2022-08-24 12:33:57 +00:00
|
|
|
|
|
|
|
my $sha = Digest::SHA->new ("sha256");
|
|
|
|
|
|
|
|
my @folders = @ARGV;
|
|
|
|
|
2022-08-25 18:33:10 +00:00
|
|
|
if (scalar @folders == 0)
|
2022-08-24 12:33:57 +00:00
|
|
|
{
|
|
|
|
die ("use: $0 folder1 folder2...\n");
|
|
|
|
}
|
|
|
|
|
2022-08-25 18:33:10 +00:00
|
|
|
my $conf =
|
|
|
|
{
|
|
|
|
wanted => \&handlefile,
|
|
|
|
no_chdir => 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
find ($conf, @folders);
|
2022-08-24 12:33:57 +00:00
|
|
|
|
2022-08-25 18:33:10 +00:00
|
|
|
sub handlefile
|
2022-08-24 12:33:57 +00:00
|
|
|
{
|
|
|
|
my $file = $_;
|
|
|
|
|
|
|
|
return unless -f $file;
|
|
|
|
return unless -r $file;
|
|
|
|
|
2022-08-25 18:33:10 +00:00
|
|
|
open (my $fh, $file) or return;
|
|
|
|
|
|
|
|
binmode $fh;
|
|
|
|
|
|
|
|
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);
|
2022-08-24 12:33:57 +00:00
|
|
|
|
2022-08-25 18:33:10 +00:00
|
|
|
my $digest = $sha_copy->hexdigest;
|
2022-08-24 12:33:57 +00:00
|
|
|
|
2022-08-25 18:33:10 +00:00
|
|
|
print "$digest\n";
|
|
|
|
}
|
2022-08-24 12:33:57 +00:00
|
|
|
}
|