SMC出题记录

发布时间 2023-10-06 12:19:55作者: zydt10

SMC出题记录:

SMC:当我们用IDA反汇编时看到的就是异或前的机器码,也就是加过密的。而程序运行中会自己调用for循环解密机器码,所以运行起来就没问题,而对静态分析会产生干扰

出题源码:

#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>

void test(){
    printf("Congratulation!!!\n");//说明解密成功
    return;
}
void decrypt() {
    DWORD old;
    VirtualProtect(test, 4096, PAGE_EXECUTE_READWRITE, &old); // 修改内存页权限
    for (int i = 0; i < 27; i++)//这里的27取决于test的字节码长度
    {
        *((char*)test + i) ^= 0x90;//SMC解密
    }
    VirtualProtect(test, 4096, old, NULL);
}

int main()
{
    printf("SMC Test\n");
    decrypt();
    test();
}

在这里取出要加密的test的字节码

image

并把字节码按照decrypt函数的密钥(0x90)xor下

a=[0x55, 0x48, 0x89, 0xE5, 0x48, 0x83, 0xEC, 0x20, 0x48, 0x8D, 0x0D, 0xA1, 0x2A, 0x00, 0x00, 0xE8, 0xAC, 0x15, 0x00, 0x00, 0x90, 0x48, 0x83, 0xC4, 0x20, 0x5D, 0xC3]
for i in range(len(a)):
    print('{:02X}'.format(a[i]),end='')#方便在010 Editor里面直接ctrl+F查找替换
print()#换行
for i in range(len(a)):
    print('{:02X}'.format(a[i]^0x90),end='')#限制格式去掉0x,转为大写,方便后面在010 Editor里面替换字节码
print('\n',len(a))

找到test函数的位置:image

Ctrl+Shift+V替换!image

此时SMC加密就完成了

拖入IDA查看

image

可以看到test在静态分析时是被混淆的

我们在decrypt函数后打好断点,F7跟进

image

可以看出此时已经被解密好了

image

CP一下后面没定义的字节码

然后就反汇编成功了

image

程序也可以正常执行到这一步