HappyTowns 34th CrackMe 算法分析及注册机 这个CrackMe放出来的时间也比较久了,好像没有人尝试过,我就一块把它也解决了吧。
用PEiD查壳,显示
Microsoft Visual C++ 6.0
经验证,确实没有加壳。
用PEiD的Krypto ANAlyzer插件检查,结果如下:
HAVAL (3 pass) :: 00002D9B :: 00402D9B
MD4 :: 00005CDA :: 00405CDA
MD5 :: 00001779 :: 00401779
RIPEMD-160 :: 00011090 :: 00411090
SHA1/RIPEMD-160 [Init] :: 00010114 :: 00410114
SHA-256 [mixing] :: 00006CBD :: 00406CBD
TIGER :: 000180F0 :: 004180F0
{Big number} :: 0001A160 :: 0041A160
用IDA载入,并加载常用的sig。找到注册验证的关键函数,初步分析的结果如下:
.text:004010A0 ; int __cdecl OnCheck(HWND hDlg)
.text:004010A0 OnCheck proc near ; CODE XREF: DialogFunc+34p
.text:004010A0
.text:004010A0 haval_ctx = dword ptr -0AE0h
.text:004010A0 szTmp7 = dword ptr -9B8h
.text:004010A0 szTmp3 = dword ptr -8F0h
.text:004010A0 szName = byte ptr -828h
.text:004010A0 szTmp6 = dword ptr -760h
.text:004010A0 var_759 = byte ptr -759h
.text:004010A0 szGroup = dword ptr -698h
.text:004010A0 szStr2 = dword ptr -5D0h
.text:004010A0 szTmp1 = dword ptr -5A4h
.text:004010A0 szTmp5 = dword ptr -4DCh
.text:004010A0 szTmp4 = dword ptr -414h
.text:004010A0 szSerial = dword ptr -34Ch
.text:004010A0 szTmp2 = dword ptr -284h
.text:004010A0 var_275 = byte ptr -275h
.text:004010A0 sha256_ctx = dword ptr -1BCh
.text:004010A0 var_154 = dword ptr -154h
.text:004010A0 szStr1 = dword ptr -0F4h
.text:004010A0 md4_ctx = dword ptr -0C8h
.text:004010A0 md5_ctx = dword ptr -70h
.text:004010A0 var_18 = dword ptr -18h
.text:004010A0 var_14 = dword ptr -14h
.text:004010A0 rsa_n = dword ptr -10h
.text:004010A0 rsa_m = dword ptr -0Ch
.text:004010A0 rsa_c = dword ptr -8
.text:004010A0 rsa_e = dword ptr -4
.text:004010A0 hDlg = dword ptr 8
.text:004010A0
.text:004010A0 push ebp
.text:004010A1 mov ebp, esp
.text:004010A3 sub esp, 0AE0h
.text:004010A9 push ebx
.text:004010AA push esi
.text:004010AB push edi
.text:004010AC xor ebx, ebx
.text:004010AE mov ecx, 49
.text:004010B3 xor eax, eax
.text:004010B5 lea edi, [ebp-827h] ;初始化字符数组变量
.text:004010BB mov [ebp+szName], bl
.text:004010C1 rep stosd
.text:004010C3 stosw
.text:004010C5 stosb
.text:004010C6 mov ecx, 49
.text:004010CB xor eax, eax
.text:004010CD lea edi, [ebp+szGroup+1] ;初始化字符数组变量
.text:004010D3 mov byte ptr [ebp+szGroup], bl
.text:004010D9 rep stosd
.text:004010DB stosw
.text:004010DD stosb
.text:004010DE mov ecx, 49
.text:004010E3 xor eax, eax
.text:004010E5 lea edi, [ebp+szSerial+1] ;初始化字符数组变量
.text:004010EB mov byte ptr [ebp+szSerial], bl
.text:004010F1 rep stosd
.text:004010F3 stosw
.text:004010F5 stosb
.text:004010F6 mov ecx, 49
.text:004010FB xor eax, eax
.text:004010FD lea edi, [ebp+szTmp1+1] ;初始化字符数组变量
.text:00401103 mov byte ptr [ebp+szTmp1], bl
.text:00401109 rep stosd
.text:0040110B stosw
.text:0040110D stosb
.text:0040110E mov ecx, 49
.text:00401113 xor eax, eax
.text:00401115 lea edi, [ebp+szTmp2+1] ;初始化字符数组变量
.text:0040111B mov byte ptr [ebp+szTmp2], bl
.text:00401121 rep stosd
.text:00401123 stosw
.text:00401125 stosb
.text:00401126 mov ecx, 49
.text:0040112B xor eax, eax
.text:0040112D lea edi, [ebp+szTmp3+1] ;初始化字符数组变量
.text:00401133 mov byte ptr [ebp+szTmp3], bl
.text:00401139 rep stosd
.text:0040113B stosw
.text:0040113D stosb
.text:0040113E mov ecx, 49
.text:00401143 xor eax, eax
.text:00401145 lea edi, [ebp+szTmp4+1] ;初始化字符数组变量
.text:0040114B mov byte ptr [ebp+szTmp4], bl
.text:00401151 rep stosd
.text:00401153 stosw
.text:00401155 stosb
.text:00401156 mov ecx, 49
.text:0040115B xor eax, eax
.text:0040115D lea edi, [ebp+szTmp5+1] ;初始化字符数组变量
.text:00401163 mov byte ptr [ebp+szTmp5], bl
.text:00401169 rep stosd
.text:0040116B stosw
.text:0040116D stosb
.text:0040116E mov ecx, 49
.text:00401173 xor eax, eax
.text:00401175 lea edi, [ebp+szTmp6+1] ;初始化字符数组变量
.text:0040117B mov byte ptr [ebp+szTmp6], bl
.text:00401181 rep stosd
.text:00401183 stosw
.text:00401185 stosb
.text:00401186 mov ecx, 49
.text:0040118B xor eax, eax
.text:0040118D lea edi, [ebp+szTmp7+1] ;初始化字符数组变量
.text:00401193 mov byte ptr [ebp+szTmp7], bl
.text:00401199 rep stosd
.text:0040119B stosw
.text:0040119D stosb
.text:0040119E mov ecx, 10
.text:004011A3 mov esi, offset aC2rmcxdlcjqxnt ; "c2RmcXdlcjQxNTE1MTUxamwzMjE1QCQhMzQyZmE"...
.text:004011A8 lea edi, [ebp+szStr1] ;初始化字符串常量
.text:004011AE rep movsd
.text:004011B0 movsb
.text:004011B1 mov ecx, 10
.text:004011B6 mov esi, offset aMzq1mzq1mjm0jk ; "MzQ1MzQ1MjM0JkBTREFGYXNkZjIzMTMyMTMX124"...
.text:004011BB lea edi, [ebp+szStr2] ;初始化字符串常量
.text:004011C1 push 10h
.text:004011C3 rep movsd
.text:004011C5 push 500h
.text:004011CA movsb
.text:004011CB call _mirsys ;mirsys( 0x500, 0x10 )
.text:004011D0 push ebx
.text:004011D1 mov dword ptr [eax+234h], 16 ;mip->IOBASE = 0x10
.text:004011DB call _mirvar
.text:004011E0 push ebx
.text:004011E1 mov [ebp+rsa_m], eax
.text:004011E4 call _mirvar
.text:004011E9 push ebx
.text:004011EA mov [ebp+rsa_n], eax
.text:004011ED call _mirvar
.text:004011F2 push ebx
.text:004011F3 mov [ebp+rsa_e], eax
.text:004011F6 call _mirvar
.text:004011FB mov edi, [ebp+hDlg]
.text:004011FE mov esi, ds:GetDlgItemTextA
.text:00401204 add esp, 18h
.text:00401207 mov [ebp+rsa_c], eax
.text:0040120A lea eax, [ebp+szName]
.text:00401210 push 201 ; nMaxCount
.text:00401215 push eax ; lpString
.text:00401216 push 3E9h ; nIDDlgItem
.text:0040121B push edi ; hDlg
.text:0040121C call esi ; GetDlgItemTextA
.text:0040121E cmp eax, 2
.text:00401221 jnb short loc_40122C
.text:00401223 xor eax, eax
.text:00401225 pop edi
.text:00401226 pop esi
.text:00401227 pop ebx
.text:00401228 mov esp, ebp
.text:0040122A pop ebp
.text:0040122B retn
.text:0040122C ; ---------------------------------------------------------------------------
.text:0040122C
.text:0040122C loc_40122C: ; CODE XREF: OnCheck+181j
.text:0040122C lea ecx, [ebp+szGroup]
.text:00401232 push 201 ; nMaxCount
.text:00401237 push ecx ; lpString
.text:00401238 push 3EBh ; nIDDlgItem
.text:0040123D push edi ; hDlg
.text:0040123E call esi ; GetDlgItemTextA
.text:00401240 cmp eax, 2
.text:00401243 mov [ebp+hDlg], eax
.text:00401246 jge short loc_401251
.text:00401248 xor eax, eax
.text:0040124A pop edi
.text:0040124B pop esi
.text:0040124C pop ebx
.text:0040124D mov esp, ebp
.text:0040124F pop ebp
.text:00401250 retn
.text:00401251 ; ---------------------------------------------------------------------------
.text:00401251
.text:00401251 loc_401251: ; CODE XREF: OnCheck+1A6j
.text:00401251 lea edx, [ebp+szSerial]
.text:00401257 push 201 ; nMaxCount
.text:0040125C push edx ; lpString
.text:0040125D push 3EAh ; nIDDlgItem
.text:00401262 push edi ; hDlg
.text:00401263 call esi ; GetDlgItemTextA
.text:00401265 cmp eax, 3
.text:00401268 jge short loc_401273
.text:0040126A xor eax, eax
.text:0040126C pop edi
.text:0040126D pop esi
.text:0040126E pop ebx
.text:0040126F mov esp, ebp
.text:00401271 pop ebp
.text:00401272 retn
.text:00401273 ; ---------------------------------------------------------------------------
.text:00401273
.text:00401273 loc_401273: ; CODE XREF: OnCheck+1C8j
.text:00401273 lea eax, [ebp+szSerial]
.text:00401279 lea ecx, [ebp+szTmp1]
.text:0040127F mov [ebp+var_18], eax
.text:00401282 mov [ebp+var_14], ecx
.text:00401285 push [ebp+var_14]
.text:00401288 push [ebp+var_18]
.text:0040128B call Base64Decode ; Base64解码
.text:00401290 add esp, 8
.text:00401293 lea edi, [ebp+szTmp1]
.text:00401299 or ecx, 0FFFFFFFFh
.text:0040129C xor eax, eax
.text:0040129E repne scasb
.text:004012A0 not ecx
.text:004012A2 dec ecx
.text:004012A3 mov edx, ecx
.text:004012A5 mov ecx, [ebp+hDlg]
.text:004012A8 cmp edx, ecx
.text:004012AA jg short loc_4012B3
.text:004012AC pop edi
.text:004012AD pop esi
.text:004012AE pop ebx
.text:004012AF mov esp, ebp
.text:004012B1 pop ebp
.text:004012B2 retn
.text:004012B3 ; ---------------------------------------------------------------------------
.text:004012B3
.text:004012B3 loc_4012B3: ; CODE XREF: OnCheck+20Aj
.text:004012B3 lea edi, [ebp+szTmp1]
.text:004012B9 lea esi, [ebp+szGroup]
.text:004012BF xor eax, eax
.text:004012C1 repe cmpsb
.text:004012C3 jz short loc_4012CC
.text:004012C5 pop edi
.text:004012C6 pop esi
.text:004012C7 pop ebx
.text:004012C8 mov esp, ebp
.text:004012CA pop ebp
.text:004012CB retn
.text:004012CC ; ---------------------------------------------------------------------------
.text:004012CC
.text:004012CC loc_4012CC: ; CODE XREF: OnCheck+223j
.text:004012CC mov ecx, 50
.text:004012D1 xor eax, eax
.text:004012D3 lea edi, [ebp+szSerial]
.text:004012D9 rep stosd
.text:004012DB mov eax, [ebp+hDlg]
.text:004012DE mov ecx, edx
.text:004012E0 sub ecx, eax
.text:004012E2 lea edi, [ebp+szSerial]
.text:004012E8 mov edx, ecx
.text:004012EA lea esi, [ebp+eax+szTmp1]
.text:004012F1 shr ecx, 2
.text:004012F4 rep movsd
.text:004012F6 mov ecx, edx
.text:004012F8 lea eax, [ebp+md4_ctx]
.text:004012FE and ecx, 3
.text:00401301 push eax
.text:00401302 rep movsb
.text:00401304 call md5_init
.text:00401309 lea edi, [ebp+szName]
.text:0040130F or ecx, 0FFFFFFFFh
.text:00401312 xor eax, eax
.text:00401314 lea edx, [ebp+md4_ctx]
.text:0040131A repne scasb
.text:0040131C not ecx
.text:0040131E dec ecx
.text:0040131F push ecx
.text:00401320 lea ecx, [ebp+szName]
.text:00401326 push ecx
.text:00401327 push edx
.text:00401328 call md4_update ;md4
.text:0040132D lea eax, [ebp+md4_ctx]
.text:00401333 lea ecx, [ebp+szTmp2]
.text:00401339 push eax
.text:0040133A push ecx
.text:0040133B call md4_final
.text:00401340 mov al, [ebp+var_275]
.text:00401346 add esp, 18h
.text:00401349 cmp al, bl
.text:0040134B lea edi, [ebp+szStr1]
.text:00401351 jz short loc_401359
.text:00401353 lea edi, [ebp+szStr2]
.text:00401359
.text:00401359 loc_401359: ; CODE XREF: OnCheck+2B1j
.text:00401359 or ecx, 0FFFFFFFFh
.text:0040135C xor eax, eax
.text:0040135E repne scasb
.text:00401360 not ecx
.text:00401362 sub edi, ecx
.text:00401364 lea edx, [ebp+szTmp2]
.text:0040136A mov esi, edi
.text:0040136C mov edi, edx
.text:0040136E mov edx, ecx
.text:00401370 or ecx, 0FFFFFFFFh
.text:00401373 repne scasb
.text:00401375 mov ecx, edx
.text:00401377 dec edi
.text:00401378 shr ecx, 2
.text:0040137B rep movsd
.text:0040137D mov ecx, edx
.text:0040137F lea eax, [ebp+sha256_ctx]
.text:00401385 and ecx, 3
.text:00401388 push eax
.text:00401389 rep movsb
.text:0040138B call sha256_init
.text:00401390 lea edi, [ebp+szTmp2]
.text:00401396 or ecx, 0FFFFFFFFh
.text:00401399 xor eax, eax
.text:0040139B lea edx, [ebp+sha256_ctx]
.text:004013A1 repne scasb
.text:004013A3 not ecx
.text:004013A5 dec ecx
.text:004013A6 push ecx
.text:004013A7 lea ecx, [ebp+szTmp2]
.text:004013AD push ecx
.text:004013AE push edx
.text:004013AF call sha256_update ;sha256
.text:004013B4 lea eax, [ebp+szTmp4]
.text:004013BA lea ecx, [ebp+sha256_ctx]
.text:004013C0 push eax
.text:004013C1 push ecx
.text:004013C2 call sha256_final
.text:004013C7 lea edi, [ebp+szGroup]
.text:004013CD or ecx, 0FFFFFFFFh
.text:004013D0 xor eax, eax
.text:004013D2 lea edx, [ebp+szTmp4]
.text:004013D8 repne scasb
.text:004013DA not ecx
.text:004013DC sub edi, ecx
.text:004013DE mov esi, edi
.text:004013E0 mov edi, edx
.text:004013E2 mov edx, ecx
.text:004013E4 or ecx, 0FFFFFFFFh
.text:004013E7 repne scasb
.text:004013E9 mov ecx, edx
.text:004013EB dec edi
.text:004013EC shr ecx, 2
.text:004013EF rep movsd
.text:004013F1 mov ecx, edx
.text:004013F3 lea edx, [ebp+szTmp4]
.text:004013F9 and ecx, 3
.text:004013FC rep movsb
.text:004013FE lea edi, [ebp+szStr1]
.text:00401404 or ecx, 0FFFFFFFFh
.text:00401407 repne scasb
.text:00401409 not ecx
.text:0040140B sub edi, ecx
.text:0040140D mov esi, edi
.text:0040140F mov edi, edx
.text:00401411 mov edx, ecx
.text:00401413 or ecx, 0FFFFFFFFh
.text:00401416 repne scasb
.text:00401418 mov ecx, edx
.text:0040141A dec edi
.text:0040141B shr ecx, 2
.text:0040141E rep movsd
.text:00401420 mov ecx, edx
.text:00401422 lea eax, [ebp+haval_ctx]
.text:00401428 and ecx, 3
.text:0040142B push eax
.text:0040142C rep movsb
.text:0040142E call haval_start
.text:00401433 or ecx, 0FFFFFFFFh
.text:00401436 lea edi, [ebp+szTmp4]
.text:0040143C xor eax, eax
.text:0040143E repne scasb
.text:00401440 not ecx
.text:00401442 dec ecx
.text:00401443 lea edx, [ebp+haval_ctx]
.text:00401449 push ecx
.text:0040144A lea ecx, [ebp+szTmp4]
.text:00401450 push ecx
.text:00401451 push edx
.text:00401452 call haval_hash ;haval
.text:00401457 lea eax, [ebp+szTmp5]
.text:0040145D lea ecx, [ebp+haval_ctx]
.text:00401463 push eax
.text:00401464 push ecx
.text:00401465 call haval_end
.text:0040146A mov eax, [ebp+szTmp5]
.text:00401470 add esp, 30h
.text:00401473 and eax, 0FFh
.text:00401478 or eax, 1
.text:0040147B jle short loc_4014B4
.text:0040147D mov [ebp+hDlg], eax
.text:00401480
.text:00401480 loc_401480: ; CODE XREF: OnCheck+412j
.text:00401480 lea edx, [ebp+szTmp3]
.text:00401486 lea eax, [ebp+szTmp5]
.text:0040148C push edx
.text:0040148D push 24
.text:0040148F push eax
.text:00401490 call tiger ;tiger
.text:00401495 mov eax, [ebp+hDlg]
.text:00401498 add esp, 0Ch
.text:0040149B mov ecx, 6
.text:004014A0 lea esi, [ebp+szTmp3]
.text:004014A6 lea edi, [ebp+szTmp5]
.text:004014AC dec eax
.text:004014AD rep movsd
.text:004014AF mov [ebp+hDlg], eax
.text:004014B2 jnz short loc_401480
.text:004014B4
.text:004014B4 loc_4014B4: ; CODE XREF: OnCheck+3DBj
.text:004014B4 lea ecx, [ebp+var_154]
.text:004014BA push ecx
.text:004014BB call _RIPEMD160_Init
.text:004014C0 lea edx, [ebp+szTmp3]
.text:004014C6 push 24
.text:004014C8 lea eax, [ebp+var_154]
.text:004014CE push edx
.text:004014CF push eax
.text:004014D0 call _RIPEMD160_Update ;ripemd160
.text:004014D5 lea ecx, [ebp+var_154]
.text:004014DB lea edx, [ebp+szTmp6]
.text:004014E1 push ecx
.text:004014E2 push edx
.text:004014E3 call _RIPEMD160_Final
.text:004014E8 lea eax, [ebp+md5_ctx]
.text:004014EB mov [ebp+var_759], 7Ah
.text:004014F2 push eax
.text:004014F3 call md5_init
.text:004014F8 lea ecx, [ebp+szTmp6]
.text:004014FE push 16
.text:00401500 lea edx, [ebp+md5_ctx]
.text:00401503 push ecx
.text:00401504 push edx
.text:00401505 call md5_update ;md5
.text:0040150A lea eax, [ebp+md5_ctx]
.text:0040150D lea ecx, [ebp+szTmp7]
.text:00401513 push eax
.text:00401514 push ecx
.text:00401515 call md5_final
.text:0040151A mov esi, [ebp+rsa_m]
.text:0040151D lea edx, [ebp+szSerial]
.text:00401523 push edx
.text:00401524 push esi
.text:00401525 call _cinstr
.text:0040152A mov edi, [ebp+rsa_n]
.text:0040152D push offset a886a71f603197c ; "886A71F603197C430E9C473BB6991BE95B45AB5"...
.text:00401532 push edi
.text:00401533 call _cinstr
.text:00401538 mov eax, [ebp+rsa_e]
.text:0040153B add esp, 40h
.text:0040153E push offset a10001 ; "10001"
.text:00401543 push eax
.text:00401544 call _cinstr
.text:00401549 mov ecx, [ebp+rsa_c]
.text:0040154C lea edx, [ebp+szTmp7]
.text:00401552 push ecx
.text:00401553 push edx
.text:00401554 push 16
.text:00401556 call _bytes_to_big
.text:0040155B push edi
.text:0040155C push esi
.text:0040155D call _compare
.text:00401562 add esp, 1Ch
.text:00401565 test eax, eax
.text:00401567 jl short loc_401572
.text:00401569 xor eax, eax
.text:0040156B pop edi
.text:0040156C pop esi
.text:0040156D pop ebx
.text:0040156E mov esp, ebp
.text:00401570 pop ebp
.text:00401571 retn
.text:00401572 ; ---------------------------------------------------------------------------
.text:00401572
.text:00401572 loc_401572: ; CODE XREF: OnCheck+4C7j
.text:00401572 mov eax, [ebp+rsa_e]
.text:00401575 push esi
.text:00401576 push edi
.text:00401577 push eax
.text:00401578 push esi
.text:00401579 call _powmod ;rsa
.text:0040157E mov ecx, [ebp+rsa_c]
.text:00401581 push ecx
.text:00401582 push esi
.text:00401583 call _compare
.text:00401588 add esp, 18h
.text:0040158B test eax, eax
.text:0040158D jnz short loc_40159D
.text:0040158F push 40h
.text:00401591 push offset aHappytownPrese ; "HappyTown presents"
.text:00401596 push offset aYourSerialNumb ; "Your serial number is valid!"
.text:0040159B jmp short loc_4015A9
.text:0040159D ; ---------------------------------------------------------------------------
.text:0040159D
.text:0040159D loc_40159D: ; CODE XREF: OnCheck+4EDj
.text:0040159D push 30h ; uType
.text:0040159F push offset Caption ; ".:BAD:."
.text:004015A4 push offset Text ; "The serial number you entered is invali"...
.text:004015A9
.text:004015A9 loc_4015A9: ; CODE XREF: OnCheck+4FBj
.text:004015A9 push ebx ; hWnd
.text:004015AA call ds:MessageBoxA
.text:004015B0 push esi
.text:004015B1 call _mirkill
.text:004015B6 push edi
.text:004015B7 call _mirkill
.text:004015BC mov edx, [ebp+rsa_e]
.text:004015BF push edx
.text:004015C0 call _mirkill
.text:004015C5 mov eax, [ebp+rsa_c]
.text:004015C8 push eax
.text:004015C9 call _mirkill
.text:004015CE add esp, 10h
.text:004015D1 call _mirexit
.text:004015D6 pop edi
.text:004015D7 pop esi
.text:004015D8 mov eax, 1
.text:004015DD pop ebx
.text:004015DE mov esp, ebp
.text:004015E0 pop ebp
.text:004015E1 retn
.text:004015E1 OnCheck endp
该CrackMe使用Miracl大数库进行RSA运算,除此之外还用了多种hash算法,以及base64解码。
注册验证关键函数逆向出来的代码如下:
void CCrackMeDlg::OnCheck()
{
char szName[200] = {0};
char szGroup[200] = {0};
char szSerial[200] = {0};
char szTmp1[200] = {0};
char szTmp2[200] = {0};
char szTmp3[200] = {0};
char szTmp4[200] = {0};
char szTmp5[200] = {0};
char szTmp6[200] = {0};
char szTmp7[200] = {0};
char str1[] = "c2RmcXdlcjQxNTE1MTUxamwzMjE1QCQhMzQyZmE=";
char str2[] = "MzQ1MzQ1MjM0JkBTREFGYXNkZjIzMTMyMTMX124=";
miracl *mip = mirsys( 0x500, 0x10 );
mip->IOBASE = 16;
big m = mirvar(0);
big c = mirvar(0);
big e = mirvar(0);
big n = mirvar(0);
unsigned int len;
unsigned char *p = NULL;
len = GetDlgItemText( IDC_NAME, szName, 201 );
if( len < 2 ) return;
len = GetDlgItemText( IDC_GROUP, szGroup, 201 );
if( len < 2 ) return;
len = GetDlgItemText( IDC_SERIAL, szSerial, 201 );
if( len < 3 ) return;
Base64Decode( (unsigned char *)szSerial, (unsigned char *)szTmp1 );
len = strlen(szGroup);
if( strlen(szTmp1) <= len ) return;
if( memcmp( szTmp1, szGroup, len ) != 0 ) return;
memset( szSerial, 0, 200 );
strcpy( szSerial, szTmp1+len );
MD4Init();
len = strlen( szName );
MD4Update( (unsigned char *)szName, len );
p = MD4Final();
len = strlen( (char *)p );
memcpy( szTmp2, p, 16 );
if( szTmp2[15] == 0 )
strcat( szTmp2, str1 );
else
strcat( szTmp2, str2 );
SHA256Init();
SHA256Update( (unsigned char *)szTmp2, strlen(szTmp2) );
p = SHA256Final();
memcpy( szTmp4, p, 32 );
strcat( szTmp4, szGroup );
strcat( szTmp4, str1 );
/* HavalInit( 256, 3 );
len = strlen(szTmp4);
HavalUpdate( (unsigned char *)szTmp4, len );
p = HavalFinal();
memcpy( szTmp5, p, 24 );
*/
haval_state haval_ctx;
haval_start( &haval_ctx );
haval_hash( &haval_ctx, (unsigned char *)szTmp4, strlen(szTmp4) );
haval_end( &haval_ctx, (unsigned char *)szTmp5 );
unsigned int count = szTmp5[0] & 0xFF | 1;
memcpy( szTmp3, szTmp5, 24 );
while( count>0 )
{
TigerInit();
TigerUpdate( (unsigned char *)szTmp3, 24 );
p = TigerFinal();
memcpy( szTmp3, p, 24 );
count--;
}
RMD160Init();
RMD160Update( (unsigned char *)szTmp3, 24 );
p = RMD160Final();
memcpy( szTmp6, p, 20 );
szTmp6[7] = 0x7A;
MD5Init();
MD5Update( (unsigned char *)szTmp6, 16 );
p = MD5Final();
memcpy( szTmp7, p, 16 );
bytes_to_big( 16, szTmp7, c );
cinstr( m, szSerial );
cinstr( e, "10001" );
cinstr( n, "886A71F603197C430E9C473BB6991BE95B45AB519F57ADB9" );
if( compare( m, n ) >= 0 ) return;
powmod( m, e, n, m );
if( compare( m, c ) == 0 )
MessageBox( "Your serial number is valid!", "HappyTown presents", MB_OK | MB_ICONINFORMATION );
else
MessageBox( "'The serial number you entered is invalid!", ".:BAD:.", MB_OK | MB_ICONERROR );
mirkill( m );
mirkill( c );
mirkill( e );
mirkill( n );
mirexit();
}
逆向时为了方便我用了miracl大数库和cryptohash库。
在调试的过程中发现cryptohash库中的haval函数的输出结果始终不对,而其它函数的输出都正常。
(参加上面代码中的注释部分。)
后来不得不换了一套haval代码实现,然后才调试通过。
我猜测cryptohash库中的haval函数可能有错,大家使用的时候要小心。
从以上分析可知注册验证过程如下:
1、用户名、组织名不能少于2各字符,注册码不能少于3个字符。
对注册码进行base64解码,得到的字符串前面一部分应该与组织名相同,后面的部分转化为大数s。
2、对用户名和组织名进行一系列的hash运算及其它操作,将最后得到的字符串的前16个字节转化为大数m。
3、对m进行RSA运算:m ^ e mod n = c。如果c与s相同则注册成功,否则失败。
那么生成注册码的过程:
1、用户名、组织名不能少于2个字符。
对用户名和组织名进行一系列的hash运算及其他操作,将最后得到的字符串的前16个字节转化为大数c。
2、对大数c进行RSA运算:c ^ d mod n = m。将大数m转化为其16进制字符串sn
3、将组织名和字符串sn连接起来,然后进行base64编码,得到的字符串即为注册码。
总结:这个CrackMe用到了base64、RSA、MD4、haval、tiger、MD5、sha256、ripeMD160算法,是一个名副其实的
算法大杂烩。其中hssh运算部分只要还原出来就可以了,无须逆向,所以其实比较简单。RSA部分其实也没什么难度。
倒是base64部分让我花了不少时间,因为这个算法没有被PEiD识别出来。我是过了好久才认出它是base64算法的。
keygen及所有源代码见附件。
just for fun!
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)
上传的附件: