【作者】ryOsUkE
转载请注明出处来自看雪论坛,以及本文的完整性,谢谢!
最近偷了点闲,再加上得到了一些很不错的Keygenme,想写一个加密算法的入门手记,以飨各位破解爱好者,便于学习交流。
闲话少说,先从RSA说起。
RSA公钥密码是1977年由Ron Rivest、Adi Shamirh和LenAdleman在MIT(美国麻省理工学院〉开发的,1978年首次公布[RIVE78]。它是目前最有影响的公钥加密算法,它能够抵抗到目前为止已知的所有密码攻击。目前它已被ISO推荐为公钥数据加密标准。RSA算法基于一个十分简单的数论事实:将两个大素数相乘十分容易,但是想分解它们的乘积却极端困难,因此可以将乘积公开作为加密密钥。
RSA的算法结构相当简单,整个算法可以描述如下:
(1)选取两个大素数p和q(保密);
(2)计算n=p*q(公开),r=(p-1〉(q-1)(保密);
(3)随机选取整数e(公开,加密密钥),使得gcd(e,r)=1;
(4)计算d(保密,私人密钥),使得ed≡1(mod r),即d=e^-1(mod r);
(5)加密:c=m^e mod n;
(6)解密:m=c^d mod n.
Keygenme见附件,采用了miracl库编程,图方便,自己手工定位找miracl函数了。
【分析】
根据信息来到
004010D6 > \8DBC24 800000>lea edi, [esp+80]
004010DD . 83C9 FF or ecx, FFFFFFFF
004010E0 . 33C0 xor eax, eax
004010E2 . 33D2 xor edx, edx
004010E4 . F2:AE repne scas byte ptr es:[edi]
004010E6 . F7D1 not ecx
004010E8 . 49 dec ecx ;计算name的长度
004010E9 . C74424 10 000>mov dword ptr [esp+10], 0
004010F1 . 85C9 test ecx, ecx
004010F3 . 7E 3D jle short 00401132 ;name长度大于0
004010F5 > 0FBE8C14 8000>movsx ecx, byte ptr [esp+edx+80]
004010FD . 8BC1 mov eax, ecx
004010FF . 8DBC24 800000>lea edi, [esp+80]
00401106 . C1E0 04 shl eax, 4
00401109 . 03C1 add eax, ecx
0040110B . C1E0 04 shl eax, 4
0040110E . 03C1 add eax, ecx
00401110 . C1E0 04 shl eax, 4
00401113 . 03C1 add eax, ecx
00401115 . 8B4C24 10 mov ecx, [esp+10]
00401119 . 42 inc edx
0040111A . 8D0480 lea eax, [eax+eax*4]
0040111D . 8D0441 lea eax, [ecx+eax*2]
00401120 . 83C9 FF or ecx, FFFFFFFF
00401123 . 894424 10 mov [esp+10], eax
00401127 . 33C0 xor eax, eax
00401129 . F2:AE repne scas byte ptr es:[edi]
0040112B . F7D1 not ecx
0040112D . 49 dec ecx
0040112E . 3BD1 cmp edx, ecx
00401130 .^ 7C C3 jl short 004010F5
//以上是变换name=>dwName
00401132 > 6A 00 push 0
00401134 . E8 77060000 call 004017B0 ;mirvar(0)
00401139 . 6A 00 push 0
0040113B . 8BF0 mov esi, eax
0040113D . E8 6E060000 call 004017B0 ;mirvar(0)
00401142 . 6A 00 push 0
00401144 . 8BD8 mov ebx, eax
00401146 . E8 65060000 call 004017B0 ;mirvar(0)
0040114B . 6A 00 push 0
0040114D . 8BE8 mov ebp, eax
0040114F . E8 5C060000 call 004017B0 ;mirvar(0)
00401154 . 894424 28 mov [esp+28], eax
00401158 . 8D7C24 2C lea edi, [esp+2C]
0040115C . 83C9 FF or ecx, FFFFFFFF
0040115F . 33C0 xor eax, eax
00401161 . 83C4 10 add esp, 10
00401164 . 33D2 xor edx, edx
00401166 . F2:AE repne scas byte ptr es:[edi]
00401168 . F7D1 not ecx
0040116A . 49 dec ecx
0040116B . 85C9 test ecx, ecx
0040116D . 7E 37 jle short 004011A6
0040116F > 8A4414 1C mov al, [esp+edx+1C]
00401173 . 3C 41 cmp al, 41
00401175 . 7C 04 jl short 0040117B
00401177 . 3C 5A cmp al, 5A
00401179 . 7E 18 jle short 00401193
0040117B > 3C 61 cmp al, 61
0040117D . 7C 04 jl short 00401183
0040117F . 3C 7A cmp al, 7A
00401181 . 7E 10 jle short 00401193
00401183 > 3C 30 cmp al, 30
00401185 . 0F8C D7000000 jl 00401262
0040118B . 3C 39 cmp al, 39
0040118D . 0F8F CF000000 jg 00401262
00401193 > 8D7C24 1C lea edi, [esp+1C]
00401197 . 83C9 FF or ecx, FFFFFFFF
0040119A . 33C0 xor eax, eax
0040119C . 42 inc edx
0040119D . F2:AE repne scas byte ptr es:[edi]
0040119F . F7D1 not ecx
004011A1 . 49 dec ecx
004011A2 . 3BD1 cmp edx, ecx
004011A4 .^ 7C C9 jl short 0040116F
//serial的格式认证
004011A6 > 8B5424 14 mov edx, [esp+14]
004011AA . 8B7C24 18 mov edi, [esp+18]
004011AE . 8D4424 1C lea eax, [esp+1C]
004011B2 . 50 push eax ;serial
004011B3 . 57 push edi ;big sn
004011B4 . C782 38020000>mov dword ptr [edx+238], 3C ;60进制
004011BE . E8 CD240000 call 00403690 ;cinstr
004011C3 . 8B4C24 1C mov ecx, [esp+1C]
004011C7 . 68 CCC04000 push 0040C0CC ;ASCII "7E2BDC8ED8856EE745A9D6F93E143B7ACE202999"
004011CC . 56 push esi ;RSA中的N
004011CD . C781 38020000>mov dword ptr [ecx+238], 10 ;16进制
004011D7 . E8 B4240000 call 00403690 ;cinstr
004011DC . 68 C4C04000 push 0040C0C4 ; ASCII "10001"
004011E1 . 53 push ebx ;RSA中的E
004011E2 . E8 A9240000 call 00403690 ;cinstr
//这里通过RSA2Tool计算,可以算出D=3FC69E031A914000E925FC61F2BF888F410EB07D
004011E7 . 55 push ebp ;c
004011E8 . 56 push esi ;n
004011E9 . 53 push ebx ;e
004011EA . 57 push edi ;sn
004011EB . E8 90220000 call 00403480 ;powmod 计算c=sn^e mod n
004011F0 . 8D5424 44 lea edx, [esp+44]
004011F4 . 6A 00 push 0
004011F6 . 52 push edx
004011F7 . 55 push ebp
004011F8 . 6A 00 push 0
004011FA . E8 F11C0000 call 00402EF0 ;big_to_bytes sn
004011FF . C64404 54 00 mov byte ptr [esp+eax+54], 0
00401204 . 8B4424 54 mov eax, [esp+54]
00401208 . 35 21433412 xor eax, 12344321
0040120D . 83C4 38 add esp, 38
00401210 . 3D 670B7754 cmp eax, 54770B67 ;big_to_bytes的前4位xor 12344321=54770B67
00401215 . 0F85 84000000 jnz 0040129F
0040121B . 8B4C24 10 mov ecx, [esp+10]
0040121F . 8D9424 800000>lea edx, [esp+80]
00401226 . 51 push ecx ;dwName
00401227 . 68 C0C04000 push 0040C0C0 ; ASCII "%0x"
0040122C . 52 push edx
0040122D . E8 7E500000 call 004062B0 ;sprintf 把dwName转成stringdwName
00401232 . 83C4 0C add esp, 0C
00401235 . 8D4424 21 lea eax, [esp+21]
00401239 . 8D8C24 800000>lea ecx, [esp+80]
00401240 . 50 push eax ; /String2 big_to_bytes从第六位开始的字符串
00401241 . 51 push ecx ; |String1 stringdwName
00401242 . FF15 08B04000 call [<&KERNEL32.lstrcmpA>] ; \lstrcmpA
00401248 . 85C0 test eax, eax ;比较
0040124A . 6A 00 push 0
0040124C . 75 3D jnz short 0040128B
0040124E . 8B9424 EC0000>mov edx, [esp+EC]
00401255 . 68 B4C04000 push 0040C0B4 ; ASCII "Nice job"
0040125A . 68 98C04000 push 0040C098 ; ASCII "Hey!!! Your key is GOOOOD"
0040125F . 52 push edx
00401260 . EB 51 jmp short 004012B3
00401262 > 8B8C24 E80000>mov ecx, [esp+E8]
00401269 . 6A 00 push 0 ; /Style = MB_OK|MB_APPLMODAL
0040126B . 68 90C04000 push 0040C090 ; |Title = "error"
00401270 . 68 7CC04000 push 0040C07C ; |Text = "Check your serial"
00401275 . 51 push ecx ; |hOwner
00401276 . FF15 B8B04000 call [<&USER32.MessageBoxA>] ; \MessageBoxA
0040127C . 5F pop edi
0040127D . 5E pop esi
0040127E . 5D pop ebp
0040127F . 33C0 xor eax, eax
00401281 . 5B pop ebx
00401282 . 81C4 D4000000 add esp, 0D4
00401288 . C2 1000 retn 10
破解过程:
就是通过12344321 XOR 54770B67加上Name构造dwName=>stringdwName,做成RSA加密后的大数,然后用D进行解密,再还原成60进制字符就可以了,算法很简单,详情见注册机。
未完待续。。。
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
上传的附件: