 ==================================================================================================
                                  Short description by Tymon//tkm!
 ==================================================================================================

 .: info :.

 what:          CrackMe #5 by ReWolf tHE Unofficial HTBTeam Trial Crackme
 tools:         softice, ida, lordpe
 protection:    MD5 (modified), MD4

 ==================================================================================================

 .: solution :.

 To solve the crackme you have to invert the modified md5 proc and solve the equation:

   / ace - bdf = ef(c-d)
   | hf - ge = c - d
   | gce - hdf = 0
   \ bf - ae = 0

 where:

 (i = pointer to suitable block of data)

 a = byte ptr NAME_HASH[0+i]
 b = byte ptr NAME_HASH[1+i]
 g = byte ptr NAME_HASH[2+i]
 h = byte ptr NAME_HASH[3+i]
 c = word ptr SN_HASH[0+i]
 d = word ptr SN_HASH[2+i]
 e = byte ptr SN_HASH[5+i]
 f = byte ptr SN_HASH[4+i]

 and abcdef must be an integer number
 and ef != 0 and c != d

 So, the solution is:

 e = b
 f = a
 d = gb
 c = ha

 the modified md5 procedure which ReWolf used in his crackme(*) you can see in md5_modified.inc
 file and the inverted proc you can see in md5_invert.inc file.

 There is possible to invert the modified md5 proc coz ReWolf used only H function in his
 implementation.

 In the modified md5 proc in crackme you can find a lot of garbage, which makes tracing more
 difficult. There are a lot of 'and', 'or' and 'not' operations. This is just a Boolean Algebra.
 Look:

 ~[(~a || b) && (~b || a)]  <==> a xor b
 ~[(~a && ~b)] || (a && b)] <==> a xor b

 So all this instructions makes as much as simple xor. Why I know that ? Here, you can just
 compare bits before and after computations and you will be know that it is only a simple xor
 but if you have more complicated operations or you want to optimize Boolean expressions then
 read more about Carnought's method, truth tables, etc. (more info: The Art Of Assembly
 Language: Chapter Three, p. 219).

 * In the crackme ReWolf always hashes the fake cast-128 sbox (2*37h bytes) and he fills up the
 initial values of md5 [MD5_CTX] with sn. In md5_modified.inc file there is always true md5_ctx.
 So if you want to hash data like in the crackme you have to delete lines 97-100, fill up the
 _data buffer with suitable part of cast-128 sbox and fill up the _buffer buffer with suitable
 part of sn (16 bytes). The cast-128 sbox you can find in keymaker.asm file.

 forgive my poor english

 ==================================================================================================
 tymon_crk@wp.pl