-
Notifications
You must be signed in to change notification settings - Fork 0
/
utctf_supersecureauthentication.html
494 lines (455 loc) · 43 KB
/
utctf_supersecureauthentication.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
<!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,java" />
<meta name="description" content="How to solve UTCTF 2019 Super Secure Authentication reversing challenge" />
<title>UTCTF 2019 Super Secure Authentication - 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/utctf_supersecureauthentication.html"
rel="bookmark"
title="Permalink to UTCTF 2019 Super Secure Authentication">
UTCTF 2019 Super Secure Authentication
</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-03-19T10:01:00+01:00"> Tue 19 March 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/java.html">java</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>This time we are given zip file containing few different, suspiciously large, compiled classes. If you want to follow along, files can be downloaded <a href="https://github.com/F3real/ctf_solutions/tree/master/2019/utctf/SuperSecureAuthentication">here</a>.</p>
<div class="highlight"><pre><span></span><code> Length Name
--- ---
1999 Authenticator.class
4097 jBaseZ85.class
3152661 Verifier0.class
3151489 Verifier1.class
3335819 Verifier2.class
3210206 Verifier3.class
3151489 Verifier4.class
3638156 Verifier5.class
3382336 Verifier6.class
3068109 Verifier7.class
</code></pre></div>
<p>We can run a given program with <code>java Authenticator <password></code> from cmd.</p>
<p>Looking at the source of the <code>Authenticator</code> in Ghidra we see that there is <code>checkFlag</code> function.</p>
<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="n">objectRef</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">param1</span><span class="p">.</span><span class="na">substring</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">7</span><span class="p">);</span>
<span class="w"> </span><span class="n">bVar3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">objectRef</span><span class="p">.</span><span class="na">equals</span><span class="p">(</span><span class="s">"utflag{"</span><span class="p">);</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">bVar3</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="kc">false</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="n">objectRef</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">param1</span><span class="p">;</span>
<span class="w"> </span><span class="n">iVar1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">param1</span><span class="p">.</span><span class="na">length</span><span class="p">();</span>
<span class="w"> </span><span class="n">cVar2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">objectRef</span><span class="p">.</span><span class="na">charAt</span><span class="p">(</span><span class="n">iVar1</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">);</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">cVar2</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="sc">'}'</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="n">objectRef_01</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="p">(</span><span class="n">StringTokenizer</span><span class="p">);</span>
<span class="w"> </span><span class="n">iVar4</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="p">;</span>
<span class="w"> </span><span class="n">objectRef_00</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">objectRef_01</span><span class="p">;</span>
<span class="w"> </span><span class="n">iVar1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">param1</span><span class="p">.</span><span class="na">length</span><span class="p">();</span>
<span class="w"> </span><span class="n">objectRef</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">param1</span><span class="p">.</span><span class="na">substring</span><span class="p">(</span><span class="n">iVar4</span><span class="p">,</span><span class="n">iVar1</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">);</span>
<span class="w"> </span><span class="n">objectRef_01</span><span class="p">.</span><span class="o"><</span><span class="n">init</span><span class="o">></span><span class="p">(</span><span class="n">objectRef</span><span class="p">,</span><span class="s">"_"</span><span class="p">);</span>
<span class="w"> </span><span class="n">objectRef</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">objectRef_00</span><span class="p">.</span><span class="na">nextToken</span><span class="p">();</span>
<span class="w"> </span><span class="n">bVar3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Verifier0</span><span class="p">.</span><span class="na">verifyFlag</span><span class="p">(</span><span class="n">objectRef</span><span class="p">);</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">bVar3</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="kc">false</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="p">...</span>
</code></pre></div>
<p>It checks if our passed string starts with <code>utflag{</code> and ends with <code>}</code>. The rest of input is split on <code>_</code> and passed to different Verifier classes.
So our flag has the format of <code>utflag{x_x_x_x_x_x_x}</code> and each Verifier is tasked with checking one part.</p>
<p>Looking at the source code of <code>Verifer0</code> we can't see much. It dynamically loads the new class from hardcoded array and calls <code>verifyFlag</code> function it provides.</p>
<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="p">....</span>
<span class="w"> </span><span class="n">objectRef_02</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Verifier0</span><span class="p">();</span>
<span class="w"> </span><span class="n">objectRef</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">objectRef_02</span><span class="p">.</span><span class="na">defineClass</span><span class="p">(</span><span class="s">"Verifier0"</span><span class="p">,</span><span class="n">Verifier0</span><span class="p">.</span><span class="na">arr</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="n">Verifier0</span><span class="p">.</span><span class="na">arr</span><span class="p">.</span><span class="na">length</span><span class="p">);</span>
<span class="w"> </span><span class="n">ppCVar1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Class</span><span class="o">[</span><span class="mi">1</span><span class="o">]</span><span class="p">;</span>
<span class="w"> </span><span class="n">ppCVar1</span><span class="o">[</span><span class="mi">0</span><span class="o">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">String</span><span class="p">.</span><span class="na">class</span><span class="p">;</span>
<span class="w"> </span><span class="n">objectRef_00</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">objectRef</span><span class="p">.</span><span class="na">getMethod</span><span class="p">(</span><span class="s">"verifyFlag"</span><span class="p">,</span><span class="n">ppCVar1</span><span class="p">);</span>
<span class="w"> </span><span class="n">ppOVar2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Object</span><span class="o">[</span><span class="mi">1</span><span class="o">]</span><span class="p">;</span>
<span class="w"> </span><span class="n">ppOVar2</span><span class="o">[</span><span class="mi">0</span><span class="o">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">param1</span><span class="p">;</span>
<span class="w"> </span><span class="n">objectRef_01</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">objectRef_00</span><span class="p">.</span><span class="na">invoke</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span><span class="n">ppOVar2</span><span class="p">);</span>
</code></pre></div>
<p>To make matters a bit harder, <code>arr0</code> is encoded in Z85 (a format for representing binary data as printable text).</p>
<p>After saving the first dynamically loaded class and decompiling it, we get almost identical code as with the original class. This led me to assume that classes are probably nested in a manner similar to matryoshka dolls and that we need to automate this process.</p>
<p>First, we can see which version of java is used to compile these class files.
For this, we are going to use <code>javap</code> disassembler which is part of JDK.</p>
<div class="highlight"><pre><span></span><code>javap -v .\Authenticator.class | findstr "major"
major version: 52
</code></pre></div>
<p>Major version 52 corresponds to java 8. We can use the same procedure to view the minor version as well.</p>
<p>To dynamically load classes and access fields we are going to use java reflection. Since we can write the solution in the same folder as extracted classes we don't have to worry about imports. </p>
<p>Solution code should be pretty understandable:</p>
<div class="highlight"><pre><span></span><code><span class="kn">import</span><span class="w"> </span><span class="nn">java.lang.reflect.Field</span><span class="p">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">java.lang.NoSuchFieldException</span><span class="p">;</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">java.io.FileOutputStream</span><span class="p">;</span>
<span class="c1">//class ClassLoader is an abstract class so we have to extend it, if we want to use it.</span>
<span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Sol</span><span class="w"> </span><span class="kd">extends</span><span class="w"> </span><span class="n">ClassLoader</span><span class="p">{</span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="kd">throws</span><span class="w"> </span><span class="n">Exception</span><span class="p">{</span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">8</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">currentVer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"Verifier"</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">String</span><span class="p">.</span><span class="na">valueOf</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="w"> </span><span class="n">Class</span><span class="w"> </span><span class="n">classT</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Class</span><span class="p">.</span><span class="na">forName</span><span class="p">(</span><span class="n">name</span><span class="p">);</span>
<span class="w"> </span><span class="n">Object</span><span class="w"> </span><span class="n">ver</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">classT</span><span class="p">.</span><span class="na">newInstance</span><span class="p">();</span>
<span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="kc">true</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Field</span><span class="w"> </span><span class="n">f</span><span class="p">;</span>
<span class="w"> </span><span class="k">try</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="c1">//arr field is private so we have to change access permission</span>
<span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ver</span><span class="p">.</span><span class="na">getClass</span><span class="p">().</span><span class="na">getDeclaredField</span><span class="p">(</span><span class="s">"arr"</span><span class="p">);</span>
<span class="w"> </span><span class="n">f</span><span class="p">.</span><span class="na">setAccessible</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">catch</span><span class="p">(</span><span class="n">NoSuchFieldException</span><span class="w"> </span><span class="n">e</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">break</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="kt">byte</span><span class="w"> </span><span class="o">[]</span><span class="w"> </span><span class="n">arr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="kt">byte</span><span class="w"> </span><span class="o">[]</span><span class="p">)</span><span class="w"> </span><span class="n">f</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">ver</span><span class="p">);</span>
<span class="w"> </span><span class="k">try</span><span class="w"> </span><span class="p">(</span><span class="n">FileOutputStream</span><span class="w"> </span><span class="n">fos</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">FileOutputStream</span><span class="p">(</span><span class="n">name</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">String</span><span class="p">.</span><span class="na">valueOf</span><span class="p">(</span><span class="n">currentVer</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">".class"</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">fos</span><span class="p">.</span><span class="na">write</span><span class="p">(</span><span class="n">arr</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="cm">/* We have to recreate class loader every time to avoid</span>
<span class="cm"> java.lang.LinkageError: loader (instance of Sol): attempted duplicate class definition</span>
<span class="cm"> */</span>
<span class="w"> </span><span class="n">Sol</span><span class="w"> </span><span class="n">_classLoader</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Sol</span><span class="p">();</span>
<span class="w"> </span><span class="n">Class</span><span class="w"> </span><span class="n">loadedClass</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">_classLoader</span><span class="p">.</span><span class="na">defineClass</span><span class="p">(</span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">arr</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">arr</span><span class="p">.</span><span class="na">length</span><span class="p">);</span>
<span class="w"> </span><span class="n">ver</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">loadedClass</span><span class="p">.</span><span class="na">newInstance</span><span class="p">();</span>
<span class="w"> </span><span class="n">currentVer</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
</code></pre></div>
<p>We can compile our solution with <code>javac</code>.</p>
<p>After running our program we see that each verifier had 28 nested classes.
Almost all of the final classes also implement some simpler form of encryption.</p>
<p>Looking at decompiled source of last class from <code>Verifier0</code> we see that it just uses XOR, which is easily reversible.</p>
<div class="highlight"><pre><span></span><code><span class="n">x</span> <span class="o">=</span> <span class="p">[</span> <span class="mh">0x32</span><span class="p">,</span> <span class="mh">0x30</span><span class="p">,</span> <span class="mh">0x2d</span><span class="p">,</span> <span class="mh">0x32</span><span class="p">,</span> <span class="mh">0x2a</span><span class="p">,</span> <span class="mh">0x27</span><span class="p">,</span> <span class="mh">0x36</span><span class="p">,</span> <span class="mh">0x31</span><span class="p">]</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">[</span> <span class="n">xx</span> <span class="o">^</span> <span class="mh">0x42</span> <span class="k">for</span> <span class="n">xx</span> <span class="ow">in</span> <span class="n">x</span><span class="p">]</span>
<span class="o">>>></span> <span class="s1">''</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">chr</span><span class="p">(</span><span class="n">xx</span><span class="p">)</span> <span class="k">for</span> <span class="n">xx</span> <span class="ow">in</span> <span class="n">y</span><span class="p">)</span>
<span class="s1">'prophets'</span>
<span class="o">>>></span>
</code></pre></div>
<p><code>Verifier1</code> just checks string in reverse order:</p>
<div class="highlight"><pre><span></span><code><span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="mh">0x73</span><span class="p">,</span> <span class="mh">0x75</span><span class="p">,</span> <span class="mh">0x6f</span><span class="p">,</span> <span class="mh">0x69</span><span class="p">,</span> <span class="mh">0x78</span><span class="p">,</span> <span class="mh">0x6e</span><span class="p">,</span> <span class="mh">0x61</span><span class="p">]</span>
<span class="n">x</span><span class="o">.</span><span class="n">reverse</span><span class="p">()</span>
<span class="o">>>></span> <span class="s2">""</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">chr</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">x</span><span class="p">)</span>
<span class="s1">'anxious'</span>
</code></pre></div>
<p><code>Verifier2</code> appends to each flag char string <code>"foo"</code> and hashes it with java <code>hashCode</code> function. Since we have saved hashes we can just hash all lowercase ascii characters and get our flag.</p>
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">string</span>
<span class="k">def</span> <span class="nf">java_string_hashcode</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
<span class="n">h</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">s</span><span class="p">:</span>
<span class="n">h</span> <span class="o">=</span> <span class="p">(</span><span class="mi">31</span> <span class="o">*</span> <span class="n">h</span> <span class="o">+</span> <span class="nb">ord</span><span class="p">(</span><span class="n">c</span><span class="p">))</span> <span class="o">&</span> <span class="mh">0xFFFFFFFF</span>
<span class="k">return</span> <span class="p">((</span><span class="n">h</span> <span class="o">+</span> <span class="mh">0x80000000</span><span class="p">)</span> <span class="o">&</span> <span class="mh">0xFFFFFFFF</span><span class="p">)</span> <span class="o">-</span> <span class="mh">0x80000000</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="mh">0x2f01e2</span><span class="p">,</span> <span class="mh">0x2f7641</span><span class="p">,</span> <span class="mh">0x331939</span><span class="p">,</span> <span class="mh">0x3401f7</span><span class="p">,</span> <span class="mh">0x32a4da</span><span class="p">,</span> <span class="mh">0x3147bd</span><span class="p">,</span> <span class="mh">0x3647d2</span><span class="p">,</span><span class="mh">0x3147bd</span><span class="p">,</span> <span class="mh">0x3401f7</span><span class="p">,</span> <span class="mh">0x338d98</span><span class="p">]</span>
<span class="n">sol</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">ch</span> <span class="ow">in</span> <span class="n">string</span><span class="o">.</span><span class="n">ascii_lowercase</span><span class="p">:</span>
<span class="n">hashcode</span> <span class="o">=</span> <span class="n">java_string_hashcode</span><span class="p">(</span><span class="n">ch</span> <span class="o">+</span> <span class="s2">"foo"</span><span class="p">)</span>
<span class="k">if</span> <span class="n">hashcode</span> <span class="ow">in</span> <span class="n">x</span><span class="p">:</span>
<span class="n">sol</span><span class="p">[</span><span class="n">hashcode</span><span class="p">]</span> <span class="o">=</span> <span class="n">ch</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">x</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">sol</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="o">>>></span> <span class="n">demolition</span>
</code></pre></div>
<p><code>Verifier3</code> does simple math operations on encrypted string:</p>
<div class="highlight"><pre><span></span><code><span class="n">x</span> <span class="o">=</span> <span class="s2">"obwaohfcbwq"</span>
<span class="n">x1</span> <span class="o">=</span> <span class="p">[</span> <span class="p">(</span><span class="nb">ord</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="o">-</span> <span class="mh">0x55</span><span class="p">)</span> <span class="o">%</span> <span class="mh">0x1a</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">x</span><span class="p">]</span>
<span class="n">x2</span> <span class="o">=</span> <span class="p">[</span> <span class="n">i</span> <span class="o">+</span> <span class="mh">0x61</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">x1</span><span class="p">]</span>
<span class="o">>>></span> <span class="s2">""</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">chr</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">x2</span><span class="p">)</span>
<span class="s1">'animatronic'</span>
</code></pre></div>
<p><code>Verifier4</code> is also similar.</p>
<div class="highlight"><pre><span></span><code><span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="mh">0xd30</span><span class="p">,</span> <span class="mh">0xcdf</span><span class="p">,</span> <span class="mh">0xe3e</span><span class="p">,</span> <span class="mh">0xc73</span><span class="p">,</span> <span class="mh">0xd9c</span><span class="p">,</span> <span class="mh">0xcc4</span><span class="p">]</span>
<span class="n">x1</span> <span class="o">=</span> <span class="p">[</span> <span class="n">i</span> <span class="o">-</span> <span class="mh">0x238</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">x</span><span class="p">]</span>
<span class="n">x2</span> <span class="o">=</span> <span class="p">[</span> <span class="n">i</span> <span class="o">//</span> <span class="mh">0x1b</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">x1</span><span class="p">]</span>
<span class="o">>>></span><span class="s2">""</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">chr</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">x2</span><span class="p">)</span>
<span class="s1">'herald'</span>
</code></pre></div>
<p><code>Verifier5</code> hashes every char of input with MD5, concatenates them and compares them do hardcoded string.</p>
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">hashlib</span>
<span class="kn">import</span> <span class="nn">string</span>
<span class="n">x</span> <span class="o">=</span> <span class="s2">"8FA14CDD754F91CC6554C9E71929CCE7865C0C0B4AB0E063E5CAA3387C1A8741FBADE9E36A3F36D3D676C1B808451DD7FBADE9E36A3F36D3D676C1B808451DD7"</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
<span class="k">while</span> <span class="n">x</span> <span class="o">!=</span> <span class="s2">""</span><span class="p">:</span>
<span class="k">for</span> <span class="n">ch</span> <span class="ow">in</span> <span class="n">string</span><span class="o">.</span><span class="n">ascii_lowercase</span><span class="p">:</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">hashlib</span><span class="o">.</span><span class="n">md5</span><span class="p">()</span>
<span class="n">m</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">ch</span><span class="o">.</span><span class="n">encode</span><span class="p">())</span> <span class="c1">#UTF-8 by default</span>
<span class="n">currentDigest</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">digest</span><span class="p">()</span><span class="o">.</span><span class="n">hex</span><span class="p">()</span>
<span class="k">if</span> <span class="n">x</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="n">currentDigest</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="n">ch</span> <span class="o">+</span> <span class="s2">" "</span> <span class="o">+</span> <span class="n">currentDigest</span><span class="p">)</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">currentDigest</span><span class="p">,</span> <span class="s2">""</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="o">>>></span>
<span class="n">f</span> <span class="mi">8</span><span class="n">fa14cdd754f91cc6554c9e71929cce7</span>
<span class="n">i</span> <span class="mi">865</span><span class="n">c0c0b4ab0e063e5caa3387c1a8741</span>
<span class="n">z</span> <span class="n">fbade9e36a3f36d3d676c1b808451dd7</span>
<span class="n">z</span> <span class="n">fbade9e36a3f36d3d676c1b808451dd7</span>
</code></pre></div>
<p><code>Verifier6</code> uses SHA1 to hash input string and compare it with hardcoded hash value <code>1B480158E1F30E0B6CEE7813E9ECF094BD6B3745</code>. We can quickly find a solution by just googling it. The solution is the string <code>stop</code>.</p>
<p><code>Verifier7</code> just checks if provided string equals to <code>goodbye</code>.</p>
<p>Combining all of this we get our flag:
<code>utflag{prophets_anxious_demolition_animatronic_herald_fizz_stop_goodbye}</code></p>
</div>
<footer class="text-right">
<p>- F3real</p>
</footer>
<div id="show-comments" class="span7 text-center">
<a href="https://f3real.github.io/utctf_supersecureauthentication.html#disqus_thread"
data-disqus-identifier="utctf_supersecureauthentication"
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 = 'utctf_supersecureauthentication';
var disqus_url = 'https://f3real.github.io/utctf_supersecureauthentication.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>