一、破解目标:JGL's Unapckme.exe(NO.2)
二、破解工具:OllyDbg v1.10,LordPE,ImportREC 1.6
三、破解作者:DarkBull@email.com.cn
四、破解过程:
1.分析父进程
用OllyDbg载入,EP如下:
JGL's_Un.> E8 0200000>CALL JGL's_Un.005D90CC
005D90CA 98 CWDE
005D90CB 4C DEC ESP
005D90CC 58 POP EAX
005D90CD 13CA ADC ECX,EDX
005D90CF F8 CLC
005D90D0 73 01 JNB SHORT JGL's_Un.005D90D3
用UnhandledExceptionFilter插件打补丁,下断HE CreateFileMappingA,返回后代码如下:
005DA56E 8985 94F6F>MOV DWORD PTR SS:[EBP-96C],EAX
005DA574 FF95 28F7F>CALL NEAR DWORD PTR SS:[EBP-8D8] ; ntdll.RtlGetLastWin32Error
005DA57A 8BF8 MOV EDI,EAX
005DA57C 6A 00 PUSH 0
005DA57E 6A 00 PUSH 0
005DA580 6A 00 PUSH 0
005DA582 68 1F000F0>PUSH 0F001F
005DA587 FFB5 94F6F>PUSH DWORD PTR SS:[EBP-96C]
005DA58D FF95 24F7F>CALL NEAR DWORD PTR SS:[EBP-8DC] ; kernel32.MapViewOfFile
005DA593 50 PUSH EAX
005DA594 8B85 98F6F>MOV EAX,DWORD PTR SS:[EBP-968]
005DA59A 05 8E00000>ADD EAX,8E
005DA59F 8F00 POP DWORD PTR DS:[EAX]
005DA5A1 FF30 PUSH DWORD PTR DS:[EAX]
005DA5A3 8F85 90F6F>POP DWORD PTR SS:[EBP-970]
005DA5A9 81FF B7000>CMP EDI,0B7
005DA5AF 0F85 A3080>JNZ JGL's_Un.005DAE58 ; 不跳则进入子进程
........
005DAE58 FF95 1CF7F>CALL NEAR DWORD PTR SS:[EBP-8E4] ; kernel32.GetCurrentProcessId
005DAE5E 8BBD 90F6F>MOV EDI,DWORD PTR SS:[EBP-970]
005DAE64 81C7 00010>ADD EDI,100
005DAE6A AB STOSD
005DAE6B 57 PUSH EDI
005DAE6C E8 1100000>CALL JGL's_Un.005DAE82
005DAE71 50 PUSH EAX
005DAE72 65:4C DEC ESP
005DAE74 6F OUTSD
005DAE75 636B 5F ARPL WORD PTR DS:[EBX+5F],BP
005DAE78 45 INC EBP
005DAE79 76 65 JBE SHORT JGL's_Un.005DAEE0
005DAE7B 6E OUTSB
005DAE7C 74 5F JE SHORT JGL's_Un.005DAEDD
005DAE7E 41 INC ECX
005DAE7F 3800 CMP BYTE PTR DS:[EAX],AL
005DAE81 005F 57 ADD BYTE PTR DS:[EDI+57],BL
005DAE84 33C0 XOR EAX,EAX
005DAE86 6A FF PUSH -1
005DAE88 59 POP ECX
005DAE89 F2:AE REPNE SCASB
005DAE8B 83EF 04 SUB EDI,4
005DAE8E 8DB5 88FBF>LEA ESI,DWORD PTR SS:[EBP-478]
005DAE94 AC LODSB
005DAE95 AA STOSB
005DAE96 0AC0 OR AL,AL
005DAE98 ^ 75 FA JNZ SHORT JGL's_Un.005DAE94
005DAE9A 6A 00 PUSH 0
005DAE9C 6A 01 PUSH 1
005DAE9E 6A 00 PUSH 0
005DAEA0 FF95 18F7F>CALL NEAR DWORD PTR SS:[EBP-8E8] ; kernel32.CreateEventA
005DAEA6 8985 8CF6F>MOV DWORD PTR SS:[EBP-974],EAX
005DAEAC 5F POP EDI
005DAEAD AB STOSD
005DAEAE 68 0001000>PUSH 100
005DAEB3 8D85 FCF5F>LEA EAX,DWORD PTR SS:[EBP-A04]
005DAEB9 50 PUSH EAX
005DAEBA C785 FCF5F>MOV DWORD PTR SS:[EBP-A04],0C
005DAEC4 33C0 XOR EAX,EAX
005DAEC6 8985 00F6F>MOV DWORD PTR SS:[EBP-A00],EAX
005DAECC 40 INC EAX
005DAECD 8985 04F6F>MOV DWORD PTR SS:[EBP-9FC],EAX
005DAED3 8D85 A8F6F>LEA EAX,DWORD PTR SS:[EBP-958]
005DAED9 50 PUSH EAX
005DAEDA 8D85 ACF6F>LEA EAX,DWORD PTR SS:[EBP-954]
005DAEE0 50 PUSH EAX
005DAEE1 FF95 14F7F>CALL NEAR DWORD PTR SS:[EBP-8EC] ; kernel32.CreatePipe
005DAEE7 68 0001000>PUSH 100
005DAEEC 8D85 FCF5F>LEA EAX,DWORD PTR SS:[EBP-A04]
005DAEF2 50 PUSH EAX
005DAEF3 8D85 A0F6F>LEA EAX,DWORD PTR SS:[EBP-960]
005DAEF9 50 PUSH EAX
005DAEFA 8D85 A4F6F>LEA EAX,DWORD PTR SS:[EBP-95C]
005DAF00 50 PUSH EAX
005DAF01 FF95 14F7F>CALL NEAR DWORD PTR SS:[EBP-8EC] ; kernel32.CreatePipe
........
005DAF60 6A 00 PUSH 0
005DAF62 6A 00 PUSH 0
005DAF64 6A 00 PUSH 0
005DAF66 6A 01 PUSH 1
005DAF68 6A 00 PUSH 0
005DAF6A 6A 00 PUSH 0
005DAF6C 8D85 88FBF>LEA EAX,DWORD PTR SS:[EBP-478]
005DAF72 50 PUSH EAX
005DAF73 8D85 00FCF>LEA EAX,DWORD PTR SS:[EBP-400]
005DAF79 50 PUSH EAX
005DAF7A FF95 0CF7F>CALL NEAR DWORD PTR SS:[EBP-8F4] ; kernel32.CreateProcessA
创建子进程,并不调试子进程,用管道进行通讯,F8至如下处:
005DAFEA 51 PUSH ECX
005DAFEB 0FB6C1 MOVZX EAX,CL
005DAFEE C1C8 08 ROR EAX,8
005DAFF1 0B85 20F6F>OR EAX,DWORD PTR SS:[EBP-9E0]
005DAFF7 C1C8 04 ROR EAX,4
005DAFFA 50 PUSH EAX
005DAFFB 8D85 A0F6F>LEA EAX,DWORD PTR SS:[EBP-960]
005DB001 FFB5 1CF6F>PUSH DWORD PTR SS:[EBP-9E4]
005DB007 FFB5 18F6F>PUSH DWORD PTR SS:[EBP-9E8]
005DB00D 50 PUSH EAX
005DB00E E8 E500000>CALL JGL's_Un.005DB0F8 ; 解密代码
005DB013 59 POP ECX
005DB014 ^ E2 D4 LOOPD SHORT JGL's_Un.005DAFEA ; 共6次
005DB016 5A POP EDX
005DB017 8D8D A0F6F>LEA ECX,DWORD PTR SS:[EBP-960]
005DB01D 8BC2 MOV EAX,EDX
005DB01F C1CA 08 ROR EDX,8
005DB022 0B95 20F6F>OR EDX,DWORD PTR SS:[EBP-9E0]
005DB028 C1CA 04 ROR EDX,4
005DB02B 52 PUSH EDX
005DB02C 50 PUSH EAX
005DB02D FFB5 18F6F>PUSH DWORD PTR SS:[EBP-9E8]
005DB033 51 PUSH ECX
005DB034 E8 BF00000>CALL JGL's_Un.005DB0F8 ; 同上
用管道读入加密代码,解密后再用管道写回,代码如下:
005DB154 6A 00 PUSH 0
005DB156 56 PUSH ESI
005DB157 FF75 10 PUSH DWORD PTR SS:[EBP+10]
005DB15A 53 PUSH EBX
005DB15B FF75 E8 PUSH DWORD PTR SS:[EBP-18]
005DB15E FF55 FC CALL NEAR DWORD PTR SS:[EBP-4] ; kernel32.ReadFile
........
005DB179 8B0E MOV ECX,DWORD PTR DS:[ESI]
005DB17B C1C0 0B ROL EAX,0B
005DB17E 304419 FF XOR BYTE PTR DS:[ECX+EBX-1],AL ; 解密代码
005DB182 ^ E2 FA LOOPD SHORT JGL's_Un.005DB17E
........
005DB192 6A 00 PUSH 0
005DB194 56 PUSH ESI
005DB195 FF75 10 PUSH DWORD PTR SS:[EBP+10]
005DB198 8D8D D4FEF>LEA ECX,DWORD PTR SS:[EBP-12C]
005DB19E 837D 0C 00 CMP DWORD PTR SS:[EBP+C],0
005DB1A2 74 03 JE SHORT JGL's_Un.005DB1A7
005DB1A4 8B4D 0C MOV ECX,DWORD PTR SS:[EBP+C]
005DB1A7 51 PUSH ECX
005DB1A8 FF75 E4 PUSH DWORD PTR SS:[EBP-1C]
005DB1AB FF55 F0 CALL NEAR DWORD PTR SS:[EBP-10] ; kernel32.WriteFile
传输完后,父进程等待子进程调试。
2.分析子进程
用OD再次加载,进入子进程,解密后的代码如下:
005DA7E9 90 NOP
005DA7EA 6A 00 PUSH 0
005DA7EC 6A 00 PUSH 0
005DA7EE 6A 11 PUSH 11
005DA7F0 FF95 C4F6F>CALL NEAR DWORD PTR SS:[EBP-93C] ; kernel32.GetCurrentThread
005DA7F6 50 PUSH EAX
005DA7F7 E8 B6E8FFF>CALL JGL's_Un.005D90B2
005DA7FC 05 7600000>ADD EAX,76
005DA801 8B00 MOV EAX,DWORD PTR DS:[EAX]
005DA803 C1C8 02 ROR EAX,2
005DA806 FFD0 CALL NEAR EAX ; ntdll.ZwSetInformationThread
005DA808 FFB5 84F6F>PUSH DWORD PTR SS:[EBP-97C] ; 父进程PID
005DA80E FF95 ECF6F>CALL NEAR DWORD PTR SS:[EBP-914] ; kernel32.DebugActiveProcess
005DA814 50 PUSH EAX
005DA815 E8 0000000>CALL JGL's_Un.005DA81A
005DA81A 58 POP EAX
005DA81B 05 9D08000>ADD EAX,89D
005DA820 C600 90 MOV BYTE PTR DS:[EAX],90
005DA823 58 POP EAX
005DA824 0BC0 OR EAX,EAX
005DA826 0F84 40080>JE JGL's_Un.005DB06C
005DA82C 68 0008000>PUSH 800
005DA831 6A 00 PUSH 0
005DA833 FF95 CCF6F>CALL NEAR DWORD PTR SS:[EBP-934] ; kernel32.LocalAlloc
005DA839 33C9 XOR ECX,ECX
005DA83B 8908 MOV DWORD PTR DS:[EAX],ECX
005DA83D 8985 7CF6F>MOV DWORD PTR SS:[EBP-984],EAX
005DA843 C785 78FAF>MOV DWORD PTR SS:[EBP-588],0
005DA84D FFB5 8CF6F>PUSH DWORD PTR SS:[EBP-974]
005DA853 68 A000000>PUSH 0A0
005DA858 FF95 FCF6F>CALL NEAR DWORD PTR SS:[EBP-904] ; kernel32.Sleep
005DA85E FF95 F4F6F>CALL NEAR DWORD PTR SS:[EBP-90C] ; kernel32.SetEvent
005DA864 6A FF PUSH -1
005DA866 8D85 18FAF>LEA EAX,DWORD PTR SS:[EBP-5E8]
005DA86C 50 PUSH EAX
005DA86D FF95 D8F6F>CALL NEAR DWORD PTR SS:[EBP-928] ; kernel32.WaitForDebugEvent
子进程调试父进程,当出现EXCEPTION_DEBUG_EVENT时:
A.子进程中处理函数地址代码如下:
005DAC26 3D B168DEF>CMP EAX,FADE68B1 ; EIP=FADE68B1
005DAC2B 0F85 D6000>JNZ JGL's_Un.005DAD07
005DAC31 8985 6CF6F>MOV DWORD PTR SS:[EBP-994],EAX
005DAC37 FF85 70F6F>INC DWORD PTR SS:[EBP-990]
005DAC3D 56 PUSH ESI
005DAC3E 8D85 F0FBF>LEA EAX,DWORD PTR SS:[EBP-410]
005DAC44 50 PUSH EAX
005DAC45 6A 30 PUSH 30
005DAC47 8BBD 7CF6F>MOV EDI,DWORD PTR SS:[EBP-984]
005DAC4D 83C7 10 ADD EDI,10
005DAC50 57 PUSH EDI
005DAC51 FFB5 08F8F>PUSH DWORD PTR SS:[EBP-7F8]
005DAC57 FFB5 90FBF>PUSH DWORD PTR SS:[EBP-470]
005DAC5D FF95 E4F6F>CALL NEAR DWORD PTR SS:[EBP-91C] ; kernel32.ReadProcessMemory
005DAC63 83BD F0FBF>CMP DWORD PTR SS:[EBP-410],30
005DAC6A 75 65 JNZ SHORT JGL's_Un.005DACD1
005DAC6C 83C4 EC ADD ESP,-14
005DAC6F 8D77 04 LEA ESI,DWORD PTR DS:[EDI+4]
005DAC72 8BFC MOV EDI,ESP
005DAC74 B9 0400000>MOV ECX,4
005DAC79 F3:A5 REP MOVSD
005DAC7B 8937 MOV DWORD PTR DS:[EDI],ESI
005DAC7D 83BD 70F6F>CMP DWORD PTR SS:[EBP-990],1
005DAC84 75 1E JNZ SHORT JGL's_Un.005DACA4
005DAC86 8BFC MOV EDI,ESP
005DAC88 8D85 F0FBF>LEA EAX,DWORD PTR SS:[EBP-410]
005DAC8E 50 PUSH EAX
005DAC8F 68 0001000>PUSH 100
005DAC94 FF37 PUSH DWORD PTR DS:[EDI]
005DAC96 FF37 PUSH DWORD PTR DS:[EDI]
005DAC98 FFB5 90FBF>PUSH DWORD PTR SS:[EBP-470]
005DAC9E FF95 E4F6F>CALL NEAR DWORD PTR SS:[EBP-91C] ; kernel32.ReadProcessMemory
005DACA4 56 PUSH ESI
005DACA5 FF95 74F6F>CALL NEAR DWORD PTR SS:[EBP-98C] ; kernel32.LoadLibraryA
005DACAB E8 ED22000>CALL JGL's_Un.005DCF9D ; 得到函数地址
005DACB0 83C4 04 ADD ESP,4
005DACB3 8985 F4F7F>MOV DWORD PTR SS:[EBP-80C],EAX
005DACB9 8B85 7CF6F>MOV EAX,DWORD PTR SS:[EBP-984]
005DACBF 83C0 10 ADD EAX,10
005DACC2 FF30 PUSH DWORD PTR DS:[EAX]
005DACC4 8F85 FCF7F>POP DWORD PTR SS:[EBP-804]
005DACCA 8385 08F8F>ADD DWORD PTR SS:[EBP-7F8],30
005DACD1 5E POP ESI
005DACD2 8D85 44F7F>LEA EAX,DWORD PTR SS:[EBP-8BC]
005DACD8 50 PUSH EAX
005DACD9 FFB5 94FBF>PUSH DWORD PTR SS:[EBP-46C]
005DACDF FF95 E0F6F>CALL NEAR DWORD PTR SS:[EBP-920] ; kernel32.SetThreadContext
005DACE5 68 0200010>PUSH 10002
005DACEA FFB5 20FAF>PUSH DWORD PTR SS:[EBP-5E0]
005DACF0 FFB5 1CFAF>PUSH DWORD PTR SS:[EBP-5E4]
005DACF6 FF95 D4F6F>CALL NEAR DWORD PTR SS:[EBP-92C] ; kernel32.ContinueDebugEvent
此时CONTEXT.regEAX为函数地址,再分析CONTEXT.regEIP处代码:
00370D25 85C0 TEST EAX,EAX ; EAX为函数地址
00370D27 0F84 950A0>JE 003717C2
00370D2D F6C1 80 TEST CL,80
00370D30 8B0E MOV ECX,DWORD PTR DS:[ESI] ; ECX=004D31B8
00370D32 74 04 JE SHORT 00370D38
00370D34 8901 MOV DWORD PTR DS:[ECX],EAX ; 写入IAT
00370D36 EB 24 JMP SHORT 00370D5C
00370D38 92 XCHG EAX,EDX
00370D39 50 PUSH EAX
00370D3A 8B4424 FC MOV EAX,DWORD PTR SS:[ESP-4]
00370D3E 57 PUSH EDI
00370D3F E8 C9F3FFF>CALL 0037010D ; 加密IAT
00370D44 41 INC ECX
00370D45 41 INC ECX
00370D46 8D79 04 LEA EDI,DWORD PTR DS:[ECX+4]
00370D49 8B09 MOV ECX,DWORD PTR DS:[ECX]
00370D4B F2:AF REPNE SCASD
00370D4D 5F POP EDI
00370D4E 8BC2 MOV EAX,EDX
00370D50 5A POP EDX
00370D51 8B0E MOV ECX,DWORD PTR DS:[ESI]
00370D53 ^ 74 DF JE SHORT 00370D34
00370D55 8919 MOV DWORD PTR DS:[ECX],EBX ; 写入加密IAT
00370D57 E8 1700000>CALL 00370D73
00370D5C 83C6 04 ADD ESI,4
00370D5F B1 FE MOV CL,0FE
00370D61 380E CMP BYTE PTR DS:[ESI],CL
00370D63 ^ 75 83 JNZ SHORT 00370CE8
00370D65 384E 01 CMP BYTE PTR DS:[ESI+1],CL
00370D68 0F84 D80A0>JE 00371846
00370D6E ^ E9 5BFFFFF>JMP 00370CCE
避开加密CALL,用ImportREC修复。
B.子进程中处理CC代码如下:
005DB0C4 55 PUSH EBP
005DB0C5 8BEC MOV EBP,ESP
005DB0C7 C1E9 02 SHR ECX,2
005DB0CA F2:AF REPNE SCASD
005DB0CC 75 24 JNZ SHORT JGL's_Un.005DB0F2
005DB0CE 8B0F MOV ECX,DWORD PTR DS:[EDI] ; 查表1
005DB0D0 83E9 08 SUB ECX,8
005DB0D3 83C7 04 ADD EDI,4
005DB0D6 D1E9 SHR ECX,1
005DB0D8 8BC2 MOV EAX,EDX
005DB0DA 25 FF0F000>AND EAX,0FFF
005DB0DF F2:66:AF REPNE SCAS
005DB0E2 75 0E JNZ SHORT JGL's_Un.005DB0F2
005DB0E4 33C0 XOR EAX,EAX
005DB0E6 66:8B07 MOV AX,WORD PTR DS:[EDI]
005DB0E9 0345 0C ADD EAX,DWORD PTR SS:[EBP+C] ; 查表2
005DB0EC 8B00 MOV EAX,DWORD PTR DS:[EAX]
005DB0EE C9 LEAVE
005DB0EF C2 0800 RET 8
表1基址为:005DBAC4,表2基址为:00148AE0,子进程先查表1得到序号,再查表2得到EIP地址,然后再写入5个字节,修复CC,下次再调用该函数时不会产生异常。偶修复时只用表1再加上序号可得到正确的IAT。
3.寻找OEP
当出现第一个CC异常时,先DUMP整个进程,通过分析对GetModuleHandleA函数的调用,得到以下代码:
dumped_.<>/$ 53 PUSH EBX
0040646D |. 8BD8 MOV EBX,EAX
0040646F |. 33C0 XOR EAX,EAX
00406471 |. A3 A0F04>MOV DWORD PTR DS:[4CF0A0],EAX
00406476 |. 6A 00 PUSH 0 ; /pModule = NULL
00406478 |. E8 2BFFF>CALL <JMP.&kernel32.GetModuleHandleA> ; \GetModuleHandleA
0040647D |. A3 68264>MOV DWORD PTR DS:[4D2668],EAX
00406482 |. A1 68264>MOV EAX,DWORD PTR DS:[4D2668]
00406487 |. A3 ACF04>MOV DWORD PTR DS:[4CF0AC],EAX
0040648C |. 33C0 XOR EAX,EAX
0040648E |. A3 B0F04>MOV DWORD PTR DS:[4CF0B0],EAX
00406493 |. 33C0 XOR EAX,EAX
00406495 |. A3 B4F04>MOV DWORD PTR DS:[4CF0B4],EAX
0040649A |. E8 C1FFF>CALL dumped_.00406460
0040649F |. BA A8F04>MOV EDX,dumped_.004CF0A8
004064A4 |. 8BC3 MOV EAX,EBX
004064A6 |. E8 1DD9F>CALL dumped_.00403DC8
004064AB |. 5B POP EBX
004064AC \. C3 RETN
此时观察父进程堆栈可得到返回地址,由于OEP变形代码很多,不贴了。修复后代码如下:
dumped.<M> $ 55 PUSH EBP
004CE801 . 8BEC MOV EBP,ESP
004CE803 . 83C4 E0 ADD ESP,-20
004CE806 . B8 40E34>MOV EAX,dumped.004CE340
004CE80B . E8 5C7CF>CALL dumped.0040646C
004CE810 . A1 08144>MOV EAX,DWORD PTR DS:[4D1408]
004CE815 . 8B00 MOV EAX,DWORD PTR DS:[EAX]
004CE817 . E8 D0FDF>CALL dumped.0047E5EC
004CE81C . 8B0D FC1>MOV ECX,DWORD PTR DS:[4D11FC]
004CE822 . A1 08144>MOV EAX,DWORD PTR DS:[4D1408]
004CE827 . 8B00 MOV EAX,DWORD PTR DS:[EAX]
004CE829 . 8B15 68C>MOV EDX,DWORD PTR DS:[4CCD68]
004CE82F . E8 D0FDF>CALL dumped.0047E604
004CE834 . A1 08144>MOV EAX,DWORD PTR DS:[4D1408]
004CE839 . 8B00 MOV EAX,DWORD PTR DS:[EAX]
004CE83B . E8 44FEF>CALL dumped.0047E684
004CE840 .^ E9 C3FDF>JMP dumped.004CE608
4.Code Replace
运行程序,出现地址不可读的异常,代码如下:
00402739 8D40 00 LEA EAX,DWORD PTR DS:[EAX]
0040273C 53 PUSH EBX
0040273D 85C0 TEST EAX,EAX
0040273F 7E 15 JLE SHORT dumped.00402756
00402741 - E9 4DDC8E0>JMP dumped.00CF0393 ; 出现异常
00402746 008B D885D>ADD BYTE PTR DS:[EBX+75DB85D8],CL
0040274C 0BB0 01E84>OR ESI,DWORD PTR DS:[EAX+144E801]
00402752 0000 ADD BYTE PTR DS:[EAX],AL
00402754 EB 02 JMP SHORT dumped.00402758
00402756 33DB XOR EBX,EBX
00402758 8BC3 MOV EAX,EBX
0040275A 5B POP EBX
0040275B C3 RETN
懒得修复,采用Loader方式。
该文纯属灌水,希望版主不要删啊。附件:dumped.part1.rar 附件:dumped.part2.rar
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)