-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwnadventure_sourcery1.html
837 lines (716 loc) · 76.8 KB
/
pwnadventure_sourcery1.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="F3real" />
<meta name="keywords" content="ctf,reversing,assembly,binary exploitation,pwnable" />
<meta name="description" content="How to solve Pwn Adventure Sourcery start challenges" />
<title>Pwn Adventure Sourcery part 1 - EnSec blog</title>
<link href="https://f3real.github.io/theme/css/combined.css" rel="stylesheet" />
<!-- Feeds -->
</head>
<body data-spy="scroll" data-target="#scrollspy">
<div id="wrapper">
<!-- Sidebar -->
<nav id="sidebar-wrapper-small" class="twitchy-background">
<ul id="accordion-small" class="sidebar-nav sidebar-nav-small">
<li>
<a href="https://f3real.github.io" title="EnSec blog" class="collapsed">
<span class="fas fa-home"></span>
</a>
</li>
<li class="nav-divider"></li>
<li>
<a href="https://f3real.github.io/archives.html" title="Recent Articles" class="collapsed">
<span class="fas fa-th-list"></span>
</a>
</li>
<li class="nav-divider"></li>
<li>
<a data-toggle="collapse" data-parent="#accordion-small" href="#collapse-social-small" title="Social" class="collapsed">
<i class="fas fa-users padding-small"></i>
</a>
</li>
<li class="panel anti-panel"><ul id="collapse-social-small" class="collapse ">
<li>
<a href="https://github.com/F3real" title="Github"><i class="fab fa-github-square padding-small"></i></a>
</li>
<li>
<a href="https://www.linkedin.com/in/stefan-ili%C4%87-61a004111" title="Linkedin"><i class="fab fa-linkedin padding-small"></i></a>
</li>
</ul></li>
<li class="nav-divider"></li>
<li>
<a href="#" title="Back to top" class="collapsed">
<span class="fas fa-arrow-up"></span>
</a>
</li>
</ul>
</nav>
<nav id="sidebar-wrapper" class="twitchy-background">
<ul id="accordion" class="sidebar-nav">
<li class="sidebar-brand">
<a href="https://f3real.github.io/">
<span class="fas fa-home padding-small"></span>
EnSec blog
</a>
</li>
<li>
<a href="https://f3real.github.io/archives.html">
<span class="fas fa-th-list padding-small"></span>
Archives
</a>
</li>
<li class="nav-divider"></li>
<li>
<a data-toggle="collapse" data-parent="#accordion" href="#collapse-social">
<i class="fas fa-users padding-small"></i>
Contact
</a>
</li>
<li class="panel anti-panel"><ul id="collapse-social" class="sidebar_submenu collapse ">
<li>
<a href="https://github.com/F3real" title="Github">
<i class="fab fa-github-square padding-small"></i>
Github
</a>
</li>
<li>
<a href="https://www.linkedin.com/in/stefan-ili%C4%87-61a004111" title="Linkedin">
<i class="fab fa-linkedin padding-small"></i>
Linkedin
</a>
</li>
</ul></li>
<li class="nav-divider"></li>
<li class="panel anti-panel"><ul id="collapse-pages" class="sidebar_submenu collapse ">
</ul></li>
<li class="nav-divider"></li>
<li>
<a data-toggle="collapse" data-parent="#accordion" href="#collapse-categories">
<i class="fas fa-folder-open padding-small"></i>
Categories
</a>
</li>
<li class="panel anti-panel"><ul id="collapse-categories" class="sidebar_submenu collapse ">
<li class="active">
<a href="https://f3real.github.io/category/ctf.html">
<i class="fas fa-folder-open padding-small"></i>
ctf
<span class="badge badge-secondary float-right categorybadge">28</span>
</a>
</li>
<li >
<a href="https://f3real.github.io/category/misc.html">
<i class="fas fa-folder-open padding-small"></i>
misc
<span class="badge badge-secondary float-right categorybadge">15</span>
</a>
</li>
<li >
<a href="https://f3real.github.io/category/reversing.html">
<i class="fas fa-folder-open padding-small"></i>
reversing
<span class="badge badge-secondary float-right categorybadge">6</span>
</a>
</li>
<li >
<a href="https://f3real.github.io/category/tutorial.html">
<i class="fas fa-folder-open padding-small"></i>
tutorial
<span class="badge badge-secondary float-right categorybadge">5</span>
</a>
</li>
</ul></li>
</ul>
</nav>
<!-- /#sidebar-wrapper -->
<!-- open/close sidebar -->
<button onclick="toggleMenu();return false;" class="btn btn-primary" id="menu-toggle">
<span id="right-arrow" class="fas fa-chevron-right" title="expand sidebar"></span>
<span id="left-arrow" class="fas fa-chevron-left" title="minimize sidebar"></span>
</button>
<!-- /open/close sidebar -->
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
<section id="content">
<article>
<div class="row">
<div class="col-lg-10">
<header class="page-header">
<h1>
<a href="https://f3real.github.io/pwnadventure_sourcery1.html"
rel="bookmark"
title="Permalink to Pwn Adventure Sourcery part 1">
Pwn Adventure Sourcery part 1
</a>
<small>
<div class="post-info">
<div class="publish-info-block">
<small>
<span class="published">
<i class="fa fa-calendar padding-small"></i><time datetime="2019-01-03T10:01:00+01:00"> Thu 03 January 2019</time>
</span>
<span class="category">
<i class="fa fa-folder-open padding-small"></i><a href="https://f3real.github.io/category/ctf.html">ctf</a>
</span>
<span class="tags">
<i class="fa fa-tags padding-small"></i>
<a href="https://f3real.github.io/tag/ctf.html">ctf</a> / <a href="https://f3real.github.io/tag/reversing.html">reversing</a> / <a href="https://f3real.github.io/tag/assembly.html">assembly</a> / <a href="https://f3real.github.io/tag/binary-exploitation.html">binary exploitation</a> / <a href="https://f3real.github.io/tag/pwnable.html">pwnable</a> </span>
</small>
</div>
</div><!-- /.post-info --> </small>
</h1>
</header>
</div>
</div>
<div class="row">
<div class="col-lg-10">
<div class="entry-content">
<p>Pwn Adventure Sourcery is a really interesting game made for CSAW finals 2018. The game was made using Rust and WebAssembly.</p>
<p>Commands are simple, we walk using arrow keys, interact using <code>E</code> key and use weapons/items with <code>SPACE</code> key. To play the game properly we (sadly) need to use Chrome browser, otherwise <code>CTRL+C/CTRL+V</code> won't work which will make the game much harder.</p>
<div class="toc">
<ul>
<li><a href="#jail-storage-door">Jail Storage Door</a></li>
<li><a href="#jail-door">Jail Door</a></li>
<li><a href="#lab-door-1">Lab Door 1</a></li>
</ul>
</div>
<p>In a brief tutorial, we see get assembly code for fire spell that we need to use to break builder standing in our way.</p>
<div class="highlight"><pre><span></span><code><span class="nf">mov</span><span class="w"> </span><span class="no">eax</span><span class="p">,</span><span class="w"> </span><span class="no">SYS_FIRE</span>
<span class="nf">mov</span><span class="w"> </span><span class="no">ebx</span><span class="p">,</span><span class="w"> </span><span class="mi">16</span><span class="w"> </span><span class="c1">; energy to use</span>
<span class="nf">int</span><span class="w"> </span><span class="mi">0x80</span>
<span class="nf">hlt</span>
</code></pre></div>
<p>Going forward we get to <code>Spell extractor</code> which we can use to get source code of doors and our first challenge <strong>Jail Storage Door</strong>.</p>
<h2 id="jail-storage-door">Jail Storage Door</h2>
<div class="highlight"><pre><span></span><code><span class="nf">TERMINAL_INPUT</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">0</span>
<span class="nf">TERMINAL_OUTPUT</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">1</span>
<span class="nf">DOOR_CONTROL</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">2</span>
<span class="nl">main:</span>
<span class="w"> </span><span class="c1">; Display initial message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="no">end_message</span><span class="w"> </span><span class="p">-</span><span class="w"> </span><span class="no">message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span>
<span class="w"> </span><span class="na">rep</span><span class="w"> </span><span class="nf">outsb</span>
<span class="nl">.input_loop:</span>
<span class="w"> </span><span class="c1">; Grab next input</span>
<span class="w"> </span><span class="nf">in</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_INPUT</span><span class="w"> </span><span class="c1">;in dest, src</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="err">'</span><span class="mi">0</span><span class="err">'</span><span class="w"> </span>
<span class="w"> </span><span class="no">jb</span><span class="w"> </span><span class="no">.input_loop</span><span class="w"> </span><span class="c1">;Jump if Below (unsigned comparison)</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="err">'</span><span class="mi">9</span><span class="err">'</span>
<span class="w"> </span><span class="nf">ja</span><span class="w"> </span><span class="no">.input_loop</span><span class="w"> </span><span class="c1">;Jump if Above (unsigned comparison)</span>
<span class="w"> </span><span class="c1">; Rolling code for last 4 digits</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">cl</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">entered_code</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="p">[</span><span class="no">entered_code</span><span class="p">],</span><span class="w"> </span><span class="no">cl</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">cl</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">entered_code</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">2</span><span class="p">]</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="p">[</span><span class="no">entered_code</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="no">cl</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">cl</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">entered_code</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">3</span><span class="p">]</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="p">[</span><span class="no">entered_code</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">2</span><span class="p">],</span><span class="w"> </span><span class="no">cl</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="p">[</span><span class="no">entered_code</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">3</span><span class="p">],</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="c1">; Display updated code</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="err">'\</span><span class="no">r</span><span class="err">'</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">entered_code</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span>
<span class="w"> </span><span class="na">rep</span><span class="w"> </span><span class="nf">outsb</span>
<span class="w"> </span><span class="c1">; Check code</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">correct_code</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">edi</span><span class="p">,</span><span class="w"> </span><span class="no">entered_code</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span>
<span class="w"> </span><span class="na">rep</span><span class="nf">e</span><span class="w"> </span><span class="no">cmpsb</span>
<span class="w"> </span><span class="nf">je</span><span class="w"> </span><span class="no">.open_door</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.input_loop</span>
<span class="nl">.open_door:</span>
<span class="w"> </span><span class="c1">; Send command to unlock door</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">DOOR_CONTROL</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="c1">; Show open message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">open</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="no">end_open</span><span class="w"> </span><span class="p">-</span><span class="w"> </span><span class="no">open</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span>
<span class="w"> </span><span class="na">rep</span><span class="w"> </span><span class="nf">outsb</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.input_loop</span>
<span class="nl">correct_code:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="err">"</span><span class="mi">5129</span><span class="err">"</span><span class="w"> </span><span class="c1">;Solution</span>
<span class="nl">message:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="err">"</span><span class="no">PIN</span><span class="w"> </span><span class="no">code</span><span class="p">:</span><span class="err">\</span><span class="no">n</span><span class="err">"</span>
<span class="nl">end_message:</span>
<span class="nl">open:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="err">"\</span><span class="no">rOPEN</span><span class="err">"</span>
<span class="nl">end_open:</span>
<span class="na">.data</span>
<span class="nl">entered_code:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span>
</code></pre></div>
<p>The only confusing part was the way in which data was loaded in memory. Characters are loaded in the last position in <code>entered_code</code> array and then moved towards the first position after each new character is entered.</p>
<p>We also see that <code>correct_code</code> is hardcoded to <code>5129</code> which is our solution.</p>
<h2 id="jail-door">Jail Door</h2>
<p>Moving forward we get <code>Pwn tool</code> which we can use to write our own assembly code to interact with items.</p>
<div class="highlight"><pre><span></span><code><span class="nf">TERMINAL_INPUT</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">0</span>
<span class="nf">TERMINAL_OUTPUT</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">1</span>
<span class="nf">SECURE_PIN_STORAGE</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">2</span>
<span class="nf">DOOR_CONTROL</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">3</span>
<span class="nl">main:</span>
<span class="na">.correct_pin</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">0</span>
<span class="w"> </span><span class="nf">sub</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="mi">32</span>
<span class="w"> </span><span class="c1">; Fetch PIN from secure memory</span>
<span class="w"> </span><span class="nf">lea</span><span class="w"> </span><span class="no">edi</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">esp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.correct_pin</span><span class="p">]</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">edi</span>
<span class="w"> </span><span class="nf">call</span><span class="w"> </span><span class="no">get_secure_pin</span>
<span class="w"> </span><span class="nf">add</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span>
<span class="nl">.main_loop:</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">edi</span>
<span class="w"> </span><span class="nf">call</span><span class="w"> </span><span class="no">ask_and_verify_pin</span>
<span class="w"> </span><span class="nf">add</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span>
<span class="w"> </span><span class="nf">test</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">jz</span><span class="w"> </span><span class="no">.invalid</span>
<span class="w"> </span><span class="nf">call</span><span class="w"> </span><span class="no">open_door</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.main_loop</span>
<span class="nl">.invalid:</span>
<span class="w"> </span><span class="c1">; Show denied message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">invalid</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="no">end_invalid</span><span class="w"> </span><span class="p">-</span><span class="w"> </span><span class="no">invalid</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span>
<span class="w"> </span><span class="na">rep</span><span class="w"> </span><span class="nf">outsb</span>
<span class="w"> </span><span class="nf">call</span><span class="w"> </span><span class="no">sleep</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.main_loop</span>
<span class="nl">ask_and_verify_pin:</span>
<span class="c1">; Args</span>
<span class="na">.correct_pin</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">16</span>
<span class="c1">; Variables</span>
<span class="na">.input</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">-32</span>
<span class="na">.len</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">-36</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">edi</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ebp</span><span class="p">,</span><span class="w"> </span><span class="no">esp</span>
<span class="w"> </span><span class="nf">sub</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="mi">36</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dword</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">],</span><span class="w"> </span><span class="mi">0</span>
<span class="w"> </span><span class="c1">; Display initial message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="no">end_message</span><span class="w"> </span><span class="p">-</span><span class="w"> </span><span class="no">message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span>
<span class="w"> </span><span class="na">rep</span><span class="w"> </span><span class="nf">outsb</span>
<span class="nl">.input_loop:</span>
<span class="w"> </span><span class="c1">; Grab next input</span>
<span class="w"> </span><span class="nf">in</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_INPUT</span><span class="w"> </span><span class="c1">;read char from input</span>
<span class="w"> </span><span class="c1">; If enter is pressed, done</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="err">'\</span><span class="no">n</span><span class="err">'</span>
<span class="w"> </span><span class="nf">je</span><span class="w"> </span><span class="no">.end_input</span>
<span class="w"> </span><span class="c1">; Look for backspace</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span>
<span class="w"> </span><span class="nf">je</span><span class="w"> </span><span class="no">.backspace</span>
<span class="w"> </span><span class="c1">; Add character to input</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">]</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.input</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">ecx</span><span class="p">],</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">dword</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">]</span><span class="w"> </span><span class="c1">;The inc instruction increments the contents of its operand by one</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.input_loop</span>
<span class="nl">.backspace:</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">dword</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">],</span><span class="w"> </span><span class="mi">0</span>
<span class="w"> </span><span class="nf">je</span><span class="w"> </span><span class="no">.input_loop</span>
<span class="w"> </span><span class="c1">; Erase last character</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="err">'</span><span class="w"> </span><span class="err">'</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">dec</span><span class="w"> </span><span class="no">dword</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">]</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.input_loop</span>
<span class="nl">.end_input:</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="c1">; Null terminate input</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">]</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">byte</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.input</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">ecx</span><span class="p">],</span><span class="w"> </span><span class="mi">0</span>
<span class="w"> </span><span class="c1">; Check code</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.correct_pin</span><span class="p">]</span>
<span class="w"> </span><span class="nf">lea</span><span class="w"> </span><span class="no">edi</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.input</span><span class="p">]</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">]</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">ecx</span>
<span class="w"> </span><span class="na">rep</span><span class="nf">e</span><span class="w"> </span><span class="no">cmpsb</span>
<span class="w"> </span><span class="nf">sete</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">edi</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">ret</span>
<span class="nl">open_door:</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="c1">; Send command to unlock door</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">DOOR_CONTROL</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="c1">; Show open message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">open</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="no">end_open</span><span class="w"> </span><span class="p">-</span><span class="w"> </span><span class="no">open</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span>
<span class="w"> </span><span class="na">rep</span><span class="w"> </span><span class="nf">outsb</span>
<span class="w"> </span><span class="nf">call</span><span class="w"> </span><span class="no">sleep</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">ret</span>
<span class="nl">get_secure_pin:</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">esp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">4</span><span class="p">]</span>
<span class="nl">.get_pin_loop:</span>
<span class="w"> </span><span class="nf">in</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="no">SECURE_PIN_STORAGE</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="p">[</span><span class="no">ecx</span><span class="p">],</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">ecx</span>
<span class="w"> </span><span class="nf">test</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="no">al</span><span class="w"> </span><span class="c1">;check if value is zero</span>
<span class="w"> </span><span class="nf">jnz</span><span class="w"> </span><span class="no">.get_pin_loop</span>
<span class="w"> </span><span class="nf">ret</span>
<span class="nl">sleep:</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="mi">120</span>
<span class="nl">.sleep_loop:</span>
<span class="w"> </span><span class="nf">pause</span>
<span class="w"> </span><span class="nf">loop</span><span class="w"> </span><span class="no">.sleep_loop</span>
<span class="w"> </span><span class="nf">ret</span>
<span class="nl">message:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="err">"\</span><span class="no">fPIN</span><span class="w"> </span><span class="no">code</span><span class="p">:</span><span class="err">\</span><span class="no">n</span><span class="err">"</span>
<span class="nl">end_message:</span>
<span class="nl">open:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="err">"</span><span class="no">ACCESS</span><span class="w"> </span><span class="no">GRANTED</span><span class="err">"</span>
<span class="nl">end_open:</span>
<span class="nl">invalid:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="err">"</span><span class="no">ACCESS</span><span class="w"> </span><span class="no">DENIED</span><span class="err">"</span>
<span class="nl">end_invalid:</span>
</code></pre></div>
<p>This time pin is read from secure storage and we can't see it in source code. The <code>input_loop</code> is pretty simple it reads a char, checks if it is backspace or return, increments the number of chars and saves our input.</p>
<p>Since no checks are being made for the length of input we have classic buffer overflow.
Let's see what's the offset to overwrite EIP.</p>
<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">eip</span><span class="w"> </span><span class="c1">;call will place EIP on stack</span>
<span class="nl">ask_and_verify_pin:</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">esi</span><span class="w"> </span><span class="c1">; esp - 4</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">edi</span><span class="w"> </span><span class="c1">; esp - 4</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">ebp</span><span class="w"> </span><span class="c1">; esp - 4</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ebp</span><span class="p">,</span><span class="w"> </span><span class="no">esp</span>
<span class="w"> </span><span class="nf">sub</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="mi">36</span><span class="w"> </span><span class="c1">; esp - 36</span>
</code></pre></div>
<p>We see that <code>esp + 48</code> will give us ability to overwrite EIP. Input starts from <code>ebp + .input</code> that is <code>ebp - 32</code> or <code>esp + 4</code>. This means that offset from input we control is <code>44</code> to EIP. Address of <code>open_door</code> function is 0x10a7.</p>
<p>The assembly solution we need to write in <code>Pwn tool</code>:</p>
<div class="highlight"><pre><span></span><code><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">data</span>
<span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="no">end-data</span>
<span class="nf">mov</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span>
<span class="na">rep</span><span class="w"> </span><span class="nf">outsb</span>
<span class="nf">hlt</span>
<span class="nl">data:</span>
<span class="nf">db</span><span class="w"> </span><span class="err">"</span><span class="mi">11111111111111111111111111111111</span><span class="err">"</span>
<span class="nf">db</span><span class="w"> </span><span class="err">"</span><span class="mi">111111111111</span><span class="err">"</span>
<span class="nf">db</span><span class="w"> </span><span class="mi">0xa7</span><span class="p">,</span><span class="mi">0x10</span>
<span class="nf">db</span><span class="w"> </span><span class="err">"\</span><span class="no">n</span><span class="err">"</span>
<span class="nl">end:</span>
</code></pre></div>
<p>After leaving jail, we can go visit town (just north) and go right to zombie map. This part is just a classic game, we need to kill zombie boss to unlock a new spell. </p>
<p>There are 3 buttons that need to be pressed to unlock the boss room. Upon entering the room with the boss, doors lock and fight is triggered but only if you move more then two steps from the door, which we can use to clear all other zombies before the boss fight itself.</p>
<p>After the fight we get <code>Explode</code> spell:</p>
<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="mi">24</span>
<span class="nl">wait:</span>
<span class="w"> </span><span class="nf">pause</span>
<span class="w"> </span><span class="nf">loop</span><span class="w"> </span><span class="no">wait</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">eax</span><span class="p">,</span><span class="w"> </span><span class="no">SYS_EXPLODE</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ebx</span><span class="p">,</span><span class="w"> </span><span class="mi">32</span>
<span class="w"> </span><span class="nf">int</span><span class="w"> </span><span class="mi">0x80</span>
<span class="w"> </span><span class="nf">hlt</span><span class="w"> </span>
</code></pre></div>
<p>Now we have to go back to the map we entered after leaving jail and then left and down to enter the desert area and down again to enter Lab.</p>
<h2 id="lab-door-1">Lab Door 1</h2>
<div class="highlight"><pre><span></span><code><span class="nf">TERMINAL_INPUT</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">0</span>
<span class="nf">TERMINAL_OUTPUT</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">1</span>
<span class="nf">DOOR_CONTROL</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">2</span>
<span class="nl">main:</span>
<span class="na">.correct_pin</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">0</span>
<span class="nl">.main_loop:</span>
<span class="w"> </span><span class="nf">call</span><span class="w"> </span><span class="no">ask_and_verify_code</span>
<span class="w"> </span><span class="nf">test</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">jz</span><span class="w"> </span><span class="no">.invalid</span>
<span class="w"> </span><span class="nf">call</span><span class="w"> </span><span class="no">open_door</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.main_loop</span>
<span class="nl">.invalid:</span>
<span class="w"> </span><span class="c1">; Show denied message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">invalid</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="no">end_invalid</span><span class="w"> </span><span class="p">-</span><span class="w"> </span><span class="no">invalid</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span>
<span class="w"> </span><span class="na">rep</span><span class="w"> </span><span class="nf">outsb</span>
<span class="w"> </span><span class="nf">call</span><span class="w"> </span><span class="no">sleep</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.main_loop</span>
<span class="nl">ask_and_verify_code:</span>
<span class="c1">; Variables</span>
<span class="na">.input</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">-32</span>
<span class="na">.len</span><span class="w"> </span><span class="err">=</span><span class="w"> </span><span class="mi">-36</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">edi</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ebp</span><span class="p">,</span><span class="w"> </span><span class="no">esp</span>
<span class="w"> </span><span class="nf">sub</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="mi">36</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dword</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">],</span><span class="w"> </span><span class="mi">0</span>
<span class="w"> </span><span class="c1">; Display initial message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="no">end_message</span><span class="w"> </span><span class="p">-</span><span class="w"> </span><span class="no">message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span>
<span class="w"> </span><span class="na">rep</span><span class="w"> </span><span class="nf">outsb</span>
<span class="nl">.input_loop:</span>
<span class="w"> </span><span class="c1">; Grab next input</span>
<span class="w"> </span><span class="nf">in</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_INPUT</span>
<span class="w"> </span><span class="c1">; If enter is pressed, done</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="err">'\</span><span class="no">n</span><span class="err">'</span>
<span class="w"> </span><span class="nf">je</span><span class="w"> </span><span class="no">.end_input</span>
<span class="w"> </span><span class="c1">; Look for backspace</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span>
<span class="w"> </span><span class="nf">je</span><span class="w"> </span><span class="no">.backspace</span>
<span class="w"> </span><span class="c1">; Printable only</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="err">'</span><span class="w"> </span><span class="err">'</span><span class="w"> </span><span class="c1">;above ' ' 0x20 and bellow ~ 0xFE</span>
<span class="w"> </span><span class="nf">jb</span><span class="w"> </span><span class="no">.input_loop</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="err">'~'</span>
<span class="w"> </span><span class="nf">ja</span><span class="w"> </span><span class="no">.input_loop</span>
<span class="w"> </span><span class="c1">; Add character to input</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">]</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="mi">31</span>
<span class="w"> </span><span class="nf">jae</span><span class="w"> </span><span class="no">.input_loop</span><span class="w"> </span><span class="c1">;if above 31 jmp input_loop; 31 max length</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.input</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">ecx</span><span class="p">],</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">dword</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">]</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.input_loop</span>
<span class="nl">.backspace:</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">dword</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">],</span><span class="w"> </span><span class="mi">0</span>
<span class="w"> </span><span class="nf">je</span><span class="w"> </span><span class="no">.input_loop</span>
<span class="w"> </span><span class="c1">; Erase last character</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="err">'</span><span class="w"> </span><span class="err">'</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">dec</span><span class="w"> </span><span class="no">dword</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">]</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.input_loop</span>
<span class="nl">.end_input:</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="c1">; Null terminate input</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.len</span><span class="p">]</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">byte</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.input</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">ecx</span><span class="p">],</span><span class="w"> </span><span class="mi">0</span>
<span class="w"> </span><span class="c1">; Check code</span>
<span class="w"> </span><span class="nf">lea</span><span class="w"> </span><span class="no">eax</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="no">.input</span><span class="p">]</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">eax</span>
<span class="w"> </span><span class="nf">call</span><span class="w"> </span><span class="no">verify_code</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">edi</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">ret</span>
<span class="nl">verify_code:</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ebp</span><span class="p">,</span><span class="w"> </span><span class="no">esp</span>
<span class="w"> </span><span class="nf">sub</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">dword</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">12</span><span class="p">]</span><span class="w"> </span>
<span class="w"> </span><span class="no">call</span><span class="w"> </span><span class="no">strlen</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">eax</span><span class="p">,</span><span class="w"> </span><span class="mi">16</span><span class="w"> </span><span class="c1">;length has to be 16</span>
<span class="w"> </span><span class="nf">jne</span><span class="w"> </span><span class="no">.bad</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">12</span><span class="p">]</span><span class="w"> </span><span class="c1">;load eax (input)</span>
<span class="w"> </span><span class="nf">lea</span><span class="w"> </span><span class="no">edx</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="p">-</span><span class="w"> </span><span class="mi">8</span><span class="p">]</span><span class="w"> </span><span class="c1">;load eax again</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="w"> </span><span class="c1">;loop 8 times</span>
<span class="nl">.loop1:</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">esi</span><span class="p">]</span><span class="w"> </span>
<span class="w"> </span><span class="no">xor</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">esi</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">8</span><span class="p">]</span><span class="w"> </span><span class="c1">; xor input + (input + 8)</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="p">[</span><span class="no">edx</span><span class="p">],</span><span class="w"> </span><span class="no">al</span><span class="w"> </span><span class="c1">; move result to input</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">edx</span>
<span class="w"> </span><span class="nf">loop</span><span class="w"> </span><span class="no">.loop1</span>
<span class="w"> </span><span class="nf">lea</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ebp</span><span class="w"> </span><span class="p">-</span><span class="w"> </span><span class="mi">8</span><span class="p">]</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">edx</span><span class="p">,</span><span class="w"> </span><span class="no">valid</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="mi">8</span><span class="w"> </span><span class="c1">;loop 8 times</span>
<span class="nl">.check:</span><span class="w"> </span><span class="c1">;check if same as `valid` array</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">esi</span><span class="p">]</span>
<span class="w"> </span><span class="nf">cmp</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">edx</span><span class="p">]</span>
<span class="w"> </span><span class="nf">jne</span><span class="w"> </span><span class="no">.bad</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">edx</span>
<span class="w"> </span><span class="nf">loop</span><span class="w"> </span><span class="no">.check</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">ret</span><span class="w"> </span><span class="mi">4</span>
<span class="nl">.bad:</span>
<span class="w"> </span><span class="nf">xor</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esp</span><span class="p">,</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">ebp</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">ret</span><span class="w"> </span><span class="mi">4</span>
<span class="nl">strlen:</span>
<span class="w"> </span><span class="nf">xor</span><span class="w"> </span><span class="no">eax</span><span class="p">,</span><span class="w"> </span><span class="no">eax</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">esp</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">4</span><span class="p">]</span>
<span class="nl">.loop:</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dl</span><span class="p">,</span><span class="w"> </span><span class="p">[</span><span class="no">ecx</span><span class="p">]</span>
<span class="w"> </span><span class="nf">test</span><span class="w"> </span><span class="no">dl</span><span class="p">,</span><span class="w"> </span><span class="no">dl</span>
<span class="w"> </span><span class="nf">jz</span><span class="w"> </span><span class="no">.end</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">eax</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">ecx</span>
<span class="w"> </span><span class="nf">jmp</span><span class="w"> </span><span class="no">.loop</span>
<span class="nl">.end:</span>
<span class="w"> </span><span class="nf">ret</span><span class="w"> </span><span class="mi">4</span>
<span class="nl">open_door:</span>
<span class="w"> </span><span class="nf">push</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="c1">; Send command to unlock door</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">al</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span>
<span class="w"> </span><span class="nf">out</span><span class="w"> </span><span class="no">DOOR_CONTROL</span><span class="p">,</span><span class="w"> </span><span class="no">al</span>
<span class="w"> </span><span class="c1">; Show open message</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">esi</span><span class="p">,</span><span class="w"> </span><span class="no">open</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="no">end_open</span><span class="w"> </span><span class="p">-</span><span class="w"> </span><span class="no">open</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">dx</span><span class="p">,</span><span class="w"> </span><span class="no">TERMINAL_OUTPUT</span>
<span class="w"> </span><span class="na">rep</span><span class="w"> </span><span class="nf">outsb</span>
<span class="w"> </span><span class="nf">call</span><span class="w"> </span><span class="no">sleep</span>
<span class="w"> </span><span class="nf">pop</span><span class="w"> </span><span class="no">esi</span>
<span class="w"> </span><span class="nf">ret</span>
<span class="nl">sleep:</span>
<span class="w"> </span><span class="nf">mov</span><span class="w"> </span><span class="no">ecx</span><span class="p">,</span><span class="w"> </span><span class="mi">120</span>
<span class="nl">.sleep_loop:</span>
<span class="w"> </span><span class="nf">pause</span>
<span class="w"> </span><span class="nf">loop</span><span class="w"> </span><span class="no">.sleep_loop</span>
<span class="w"> </span><span class="nf">ret</span>
<span class="nl">valid:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="mi">0x09</span><span class="p">,</span><span class="w"> </span><span class="mi">0x23</span><span class="p">,</span><span class="w"> </span><span class="mi">0x06</span><span class="p">,</span><span class="w"> </span><span class="mi">0x07</span><span class="p">,</span><span class="w"> </span><span class="mi">0x36</span><span class="p">,</span><span class="w"> </span><span class="mi">0x38</span><span class="p">,</span><span class="w"> </span><span class="mi">0x22</span><span class="p">,</span><span class="w"> </span><span class="mi">0x2c</span>
<span class="nl">message:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="err">"\</span><span class="no">fCLEARENCE</span><span class="w"> </span><span class="no">LEVEL</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="no">REQUIRED</span><span class="err">\</span><span class="no">nAuthorization</span><span class="w"> </span><span class="no">code</span><span class="p">:</span><span class="err">\</span><span class="no">n</span><span class="err">"</span>
<span class="nl">end_message:</span>
<span class="nl">open:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="err">"</span><span class="no">ACCESS</span><span class="w"> </span><span class="no">GRANTED</span><span class="err">"</span>
<span class="nl">end_open:</span>
<span class="nl">invalid:</span>
<span class="w"> </span><span class="nf">db</span><span class="w"> </span><span class="err">"</span><span class="no">ACCESS</span><span class="w"> </span><span class="no">DENIED</span><span class="err">"</span>
<span class="nl">end_invalid:</span>
</code></pre></div>
<p>We have another reversing challenge that we need to pass to unlock the door. The length of the input is checked so we need to understand how the code works to bypass the pin check. I have left some comments that should make code a bit clearer. </p>
<p>Basically, we can only enter characters between <code>' '</code> and <code>~</code>. The length of input has to be 16 and each of the first eight characters from the input are XORed with the input characters 8 positions ahead from them. The result we get is then checked with <code>valid</code> array.</p>
<p>Brute-force python solution:</p>
<div class="highlight"><pre><span></span><code><span class="n">alphabet</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mh">0x20</span><span class="p">,</span> <span class="mh">0xFE</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)]</span>
<span class="n">values</span> <span class="o">=</span> <span class="p">[</span><span class="mh">0x09</span><span class="p">,</span> <span class="mh">0x23</span><span class="p">,</span> <span class="mh">0x06</span><span class="p">,</span> <span class="mh">0x07</span><span class="p">,</span> <span class="mh">0x36</span><span class="p">,</span> <span class="mh">0x38</span><span class="p">,</span> <span class="mh">0x22</span><span class="p">,</span> <span class="mh">0x2c</span><span class="p">]</span>
<span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">values</span><span class="p">:</span>
<span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">alphabet</span><span class="p">:</span>
<span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">alphabet</span><span class="p">:</span>
<span class="k">if</span> <span class="n">x</span> <span class="o">^</span> <span class="n">y</span> <span class="o">==</span> <span class="n">val</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="si">%x</span><span class="s2"> (</span><span class="si">%c</span><span class="s2">) ^ </span><span class="si">%x</span><span class="s2"> (</span><span class="si">%c</span><span class="s2">)= </span><span class="si">%x</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="nb">chr</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">y</span><span class="p">,</span> <span class="nb">chr</span><span class="p">(</span><span class="n">y</span><span class="p">),</span> <span class="n">val</span><span class="p">))</span>
<span class="k">continue</span>
<span class="c1"># Verify solution</span>
<span class="n">sol</span> <span class="o">=</span> <span class="p">[</span><span class="mh">0x20</span><span class="p">,</span> <span class="mh">0x40</span><span class="p">,</span> <span class="mh">0x21</span><span class="p">,</span> <span class="mh">0x20</span><span class="p">,</span> <span class="mh">0x40</span><span class="p">,</span> <span class="mh">0x40</span><span class="p">,</span> <span class="mh">0x40</span><span class="p">,</span> <span class="mh">0x40</span><span class="p">,</span> <span class="mh">0x29</span><span class="p">,</span> <span class="mh">0x63</span><span class="p">,</span> <span class="mh">0x27</span><span class="p">,</span> <span class="mh">0x27</span><span class="p">,</span> <span class="mh">0x76</span><span class="p">,</span> <span class="mh">0x78</span><span class="p">,</span> <span class="mh">0x62</span><span class="p">,</span> <span class="mh">0x6c</span><span class="p">]</span>
<span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">8</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="nb">hex</span><span class="p">(</span><span class="n">sol</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">^</span> <span class="n">sol</span><span class="p">[</span><span class="n">x</span><span class="o">+</span><span class="mi">8</span><span class="p">]))</span>
</code></pre></div>
<p>In the room ahead we get flying boots.
And that's it for this part of writeup :D </p>
</div>
<footer class="text-right">
<p>- F3real</p>
</footer>
<div id="show-comments" class="span7 text-center">
<a href="https://f3real.github.io/pwnadventure_sourcery1.html#disqus_thread"
data-disqus-identifier="pwnadventure_sourcery1"
class="btn btn-primary twitchy-background">Show Comments</a>
</div>
<section id="comments" class="comments hidden">
<hr/>
<h2>Comments</h2>
<div id="disqus_thread"></div>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by
Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</section>
</div>
</div>
</article>
</section>
<footer>
<hr>
<div class="row">
<div class="col-lg-10 text-center">
<p><small>
Built by <a href="http://docs.getpelican.com/en/latest">Pelican</a> / <a href="https://github.com/F3real/pelican-twitchy">pelican-twitchy</a>
· © 2024 F3real
</small></p>
</div>
</div>
</footer> </div>
</div>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
<!-- disqus -->
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'https-f3real-github-io'; // required: replace example with your forum shortname
var disqus_identifier = 'pwnadventure_sourcery1';
var disqus_url = 'https://f3real.github.io/pwnadventure_sourcery1.html';
var disqus_config = function () {
this.language = "en";
};
var commentsDiv = document.getElementById('show-comments');
commentsDiv.onclick = function() {
/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
this.style.display = 'none';
};
</script>
<!-- /disqus -->
<script>
const wrapper = document.getElementById('wrapper');
const sidebarBig = document.getElementById('sidebar-wrapper');
const sidebarSmall = document.getElementById('sidebar-wrapper-small');
const triggers = Array.from(document.querySelectorAll('[data-toggle="collapse"]'));
for (var i = 0; i < triggers.length; i++) {
triggers[i].addEventListener('click', (ev) => {
const elm = ev.currentTarget;
ev.preventDefault();
const selector = elm.getAttribute('href').replace('#','');
elm.classList.toggle('collapsed');
document.getElementById(selector).classList.toggle('show');
}, false);
}
function showBigNav() {;
sidebarBig.style.display = 'block';
sidebarSmall.style.display = 'none';
}
function showSmallNav() {
sidebarBig.style.display = 'none';
sidebarSmall.style.display = 'block';
}
const mediaQuery = window.matchMedia('(min-width:768px)');
mediaQuery.onchange = e => {
if (wrapper.classList.contains('toggled')) {
wrapper.classList.remove('toggled');
} else {
if (e.matches) {
showBigNav();
} else {
showSmallNav();
}
}
}
function setNavbar() {
var condition = wrapper.classList.contains('toggled');
if (!mediaQuery.matches) {
condition = !condition;
}
if (condition) {
showSmallNav();
} else {
showBigNav();
}
}
function toggleMenu(){
wrapper.classList.toggle('toggled');
setNavbar();
}
window.onload = setNavbar;
</script>
<script data-goatcounter="https://f3real.goatcounter.com/count"
async src="//gc.zgo.at/count.js"></script>
</body>
</html>