-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathhuman.html
More file actions
331 lines (310 loc) · 17.8 KB
/
human.html
File metadata and controls
331 lines (310 loc) · 17.8 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<link rel="stylesheet" href="/human/css/human.css">
<div id="human-section-1" class="section-profile">
<div class="row">
<div class="topleft duk-icon"><img onclick="removeSection('human-section-1')" src="/gui/img/x.png"></div>
<div class="column section-border" style="flex:25%;text-align:left;padding:15px;">
<h1 style="font-size: 70px;margin-top:-20px;">Human</h1>
<h2 style="margin-top:-55px;">emulate human behavior</h2>
<p>
This plugin allows you to design a human that will emulate user behavior on an endpoint. Use the following instructions to build and deploy your own human.
</p>
<br/>
</div>
<div class="column" style="flex:75%;margin-right: -25px;align-items: stretch;display: flex;">
<div class="row row-interior install-list">
<div class="column column-interior install-container" style="text-align: left; flex:25%;">
<div class="background-text">1</div>
<span>Install Python3 on the target workstation</span>
</div>
<div class="column column-interior install-container" style="text-align: left; flex:25%;">
<div class="background-text">2</div>
<span>Install Python3 Virtualenv on the target workstation</span>
</div>
<div class="column column-interior install-container" style="text-align: left; flex:25%;">
<div class="background-text">3</div>
<span>Install Chrome on the target workstation</span>
</div>
<div class="column column-interior install-container" style="text-align: left; flex:25%;">
<div class="background-text">4</div>
<span>Build a human below and run the download cradle on the target workstation</span>
</div>
</div>
</div>
</div>
</div>
<div id="human-section-2" class="section-profile human-basic">
<div class="row">
<div class="topleft duk-icon"><img onclick="removeSection('human-section-2')" src="/gui/img/x.png"></div>
<div class="topright duk-icon"></div>
<div class="column section-border" style="flex:25%;text-align:left;padding:15px;">
<h1 id="human-name-header" style="font-size:70px;margin-top:-20px;">Name...</h1>
<h2 style="margin-top:-55px">build your human</h2>
<p>
Design and generate your human here, or select a pre-existing human to deploy. Use the download command to install and start your human.
</p>
<br>
</div>
<div class="column" style="flex:75%;text-align: left;margin-right: -25px;">
<div class="row row-interior">
<div id="behavior-options" class="column column-interior human-box">
<table>
<tr>
<td><p>Name:</p></td>
<td><input id="human-name" type="text" placeholder="Enter human's name..."></td>
</tr>
<tr>
<td><p>Platform:</p></td>
<td>
<select id="base-platform">
<option disabled="disabled" selected="">Select target OS</option>
<option value="freebsd">FreeBSD</option>
<option value="darwin">MacOS</option>
<option value="linux">Linux</option>
<option value="windows-psh">Windows (PowerShell)</option>
</select>
</td>
</tr>
</table>
<hr>
<h4>Select your human's behaviors:</h4>
<ul id="human-tasks">
{% for w in workflows %}
<li>
<input type="checkbox" name="human-{{w.name}}" id="human-{{w.name}}"/>
<span>{{ w.description }}</span>
</li>
{% endfor %}
</ul>
<hr>
<h4>Custom Commands:</h4>
<button id="append-command" class="command-button atomic-button" style="width:30%;background-color:green">Add Command</button>
<button id="clear-commands" class="command-button atomic-button" style="width:30%;background-color:firebrick">Clear Commands</button>
<br><br>
<div id="input-command">
<!-- Place holder for appended custom commands -->
</div>
<hr>
<h4>Human behavior configuration:</h4>
<table>
<tr>
<td><p>Task Sleep Interval</p></td>
<td class="duk-icon duk-table-icon"><img id="duk-task-sleep-interval" src="/gui/img/duk.png"></td>
<td><div><input class="queueOption" type="range" min="5" max="50" value="10" class="slider" id="human-task-interval" name="human-task-interval" onchange="updateNumberField(this);"/></div></td>
<td><input type="number" id="human-task-interval-text" onchange="updateSlider(this);" onload="defaultNumberField(this);"></td>
</tr>
<tr>
<td><p>Task Cluster Sleep Interval</p></td>
<td class="duk-icon duk-table-icon"><img id="duk-cluster-sleep-interval" src="/gui/img/duk.png"></td>
<td><input class="queueOption" type="range" min="5" max="1000" value="500" class="slider" id="human-cluster-interval" name="human-cluster-interval" onchange="updateNumberField(this);"/></td>
<td><input type="number" id="human-cluster-interval-text" onchange="updateSlider(this);"></td>
</tr>
<tr>
<td><p>Tasks per Cluster</p></td>
<td class="duk-icon duk-table-icon"><img id="duk-task-per-cluster" src="/gui/img/duk.png"></td>
<td><input class="queueOption" type="range" min="1" max="20" value="5" class="slider" id="human-task-count" name="human-task-count" onchange="updateNumberField(this);"/></td>
<td><input type="number" id="human-task-count-text" onchange="updateSlider(this);"></td>
</tr>
</table>
<button id="generateLayer" type="button" class="button-success" style="" onclick="generateHuman();">Generate Human</button>
<div id="human-built">
<span id="message"></span>
</div>
</div>
<div class="column column-interior human-box" style="text-align: left;">
<table>
<tr>
<td><p>CALDERA Server IP: </p></td>
<td><input id="server-ip" type="text" value="http://localhost:8888" placeholder="http://localhost:8888" oninput="updateRenderedHuman();" /></td>
</tr>
<tr>
<td><p>Select existing human: </p></td>
<td>
<select id="existing-humans" style="width: 100%;margin-left: 0;" onchange="refreshSelectHuman(this);">
<option disabled="disabled" selected="">Select existing human...</option>
{% for h in humans %}
<option id="human-{{h.name}}" value="human-{{h.name}}">{{h.name}}</option>
{% endfor %}
</select>
</td>
</tr>
</table>
<hr/>
<div class="box container">
<div x-show="window.isSecureContext">
<a class="button is-small is-outlined cmd-copy-button" @click="copyCommandToClipboard();">
<span class="icon"><i class="far fa-lg fa-copy"></i></span>
<span>Copy</span>
</a>
<br /><br />
</div>
<code id="delivery-commands" style="text-align: left; font-size:14px;"></code>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
/**
* Function that stores and renders a human command. When no new human is provided, calling the function will still re-render the command
* to account for other input changes.
*/
const updateRenderedHuman = (() => {
let human_data = null;
return (new_human=null) => {
if (new_human) human_data = new_human;
if (human_data) renderCommandBlock(human_data.task_cluster_interval, human_data.task_interval, human_data.tasks_per_cluster, human_data.extra, human_data.name, human_data.platform);
};
})();
$( document ).ready(function () {
['human-task-interval', 'human-cluster-interval', 'human-task-count'].forEach(elem => defaultNumberField(elem));
stream('Design and generate a human to create noise on hosts');
document.getElementById("server-ip").placeholder = `${location.protocol}//${location.hostname}:${location.port}`;
document.getElementById("server-ip").value = `${location.protocol}//${location.hostname}:${location.port}`;
});
$('#duk-task-sleep-interval').click(function() {
stream('Task Sleep Interval - Maximum sleep time between individual tasks executing')
});
$('#duk-cluster-sleep-interval').click(function () {
stream('Task Cluster Sleep Interval - Maximum sleep time between clusters of tasks executing')
});
$('#duk-task-per-cluster').click(function () {
stream('Tasks per Cluster - Maximum number of tasks to execute per cluster')
});
$('#append-command').click(function () {
$('#input-command').append('<div class="command-wrapper" style="display:flex"><input type="text" class="command" style="flex:90%" placeholder="Enter a single command to run"><div class="delete-command" onclick="deleteHumanCommand(this)">×</div><br class="command-break"></div>');
stream('Input Custom Human Command');
});
$('#clear-commands').click(function () {
$('.command-wrapper').remove();
stream('Cleared Custom Human Commands');
});
function defaultNumberField(elem) {
document.getElementById(elem+'-text').value = document.getElementById(elem).value;
}
function updateNumberField(elem){
document.getElementById(elem.name+'-text').value=elem.value;
}
function updateSlider(elem) {
let slider = elem.id.replace('-text', '');
document.getElementById(slider).value = elem.value;
}
function generateHuman() {
let cmdBlock = $("#delivery-commands");
cmdBlock.empty();
let humanName = $('#human-name').val();
if (humanName === '') {
warn('Enter a human name');
return;
}
let platform = $("#base-platform").val();
if (platform === null) {
warn('Select a platform!');
return;
}
let taskList = [];
$('#human-tasks').find('li > input').each(function (e) {
if ($(this).is(':checked')) {
taskList.push($(this).attr('name').replace('human-', ''));
}
});
if (taskList.length === 0) {
warn('Select tasks for your human to execute!');
return
}
let commands = []
$('.command').each(function(){
commands.push($(this).val())
})
let postData = {
'index': 'build_human',
'platform': platform,
'name': humanName,
'task_cluster_interval': $('#human-cluster-interval').val(),
'task_interval': $('#human-task-interval').val(),
'task_count': $('#human-task-count').val(),
'tasks': taskList,
'extra': commands
};
restRequest('POST', postData, renderBuiltHumanCallback, endpoint = '/plugin/human/api');
}
function deleteHumanCommand(elem) {
$(elem).parent().remove();
}
function renderCommandBlock(taskClusterInterval, taskInterval, taskCount, extra, humanName, platform){
let http = getServerIP();
let baseHuman = "";
let cmdBlock = $("#delivery-commands");
cmdBlock.empty();
$('#human-name-header').text(humanName);
extra = renderExtra(extra, platform);
switch (platform) {
case "darwin":
baseHuman = 'curl -sk -o \''+humanName+'.tar.gz\' -X POST -H \'file:'+humanName+'.tar.gz\' '+http+'/file/download 2>&1 && mkdir \''+humanName+'\' && tar -C \''+humanName+'\' -zxvf \''+humanName+'.tar.gz\' ' +
' && virtualenv -p python3 \''+humanName+'\' && \''+humanName+'/bin/pip\' install -r \''+humanName+'/requirements.txt\' && \''+humanName+'/bin/python\' \''+humanName+'/human.py\' --clustersize '+taskCount+' ' +
'--taskinterval '+taskInterval+' --taskgroupinterval '+taskClusterInterval+' --extra '+extra;
break;
case "freebsd":
baseHuman = 'curl -sk -o \''+humanName+'.tar.gz\' -X POST -H \'file:'+humanName+'.tar.gz\' '+http+'/file/download 2>&1 && mkdir \''+humanName+'\' && tar -C \''+humanName+'\' -zxvf \''+humanName+'.tar.gz\' ' +
' && virtualenv -p python3.9 \''+humanName+'\' && \''+humanName+'/bin/pip\' install -r \''+humanName+'/requirements.txt\' && \''+humanName+'/bin/python\' \''+humanName+'/human.py\' --clustersize '+taskCount+' ' +
'--taskinterval '+taskInterval+' --taskgroupinterval '+taskClusterInterval+' --extra '+extra;
break;
case "linux":
baseHuman = 'curl -sk -o \''+humanName+'.tar.gz\' -X POST -H \'file:'+humanName+'.tar.gz\' '+http+'/file/download 2>&1 && mkdir \''+humanName+'\' && tar -C \''+humanName+'\' -zxvf \''+humanName+'.tar.gz\' ' +
' && virtualenv -p python3 \''+humanName+'\' && \''+humanName+'/bin/pip\' install -r \''+humanName+'/requirements.txt\' && \''+humanName+'/bin/python\' \''+humanName+'/human.py\' --clustersize '+taskCount+' ' +
'--taskinterval '+taskInterval+' --taskgroupinterval '+taskClusterInterval+' --extra '+extra;
break;
case "windows-psh":
baseHuman = '$server="'+http+'"; $url="$server/file/download"; $wc=New-Object System.Net.WebClient; $wc.Headers.add("file","'+humanName+'.zip"); $wc.DownloadFile($url, "$pwd\\'+humanName+'.zip"); ' +
'Expand-Archive "'+humanName+'.zip" -DestinationPath "'+humanName+'" -Force; python.exe -m venv "'+humanName+'";' +
'Start-Process -FilePath ".\\'+humanName+'\\Scripts\\pip.exe" -ArgumentList "install -r '+humanName+'\\requirements.txt" -Wait; Start-Process -FilePath ".\\\\'+humanName+'\\\\Scripts\\\\python.exe" -ArgumentList "'+humanName+'\\human.py --clustersize '+taskCount+' ' +
'--taskinterval '+taskInterval+' --taskgroupinterval '+taskClusterInterval+' --extra '+extra+'"';
break;
}
cmdBlock.append(baseHuman);
}
function refreshSelectHuman(selected) {
// Name stored in the list is in the format 'human-name-of-human', the backend expects the name to look like 'name of human'
let modifiedName = selected.value.replace('human-', '');
modifiedName = modifiedName.replaceAll('-', ' ');
restRequest('POST', {'index': 'load_human', 'name': modifiedName}, data => updateRenderedHuman(data[0]), endpoint='/plugin/human/api');
}
function renderBuiltHumanCallback(data){
// Remove spaces from name and appends 'human-' to fit key structure
let modifiedName = 'human-' + data.name.replaceAll(' ', '-');
let opts = $('#existing-humans');
opts.append('<option id="' + modifiedName + '" value="' + modifiedName + '">' + data.name + '</option>');
opts.find('option[value=' + modifiedName + ']').attr('selected', 'selected');
updateRenderedHuman(data);
}
function renderExtra(extra, platform) {
let formatted_commands = '';
$.each(extra, function(i, command) {
switch (platform) {
case "darwin":
command = command.replace(/\\/g, '\\\\');
command = command.replace(/"/g, '\\\"');
break;
case "freebsd":
command = command.replace(/\\/g, '\\\\');
command = command.replace(/"/g, '\\\"');
break;
case "linux":
command = command.replace(/\\/g, '\\\\');
command = command.replace(/"/g, '\\\"');
break;
}
formatted_commands += '"' + command + '" ';
});
return formatted_commands;
}
function copyCommandToClipboard() {
const command = $('#delivery-commands')[0].innerText;
navigator.clipboard.writeText(command);
}
function getServerIP() {
const provided_value = $('#server-ip').val();
const default_value = `${location.protocol}//${location.hostname}:${location.port}`;
return provided_value || default_value;
}
</script>