好友
阅读权限255
听众
最后登录1970-1-1
|
Hmily
发表于 2008-10-29 14:25
From:cyto 博客
zp_1.4_demo_notepad.exe
自己加的壳,主要学习iat修复.anti没有设置,到达oep可能有所差异.
到达oep:
ep:
01011B0F N> 8D84C0 00010401lea eax,dword ptr ds:[eax+eax*8+1040100]
01011B16 ^ E9 34FAFFFFjmp 0101154F ; NOTEPAD_.0101154F
01011B1B A5 movs dword ptr es:[edi],dword ptr ds:[esi]
01011B1C 0B05 8880FC05or eax,dword ptr ds:[5FC8088]
01011B22 ^ E9 EDF8FFFFjmp 01011414 ; NOTEPAD_.01011414
在code下内存写入断点,F9,断下后在sfx区段下内存访问断点,F9,断下后在code下内存访问断点,F9,来到oep:
01006420 55 push ebp
01006421 8BEC mov ebp,esp
01006423 6A FFpush -1
01006425 68 88180001push 1001888
0100642A 68 D0650001push 10065D0
0100642F 64:A1 00000000 mov eax,dword ptr fs:[0]
01006435 50 push eax
01006436 64:8925 00000000 mov dword ptr fs:[0],esp
0100643D 83C4 98add esp,-68
01006440 53 push ebx
01006441 56 push esi
01006442 57 push edi
01006443 8965 E8mov dword ptr ss:[ebp-18],esp
01006446 C745 FC 00000000 mov dword ptr ss:[ebp-4],0
0100644D 6A 02push 2
0100644F E8 20BD0000call 01012174; NOTEPAD_.01012174
01006454 90 nop
01006455 83C4 04add esp,4
01006458 C705 38990001 FFFFFFFF mov dword ptr ds:[1009938],-1
01006462 C705 3C990001 FFFFFFFF mov dword ptr ds:[100993C],-1
0100646C E8 6BBE0000call 010122DC; NOTEPAD_.010122DC
01006471 90 nop
iat:
01001000 00CE00C4 ; 加密方式1
01001004 00CE00D2
01001008 00CE00E0
0100100C 0101269C NOTEPAD_.0101269C ; 加密方式2
01001010 00CE00EE
01001014 00CE00FC
01001018 00CE010A
0100101C 00000000
01001020 01012600 NOTEPAD_.01012600
01001024 0101203C NOTEPAD_.0101203C
...
01001094 00722410 ; 加密方式3
...
010012DC 00CE001C
010012E0 00CE002A
010012E4 010120CC NOTEPAD_.010120CC
010012E8 01012108 NOTEPAD_.01012108
010012EC 00CE0038
010012F0 010124B0 NOTEPAD_.010124B0
010012F4 00CE0046
010012F8 00000000
010012FC 00000000
加密方式1:
00CE00C4 50 push eax
00CE00C5 60 pushad
00CE00C6 68 0AE342B7push B742E30A
00CE00CB E8 5028A3FFcall 00712920
00CE00D0 61 popad
00CE00D1 C3 retn
跟进过程有些东西如下:
007353BF FF15 F8987100call dword ptr ds:[7198F8] ; kernel32.GetTickCount
0072E57B FF15 64987100call dword ptr ds:[719864] ; kernel32.ResumeThread
00735408 FF15 6C5F7200call dword ptr ds:[725F6C]
0072DAC6 8B0CB1 mov ecx,dword ptr ds:[ecx+esi*4] ; ADVAPI32.IsTextUnicode
0072B453 894C24 2Cmov dword ptr ss:[esp+2C],ecx; ADVAPI32.IsTextUnicode
0072B457 E9 62860000jmp 00733ABE ; 这里patch挺好
这个有点象某个狗加密的iat.patch的地方可能有好几个,这只是其中一个,地址每次加载可能不一样,根据代码.
[ecx+esi*4]的ecx就是乱序后的api地址:
0074AE98 77DFDD3C USER32.DestroyWindow
0074AE9C 78FD0CD5 SHELL32.DragAcceptFiles
0074AEA0 76B0E83C comdlg32.PrintDlgExW
0074AEA4 77E7E283 kernel32.GlobalUnlock
0074AEA8 78007778 msvcrt.__setusermatherr
0074AEAC 00000000
0074AEB0 0048006B
0074AEB4 000C0100
0074AEB8 77F52AD2 GDI32.GetTextExtentPoint32W
0074AEBC 77EAC113 kernel32.GetDateFormatW
0074AEC0 780290A1 msvcrt.time
0074AEC4 77E0E922 USER32.IsDialogMessageW
0074AEC8 77EABF89 kernel32.GetTimeFormatW
0074AECC 77F61436 GDI32.SetAbortProc
加密方式2:
跟进过程有以下东西:
0073A6E6 FF15 685F7300call dword ptr ds:[735F68]
0073B6E2 9D popfd
0073B6E3 E9 8B000000jmp 0073B773
00783BC7 60 pushad
00783BC8 ^ E9 D3FBFFFFjmp 007837A0
007453BF FF15 F8987200call dword ptr ds:[7298F8] ; kernel32.GetTickCount
0073E57B FF15 64987200call dword ptr ds:[729864] ; kernel32.ResumeThread
00745408 FF15 6C5F7300call dword ptr ds:[735F6C]
0073B453 894C24 2Cmov dword ptr ss:[esp+2C],ecx; ADVAPI32.RegSetValueExW
0073B457 E9 62860000jmp 00743ABE ; patch,jmp patch_retn
这个原来殊途同归啊.
跟踪过程中有些判断跳转,可能是不同的加密方式,在notepad里没有实现.
加密方式3:
00722410 8B4424 04mov eax,dword ptr ss:[esp+4]
00722414 E8 C7040000call 007228E0
00722419 C2 0400retn 4
007228E0 50 push eax ; NOTEPAD_.0100108C
007228E1 FF15 68987200call dword ptr ds:[729868] ; kernel32.GetModuleHandleA
007228E7 C3 retn
解密思路:
取出iat,call,patch,写入.
mov eax,iat_start
search:
cmp dword[eax],0 ; dll间隔,跳过
je continue
cmp dword[eax],20000000 ; 以防有没加密的api
jg continue
mov [addr_1],eax ; 暂存
call [eax]
mov eax,[addr_1]
jmp continue; maybe error
patch_retn:
mov eax,[addr_1]
mov [eax],ecx
jmp continue
continue:
add eax,4
cmp eax,iat_end
jb search
jmp here ; finish
iat:1001000-10012F8
B8 00 10 00 01 83 38 00 74 23 81 38 00 00 00 20 7F 1B A3 00 10 3C 00 FF 10 EB 0D 00 00 A1 00 10
3C 00 89 08 EB 02 00 00 A1 00 10 3C 00 83 C0 04 3D F8 12 00 01 72 CE EB FE
patch的地方每次加载都变,不过可以搜索特征码定位:
0072B457 E9 62860000jmp 00733ABE ; jmp patch_retn
注意先把1001094的函数先手工恢复了,要不会出错的.
补丁后就把函数全部解密了.
修复code:
jmp api的修复:
010030C6 - E9 31F60000jmp 010126FC ; notepad_.010126FC
010030CB 90 nop
010030CC - E9 FBEF0000jmp 010120CC ; notepad_.010120CC
010030D1 90 nop
010030D2 - E9 9DF30000jmp 01012474 ; notepad_.01012474
010030D7 90 nop
call api的修复:
0100644D 6A 02push 2
0100644F E8 20BD0000call 01012174; notepad_.01012174
01006454 90 nop
01006455 83C4 04add esp,4
01006458 C705 38990001 FFFFFFFF mov dword ptr ds:[1009938],-1
01006462 C705 3C990001 FFFFFFFF mov dword ptr ds:[100993C],-1
0100646C E8 6BBE0000call 010122DC; notepad_.010122DC
01006471 90 nop
这两种变形跟踪进入后发现跟iat的加密解密是一样的,同一个地方patch.
思路:搜索code,找到E9 ???????? 90(或者E8 ???????? 90),然后跟进,到达patch的地方获取到api地址,然后与iat表比较,相等就把iat的地址写回去.
修复jmp [api]
mov eax,code_start
search:
cmp byte[eax],0e9
jne continue
cmp byte[eax+5],90
jne continue
mov [addr_1],eax
call eax
mov eax,[addr_1] ; maybe error, continue
jmp continue
patch_retn:
mov ebx,iat_start
cmp_api:
cmp ecx,[ebx]
je fix
add ebx,4
cmp ebx,iat_end
jb cmp_api
mov eax,[addr_1] ; no find api,continue
jmp continue
fix:
mov eax,[addr_1]
mov word[eax],25ff
mov [eax+2],ebx
jmp continue
continue:
add eax,1
cmp eax,code_end
jb search
jmp here; finish
code:1001000-1011000
iat:1001000-10012f8
B8 00 10 00 01 80 38 E9 75 3E 80 78 05 90 75 38 A3 00 10 7D 00 FF 10 A1 00 10 7D 00 EB 2A BB 00
10 00 01 3B 0B 74 12 83 C3 04 81 FB F8 12 00 01 72 F1 A1 00 10 7D 00 EB 0F A1 00 10 7D 00 66 C7
00 FF 25 89 58 02 90 90 83 C0 01 3D 00 10 01 01 72 B3 EB FE
稍微修改下就可以用于call api的修复.可能会有异常,那是因为有些不是加密的也修复了.可以多加几个判断以防过度修复. |
|