[原创]C++利用活跃变量分析清除基本块中的垃圾指令
2023-6-30 14:19:28 Author: bbs.pediy.com(查看原文) 阅读量:11 收藏

本文将主要介绍,清洗一个"Basic Block"中无用指令的原理及实现方案。该项目用到的主要技术包括Capstone和活跃变量分析,最后,以本人在工作时所遇到的一恶意样本中"带混淆加密算法"分析为例,展示了该项目的使用方式和实际效果

本文主要关注的是,如何通过虚拟地址(Virtual Address, VA)来获取文件中的对应数据,因而不再对PE结构进行详细解释,重点聚焦于文件偏移和虚拟地址之间的转换。

注: 本例来自一个恶意Loader中的解密算法部分(样本MD5为:B7D90C9D14D124A163F5B3476160E1CF),若对该样本的整体流程感兴趣,可阅读本人所撰写的该样本分析文章,可能会有所收获!
去混淆前:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

.text:00411190                               loc_411190:                   ; CODE XREF: decrypt_shellcode_411040+111↑j

.text:00411190 2B 7C 24 10                   sub     edi, [esp+6F4h+var_6E4]

.text:00411194 C7 84 24 78 01 00 00 C5 BC 71+mov     [esp+6F4h+var_57C], 4B71BCC5h

.text:00411194 4B

.text:0041119F C7 84 24 1C 02 00 00 53 8D 22+mov     [esp+6F4h+var_4D8], 14228D53h

.text:0041119F 14

.text:004111AA C7 84 24 A4 00 00 00 55 D3 1F+mov     [esp+6F4h+var_650], 4B1FD355h

.text:004111AA 4B

.text:004111B5 C7 84 24 EC 00 00 00 40 0D 8E+mov     [esp+6F4h+var_608], 458E0D40h

.text:004111B5 45

.text:004111C0 C7 84 24 D4 01 00 00 6E E9 24+mov     [esp+6F4h+var_520], 7524E96Eh

.text:004111C0 75

.text:004111CB C7 84 24 A0 01 00 00 FA 0B 77+mov     [esp+6F4h+var_554], 6B770BFAh

........

.text:00412994 81 84 24 F4 01 00 00 52 F7 57+add     [esp+6F4h+var_500], 5657F752h

.text:00412994 56

.text:0041299F 81 AC 24 08 02 00 00 5C EB 35+sub     [esp+6F4h+var_4EC], 1B35EB5Ch

.text:0041299F 1B

.text:004129AA 81 84 24 40 01 00 00 C4 CB 36+add     [esp+6F4h+var_5B4], 7336CBC4h

.text:004129AA 73

.text:004129B5 81 6C 24 28 8B 9F 9C 39       sub     [esp+6F4h+var_6CC], 399C9F8Bh

.text:004129BD 81 84 24 80 02 00 00 7E C6 AC+add     [esp+6F4h+var_474], 20ACC67Eh

.text:004129BD 20

.text:004129C8 8B C7                         mov     eax, edi

.text:004129CA C1 E0 04                      shl     eax, 4

.text:004129CD 89 44 24 14                   mov     [esp+6F4h+var_6E0], eax

.text:004129D1 8B 84 24 B0 02 00 00          mov     eax, [esp+6F4h+var_444]

.text:004129D8 01 44 24 14                   add     [esp+6F4h+var_6E0], eax

.text:004129DC 81 3D 74 44 83 00 96 01 00 00 cmp     uBytes, 196h

.text:004129E6 8D 34 3B                      lea     esi, [ebx+edi]

.text:004129E9 75 0E                         jnz     short loc_4129F9

希望大家读的开心,有所收获。目前,本人也在学习基本块合并的相关知识,使得清洗范围可以扩大到一个函数或整个程序,希望各位大佬可以给出更多相关资料和宝贵意见。对于本文有任何想问的以及意见也欢迎随时指出。


文章来源: https://bbs.pediy.com/thread-277825.htm
如有侵权请联系:admin#unsafe.sh