Reversing : The Hacker's Guide to Reverse Engineering

(ff) #1
quick check shows that 70597243 is the hexadecimal value for the characters
CrYp, and 39586554 for the characters TeX9. Cryptex is simply verifying the
header and printing an error message if there is a mismatch.
The following code sequence is the one you’re after (because it decides
whether the function returns 1 or prints out the bad password message). This
sequence compares two 16-byte sequences in memory and prints the error
message if there is a mismatch. The first sequence starts at 00405038 and is
another global variable whose contents are unknown at this point. The second
data sequence starts at 00406070 , which is a part of the header global variable
you looked at before, that starts at 00406058. This is apparent because earlier
ReadFile was reading 0x28bytes into this address— 00406070 is only
0x18bytes past the beginning, so there are still 0x10(or 16 in decimal) bytes
left in this buffer.
The actual comparison is performed using the REPE CMPSinstruction,
which repeatedly compares a pair of DWORDs, one pointed at by EDIand the
other by ESI, and increments both index registers after each iteration. The
number of iterations depends on the value of ECX, and in this case is set to 4,
which means that the instruction will compare four DWORDs (16 bytes) and
will jump to 00401234 if the buffers are identical. If the buffers are not iden-
tical execution will flow into 0040121E, which is where we wound up.
The obvious question at this point is what are those buffers that Cryptex is
comparing? Is it the actual passwords? A quick look in OllyDbg reveals the
contents of both buffers. The following is the contents of the global variable at
00405038 with whom we are comparing the archive’s header buffer:

00405038 1F 79 A0 18 0B 91 0D AC A2 0B 09 7B 8D B4 CF 0E

The buffer that originated in the archive’s header contains the following:

00406070 5F 60 43 BC 26 F0 F7 CA 68 16 0D 2B 99 E7 FA 61

The two are obviously different, and are also clearly not the plaintext pass-
words. It looks like Cryptex is storing some kind of altered version of the pass-
word inside the file and is comparing that with what must be an altered
version of the currently typed password (which must have been altered with
the exact same algorithm in order for this to work). The interesting questions
are how are passwords transformed, and is that transformation secure—would
it be somehow possible to reconstruct the password using only that altered
version? If so, you could extract the password from the archive header.

The Password Transformation Algorithm


The easiest way to locate the algorithm that transforms the plaintext password
into this 16-byte sequence is to place a memory breakpoint on the global variable

210 Chapter 6

Free download pdf