forked from nickvourd/CS-Aggressor-Kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSonata.cna
93 lines (83 loc) · 3.35 KB
/
Sonata.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Function to display banner
sub show_banner {
local('$bid');
$bid = $1;
blog($bid, "");
blog($bid, "███████╗ ██████╗ ███╗ ██╗ █████╗ ████████╗ █████╗ ");
blog($bid, "██╔════╝██╔═══██╗████╗ ██║██╔══██╗╚══██╔══╝██╔══██╗ ");
blog($bid, "███████╗██║ ██║██╔██╗ ██║███████║ ██║ ███████║ ");
blog($bid, "╚════██║██║ ██║██║╚██╗██║██╔══██║ ██║ ██╔══██║ ");
blog($bid, "███████║╚██████╔╝██║ ╚████║██║ ██║ ██║ ██║ ██║ ");
blog($bid, "╚══════╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ");
blog($bid, "Version: 1.1");
blog($bid, "Created with <3 by @nickvourd");
blog($bid, "");
}
# Register the Sonata command
beacon_command_register(
"Sonata",
"Hash calculator for local files and strings",
"Usage: Sonata -f/--file <local_filepath> OR Sonata -s/--string <string>"
);
# Function to calculate local file hashes
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);
}
# Function to calculate string hashes
sub hashstring {
local('$string $algo $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);
}
# Main command handler
alias Sonata {
local('$args $type $input');
# Show the banner first
show_banner($1);
$args = substr($0, 7); # Remove "Sonata " from beginning
# Parse arguments
if ($args ismatch '-f (.+)' || $args ismatch '--file (.+)') {
$type = "file";
$input = matched()[0];
}
else if ($args ismatch '-s (.+)' || $args ismatch '--string (.+)') {
$type = "string";
$input = matched()[0];
}
else {
berror($1, "Usage: Sonata -f/--file <filepath> OR Sonata -s/--string <string>");
return;
}
# Calculate and display hashes
if ($type eq "file") {
if (!-exists $input) {
berror($1, "File not found: $input");
return;
}
blog($1, "File: $input");
blog($1, "MD5 : " . hashfile("MD5", $input));
blog($1, "SHA1 : " . hashfile("SHA1", $input));
blog($1, "SHA-256: " . hashfile("SHA-256", $input));
blog($1, "SHA-512: " . hashfile("SHA-512", $input));
}
else {
blog($1, "String: $input");
blog($1, "MD5 : " . hashstring("MD5", $input));
blog($1, "SHA1 : " . hashstring("SHA1", $input));
blog($1, "SHA-256: " . hashstring("SHA-256", $input));
blog($1, "SHA-512: " . hashstring("SHA-512", $input));
}
}