-
Notifications
You must be signed in to change notification settings - Fork 26
/
pathfinder.html
488 lines (449 loc) · 20.4 KB
/
pathfinder.html
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
<script src="/pathfinder/js/d3.v4.min.js" type="text/javascript"></script>
<script src="/pathfinder/js/d3-v4-contextmenu.js" type="text/javascript"></script>
<script src="/pathfinder/js/graph.js"></script>
<div x-data="alpinePathfinder()" x-init="initPage()">
<div x-ref="headerPathfinder">
<h2>Pathfinder</h2>
<p>CALDERA Rapid Attack Grapher</p>
</div>
<hr>
<div class="columns">
<div class="column is-3 m-0">
<div class="tabs">
<ul class="m-0">
<li @click="activeTab = 'scan'" :class="{ 'is-active': activeTab === 'scan' }">
<a>Scan</a>
</li>
<li @click="activeTab = 'reports'" :class="{ 'is-active': activeTab === 'reports' }">
<a>Reports</a>
</li>
</ul>
</div>
<!-- Scan view -->
<div x-show="activeTab === 'scan'">
<form>
<div class="field">
<div class="control has-text-centered">
<div class="select is-small">
<select x-model="selectedScanner" @change="selectScanner()">
<option default disabled value="">Select a scanner to get started</option>
<template x-for="scanner in scanners" :key="scanner">
<option :value="scanner" x-text="scanner"></option>
</template>
</select>
</div>
</div>
</div>
<template x-for="field in scannerFields">
<div class="field">
<label class="label is-small" x-text="field.name"></label>
<div class="control">
<template x-if="field.type === 'text'">
<input class="input is-small" type="text" x-model="field.value">
</template>
<template x-if="field.type === 'pulldown'">
<div class="select is-small">
<select x-model="field.value">
<template x-for="value in field.values">
<option :value="value" x-text="value"></option>
</template>
</select>
</div>
</template>
<template x-if="field.type === 'checkbox'">
<input type="checkbox" x-model="field.value">
</template>
</div>
</div>
</template>
<div class="field">
<div class="control">
<button class="button is-small is-primary is-fullwidth" type="button" :disabled="!selectedScanner" @click="startScan()">
Scan
</button>
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-small is-fullwidth" type="button" @click="addTab('fact sources', '/advanced/sources')">
View Facts
</button>
</div>
</div>
</form>
</div>
<!-- Reports view -->
<div x-show="activeTab === 'reports'">
<form>
<label class="label is-small">Vulnerability Report</label>
<div class="field has-addons">
<div class="control is-expanded">
<div class="select is-small is-fullwidth">
<select id="reportId" x-model="selectedReportId">
<option value="" disabled selected>Select a report</option>
<template x-for="report in reports">
<option :value="report.id" x-text="report.name"></option>
</template>
</select>
</div>
</div>
<div class="control">
<button class="button is-small has-tooltip-top" @click="showImportModal = true" data-tooltip="Import Report">
<span class="icon"><em class="fas fa-file-import"></em></span>
</button>
</div>
<div class="control">
<a class="button is-small has-tooltip-top" x-bind:href="'/plugin/pathfinder/download?report_id=' + selectedReportId" :disabled="!selectedReportId" data-tooltip="Download">
<span class="icon"><em class="fas fa-download"></em></span>
</a>
</div>
<div class="control">
<button class="button is-small has-tooltip-top" @click="openRenameModal()" :disabled="!selectedReportId" data-tooltip="Rename Report">
<span class="icon"><em class="fas fa-pencil-alt"></em></span>
</button>
</div>
<div class="control">
<button class="button is-small is-outlined is-danger has-tooltip-top" @click="deleteReport()" :disabled="!selectedReportId" data-tooltip="Delete Report">
<span class="icon"><em class="fas fa-trash"></em></span>
</button>
</div>
</div>
<div x-show="selectedReportId">
<hr>
<label class="label has-text-centered">Graph Options</label>
<div class="field">
<label class="label is-small">
Link distance
</label>
<div class="control">
<input type="range" min="1" max="100" default="50" x-model="linkDistance" @change="updateLinkDistance(linkDistance)" style="width: 100%">
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-small is-primary is-fullwidth" type="button" @click="graphReport()">Generate Graph</button>
</div>
</div>
<div class="field">
<div class="control">
<button id="pathfinderCreateAdversary" class="button is-small is-fullwidth" type="button" @click="showAdversaryModal = true" disabled>Create Adversary</button>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="column is-9 m-0">
<div class="box" x-show="activeTab === 'reports'">
<div class="is-flex is-justify-content-center is-align-items-center mb-3">
<label class="mr-3">Legend:</label>
<span class="legend-dot mr-2" style="background-color:gray"></span>
<span>Scanner </span>
<span class="legend-dot mr-2" style="background-color:deepskyblue"></span>
<span>Network Host </span>
<span class="legend-dot mr-2" style="background-color:orangered"></span>
<span>CVE </span>
<span class="legend-dot mr-2" style="background-color:blue"></span>
<span>Open Port </span>
</div>
<div id="graphContainer">
<svg id="networkGraph" style="width: 100%; height: 100%; display: inline"></svg>
</div>
</div>
<div class="box" x-show="activeTab === 'scan'">
<p class="has-text-centered">Output</p>
<template x-for="log in logs">
<pre x-text="log" class="output p-0"></pre>
</template>
</div>
</div>
</div>
<!-- MODALS -->
<div class="modal" :class="{ 'is-active': showImportModal }">
<div class="modal-background" @click="showImportModal = false"></div>
<div class="modal-content simple-modal">
<h2>Import a Report</h2>
<form>
<div class="field">
<label class="label is-small">Report Format</label>
<div class="control">
<div class="select is-small is-fullwidth">
<select x-model="selectedParser">
<option value="" disabled selected>Select the report format</option>
<template x-for="parser in inputParsers">
<option :value="parser" x-text="parser"></option>
</template>
</select>
</div>
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-small is-primary is-fullwidth" :disabled="!selectedParser" type="button" @click="$refs.importFile.click()">Import</button>
<input x-ref="importFile" type="file" name="name" x-show="false" @change="uploadFile">
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-small is-fullwidth" type="button" @click="showImportModal = false">Cancel</button>
</div>
</div>
</form>
</div>
</div>
<div class="modal" :class="{ 'is-active': showRenameModal }">
<div class="modal-background" @click="showRenameModal = false"></div>
<div class="modal-content simple-modal">
<h2>Rename Report</h2>
<div class="field">
<label class="label is-small">Report name</label>
<div class="control">
<input class="input is-small" type="text" placeholder="Enter a name for the report" x-model="reportNameEdited">
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-small is-primary is-fullwidth" type="button" @click="renameReport()" :disabled="!reportNameEdited">Rename</button>
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-small is-fullwidth" type="button" @click="showRenameModal = false">Cancel</button>
</div>
</div>
</div>
</div>
<div class="modal" :class="{ 'is-active': showAdversaryModal }">
<div class="modal-background" @click="showAdversaryModal = false"></div>
<div class="modal-content simple-modal">
<h2>Create an Adversary</h2>
<p>
Create a custom adversary using the source and target nodes specified in the attach graph.
Once created, this adversary will appear in the "adversaries" tab.
<br><br>
Existing Pathfinder adversaries can be merged by including their name in the "Adversary Merging Tags".
</p>
<div class="field">
<label class="label is-small">Adversary Merging Tags</label>
<div class="control">
<input id="adversaryTags" class="input is-small" placeholder="Enter merging tags" x-model="adversaryTags">
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-small is-primary is-fullwidth" type="button" @click="createAdversary()">Create Adversary</button>
</div>
</div>
<button class="button is-small is-fullwidth" type="button" @click="showAdversaryModal = false">Cancel</button>
</div>
</div>
</div>
<script>
function alpinePathfinder() {
return {
activeTab: 'scan',
logs: [],
doRefresh: false,
latestSource: '',
scanners: JSON.parse('{{ scanners | tojson }}'),
selectedScanner: "",
scannerFields: [],
inputParsers: JSON.parse('{{ input_parsers | tojson }}'),
selectedParser: "",
reports: [],
selectedReportId: "",
reportNameEdited: "",
linkDistance: 50,
adversaryTags: "",
graphData: {},
showImportModal: false,
showRenameModal: false,
showAdversaryModal: false,
initPage() {
this.reloadReports();
},
logOutput(text) {
this.logs.push(`${text}\n`);
},
async selectScanner() {
if (!this.selectScanner) return;
try {
const response = await apiV2('POST', '/plugin/pathfinder/api', {
index: 'scanner_config',
name: this.selectedScanner
});
if (response.error) {
this.logOutput(`${response.name}: ${response.error}`);
return;
}
if (!response.enabled) {
this.logOutput(`${response.name}: Please install scanner dependencies before scanning, scanning disabled!`);
return;
}
this.scannerFields = [];
response.fields.forEach((field) => {
this.scannerFields.push({
...field,
value: field.default === null ? '' : field.default
})
});
} catch(error) {
console.error("Error selecting scanner", error);
}
},
async startScan() {
let fields = {};
this.scannerFields.forEach((field) => fields[field.param] = field.value);
this.logOutput(`${this.selectedScanner} scan started with parameters:\n ${JSON.stringify(fields, null, 4)}`);
try {
await apiV2('POST', '/plugin/pathfinder/api', {
index: 'scan',
scanner: this.selectedScanner,
fields: fields
});
this.doRefresh = true;
while (this.$refs.headerPathfinder && this.doRefresh) {
await sleep(10000);
this.checkScanStatus();
}
} catch(error) {
this.logOutput(`ERROR: scan issue, please check server logs for more details`);
console.error(error);
}
},
async checkScanStatus() {
try {
const response = await apiV2('POST', '/plugin/pathfinder/api', { index: 'status' });
if (response.pending.length === 0 && Object.keys(response.finished).length === 0 && Object.keys(response.errors).length === 0) {
this.doRefresh = false;
this.logOutput("Scan finished.");
}
Object.keys(response.finished || {}).forEach((key) => {
this.logOutput(`Scan ID: ${key} finished. New source created: ${response.finished[key].source}`);
this.latestSource = response.finished[key].source_id;
});
Object.keys(response.errors || {}).forEach((key) => {
this.logOutput(`Scan ID: ${key} failed. Error output: ${response.errors[key].message}`);
});
this.reloadReports();
} catch(error) {
console.error("Error checking scan status", error);
}
},
async reloadReports() {
try {
const response = await apiV2('POST', '/plugin/pathfinder/api', { index: 'reports' });
this.reports = response.reports;
} catch(error) {
console.error("Error reloading Pathfinder reports", error);
}
},
async uploadFile(event) {
if (!event.currentTarget) return;
let filename = event.currentTarget.files[0].name;
if (!filename) return;
let fd = new FormData();
fd.append('file', event.currentTarget.files[0]);
try {
await apiV2('POST', '/plugin/pathfinder/upload', fd, false);
this.processImportScan(filename);
} catch(error) {
console.error("Error uploading file", error);
}
},
async processImportScan(filename) {
try {
const response = await apiV2('POST', '/plugin/pathfinder/api', {
index: 'import_scan',
format: this.selectedParser,
filename: filename
});
this.logOutput('Report imported, new source created. You can view it in the "View" tab.');
this.logOutput(response.output);
this.latestSource = response.source;
this.reloadReports();
this.showImportModal = false;
toast('Report imported!', true);
} catch(error) {
toast('Could not import file, please check server logs for issue and ensure the input file matches the selected parser.')
console.error("Error importing report", error);
}
},
async graphReport() {
try {
this.graphData = await apiV2('GET', `/plugin/pathfinder/graph?report=${this.selectedReportId}`);
initGraph(this.graphData, this.linkDistance); // Found in graph.js
} catch(error) {
console.error("Error loading graph", error);
}
},
openRenameModal() {
this.reportNameEdited = this.reports.find((report) => report. id === this.selectedReportId).name;
this.showRenameModal = true;
},
async renameReport() {
try {
apiV2('PATCH', '/plugin/pathfinder/api', {
index: 'report',
id: this.selectedReportId,
rename: this.reportNameEdited
});
this.reloadReports();
this.showRenameModal = false;
} catch(error) {
console.error("Error renaming report", error);
}
},
async deleteReport() {
if (!confirm('Are you sure you want to delete this report? This cannot be undone.')) return;
try {
apiV2('DELETE', '/plugin/pathfinder/api', {
index: 'report',
id: this.selectedReportId
});
this.selectedReportId = "";
this.graphData = "";
this.reloadReports();
} catch(error) {
console.error("Error deleting report", error);
}
},
};
}
//sourceURL=pathfinder.js
</script>
<style>
#graphContainer {
background-color: black;
height: 800px;
width: 100%;
border-radius: 4px;
border: 1px solid #515151;
}
.legend-dot {
height: 16px;
width: 16px;
border-radius: 50%;
border: 1px white solid;
}
.simple-modal.modal-content {
background-color: #1c1c1c;
padding: 20px;
}
pre.output {
background-color: #0d0d0d;
}
.links line {
stroke-opacity: 0.6;
}
.nodes circle {
fill: 'tomato';
stroke: #fff;
stroke-width: 1.5px;
}
g.qualifier circle {
fill: cornsilk;
stroke: #333;
stroke-width: 6px;
}
</style>