|  | 
| Ghost32.exe如何成功压缩+兼谈某些壳对CertificateTable处理 ↑
 
 2008.02.08
 今天是农历戊子年大年初二,fly祝福朋友们春节快乐平安如意
 
 拜完年,再看看UnPacKcN 论坛『 悬赏问答 』版h2bx86提出悬赏引用:
 [求助] 用什么软件能把GHOST11中的GHOST32.exe 压缩(可执行文件压缩)
 http://www.unpack.cn/viewthread.php?tid=22062简单分析后发现一个现象,特记录如下
 _____________________________________________________________
 一.压缩Ghost32.exe
 
 
 ghost.exe是NE,已经使用UPX V1.20压缩。ghost32.exe是PE,先用最爱的UPX来压缩吧复制内容到剪贴板代码:
 upx302w.exe --best ghost32.exe
 3280264 ->   1244040   37.92%    win32/pe     ghost32.exe再看看其他压缩选项复制内容到剪贴板代码:
 upx302w.exe ghost32.exe
 3280264 ->   1262984   38.50%    win32/pe     ghost32.exe复制内容到剪贴板代码:
 upx302w.exe -9 ghost32.exe
 3280264 ->   1244552   37.94%    win32/pe     ghost32.exe如果你有时间可以用这个--ultra-brute选项,呵呵,很多圈复制内容到剪贴板代码:
 upx302w.exe --ultra-brute ghost32.exe
 3280264 ->   1055624   32.18%    win32/pe     ghost32.exe但是程序压缩后无法运行了,貌似有检验啊
 
 _____________________________________________________________
 二.调试
 
 
 但是程序貌似有检验,压缩后无法运行了
 怎么办?调试啊。拿出OnlyDBG,载入加壳后的文件
 BP CreateFileA 跟踪来到这里复制内容到剪贴板代码:
 004AB33A    FF15 38716300   call dword ptr ds:[637138] ; kernel32.CreateFileA
 004AB340    8BF0            mov esi,eax
 004AB342    83C8 FF         or eax,FFFFFFFF
 004AB345    3BF0            cmp esi,eax
 004AB347    74 34           je short 004AB37D
 004AB349    57              push edi
 004AB34A    33C0            xor eax,eax
 004AB34C    895D F0         mov dword ptr ss:[ebp-10],ebx
 004AB34F    8D7D F4         lea edi,dword ptr ss:[ebp-C]
 004AB352    AB              stos dword ptr es:[edi]
 004AB353    AB              stos dword ptr es:[edi]
 004AB354    8D45 F0         lea eax,dword ptr ss:[ebp-10]
 004AB357    50              push eax
 004AB358    53              push ebx
 004AB359    56              push esi
 004AB35A    FF15 D8736300   call dword ptr ds:[6373D8] ; imagehlp.ImageGetCertificateHeader
 004AB360    8BD8            mov ebx,eax
 //原版ImageGetCertificateHeader后返回1,而加壳版返回0
 004AB362    4B              dec ebx
 004AB363    F7DB            neg ebx
 004AB365    1ADB            sbb bl,bl
 004AB367    56              push esi
 004AB368    FEC3            inc bl
 004AB36A    FF15 B0706300   call dword ptr ds:[6370B0] ; kernel32.CloseHandle原版和加壳版调用ImageGetCertificateHeader后返回的数据不同,可疑啊
 
 _____________________________________________________________
 三.CertificateTable
 
 
 ImageGetCertificateHeader,搜索了一下没找到详细的信息
 顾名思义,是获取PE中CertificateTable信息的
 
 用OnlyDBG打开原版ghost32.exe,数据窗口中Ctrl+G:00400000
 点右键->特殊->PE文件头,查看PEHeader信息复制内容到剪贴板代码:
 00400168    00000000    DD 00000000          ;  Export Table address = 0
 0040016C    00000000    DD 00000000          ;  Export Table size = 0
 00400170    80F82D00    DD 002DF880          ;  Import Table address = 2DF880
 00400174    F0000000    DD 000000F0          ;  Import Table size = F0 (240.)
 00400178    00503800    DD 00385000          ;  Resource Table address = 385000
 0040017C    482F0000    DD 00002F48          ;  Resource Table size = 2F48 (12104.)
 00400180    00000000    DD 00000000          ;  Exception Table address = 0
 00400184    00000000    DD 00000000          ;  Exception Table size = 0
 00400188    00F83100    DD 0031F800          ;  Certificate File pointer = 31F800
 0040018C    88150000    DD 00001588          ;  Certificate Table size = 1588 (5512.)
 00400190    00000000    DD 00000000          ;  Relocation Table address = 0
 00400194    00000000    DD 00000000          ;  Relocation Table size = 0
 00400198    50772300    DD 00237750          ;  Debug Data address = 237750
 0040019C    1C000000    DD 0000001C          ;  Debug Data size = 1C (28.)原来ghost32.exe需要取CertificateTable数据验证
 奇怪的是LordPE显示此名为Security
 
 CFF Explorer也是显示为Security
 
 StudPE显示为Certificate Table
 
 _____________________________________________________________
 四.解决问题
 
 
 ghost32.exe的SectionAlignment=FileAlignment复制内容到剪贴板代码:
 00400124    00004000    DD 00400000          ;  ImageBase = 400000
 00400128    00100000    DD 00001000          ;  SectionAlignment = 1000
 0040012C    00100000    DD 00001000          ;  FileAlignment = 1000
 00400130    0400        DW 0004              ;  MajorOSVersion = 4
 00400132    0000        DW 0000              ;  MinorOSVersion = 0
 00400134    0000        DW 0000              ;  MajorImageVersion = 0
 00400136    0000        DW 0000              ;  MinorImageVersion = 0
 00400138    0400        DW 0004              ;  MajorSubsystemVersion = 4
 0040013A    0000        DW 0000              ;  MinorSubsystemVersion = 0
 0040013C    00000000    DD 00000000          ;  Reserved
 00400140    00803800    DD 00388000          ;  SizeOfImage = 388000 (3702784.)
 00400144    00100000    DD 00001000          ;  SizeOfHeaders = 1000 (4096.)Certificate File pointer = 31F800 ,0031F800处数据在附加数据里面
 
 UPX压缩保留了附加数据,但是把Certificate File pointer和Size信息都清0了,因此UPX压缩后的文件验证失败而无法运行起来
 因此我们把UPX压缩后的文件修正新的CertificateTable信息即可
 如何修正?很简单
 WinHex打开原版ghost32.exe,->转到偏移量:0031F800,复制0031F800处一行16进制数值复制内容到剪贴板代码:
 0031F800   88 15 00 00 00 02 02 00  30 82 15 76 06 09 2A 86   ?......0?v..*?
 0031F810   48 86 F7 0D 01 07 02 A0  82 15 67 30 82 15 63 02   H嗺....爞.g0?c.
 0031F820   01 01 31 0B 30 09 06 05  2B 0E 03 02 1A 05 00 30   ..1.0...+......0
 0031F830   68 06 0A 2B 06 01 04 01  82 37 02 01 04 A0 5A 30   h..+....?...燴0再用WinHex打开UPX压缩后的ghost32.exe,查找16进制值
 搜索刚才复制的0031F800处数据:88150000000202003082157606092A86复制内容到剪贴板代码:
 00100600   88 15 00 00 00 02 02 00  30 82 15 76 06 09 2A 86   ?......0?v..*?
 00100610   48 86 F7 0D 01 07 02 A0  82 15 67 30 82 15 63 02   H嗺....爞.g0?c.
 00100620   01 01 31 0B 30 09 06 05  2B 0E 03 02 1A 05 00 30   ..1.0...+......0
 00100630   68 06 0A 2B 06 01 04 01  82 37 02 01 04 A0 5A 30   h..+....?...燴0搜索到00100600处,比较此处上下数据与0031F800处相同
 嗯,CertificateTable找到了
 用LordPE打开UPX压缩后的ghost32.exe,修改Security RVA=00100600 Size=1588
 
 点击Save,压缩后的ghost32.exe可以运行了
 
 但是请注意:Ghost类软件尽量少改,万一备份的系统镜像有问题就不好了。
 
 _____________________________________________________________
 五.壳对CertificateTable处理
 
 
 为了这个帖子,我测试了几个压缩壳对ghost32.exe的处理
 UPX、NsPacK、AsPacK、UPacK、nPack、KByS、FSG、PECompact等等,都没有处理好CertificateTable引用:
 Warning:RLPack has detected a security certificate apended to file.Since this certificate will not work after file packing it will be stripped!RlPacK虽然压缩是有提示,但也没处理好
 
 如果有壳还在继续升级,希望壳们能够处理好CertificateTable问题
 好了,就这样吧
 一元复始万象更新
 | 
 |