【文章标题】: [破]CrackMe.bLaCk-eye.VC6.4
【文章作者】: HappyTown
【作者邮箱】: [email]wxr277@163.com[/email]
【作者主页】: www.pediy.com
【软件名称】: AiNAMOR
【下载地址】: 附件内
【加壳方式】: FSG 2.0
【保护方式】: RSA-512
【编写语言】: VC6
【使用工具】: OD,IDA
【作者声明】: 只是感兴趣,没有其他目的。失误之处敬请诸位大侠赐教!
--------------------------------------------------------------------------------
【详细过程】
题记:程序作者给出的难度是2-3/10,我个人感觉其应在1.5~1.8之间。
1. bLaCk-eye是www.crackmes.de 的moderator。他的这个CrackMe与其说是考察RSA-512,倒不如说是考察数论的基本知识,因为没有用到大数分解,只是用到了大数的相关计算。
2. 由于是512位,所以计算过程中用到的大数我会尽量简写,比如:
7C1634005E8AD772D8CA1A64A8BE87F14A0ACE88FAE2839D2609AF4A16A76699
将写成:
7C 16 34 00...16 A7 66 99
3. 该程序在编译时估计使用了wrapped方式(是这样叫吗?)的miracl库函数,但wrapped过的函数还是比较容易识别出来的,因为我们有IDA。你如果对这种方式不熟悉,不要紧,你可以跟着本分析实践一下,当然,前提是你必须熟悉miracl库。
4. OK,输入
User Name:happy
Registration:7654321
004015D6 .>push 100 ; /Count = 100 (256.)
004015DB .>push ecx ; |Buffer
004015DC .>push 3EC ; |ControlID = 3EC (1004.)
004015E1 .>push esi ; |hWnd
004015E2 .>call edi ; \GetDlgItemTextA
004015E4 .>lea edx, [esp+C]
004015E8 .>push 100 ; /Count = 100 (256.)
004015ED .>push edx ; |Buffer
004015EE .>push 3ED ; |ControlID = 3ED (1005.)
004015F3 .>push esi ; |hWnd
004015F4 .>call edi ; \GetDlgItemTextA
004015F6 .>lea eax, [esp+C]
004015FA .>lea ecx, [esp+10C]
00401601 .>push eax ; sn
00401602 .>push ecx ; name
00401603 .>call 004010B0 ======>核心代码
00401608 .>add esp, 8
0040160B .>test eax, eax
0040160D .>jnz short 00401616
0040160F .>push <aSendBlack@rete> ; ASCII "Send [email]bLaCk@reteam.org[/email] your solution!"
00401614 .>jmp short 0040161B
00401616 >>push <String>
0040161B >>push 3EE ; |ControlID = 3EE (1006.)
00401620 .>push esi ; |hWnd
00401621 .>call [<&USER32.SetDlgItemTextA>] ; \SetDlgItemTextA
=====>核心代码:
.......
0040113F |.>push ecx ; sn
00401140 |.>mov dword ptr [eax+220], 3C ; 60进制
0040114A |.>mov edx, [esp+50]
0040114E |.>push edx
0040114F |.>mov [esp+1E4], bl
00401156 |.>call <_cinstr> ; sn = 4D 24 67 F6 A9
0040115B |.>mov eax, [esp+50]
0040115F |.>push <aD1wjgnkjifajre> ; ASCII
"d1WJGnkJiFAJReBRRmEBlNYJs6AK5p82TZFbUX8lnL1IbLoHpfWx9G0jetjscI3tGQ5Bf3PwI6x6HJcTi4sGVu"
00401164 |.>push eax ; a
00401165 |.>call <_cinstr> ; 0A 5A 81 1C E6... 3E 71 86 FC
0040116A |.>mov esi, [esp+1F4]
00401171 |.>or ecx, FFFFFFFF
00401174 |.>mov edi, esi ; name
00401176 |.>xor eax, eax
00401178 |.>repne scas byte ptr es:[edi]
0040117A |.>not ecx
0040117C |.>dec ecx
0040117D |.>push ecx ; nameLen
0040117E |.>push esi ; name
0040117F |.>push -1
00401181 |.>call 00401050 ; c:06890230=FHash(name)(IDA rips it.)
00401186 |.>mov ecx, [esp+48]
0040118A |.>push <a8xl1bra4boktp7> ; ASCII
"8xl1BRa4boktp7B5v3mw7xXQpITKXDnfUng7KqY3nUHGgAQCOVqLNj4b0IulVfaRadA0iQgalrLsXJa6orf8flb"
0040118F |.>push ecx ; b
00401190 |.>mov edi, eax
00401192 |.>call <_cinstr> ; 8F 34 7B 62 D5...
00401197 |.>mov edx, [esp+5C]
0040119B |.>add esp, 44
0040119E |.>push edx
0040119F |.>push edi ; 06890230
004011A0 |.>call <_convert> ; c
004011A5 |.>lea eax, [esp+64]
004011A9 |.>push eax
004011AA |.>call <MD5_Init>
004011AF |.>mov edi, esi
004011B1 |.>or ecx, FFFFFFFF
004011B4 |.>xor eax, eax
004011B6 |.>repne scas byte ptr es:[edi]
004011B8 |.>not ecx
004011BA |.>dec ecx
004011BB |.>push ecx ; nameLen
004011BC |.>push esi ; name
004011BD |.>lea ecx, [esp+70]
004011C1 |.>push ecx
004011C2 |.>call <MD5_Update>
004011C7 |.>lea edx, [esp+64]
004011CB |.>lea eax, [esp+74]
004011CF |.>push edx
004011D0 |.>push eax
004011D1 |.>call <MD5_Final> ; MD5(name) = 56 AB 24 C1 5B 72 A4 57 06 9C 5E A4 2F CF 40
004011D6 |.>lea ecx, [esp+6C]
004011DA |.>lea edx, [esp+34]
004011DE |.>push ecx ; MD5(name)
004011DF |.>push 10 ; 16d
004011E1 |.>push edx
004011E2 |.>call <bytes_to_big> ; j = MD5(name)
004011E7 |.>mov ecx, [esp+48]
004011EB |.>mov edx, [eax]
004011ED |.>push ecx ; h
004011EE |.>push edx ; j
004011EF |.>call <_copy> ; h = j
004011F4 |.>mov eax, [esp+48]
004011F8 |.>push eax
004011F9 |.>call <_mirkill>
004011FE |.>lea ecx, [esp+54]
00401202 |.>push 3 ; 3
00401204 |.>lea edx, [esp+4C]
00401208 |.>push ecx ; h
00401209 |.>push edx ; k= h^3
0040120A |.>call <power> ; k = h^3 = 09EEFCF117....A8 24 00 00
0040120F |.>add esp, 44
00401212 |.>mov esi, eax
00401214 |.>lea eax, [esp+18]
00401218 |.>push 3 ; 3
0040121A |.>lea ecx, [esp+24]
0040121E |.>push eax ; c
0040121F |.>push ecx ; L
00401220 |.>mov byte ptr [esp+1C8], 8
00401228 |.>call <power> ; L = c^3 =00 01 17 1C 06 9F 41...BD 77 B0 00
0040122D |.>push eax ; L
0040122E |.>lea edx, [esp+34]
00401232 |.>push 2
00401234 |.>push edx ; m = L*2 = 00 02 2E 38 0D...7A EF 60 00
00401235 |.>mov byte ptr [esp+1D4], 9
0040123D |.>call <premult>
00401242 |.>lea ecx, [esp+40]
00401246 |.>lea edx, [esp+58]
0040124A |.>push ecx ; a
0040124B |.>push eax ; m
0040124C |.>push edx
0040124D |.>mov byte ptr [esp+1E0], 0A
00401255 |.>call <multiply> ; n = a*m = 00 00 16 93 89 C2...AF E2 80 00
0040125A |.>push eax ; n
0040125B |.>lea eax, [esp+54]
0040125F |.>lea ecx, [esp+6C]
00401263 |.>push eax ; sn:00 4D 24 67 F6 A9
00401264 |.>push ecx ; p
00401265 |.>mov byte ptr [esp+1EC], 0B
0040126D |.>call <add> ; p=sn + n=16 93 89 C2...D4 4A 76 A9
00401272 |.>push esi ; k
00401273 |.>lea edx, [esp+6C]
00401277 |.>push eax ; p
00401278 |.>push edx ; q
00401279 |.>mov byte ptr [esp+1F8], 0C
00401281 |.>call <subtract> ; q=p - k=16 93 89 C2...2C 26 76 A9
00401286 |.>push eax ; q
00401287 |.>lea eax, [esp+5C]
0040128B |.>lea ecx, [esp+70]
0040128F |.>push eax ; h
00401290 |.>push ecx ; r
00401291 |.>mov byte ptr [esp+204], 0D
00401299 |.>call <multiply> ; r=h * q=07 A4 A8 12...C3 0B 60 40
0040129E |.>add esp, 48
004012A1 |.>lea edx, [esp+C]
004012A5 |.>mov byte ptr [esp+1BC], 0E
004012AD |.>push edx ; b
004012AE |.>push eax ; r
004012AF |.>lea eax, [esp+1C]
004012B3 |.>push eax ; s
004012B4 |.>call <divide> ; s=r mod b=78 4F A8 00 3B...EA D6 34 01
004012B9 |.>mov ecx, [esp+48]
004012BD |.>mov edx, [eax]
004012BF |.>push ecx
004012C0 |.>push edx
004012C1 |.>call <_copy> ; s
到这里小总一下,看看上面的代码是什么意思:
h = MD5(name)
k = h^3
L = c^3
m = L*2
n = a*m
p = sn + n
q = p - k
r = h*q
s = r (mod b)
进一步递推化简,可得:s = h*[sn + a*(c^3)*2 - (h^3)] (mod b),OK,记住这一结果。
.....
00401317 |.>push ecx
00401318 |.>call <_mirkill>
0040131D |.>lea edx, [esp+50]
00401321 |.>push 3 ; 3
00401323 |.>lea eax, [esp+4C]
00401327 |.>push edx ; h
00401328 |.>push eax ; t
00401329 |.>call <power> ; t=h^3=9EEFCF117C8B2A...A8240000
0040132E |.>add esp, 40
00401331 |.>push eax ; t
00401332 |.>lea ecx, [esp+34]
00401336 |.>push 2
00401338 |.>push ecx ; u
00401339 |.>mov byte ptr [esp+1C8], 0F
00401341 |.>call <premult> ; u =t*2=13DDF9E22F916...50480000
00401346 |.>mov esi, eax
00401348 |.>lea edx, [esp+24]
0040134C |.>push 3 ; 3
0040134E |.>lea eax, [esp+48]
00401352 |.>push edx ; c
00401353 |.>push eax ; v
00401354 |.>mov byte ptr [esp+1D4], 10
0040135C |.>call <power> ; v=c^3=01 17 1C 06...BD 77 B0 00
00401361 |.>lea ecx, [esp+40]
00401365 |.>lea edx, [esp+5C]
00401369 |.>push ecx ; a
0040136A |.>push eax ; v
0040136B |.>push edx ; w
0040136C |.>mov byte ptr [esp+1E0], 11
00401374 |.>call <multiply> ; w=v*a=0B 49 C4 E1...D7 F1 40 00
00401379 |.>push eax ; w
0040137A |.>lea eax, [esp+54]
0040137E |.>lea ecx, [esp+68]
00401382 |.>push eax ; sn
00401383 |.>push ecx ; y
00401384 |.>mov byte ptr [esp+1EC], 12
0040138C |.>call <subtract> ; y=sn - w= -0B 49 C4 E1 2E...B3 89 49 57
00401391 |.>push esi ; u
00401392 |.>lea edx, [esp+58]
00401396 |.>push eax ; y
00401397 |.>push edx ; z
00401398 |.>mov byte ptr [esp+1F8], 13
004013A0 |.>call <add> ; z=y + u=- 0B 49 C4 E1...63 41 49 57
004013A5 |.>push eax ; z
004013A6 |.>lea eax, [esp+58]
004013AA |.>lea ecx, [esp+60]
004013AE |.>push eax ; c
004013AF |.>push ecx ; aa
004013B0 |.>mov byte ptr [esp+204], 14
004013B8 |.>call <multiply> ; aa=c * z=-49 C5 30 54 F8...68 5F 6E 50
004013BD |.>add esp, 48
004013C0 |.>lea edx, [esp+C]
004013C4 |.>mov byte ptr [esp+1BC], 15
004013CC |.>push edx ; b
004013CD |.>push eax ; aa
004013CE |.>lea eax, [esp+18]
004013D2 |.>push eax ; bb
004013D3 |.>call <divide> ; bb=aa mod b=-69 3E 35 18...34 AA 74 DD
004013D8 |.>mov ecx, [esp+40]
004013DC |.>mov edx, [eax]
004013DE |.>push ecx
004013DF |.>push edx
004013E0 |.>call <_copy> ; bb
再总结一下上面一小段:
t = h^3
u = t*2
v = c^3
w = v*a
y = sn - w
z = y + u
aa = c*z
bb = aa (mod b)
进一步递推化简,可得:bb = c*[sn - a*(c^3) + 2*(h^3)] (mod b),OK,也记住这个结果。
.....
00401436 |.>push ecx
00401437 |.>call <_mirkill>
0040143C |.>lea edx, [esp+40]
00401440 |.>lea eax, [esp+68]
00401444 |.>push edx ; b
00401445 |.>lea ecx, [esp+5C]
00401449 |.>push eax ; bb
0040144A |.>push ecx ; cc
0040144B |.>call <xgcd> ; cc=bb^-1 (mod b)=06 AA FE 28 52...FB 97 FD 86
00401450 |.>add esp, 40
00401453 |.>lea edx, [esp+3C]
00401457 |.>mov byte ptr [esp+1BC], 16
0040145F |.>push edx ; s
00401460 |.>push eax ; cc
00401461 |.>lea eax, [esp+28]
00401465 |.>push eax ; dd
00401466 |.>call <multiply> ; dd=cc*s=03 22 3A 47 8D...45 1B 35 86
0040146B |.>lea ecx, [esp+18]
0040146F |.>lea edx, [esp+1C]
00401473 |.>push ecx ; b
00401474 |.>push eax ; dd
00401475 |.>push edx ; ee
00401476 |.>mov byte ptr [esp+1D4], 17
0040147E |.>call <divide> ; ee=dd (mod b)=06 FE A4 A9...4C C2 38 3D
00401483 |.>mov ecx, [esp+60]
00401487 |.>mov edx, [eax]
00401489 |.>push ecx
0040148A |.>push edx
0040148B |.>call <_copy> ; ee
00401490 |.>mov eax, [esp+30]
00401494 |.>push eax
00401495 |.>call <_mirkill>
0040149A |.>mov ecx, [esp+44]
0040149E |.>push ecx
0040149F |.>call <_mirkill>
004014A4 |.>mov edx, [esp+4C]
004014A8 |.>mov [esp+1E4], bl
004014AF |.>push edx
004014B0 |.>call <_mirkill>
004014B5 |.>mov eax, [40E600]
004014BA |.>lea ecx, [esp+74]
004014BE |.>lea edx, [esp+E0]
004014C5 |.>push ecx ; ee
004014C6 |.>push edx
004014C7 |.>mov dword ptr [eax+220], 100
004014D1 |.>call <cotstr>
004014D6 |.>add esp, 34
004014D9 |.>mov esi, <aRsaR_RivestA_S> ; ASCII "RSA = R. Rivest + A. Shamir + L. Adleman"
004014DE |.>lea eax, [esp+B4]
004014E5 |>>/mov dl, [eax] ; ee
004014E7 |.>|mov bl, [esi] ; "RSA = R. Rivest....
004014E9 |.>|mov cl, dl
004014EB |.>|cmp dl, bl
004014ED |.>|jnz short 0040150D
004014EF |.>|test cl, cl
004014F1 |.>|je short 00401509
004014F3 |.>|mov dl, [eax+1]
004014F6 |.>|mov bl, [esi+1]
004014F9 |.>|mov cl, dl
004014FB |.>|cmp dl, bl
004014FD |.>|jnz short 0040150D
004014FF |.>|add eax, 2
00401502 |.>|add esi, 2
00401505 |.>|test cl, cl
00401507 |.>\jnz short 004014E5
00401509 |>>xor esi, esi
0040150B |.>jmp short 00401512
让我们来看看最后的这段代码是什么意思:
cc = bb(^-1) (mod b) //也就是说cc是bb模b的乘法逆元
dd = cc*s
ee = dd (mod b)
最终注册成功与否的判断:
ee ?= RSAStr(即"RSA = R. Rivest + A. Shamir + L. Adleman")
让我们再把问题表述的更清楚一些:
RSAStr ?= ee = s*b^(-1)= h[sn + a*(c^3)*2 - (h^3)]*{[c*(sn - a*(c^3) + 2*(h^3)]^(-1)}
我们令RSAStr = ee,那么给ee = s*b^(-1)两边同时乘以b^(-1),可得,ee*b = s,即:
ee*[c*(sn - a*(c^3) +2*(h^3))] = h[sn + a*(c^3)*2 - (h^3)]
为了求出sn,通过移项,我们把sn的系数合并,可得:
(ee*c - h)*sn = h*[2*a*(c^3) - (h^3)] - ee*c*[2*(h^3) - a*(c^3)]
所以,
sn = [(ee*c - h)^(-1)]*{h*[2*a*(c^3) - (h^3)] - ee*c*[2*(h^3) - a*(c^3)]} (mod b)
这里,(ee*c - h)^(-1)意为 (ee*c - h)模b 的乘法逆元。
别忘了,sn最后须转换为60进制。
一组可用的注册码:
User Name:happytown
Registration:6CLhaMTExadnDghfWPWcCXodurcMQqr5AlBESqNU6eYbesbBTDjseOFx20mUUtK49nvCjobtPZgksCOCB5KQcsc
注册机详见附件。
--------------------------------------------------------------------------------
【经验总结】
真是考验耐性的一个CrackMe,不过总体上感觉还是不错的。感谢bLaCk-eye,感谢看到这里的你。
--------------------------------------------------------------------------------
【版权声明】: 本文原创于看雪技术论坛, 转载请注明作者并保持文章的完整, 谢谢!
2006年11月24日 17:32:25
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
上传的附件: