-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_integration_external_id.html
539 lines (461 loc) · 21.9 KB
/
aws_integration_external_id.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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
<!DOCTYPE html>
<!-- Brython code comes from https://www.youtube.com/watch?v=VJj-H4we71g -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.8/brython.js" integrity="sha256-rA89wPrTJJQFWJaZveKW8jpdmC3t5F9rRkPyBjz8G04=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.8/brython_stdlib.js" integrity="sha256-Gnrw9tIjrsXcZSCh/wos5Jrpn0bNVNFJuNJI9d71TDs=" crossorigin="anonymous"></script>
<title>Confused Deputy Demo</title>
<link rel="stylesheet" type="text/css" media="screen" href="main.css">
<script type="text/javascript" id="uuid_script">
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r224/prettify.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r224/prettify.js"></script>
</head>
<body onload="brython()">
<h1>Super Secure Your Cloud We Will Make</h1>
<div class="switch-toggle switch-3 switch-candy">
<input id="trivial" name="state-d" type="radio" checked="checked"/>
<label for="trivial" onclick="toggleBtnTrivial()">Trivial</label>
<input id="easy" class="disabled" name="state-d" type="radio"/>
<label for="easy" onclick="toggleBtnEasy()">Easy</label>
<input id="tamper" class="disabled" name="state-d" type="radio"/>
<label for="tamper" onclick="toggleBtnTamper()">Tamper</label>
<input id="insider_attack" class="disabled" name="state-d" type="radio" />
<label for="insider_attack" onclick="toggleBtnInsider()">Insider Attack</label>
<input id="secure" class="disabled" name="state-d" type="radio" />
<label for="secure" onclick="toggleBtnSecure()">Secure</label>
</div>
<br>
<script id="global-js">
var game_state = "Trivial"
</script>
<br>
Your AWS Account Id <div class="tooltip" value="">
<button id="guess_account_id" type="text" class="white-button">Guess the account Id</button>
<span class="tooltiptext">It must match the policy below. Blog coming soon: A million and one ways to find AWS Account IDs.</span>
</div>
<br>
<input type="text" id="account_id" placeholder="eg. 123456789012" value="" maxlength="12">
<span id="displayErrorID" class="display-error"></span>
<span id="output"></span>
<br>
Role Name <very-small>You create this in your account for Super Secure Cloud to access your data</very-small>
<br>
<input type="text" id="role" placeholder="eg. SSC_role" value="" maxlength="64">
<span id="input_role"></span>
<div class="tooltip" value="" visibility="hidden">
<button id="brute_force_role" type="text" class="white-button" visibility="hidden">Brute for the role</button>
<span class="tooltiptext">Click to simulate running Pacu to brute-force the role name</span>
</div>
<span id="displayErrorROLE" class="display-error"></span>
<br>
ExternalId <very-small>Copy the ExternalID into your policy in the AWS Console</very-small>
<br>
<input type="text" id="input_external_id" value="SecureCloud" placeholder="SecureCloud" class="grey-input" readonly>
<span id="displayErrorEXT" class="display-error"></span>
<span id="input_external"></span>
<br>
<button id="test-connection-btn">Test Connection</button>
<button id="regenerate-btn" visibility="hidden" class="show-secure hide-btn">Regenerate External ID</button>
<br>
<script>
function setImageVisible(id, visible) {
var img = document.getElementById(id);
img.style.visibility = (visible ? 'visible' : 'hidden');
}
</script>
<img id="intercepted" src="burp_intercepted.png" visibility="hidden" style="display:none" alt="Burped change image">
<button id="intercepted-btn" src="burp_intercepted.png" visibility="hidden" style="display:none">Replace with stolen externalID</button>
<img id="changed" src="burp_changed.png" visibility="hidden" style="display:none" alt="Burped changed image">
<hr style="height:2px;border-width:1;color:orange">
<div width: 320px padding="10px" border="5px solid orange" margin="0">
<small type="text" padding="0px">SSC_role Assume Role Trust Policy in Victim Account AWS Portal</small><br>
<very-small type="text">role: SSC_role (the attacker cannot change this)</very-small>
<pre id="AWSPolicy" class="grey-input"></pre>
</div>
<!-- Add your javascript here
-->
<script type="text/javascript" id="highlight">
highlight = function(jsonString, searchFor) {
var regex = new RegExp(searchFor, 'g');
var highlighted = '<span class="highlighted">' + searchFor + '</span>';
var newJsonString = jsonString.replace(regex, highlighted);
return prettyPrintOne(newJsonString);
};
var highlightLine = function(jsonString, searchFor) {
var regex = new RegExp('(.*' + searchFor + '.*)', 'g');
var highlighted = '<span class="highlighted">$1</span>';
var newJsonString = jsonString.replace(regex, highlighted);
console.log(jsonString.match(regex));
return prettyPrintOne(newJsonString);
};
var input_external_id = document.getElementById('input_external_id').innerHTML;
var external_id_policy_value = "SecureCloud";
var renderJson = function() {
console.log("exteranl_id_policy_value " + window.external_id_policy_value)
console.log("input_external_id " + document.getElementById("input_external_id").value);
var jsonVar = {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::999999999999:root"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringLike": {
"sts:ExternalId": ["SecureCloud"]
}
}
}
]
};
jsonVar['Statement'][0]['Condition']['StringLike']['sts:ExternalId'][0] = window.external_id_policy_value;
jsonStr = JSON.stringify(jsonVar, null, 2);
var hlight = highlight(jsonStr, window.external_id_policy_value);
document.getElementById('AWSPolicy').innerHTML = hlight;
};
renderJson();
</script>
<script>
function resetState () {
setImageVisible('intercepted', false)
setImageVisible('changed', false)
document.getElementById('test-connection-btn').style.backgroundColor = '#24a0ed';
document.getElementById('test-connection-btn').innerHTML = 'Test Connection';
document.getElementById('input_external_id').value = "" ;
renderJson();
};
function setExternalBox (color) {
if (color === 'white') {
document.getElementById('input_external_id').class_name = 'white-input';
document.getElementById('input_external_id').style.backgroundColor = "white";
document.getElementById('input_external_id').removeAttribute('readonly');
} else {
document.getElementById('input_external_id').style.backgroundColor = "lightgrey";
document.getElementById('input_external_id').setAttribute('readonly', true);
}
};
function toggleBtnTrivial() {
window.game_state = "Trivial"
document.getElementById('input_external_id').setAttribute('placeholder', "SecureCloud");
window.external_id_policy_value = "SecureCloud"
resetState();
setExternalBox('white');
var btn = document.getElementById('regenerate-btn');
btn.classList.add('hide-btn');
btn.classList.remove('show-btn');
document.getElementById('intercepted-btn').style.visibility = "hidden";
};
function toggleBtnEasy() {
window.game_state = "Easy"
document.getElementById('input_external_id').setAttribute('placeholder', "eg. SecureCloud_prod");
window.external_id_policy_value = "SecureCloud_Dev"
resetState();
setExternalBox('white');
var btn = document.getElementById('regenerate-btn');
btn.classList.add('hide-btn');
btn.classList.remove('show-btn');
document.getElementById('intercepted-btn').style.visibility = "hidden";
};
function toggleBtnTamper() {
window.game_state = "Tamper"
document.getElementById('input_external_id').setAttribute('placeholder', "22813a05-959f-4a1e-9698-fc811388c298");
window.external_id_policy_value = "fc2a0258-aee3-41f9-a37a-7db9c9e16cee"
resetState();
setExternalBox('grey');
var btn = document.getElementById('regenerate-btn');
btn.classList.add('hide-btn');
btn.classList.remove('show-btn');
};
function toggleBtnInsider() {
window.game_state = "Insider"
var ext = uuidv4();
document.getElementById('input_external_id').setAttribute('placeholder', ext);
window.external_id_policy_value = 'fc2a0258-aee3-41f9-a37a-7db9c9e16cee';
resetState();
setExternalBox('white');
var btn = document.getElementById('regenerate-btn');
btn.classList.add('hide-btn');
btn.classList.remove('show-btn');
document.getElementById('intercepted-btn').style.visibility = "hidden";
};
function toggleBtnSecure() {
window.game_state = "Secure"
var ext = uuidv4();
document.getElementById('input_external_id').setAttribute('placeholder', ext);
window.external_id_policy_value = 'fc2a0258-aee3-41f9-a37a-7db9c9e16cee';
resetState();
setExternalBox('grey');
var btn = document.getElementById('regenerate-btn');
btn.classList.remove('hide-btn');
btn.classList.add('show-btn');
document.getElementById('intercepted-btn').style.visibility = "hidden";
};
</script>
<script type="text/python" id="guess_account_id_script">
from browser import document, console, alert, window, timer
def guess_account(e):
if document['account_id'].value == "":
document['account_id'].value = "513589784635"
document['account_id'].text = "513589784635"
else:
# document['account_id'].value == "513589784635":
document['account_id'].value = "999999999999"
console.log("guess_account " + document['account_id'].value)
document['guess_account_id'].bind('click', guess_account)
</script>
<script>
var role_txt = document.getElementById('role');
var button = document.getElementById('brute_force_role');
button.addEventListener('click', function(e) {
brute_force_role();
})
function brute_force_role() {
var roles = ["SSC", "SSC-role", "SecureCloud-role", "SecureCloudRole", "SSC_role_Dev", "SSC_role_prod", "SSC_role"];
role_txt.value = roles[0];
for(let i = 1 ; i < roles.length ; i++){
setTimeout(function() {
role_txt.value = roles[i];
}, i*1000);
}
}
</script>
<script>
var $ = function(id) { return document.getElementById(id); };
$('account_id').oninput = function () {
if($('account_id').value.search(/\D+/) > -1){
$('account_id').value = $('account_id').value.replace(/\D+/, "");
$('displayErrorID').innerHTML = 'Invalid character';
setTimeout(function() {
$('displayErrorID').innerHTML = ""
}, 1000);
}
}
$('role').oninput = function () {
if($('role').value.search(/[^\w+=,.@-]+/) > -1){
$('role').value = $('role').value.replace(/[^\w+=,.@-]+/, "");
$('displayErrorROLE').innerHTML = 'Invalid character';
setTimeout(function() {
$('displayErrorROLE').innerHTML = ""
}, 1000);
}
}
$('input_external_id').oninput = function () {
if($('input_external_id').value.search(/[^a-zA-Z0-9+=:,.@/-]+/) > -1){
$('input_external_id').value = $('input_external_id').value.replace(/[^a-zA-Z0-9+=:,.@/-]+/, "");
$('displayErrorEXT').innerHTML = 'Invalid character';
setTimeout(function() {
$('displayErrorEXT').innerHTML = ""
}, 1000);
}
}
</script>
<script>
var $ = function(id) { return document.getElementById(id); };
$('account_id').oninput = function () {
if($('account_id').value.search(/\D+/) > -1){
$('account_id').value = $('account_id').value.replace(/\D+/, "");
$('displayErrorID').innerHTML = 'Invalid character';
setTimeout(function() {
$('displayErrorID').innerHTML = ""
}, 1000);
}
}
$('role').oninput = function () {
if($('role').value.search(/[^\w+=,.@-]+/) > -1){
$('role').value = $('role').value.replace(/[^\w+=,.@-]+/, "");
$('displayErrorROLE').innerHTML = 'Invalid character';
setTimeout(function() {
$('displayErrorROLE').innerHTML = ""
}, 1000);
}
}
$('input_external_id').oninput = function () {
if($('input_external_id').value.search(/[^a-zA-Z0-9+=:,.@/-]+/) > -1){
$('input_external_id').value = $('input_external_id').value.replace(/[^a-zA-Z0-9+=:,.@/-]+/, "");
$('displayErrorEXT').innerHTML = 'Invalid character';
setTimeout(function() {
$('displayErrorEXT').innerHTML = ""
}, 1000);
}
}
</script>
<!-- Test Connection (only for Tamper mode) -> Success; Someday real test -->
<script>
var testc_btn = document.getElementById('test-connection-btn');
var game_state = window.game_state;
var replace_btn = document.getElementById('intercepted-btn');
testc_btn.addEventListener('click', function(e) {
show();
});
replace_btn.addEventListener('click', function(e) {
var img_changed = document.getElementById('changed');
img_changed.style.visibility = "visible";
img_changed.style.display = "block";
setTimeout(function() {
testc_btn.style.backgroundColor = "#4CAF50";
testc_btn.textContent = "Success!";
document.getElementById('input_external_id').value = "fc2a0258-aee3-41f9-a37a-7db9c9e16cee"
}, 1000);
setTimeout(reset_button, 3000);
})
function show () {
var input_account_id = document.getElementById('account_id').value;
var input_role = document.getElementById('role').value;
if (game_state == "Tamper") {
if(test_connection()){
var img_intercepted = document.getElementById('intercepted');
img_intercepted.style.visibility = "visible";
img_intercepted.style.display = "block";
replace_btn.style.visibility= "visible";
replace_btn.style.display= "block";
}
else {
testc_btn.style.backgroundColor = "#D01010";
testc_btn.textContent = 'Connection Failed!';
setTimeout(reset_button, 2000);
}
}
}
function reset_button () {
testc_btn.style.backgroundColor = "#24a0ed";
testc_btn.textContent = 'Test Connection';
}
function test_connection () {
var input_account_id = document.getElementById('account_id').value;
var input_role = document.getElementById('role').value;
if (input_role == "SSC_role" && input_account_id == "999999999999") { return true; }
else { return false; }
}
</script>
<!-- Test Connection (not Tamper mode) -> Success; Someday real test -->
<script type="text/python" id="test_connection">
from browser import document, console, alert, window, timer
def reset_button():
document['test-connection-btn'].style.backgroundColor = "#24a0ed"
document['test-connection-btn'].text = 'Test Connection'
def set_image_visible(image_id, value):
visibility = 'hidden'
display = "none"
if value:
visibility = 'visible'
display = "block"
document[image_id].style.visibility = visibility
document[image_id].style.display = display
def dummy():
print("here")
def test_connection():
game_state = window.game_state
input_external_id = document["input_external_id"].value
input_role = document["role"].value
input_account_id = document["account_id"].value
'''
This block is commented because the Tamper game state is treated in a js script
if game_state == "Tamper":
if (input_role != "SSC_role") or (input_account_id != "999999999999"):
return False
set_image_visible('intercepted', True)
timer.set_timeout(dummy, 2000)
#set_image_visible('intercepted', False)
set_image_visible('changed', True)
timer.set_timeout(dummy, 2000)
#set_image_visible('changed', False)
return True
'''
if (input_external_id == window.external_id_policy_value) and \
(input_role == "SSC_role") and \
(input_account_id == "999999999999"):
return True
else:
return False
def show(e):
game_state = window.game_state
if game_state != "Tamper":
console.log(e)
input_external_id = document["input_external_id"].value
console.log("TEST")
console.log(input_external_id)
console.log(window.external_id_policy_value)
#if window.external_id_policy_value == input_external_id:
if test_connection():
document["test-connection-btn"].style.backgroundColor = "#4CAF50"
document['test-connection-btn'].text = 'Success!'
else:
document['test-connection-btn'].style.backgroundColor = "#D01010"
document['test-connection-btn'].text = 'Connection Failed!'
console.log(document['test-connection-btn'])
timer.set_timeout(reset_button, 2000)
document['test-connection-btn'].bind('click', show)
'''
from browser import document, ajax, console
from browser.template import Template
url = 'https://api.chucknorris.io/jokes/random'
def on_complete(req):
import json
data = json.loads(req.responseText)
joke = data['value']
document['joke'].text = joke
def get_joke(e):
req = ajax.ajax()
req.open('GET', url, True)
req.bind('complete', on_complete)
document['joke'].text = 'Loading...'
req.send()
import uuid, random
uuid_val = str(uuid.uuid4())
console.log(uuid_val)
Template(document['greet']).render(name=uuid_val)
document['regenerate-btn'].bind('click', get_joke) '''
</script>
<!-- Unused Text bind -->
<script type="text/python" id="script1">
from browser import document
def show_text(e):
document['output'].textContent = e.target.value;
document['output'].bind('input', show_text)
</script>
<script type="text/python" id="script2">
from browser import document, console, window
from browser.template import Template
uuid_val = '22813a05-959f-4a1e-9698-fc811388c298'
console.log(uuid_val)
def regenerate_externalid(e):
uuid_val = window.uuidv4()
console.log(uuid_val)
document["input_external_id"].value = uuid_val
document['regenerate-btn'].bind('click', regenerate_externalid)
</script>
<!-- Ajax call -->
<script type="text/python" id="script3">
from browser import document, ajax, console
from browser.template import Template
url = 'https://api.chucknorris.io/jokes/random'
def on_complete(req):
import json
data = json.loads(req.responseText)
joke = data['value']
document['joke'].text = joke
def get_joke(e):
req = ajax.ajax()
req.open('GET', url, True)
req.bind('complete', on_complete)
document['joke'].text = 'Loading...'
req.send()
import uuid, random
uuid_val = str(uuid.uuid4())
console.log(uuid_val)
Template(document['greet']).render(name=uuid_val)
#document['regenerate-btn'].bind('click', get_joke)
</script>
</body>
</html>