-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
hash.cna
41 lines (34 loc) · 883 Bytes
/
hash.cna
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#
# This script shows how to compute hash value in Aggressor Script.
#
# Supported algorithms:
# - MD5
# - SHA-1
# - SHA-256
#
# Mariusz Banach / mgeeky, '20
# <mb [at] binary-offensive . com
#
# Usage: hashfile("algo", "filepath")
sub hashfile {
local('$f $filepath $algo $d $digest $hash');
$algo = $1;
$filepath = $2;
$f = openf($filepath);
$d = readb($f, -1);
closef($f);
$md = [java.security.MessageDigest getInstance: $algo];
$digest = [$md digest: $d];
$hash = transform($digest, "hex");
return lc($hash);
}
# Usage: hashfile("algo", "string")
sub hashstring {
local('$f $string $algo $d $digest $hash');
$algo = $1;
$string = [$2 getBytes: "UTF-8"];
$md = [java.security.MessageDigest getInstance: $algo];
$digest = [$md digest: $string];
$hash = transform($digest, "hex");
return lc($hash);
}