-
Notifications
You must be signed in to change notification settings - Fork 300
/
SMBPayloadGenerator.cna
212 lines (181 loc) · 7.2 KB
/
SMBPayloadGenerator.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#SMB Artifact Payload Generator
#Author: @r3dQu1nn
#Generates any type of Stageless/Staged Payload based off a SMB Listener
#Custom Directory for Payloads
mkdir("/opt/cobaltstrike/SMB_Staged_Payloads");
mkdir("/opt/cobaltstrike/SMB_Stageless_Payloads");
menubar("SMB Payload Generator", "payloadgenerator", 2);
popup payloadgenerator {
menu "&SMB Payload Generator" {
item "&SMB Staged Payloads" {
payloadgeneratestaged();
}
item "&SMB Stageless Payloads" {
payloadgeneratestageless();
}
}
}
sub payloadgeneratestaged {
$dialog = dialog("SMB Payload Generator", %(listener => "Listener: ", payload_type => "Payload Type: ", Output => "Output: "), &Staged_Output);
dialog_description($dialog, "Generates a Staged or Stageless SMB Payload based on the selected SMB listener. **Payloads will be stored in /opt/cobaltstrike/SMB_Staged_Payloads**");
drow_listener_smb($dialog, "listener", "Listener: ");
drow_text($dialog, "Name", "Payload Name: ");
drow_combobox($dialog, "payload_type", "Payload Type: ", @("Staged"));
drow_combobox($dialog, "Output", "Output: ", @("dll", "dllx64", "exe", "powershell", "python", "svcexe", "vbscript"));
dbutton_action($dialog, "Generate");
dialog_show($dialog);
}
sub payloadgeneratestageless {
$dialog = dialog("SMB Payload Generator", %(listener => "Listener: ", payload_type => "Payload Type: ", Output => "Output: "), &Stageless_Output);
dialog_description($dialog, "Generates a Staged or Stageless SMB Payload based on the selected SMB listener. **Payloads will be stored in /opt/cobaltstrike/SMB_Stageless_Payloads**");
drow_listener_smb($dialog, "listener", "Listener: ");
drow_text($dialog, "Name", "Payload Name: ");
drow_combobox($dialog, "payload_type", "Payload Type: ", @("Stageless"));
drow_combobox($dialog, "Output", "Output: ", @("dll", "dllx64", "exe", "powershell", "svcexe", "raw"));
dbutton_action($dialog, "Generate");
dialog_show($dialog);
}
sub Staged_Output {
#Error Check
if ($3['Name'] ismatch "") {
berror($1, 'You did not select a proper SMB Listener or Input a Payload Name!');
show_message("Please select a proper SMB Listener and Input a Payload Name!");
}
#Staged Payloads
else if ($3['Output'] eq 'dll') {
$data = artifact($3['listener'], "dll");
$handle = openf(">/opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".dll");
writeb($handle, $data);
closef($handle);
show_message("Saved SMB DLL at /opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".dll");
clear($3);
}
else if ($3['Output'] eq 'dllx64') {
$data = artifact($3['listener'], "dllx64");
$handle = openf(">/opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".dll");
writeb($handle, $data);
closef($handle);
show_message("Saved 64 bit SMB DLL at /opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".dll");
clear($3);
}
else if ($3['Output'] eq 'exe') {
$data = artifact($3['listener'], "exe");
$handle = openf(">/opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".exe");
writeb($handle, $data);
closef($handle);
show_message("Saved EXE at /opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".exe");
clear($3);
}
else if ($3['Output'] eq 'powershell') {
$data = artifact($3['listener'], "powershell");
$handle = openf(">/opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] ."");
writeb($handle, $data);
closef($handle);
show_message("Saved Powershell SMB Payload at /opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] ."");
clear($3);
}
else if ($3['payload_type'] eq 'Staged' && $3['Output'] eq 'python') {
$data = artifact($3['listener'], "python");
$handle = openf(">/opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".py");
writeb($handle, $data);
closef($handle);
show_message("Saved Python SMB Payload at /opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".py");
clear($3);
}
else if ($3['payload_type'] eq 'Staged' && $3['Output'] eq 'svcexe') {
$data = artifact($3['listener'], "svcexe");
$handle = openf(">/opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".exe");
writeb($handle, $data);
closef($handle);
show_message("Saved SVCEXE at /opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".exe");
clear($3);
}
else if ($3['payload_type'] eq 'Staged' && $3['Output'] eq 'vbscript') {
$data = artifact($3['listener'], "vbscript");
$handle = openf(">/opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".vbs");
writeb($handle, $data);
closef($handle);
show_message("Saved vbscript SMB Payload at /opt/cobaltstrike/SMB_Staged_Payloads/". $3['Name'] .".vbs");
clear($3);
}
}
sub Stageless_Output {
if ($3['Name'] ismatch "") {
berror($1, 'You did not select a proper SMB Listener or Input a Payload Name!');
show_message("Please select a proper SMB Listener and Input a Payload Name!");
}
#Stageless Payloads
else if ($3['Output'] eq 'dll') {
artifact_stageless($3['listener'], "dll", "x86", "", &dll);
$Name = "".$3['Name']."";
}
else if ($3['Output'] eq 'dllx64') {
artifact_stageless($3['listener'], "dllx64", "x86", "", &dllx64);
$Name = "".$3['Name']."";
}
else if ($3['Output'] eq 'exe') {
artifact_stageless($3['listener'], "exe", "x86", "", &exe);
$Name = "".$3['Name']."";
}
else if ($3['Output'] eq 'powershell') {
artifact_stageless($3['listener'], "powershell", "x86", "", &ps1);
$Name = "".$3['Name']."";
}
else if ($3['Output'] eq 'raw') {
artifact_stageless($3['listener'], "raw", "x86", "", &raw);
$Name = "".$3['Name']."";
}
else if ($3['Output'] eq 'svcexe') {
artifact_stageless($3['listener'], "svcexe", "x86", "", &svcexe);
$Name = "".$3['Name']."";
}
}
#Sub Functions for Stageless Artifacts
sub dll {
#Write and Save Payload
local('$cradle');
$cradle = openf(">/opt/cobaltstrike/SMB_Stageless_Payloads/". $Name .".dll");
writeb($cradle, $1);
closef($cradle);
show_message("Saved SMB DLL at /opt/cobaltstrike/SMB_Stageless_Payloads/". $Name .".dll");
}
sub dllx64 {
#Write and Save Payload
local('$cradle1');
$cradle1 = openf(">/opt/cobaltstrike/SMB_Stageless_Payloads/". $Name .".dll");
writeb($cradle1, $1);
closef($cradle1);
show_message("Saved 64 bit SMB DLL at /opt/cobaltstrike/SMB_Stageless_Payloads/". $Name .".dll");
}
sub exe {
#Write and Save Payload
local('$cradle2');
$cradle2 = openf(">/opt/cobaltstrike/SMB_Stageless_Payloads/". $Name .".exe");
writeb($cradle2, $1);
closef($cradle2);
show_message("Saved EXE at /opt/cobaltstrike/SMB_Stageless_Payloads/". $Name .".exe");
}
sub ps1 {
#Write and Save Payload
local('$cradle3');
$cradle3 = openf(">/opt/cobaltstrike/SMB_Stageless_Payloads/". $Name ."");
writeb($cradle3, $1);
closef($cradle3);
show_message("Saved Powershell SMB Payload at /opt/cobaltstrike/SMB_Stageless_Payloads/". $Name ."");
}
sub raw {
#Write and Save Payload
local('$cradle4');
$cradle4 = openf(">/opt/cobaltstrike/SMB_Stageless_Payloads/". $Name .".bin");
writeb($cradle4, $1);
closef($cradle4);
show_message("Saved Raw SMB Payload at /opt/cobaltstrike/SMB_Stageless_Payloads/". $Name .".bin");
}
sub svcexe {
#Write and Save Payload
local('$cradle5');
$cradle5 = openf(">/opt/cobaltstrike/SMB_Stageless_Payloads/". $Name .".exe");
writeb($cradle5, $1);
closef($cradle5);
show_message("Saved EXE at /opt/cobaltstrike/SMB_Stageless_Payloads/". $Name .".exe");
}