-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrackmes_one2.html
446 lines (406 loc) · 31.3 KB
/
crackmes_one2.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
<!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="crackme,windows,radare2,unicorn" />
<meta name="description" content="Solutions to 7eRoM's 1st challenge crackme" />
<title>Crackmes one 7eRoM's 1st one challenge - 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 >
<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 class="active">
<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/crackmes_one2.html"
rel="bookmark"
title="Permalink to Crackmes one 7eRoM's 1st one challenge">
Crackmes one 7eRoM's 1st one challenge
</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-11-16T10:02:00+01:00"> Sat 16 November 2019</time>
</span>
<span class="category">
<i class="fa fa-folder-open padding-small"></i><a href="https://f3real.github.io/category/reversing.html">reversing</a>
</span>
<span class="tags">
<i class="fa fa-tags padding-small"></i>
<a href="https://f3real.github.io/tag/crackme.html">crackme</a> / <a href="https://f3real.github.io/tag/windows.html">windows</a> / <a href="https://f3real.github.io/tag/radare2.html">radare2</a> / <a href="https://f3real.github.io/tag/unicorn.html">unicorn</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>Today we will take a look at this <a href="https://crackmes.one/crackme/5cd7153f33c5d4419da55a36">crackme</a>.</p>
<p>One of the first things we notice if we open given exe in Ghidra is:</p>
<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="n">local_414</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">*</span><span class="p">(</span><span class="n">uint</span><span class="w"> </span><span class="o">*</span><span class="p">)(</span><span class="o">*</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)(</span><span class="o">*</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="o">*</span><span class="p">)(</span><span class="n">in_FS_OFFSET</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x18</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mh">0x30</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="o">&</span><span class="w"> </span><span class="mh">0xff</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="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">local_414</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="p">{</span>
<span class="w"> </span><span class="p">....</span>
<span class="w"> </span><span class="p">}</span>
</code></pre></div>
<p>This is actually anti-debugger trick that diverts execution to a false password check way if it detects debugger.</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">large</span><span class="w"> </span><span class="no">fs</span><span class="p">:</span><span class="mi">18</span><span class="no">h</span><span class="w"> </span><span class="c1">; Offset 18h has self-pointer to TEB</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="p">[</span><span class="no">eax</span><span class="err">+</span><span class="mi">30</span><span class="no">h</span><span class="p">]</span><span class="w"> </span><span class="c1">; Offset 30h has pointer to PEB</span>
<span class="nf">movzx</span><span class="w"> </span><span class="no">eax</span><span class="p">,</span><span class="w"> </span><span class="no">byte</span><span class="w"> </span><span class="no">ptr</span><span class="p">[</span><span class="no">eax</span><span class="err">+</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="c1">; PEB.BeingDebugged</span>
<span class="nf">test</span><span class="w"> </span><span class="no">eax</span><span class="p">,</span><span class="w"> </span><span class="no">eax</span>
</code></pre></div>
<p>This is equivalent to <code>IsDebuggerPresent</code> call.
The TIB (Thread Information Block) of the current thread can be accessed as an offset of segment register FS for Win32. It is common to first get a linear self-referencing pointer to it stored at FS:[0x18].
On offset 0x30 of TIB we have a pointer to PEB (Process Environment Block). From there with offset 0x02 we can access <code>BeingDebugged</code> flag. <code>BeingDebugged</code> flag is set to 1 if the process is being debugged, 0 otherwise.</p>
<p>To bypass this check we can use radare2 and just patch it:</p>
<div class="highlight"><pre><span></span><code>radare2.exe -w CrackMe_1.exe
[0x004075a5]> s 0x00403b3c
[0x00403b3c]> pd 6
0x00403b3c 81e2ff000000 and edx, 0xff ; 255
0x00403b42 89542414 mov dword [esp + 0x14], edx
0x00403b46 e825e5ffff call 0x402070
0x00403b4b e8d0e9ffff call 0x402520
0x00403b50 6a06 push 6 ; 6
0x00403b52 e818380000 call 0x40736f
[0x00403b3c]> "wa xor edx, edx; nop; nop; nop; nop;"
Written 6 byte(s) (xor edx, edx; nop; nop; nop; nop;) = wx 31d290909090
[0x00403b3c]> pd 6
0x00403b3c 31d2 xor edx, edx
0x00403b3e 90 nop
0x00403b3f 90 nop
0x00403b40 90 nop
0x00403b41 90 nop
0x00403b42 89542414 mov dword [esp + 0x14], edx
[0x00403b3c]>
</code></pre></div>
<p>After this change, we can use simply debug the given exe. I used x64dbg. We can just run app to the password prompt, pause executing enter the password and run to user code.</p>
<p><img alt="x64dbg" class="img-fluid centerimage" src="https://f3real.github.io/images/2019_11_16_debugger.png"></p>
<p>One interesting detail is that the program is using <a href="https://github.com/7eRoM/Ftring">Ftring</a> to encrypt strings. Ftring will generate instructions to set flags corresponding to the given letter and then use <code>lahf</code> instruction to transfer them to <code>al</code> register. For example, to generate the letter <code>A</code> following instruction sequence will be used:</p>
<div class="highlight"><pre><span></span><code><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">cl</span><span class="p">,</span><span class="w"> </span><span class="mi">225</span>
<span class="w"> </span><span class="nf">add</span><span class="w"> </span><span class="no">cl</span><span class="p">,</span><span class="w"> </span><span class="mi">9</span>
<span class="w"> </span><span class="nf">setc</span><span class="w"> </span><span class="no">bl</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">bl</span>
<span class="w"> </span><span class="nf">shl</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">dl</span><span class="p">,</span><span class="w"> </span><span class="mi">144</span>
<span class="w"> </span><span class="nf">dec</span><span class="w"> </span><span class="no">dl</span>
<span class="w"> </span><span class="nf">lahf</span>
<span class="w"> </span><span class="nf">test</span><span class="w"> </span><span class="no">ah</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="no">h</span>
<span class="w"> </span><span class="nf">jz</span><span class="w"> </span><span class="no">RHpFexiD</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="mi">1</span>
<span class="w"> </span><span class="nl">RHpFexiD:</span>
<span class="w"> </span><span class="nf">shl</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">dh</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span>
<span class="w"> </span><span class="nf">inc</span><span class="w"> </span><span class="no">dh</span>
<span class="w"> </span><span class="nf">setz</span><span class="w"> </span><span class="no">bl</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">bl</span>
<span class="w"> </span><span class="nf">shl</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">edx</span><span class="p">,</span><span class="w"> </span><span class="mi">803704434</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">setp</span><span class="w"> </span><span class="no">bl</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">bl</span>
<span class="w"> </span><span class="nf">shl</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">si</span><span class="p">,</span><span class="w"> </span><span class="mi">27175</span>
<span class="w"> </span><span class="nf">sub</span><span class="w"> </span><span class="no">si</span><span class="p">,</span><span class="w"> </span><span class="mi">20613</span>
<span class="w"> </span><span class="nf">setz</span><span class="w"> </span><span class="no">bl</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">bl</span>
<span class="w"> </span><span class="nf">shl</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">bl</span><span class="p">,</span><span class="w"> </span><span class="mi">149</span>
<span class="w"> </span><span class="nf">add</span><span class="w"> </span><span class="no">bl</span><span class="p">,</span><span class="w"> </span><span class="mi">39</span>
<span class="w"> </span><span class="nf">setp</span><span class="w"> </span><span class="no">bl</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">bl</span>
<span class="w"> </span><span class="nf">shl</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">dh</span><span class="p">,</span><span class="w"> </span><span class="mi">59</span>
<span class="w"> </span><span class="nf">sub</span><span class="w"> </span><span class="no">dh</span><span class="p">,</span><span class="w"> </span><span class="mi">218</span>
<span class="w"> </span><span class="nf">lahf</span>
<span class="w"> </span><span class="nf">test</span><span class="w"> </span><span class="no">ah</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="no">h</span>
<span class="w"> </span><span class="nf">jz</span><span class="w"> </span><span class="no">IWsajNHQ</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="mi">1</span>
<span class="w"> </span><span class="nl">IWsajNHQ:</span>
<span class="w"> </span><span class="nf">shl</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">cx</span><span class="p">,</span><span class="w"> </span><span class="mi">19329</span>
<span class="w"> </span><span class="nf">add</span><span class="w"> </span><span class="no">cx</span><span class="p">,</span><span class="w"> </span><span class="mi">16579</span>
<span class="w"> </span><span class="nf">setp</span><span class="w"> </span><span class="no">bl</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">bl</span>
<span class="w"> </span><span class="c1">// Writing char 'A' to memory</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="no">ptr</span><span class="p">[</span><span class="no">static_array</span><span class="w"> </span><span class="err">+</span><span class="w"> </span><span class="mi">0</span><span class="p">],</span><span class="w"> </span><span class="no">al</span>
</code></pre></div>
<p>We can locate reasonably well the ftring instruction sequences using radare2 with:</p>
<div class="highlight"><pre><span></span><code>"/a lahf; test ah, 0x10;"
</code></pre></div>
<p>Unfortunately, radare2 had trouble with <code>lahf</code> instruction but it turned to be very easy to <a href="https://github.com/radareorg/radare2/pull/15463">fix</a>. Just make sure to use the latest version of radare2 (and git is recommended way to get radare2 anyway).</p>
<p>Once we extract instruction sequences we can use unicorn to emulate them and see what are they evaluating to. Example of using unicorn to decode the fstring sequences is given bellow:</p>
<div class="highlight"><pre><span></span><code><span class="kn">from</span> <span class="nn">unicorn</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">unicorn.x86_const</span> <span class="kn">import</span> <span class="o">*</span>
<span class="n">X86_CODE32_ARR</span> <span class="o">=</span> <span class="p">[</span> <span class="s2">"32c0b61b80c66d0f92c332c3d0e0b27ffec20f98c332c3d0e0f90f92c332c3d0e0b2c680c23a0f92c332c3d0e0beb79c913081ee50a1e1150f92c332c3d0e0b580fecd0f98c332c3d0e066be2f5f66460f9ac332c3d0e066be0000664e0f98c332c3"</span><span class="p">,</span> <span class="s2">"32c0b1aa80c1a70f98c332c3d0e0b1a0fec90f9ac332c3d0e0b200feca0f98c332c3d0e066ba6aba6681c22a810f9ac332c3d0e0b1c8fec10f94c332c3d0e066be0080664e0f98c332c3d0e0bf1a1c119e81c7e6e3ee610f94c332c3d0e066bafcdd6681c204220f94c332c3"</span><span class="p">,</span>
<span class="s2">"32c0b3ad80eb9f0f94c332c3d0e066b9000066490f98c332c3d0e0bf697ca53381ef697ca5330f94c332c3d0e0b6f580eec90f98c332c3d0e0b1fb80e9560f92c332c3d0e0b267feca0f94c332c3d0e066b9b0276681c18ca59ff6c41074023401d0e0b1affec19ff6c41074023401"</span><span class="p">,</span>
<span class="s2">"32c0f80f92c332c3d0e0b15180c16b0f98c332c3d0e066bfb9086681c707f89ff6c41074023401d0e0b157fec99ff6c41074023401d0e066bbffff66430f94c332c3d0e0bbbfdd791f4b0f9ac332c3d0e066bf67626681c75cd70f92c332c3d0e0badb2036c4420f94c332c3"</span><span class="p">,</span>
<span class="s2">"32c0bffebb799e81effa67247f0f9ac332c3d0e066ba5782664a0f9ac332c3d0e0b63980eeaf9ff6c41074023401d0e066bbf0a26681ebc0dc9ff6c41074023401d0e0b580fecd0f98c332c3d0e0b9ffffff7f410f98c332c3d0e0b301fecb0f94c332c3d0e0ba2042c27b81ead42d50730f9ac332c3"</span><span class="p">]</span>
<span class="n">ADDRESS</span> <span class="o">=</span> <span class="mh">0x1000000</span>
<span class="k">for</span> <span class="n">ftring_insc</span> <span class="ow">in</span> <span class="n">X86_CODE32_ARR</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">ftring_insc_dec</span> <span class="o">=</span> <span class="nb">bytes</span><span class="o">.</span><span class="n">fromhex</span><span class="p">(</span><span class="n">ftring_insc</span><span class="p">)</span>
<span class="c1"># Initialize emulator in X86-32bit mode</span>
<span class="n">mu</span> <span class="o">=</span> <span class="n">Uc</span><span class="p">(</span><span class="n">UC_ARCH_X86</span><span class="p">,</span> <span class="n">UC_MODE_32</span><span class="p">)</span>
<span class="c1"># map 2MB memory for this emulation</span>
<span class="n">mu</span><span class="o">.</span><span class="n">mem_map</span><span class="p">(</span><span class="n">ADDRESS</span><span class="p">,</span> <span class="mi">2</span> <span class="o">*</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span><span class="p">)</span>
<span class="c1"># write machine code to be emulated to memory</span>
<span class="n">mu</span><span class="o">.</span><span class="n">mem_write</span><span class="p">(</span><span class="n">ADDRESS</span><span class="p">,</span> <span class="n">ftring_insc_dec</span><span class="p">)</span>
<span class="c1"># emulate machine code in infinite time</span>
<span class="n">mu</span><span class="o">.</span><span class="n">emu_start</span><span class="p">(</span><span class="n">ADDRESS</span><span class="p">,</span> <span class="n">ADDRESS</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">ftring_insc_dec</span><span class="p">))</span>
<span class="n">r_al</span> <span class="o">=</span> <span class="n">mu</span><span class="o">.</span><span class="n">reg_read</span><span class="p">(</span><span class="n">UC_X86_REG_AL</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">'>>> AL = </span><span class="si">{</span><span class="nb">hex</span><span class="p">(</span><span class="n">r_al</span><span class="p">)</span><span class="si">}</span><span class="s1"> </span><span class="si">{</span><span class="nb">chr</span><span class="p">(</span><span class="n">r_al</span><span class="p">)</span><span class="si">}</span><span class="s1">'</span><span class="p">)</span>
<span class="k">except</span> <span class="n">UcError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"ERROR: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">e</span><span class="p">)</span>
</code></pre></div>
<p>I was kinda lazy and didn't finish it completely. To automate example more we could either map memory properly or implement a handler that will skip store/read instructions and just print values from <code>al</code> when they are called.</p>
</div>
<footer class="text-right">
<p>- F3real</p>
</footer>
<div id="show-comments" class="span7 text-center">
<a href="https://f3real.github.io/crackmes_one2.html#disqus_thread"
data-disqus-identifier="crackmes_one2"
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 = 'crackmes_one2';
var disqus_url = 'https://f3real.github.io/crackmes_one2.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>