本帖最后由 dsong 于 2015-2-4 22:13 编辑
在这个寒假,我的空余时间不多了,这个寒假最后一个帖子来扯扯其他话题。技术太菜不要喷啊!
(1)防脱壳机脱壳
大家都知道,UPX是一个开源软件,而且它本身除了压缩也有解压的功能,即upx -d。如何防止被轻松解压缩,其实方法很简单.
我们试验的程序是一个 很小的E-pointer,用UPX给它压缩: Ultimate Packer for eXecutables
Copyright (C) 1996 - 2013
UPX 3.91w Markus Oberhumer, Laszlo Molnar & John Reiser Sep 30th 2013
File size Ratio Format Name
-------------------- ------ ----------- -----------
90112 -> 40960 45.45% win32/pe packed.exe
Packed 1 file.
应该说压缩率是非常不错的。现在我们使用UPX的Unpack功能试试看:C:\Documents and Settings\Administrator>"C:\Documents and Settings\Administrator
\桌面\upx391w\upx.exe" "C:\Documents and Settings\Administrator\桌面\packed.exe"
-d -o"C:\Documents and Settings\Administrator\桌面\unpacked.exe"
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2013
UPX 3.91w Markus Oberhumer, Laszlo Molnar & John Reiser Sep 30th 2013
File size Ratio Format Name
-------------------- ------ ----------- -----------
90112 <- 40960 45.45% win32/pe unpacked.exe
Unpacked 1 file.
应该说它解压的非常完美。貌似和没压缩的一模一样??. PEiD查壳试试看:PEiD v0.94
文件: :\Documents and Settings\Administrator\桌面\unpacked.e ...
入口点: 00006023 EP 区段: text
文件偏移量: 00006023 首字节: 55,8B,EC,6A
连接器版本: .0 子系统: Win32 GUI
Microsoft Visual C++ 6.0
多重扫描( ) 任务查看器( ) 选项( ) 关于( ) 关闭
总是置于最前( ) 扩展 >
区段查看器
名称 V. 偏移 V. 大小 R. 偏移 R. 大小 标志
.text 00001000 00009A82 00001000 0000A000 60000020
.rdata 0000B000 00001DB4 0000B000 00002000 40000040
.data 0000D000 00003D98 0000D000 00003000 C0000040
.rsrc 00011000 00005818 00010000 00006000 40000040
关闭( )
可以说,所有信息包括区段名称等全部都正确。我们开始先尝试一下怎样去防止-d。
<1>修改区段名
我们看看加壳后的区段:区段查看器
名称 V. 偏移 V. 大小 R. 偏移 R. 大小 标志
UPX0 00001000 0000F000 00000400 00000000 E0000080
UPX1 00010000 00009000 00000400 00008400 E0000040
.rsrc 00019000 00002000 00008800 00001800 C0000040
关闭( )
最明显的特征:UPX0,UPX1,我们改掉它,拿出Winhex,U改成R:Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
000001D0 52 50 58 30 RPX0
结果: Ultimate Packer for eXecutables
Copyright (C) 1996 - 2013
UPX 3.91w Markus Oberhumer, Laszlo Molnar & John Reiser Sep 30th 2013
File size Ratio Format Name
-------------------- ------ ----------- -----------
upx: C:\Documents and Settings\Administrator\桌面\packed.exe: CantUnpackExceptio
n: file is modified/hacked/protected; take care!!!
呵呵,好神奇!(其实一点都不奇怪)
<2>改标识
我们把RPX改回UPX,看到这里:Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
000003D0 00 00 00 00 00 00 00 00 00 00 00 33 2E 39 31 00 3.91
000003E0 55 50 58 21 0D 09 02 08 5A 34 28 27 60 95 D0 97 UPX! Z4('`曅?
000003F0 AA 6B 01 00 0A 81 00 00 00 60 01 00 26 05 00 9F 猭 ? ` &
可以发现特征UPX!我们再来改改:Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
000003D0 00 00 00 00 00 00 00 00 00 00 00 30 2E 30 30 00 0.00
000003E0 76 6D 70 21 0D 09 02 08 5A 34 28 27 60 95 D0 97 vmp! Z4('`曅
同样的出错语句,不贴了。其实0x3db到0x3FF都可以用00填充,对于程序运行无影响.
(2)去掉UPX特征码
前面的修改方法太菜了吧,PEiD检测一下修改过的文件: PEiD v0.94PEiD v0.94
文件: :\Documents and Settings\Administrator\桌面\packed.exe ...
入口点: 00018110 EP 区段: UPX1
文件偏移量: 00008510 首字节: 60,BE,00,00
连接器版本: .0 子系统: Win32 GUI
UPX -> [url]www.upx.sourceforge.net[/url] *
多重扫描( ) 任务查看器( ) 选项( ) 关于( ) 关闭
总是置于最前( ) 扩展 >
ExEinfoPE:文件: packed.exe H R
00018110 oo < UPX1 ... -> 96MB
00008510 60,BE,00,00,41 S 插件
.0 Windows GUI 关于
0000A000h < NO 00000000 选项
退出
UPX 0.89 - 3.xx -> Markus & Laszlo ver. [ 0.00 ] <- info from file. ( sig >
提取
unpack "upx.exe -d" from [url]http://upx.sf.net[/url] or any UPX/Generic unpa i >>
呵呵,解决方案都出来了,区段名只要修复成UPX即可用upx -d了,但是对于前面提到的0x3e0~0x3ff的数据被填充的话,就不一定能恢复成功。但是著名的MistHill大牛早就针对这种东西做深入研究并写了一个检验性不那么强的脚本"UPX Unpacker for Dummies",用它可以脱掉,所以我们要改掉UPX的特征码,让它识别不出是UPX加壳。
以下信息是仔细阅读userdb.txt后总结出来的:特征码1:60 BE ?? ?? ?? 00 8D BE ?? ?? ?? FF
特征码2:60 BE ?? ?? ?? ?? 8D BE ?? ?? ?? ?? 57 EB 0B 90 8A 06 46 88 07 47 01 DB 75 ?? 8B 1E 83 ?? ?? 11 DB 72 ?? B8 01 00 00 00 01 DB 75
特征码3:55 FF 96 ?? ?? ?? ?? 09 C0 74 07 89 03 83 C3 04 EB ?? FF 96 ?? ?? ?? ?? 8B AE ?? ?? ?? ?? 8D BE 00 F0 FF FF BB 00 10 00 00 50 54 6A 04 53 57 FF D5 8D 87 ?? ?? 00 00 80 20 7F 80 60 28 7F 58 50 54 50 53 57 FF D5 58 61 8D 44 24 80 6A 00 39 C4 75 FA 83 EC 80
把加壳程序载入OD:
对付特征码1:
修改前:00418110 > 60 pushad
00418111 BE 00004100 mov esi,packed.00410000
00418116 8DBE 0010FFFF lea edi,dword ptr ds:[esi+FFFF1000]
0041811C 57 push edi
0041811D EB 0B jmp short packed.0041812A
0041811F 90 nop
00418120 8A06 mov al,byte ptr ds:[esi]
修改后:00418130 > 60 pushad
00418131 90 nop
00418132 BE 00004100 mov esi,Ep_2_5_1.00410000
00418137 8DBE 0010FFFF lea edi,dword ptr ds:[esi+FFFF1000]
0041813D 57 push edi
0041813E EB 0A jmp short Ep_2_5_1.0041814A
00418140 8A06 mov al,byte ptr ds:[esi]
00418142 46 inc esi
(这样改貌似把原来入口点的花指令弄没了。。。不过没关系,入口点的花指令没用。)
对付特征码2:
修改前:00418131 ^\72 ED jb short packed.00418120
00418133 B8 01000000 mov eax,1
00418138 01DB add ebx,ebx
修改后:00418151 ^\72 ED jb short Ep_2_5_1.00418140
00418153 33C0 xor eax,eax
00418155 40 inc eax
00418156 8BC0 mov eax,eax
00418158 01DB add ebx,ebx
对付特征码3:
修改前:00418295 39C4 cmp esp,eax
00418297 ^ 75 FA jnz short packed.00418293
00418299 83EC 80 sub esp,-80
0041829C - E9 82DDFEFF jmp packed.00406023
修改后:00418295 39C4 cmp esp,eax
00418297 ^ 0F85 F6FFFFFF jnz packed.00418293
0041829D 83EC 80 sub esp,-80
004182A0 - E9 7EDDFEFF jmp packed.00406023
(其实就是把jnz short XXX改成jnz long XXX,long的不能改short,那么short的为什么不能改long呢?)
测试一下,程序仍能执行,但是.......
PEiD: PEiD v0.94PEiD v0.94
文件: :\Documents and Settings\Administrator\桌面\packed.exe ...
入口点: 00018110 EP 区段: UPX1
文件偏移量: 00008510 首字节: 60,90,BE,00
连接器版本: .0 子系统: Win32 GUI
yoda's Protector v1.02 (.dll,.ocx) -> Ashkbiz Danehkar (h) *
多重扫描( ) 任务查看器( ) 选项( ) 关于( ) 关闭
总是置于最前( ) 扩展 >
ExEinfoPE:文件: packed.exe H R
00018110 oo < UPX1 ... -> 96MB
00008510 60,90,BE,00,00 S 插件
.0 Windows GUI 关于
0000A000h < NO 00000000 选项
退出
Unknown Packer-Protector , 3 sections like UPX S-Structure UPX! >
提取
try : Protection_ID.exe from [url]http://pid.gamecopyworld.com[/url] , PEiD. i >>
看看,PEiD已经认不出了,ExEinfoPE有点识别出来,看来是它强啊,不过没关系,待会也爆了它.
爆ExEinfoPE的方法:
<1>加垃圾区段:
拿出神器LordPE:[ 区段表 ]
名称 V.偏移 V.大小 R.偏移 R.大小 标志
UPX0 00001000 0000F000 00000400 00000000 E0000080
UPX1 00010000 00009000 00000400 00008400 E0000040
.rsrc 00019000 00002000 00008800 00001800 C0000040
.dsong 0001B000 00000200 0000A000 00000200 E00000E0
再用Winhex在文件尾部粘帖512个00,完成后,测试可以运行. 再拖入ExEinfoPE:文件: 复件 packed.exe H R
00018110 oo < UPX1 ... -> 96MB
00008510 60,90,BE,00,00 S 插件
.0 Windows GUI 关于
0000A200h < NO 00000000 选项
退出
Unknown Packer-Protector , 4 sections >
提取
try : Protection_ID.exe from [url]http://pid.gamecopyworld.com[/url] , PEiD. i >>
马上就*了。呵呵
至此,此程序已失去大部分UPX特征. 应该够了.
<2>PE头移动
拿出神器Winhex:
编辑前:Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
00000000 4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00 MZ?
00000010 B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 ? @
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000030 00 00 00 00 00 00 00 00 00 00 00 00 D8 00 00 00 ?
00000040 0E 1F BA 0E 00 B4 09 CD 21 B8 01 4C CD 21 54 68 ? ???L?Th
00000050 69 73 20 70 72 6F 67 72 61 6D 20 63 61 6E 6E 6F is program canno
00000060 74 20 62 65 20 72 75 6E 20 69 6E 20 44 4F 53 20 t be run in DOS
00000070 6D 6F 64 65 2E 0D 0D 0A 24 00 00 00 00 00 00 00 mode. nbsp;
00000080 99 3C 71 89 DD 5D 1F DA DD 5D 1F DA DD 5D 1F DA ?q壿] 谳] 谳] ?
00000090 5E 41 11 DA D2 5D 1F DA 53 55 40 DA DC 5D 1F DA ^A 谝] 赟U@谲] ?
000000A0 DD 5D 1E DA 66 5D 1F DA 5E 55 42 DA CE 5D 1F DA 輂 趂] 赹UB谖] ?
000000B0 35 42 14 DA DF 5D 1F DA 35 42 15 DA A9 5D 1F DA 5B 谶] ?B 讴] ?
000000C0 65 5B 19 DA DC 5D 1F DA 52 69 63 68 DD 5D 1F DA e[ 谲] 赗ich輂 ?
000000D0 00 00 00 00 00 00 00 00 50 45 00 00 4C 01 03 00 PE L
000000E0 9A DA 22 4D 00 00 00 00 00 00 00 00 E0 00 0F 01 氌"M ?
000000F0 0B 01 06 00 00 90 00 00 00 20 00 00 00 F0 00 00 ? ?
00000100 10 81 01 00 00 00 01 00 00 90 01 00 00 00 40 00 ? ? @
00000110 00 10 00 00 00 02 00 00 04 00 00 00 00 00 00 00
00000120 04 00 00 00 00 00 00 00 00 B0 01 00 00 10 00 00 ?
00000130 00 00 00 00 02 00 00 00 00 00 10 00 00 10 00 00
00000140 00 00 10 00 00 10 00 00 00 00 00 00 10 00 00 00
00000150 00 00 00 00 00 00 00 00 D0 A5 01 00 04 02 00 00 啸
00000160 00 90 01 00 D0 15 00 00 00 00 00 00 00 00 00 00 ? ?
00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001B0 00 00 00 00 00 00 00 00
编辑后:Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
00000000 4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00 MZ?
00000010 B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 ? @
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000030 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 @
00000040 50 45 00 00 4C 01 03 00 9A DA 22 4D 00 00 00 00 PE L 氌"M
00000050 00 00 00 00 78 01 0F 01 0B 01 06 00 00 90 00 00 x ?
00000060 00 20 00 00 00 F0 00 00 10 81 01 00 00 00 01 00 ? ?
00000070 00 90 01 00 00 00 40 00 00 10 00 00 00 02 00 00 ? @
00000080 04 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00
00000090 00 B0 01 00 00 10 00 00 00 00 00 00 02 00 00 00 ?
000000A0 00 00 10 00 00 10 00 00 00 00 10 00 00 10 00 00
000000B0 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00
000000C0 D0 A5 01 00 04 02 00 00 00 90 01 00 D0 15 00 00 啸 ? ?
000000D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000000E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000000F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001B0 00 00 00 00 00 00 00 00
提示:1.原来0xec、后来的0x54、0x55处是PE头大小,0x3c是PE头起始位置,所有地址反着写.
测试可以正常运行后,拖进ExEinfoPE,显示:文件: packed_.exe H R
00018110 oo < ... -> 96MB
00018110 00,00,00,00,00 S 插件
.0 Windows GUI 关于
0000A000h < 0000A000 选项
退出
ExE Corrupted - over 100 bytes are ZERO data - WRONG Entry Point , >
提取
try EP Corrector or another Dump method i >>
彻底挂. ;-)
(3)添加花指令在入口点代码跳转处,扰乱静态分析(简述)
网上有很多写得很好的花指令,还有防止动态分析的!我没那么高水平,只能玩玩。
花指令成功关键技巧:
1.反汇编器是从上到下的代码分析,所以你可以这样写代码:l1:
pushad
xor eax,eax
inc eax
cmp eax,eax
je l2-1
jmp l2
l2:
xxxxxx
这些代码显而易见,l2-1的命令是执行不到的,只会跳到l2,所以你在l2-1的这个字节随便写个东西就行,但是千万不能是90或CC,否则反汇编器不会被你干扰!千万不能把正确跳转写在前面,否则会被反汇编器识别,就把你l2-1作为数据而不是代码标出来了。
2. 对于EB,E2,90,CC这种代码非常优先分析,很容易直接把它认为是正常代码于是你可以用上面的例子,在l2-1这个字节写上E2,然后就等着反汇编器把它识别到下一个字节去吧。反正一行代码分析错,很容易出现后面的行行代码都错的情况!
3. 增加静态分析步骤还有一个方法就是使用Call dword [0xxxxx]、jmp dword [0xxxx]。比如上面的 例子你已经给eax赋值1,那么你如果要调用的话使用call dword [eax+(0xxxxx-1)]即可.然后你选个好一点的地址,,比如call dword [eax+417290]这样的,地址里面包含90很容易混淆反汇编器的识别!
就比如我那这个程序,我把它修改成这样了:
OD不分析:004182B9 BE FFFFFFFF mov esi,-1
004182BE 3BC6 cmp eax,esi
004182C0 74 FF je short Ep_2_5_1.004182C1
004182C2 FF96 70834100 call dword ptr ds:[esi+418370]
004182C8 EB 00 jmp short Ep_2_5_1.004182CA
004182CA C0FF A6 sar bh,0A6
004182CD 90 nop
004182CE 8341 00 0F add dword ptr ds:[ecx],0F
004182D2 54 push esp
004182D3 2055 8B and byte ptr ss:[ebp-75],dl
004182D6 EC in al,dx
004182D7 83C4 F1 add esp,-0F
004182DA 83C4 0F add esp,0F
004182DD B8 7F9B4000 mov eax,Ep_2_5_1.00409B7F
004182E2 50 push eax
004182E3 C3 retn
OD分析:004182B9 . BE FFFFFFFF mov esi,-1
004182BE . 3BC6 cmp eax,esi
004182C0 . 74 FF je short Ep_2_5_1.004182C1
004182C2 . FF96 70834100 call dword ptr ds:[esi+418370]
004182C8 . EB 00 jmp short Ep_2_5_1.004182CA
004182CA > C0FF A6 sar bh,0A6
004182CD . 90 nop
004182CE . 8341 00 0F add dword ptr ds:[ecx],0F
004182D2 . 54 push esp
004182D3 . 2055 8B and byte ptr ss:[ebp-75],dl
004182D6 . EC in al,dx
004182D7 . 83C4 F1 add esp,-0F
004182DA . 83C4 0F add esp,0F
004182DD . B8 7F9B4000 mov eax,Ep_2_5_1.00409B7F ;注意,其实这个不是OEP......是我找了一个和OEP差不多的地方......
004182E2 . 50 push eax
004182E3 . C3 retn[code]
其他数值:
[code]0041836F \CB824100 dd Ep_2_5_1.004182CB
0041838F 23604000 dd Ep_2_5_1.00406023
另外,如果你把代码写在另外一个区段,oD就没法分析了哦!呵呵。
这个花指令只是简单的,如果有更深入的研究,说不定还可以防掉动态调试。。。。嘿嘿。
********************************
上面花指令突破:只要把0x4182CA的C0改成90即可,然后就暴露了:004182C1 > \FFFF ??? ; 未知命令
004182C3 ? 96 xchg eax,esi
004182C4 ?^ 70 83 jo short Ep_2_5_1.00418249
004182C6 ? 41 inc ecx
004182C7 ? 00EB add bl,ch
004182C9 ? 0090 FFA69083 add byte ptr ds:[eax+8390A6FF],dl
004182CF ? 41 inc ecx
004182D0 ? 000F add byte ptr ds:[edi],cl
004182D2 . 54 push esp
004182D3 . 2055 8B and byte ptr ss:[ebp-75],dl
004182D6 . EC in al,dx
004182D7 . 83C4 F1 add esp,-0F
004182DA . 83C4 0F add esp,0F
004182DD . B8 7F9B4000 mov eax,Ep_2_5_1.00409B7F
004182E2 . 50 push eax
004182E3 . C3 retn
额不对,貌似复制出来有问题呵呵,OD里显示还是没问题的。
先发那么多,如果有记起来什么东西再补上.
|