反检测技术(上)——反沙箱与反调试

admin 2026-04-02 05:17:24 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 本文深入探讨反检测技术中的反沙箱与反调试方法,详细列举了检测虚拟机特征、进程、MAC地址、时间加速及用户交互等反沙箱技术,并介绍了IsDebuggerPresent、CheckRemoteDebuggerPresent、NtGlobalFlag、硬件断点及时间检测等反调试技术,旨在帮助理解恶意软件如何逃避安全分析。 综合评分: 85 文章分类: 恶意软件,免杀,逆向分析,二进制安全,渗透测试


cover_image

反检测技术(上)——反沙箱与反调试

原创

pandazhengzheng pandazhengzheng

安全分析与研究

2026年3月31日 08:31 广东

一、前言概述

反检测技术用于逃避安全软件的分析和检测,本课将深入介绍反沙箱技术和反调试技术,帮助读者理解恶意软件如何逃避分析。

二、相关内容

2.1 反沙箱技术

原理:检测当前环境是否为沙箱或虚拟机,如果是则不执行恶意代码。

常见检测方法:

1. 检测虚拟机特征:

BOOL IsVM() {
    HKEY hKey;
    if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
                      "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0",
                      0, KEY_READ, &hKey) == ERROR_SUCCESS) {
        char identifier[256];
        DWORD size = sizeof(identifier);
        RegQueryValueExA(hKey, "Identifier", NULL, NULL, (LPBYTE)identifier, &size);
        RegCloseKey(hKey);

        if (strstr(identifier, "VMWARE") || strstr(identifier, "VBOX")) {
            return TRUE;
        }
    }
    return FALSE;
}

2. 检测虚拟机进程:

BOOL IsVMProcess() {
    const char* vmProcesses[] = {
        "vmtoolsd.exe",
        "vmwaretray.exe",
        "VBoxService.exe",
        "VBoxTray.exe"
    };

    // 遍历进程检查...
}

3. 检测虚拟机MAC地址:

BOOL IsVMMac() {
    // VMware MAC: 00:0C:29, 00:50:56
    // VirtualBox MAC: 08:00:27
    // 检查MAC地址...
}

4. 检测时间加速:

BOOL IsTimeAccelerated() {
    DWORD start = GetTickCount();
    Sleep(1000);
    DWORD end = GetTickCount();

&nbsp; &nbsp;&nbsp;if&nbsp;(end - start <&nbsp;900) {
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;TRUE;
&nbsp; &nbsp; }
&nbsp; &nbsp;&nbsp;return&nbsp;FALSE;
}

5. 检测用户交互:

BOOL&nbsp;IsUserInteractive()&nbsp;{
&nbsp; &nbsp; POINT pt1, pt2;
&nbsp; &nbsp; GetCursorPos(&pt1);
&nbsp; &nbsp; Sleep(1000);
&nbsp; &nbsp; GetCursorPos(&pt2);

&nbsp; &nbsp;&nbsp;if&nbsp;(pt1.x == pt2.x && pt1.y == pt2.y) {
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;FALSE;
&nbsp; &nbsp; }
&nbsp; &nbsp;&nbsp;return&nbsp;TRUE;
}

2.2 反调试技术

原理:检测当前进程是否被调试器附加,如果是则终止或改变行为。

常见检测方法:

1. IsDebuggerPresent:

if&nbsp;(IsDebuggerPresent()) {
&nbsp; &nbsp; ExitProcess(0);
}

2. CheckRemoteDebuggerPresent:

BOOL isDebuggerPresent = FALSE;
CheckRemoteDebuggerPresent(GetCurrentProcess(), &isDebuggerPresent);
if&nbsp;(isDebuggerPresent) {
&nbsp; &nbsp; ExitProcess(0);
}

3. NtGlobalFlag:

BOOL&nbsp;IsDebuggerPresent_NtGlobalFlag()&nbsp;{
&nbsp; &nbsp; PDWORD pNtGlobalFlag = (PDWORD)(__readgsqword(0x60) +&nbsp;0xBC);
&nbsp; &nbsp;&nbsp;if&nbsp;(*pNtGlobalFlag &&nbsp;0x70) {
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;TRUE;
&nbsp; &nbsp; }
&nbsp; &nbsp;&nbsp;return&nbsp;FALSE;
}

4. 硬件断点:

BOOL&nbsp;IsHardwareBreakpointPresent()&nbsp;{
&nbsp; &nbsp; CONTEXT ctx;
&nbsp; &nbsp; ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
&nbsp; &nbsp; GetThreadContext(GetCurrentThread(), &ctx);

&nbsp; &nbsp;&nbsp;if&nbsp;(ctx.Dr0 || ctx.Dr1 || ctx.Dr2 || ctx.Dr3) {
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;TRUE;
&nbsp; &nbsp; }
&nbsp; &nbsp;&nbsp;return&nbsp;FALSE;
}

5. 时间检测:

BOOL&nbsp;IsDebuggerPresent_RDTSC()&nbsp;{
&nbsp; &nbsp; DWORD64 start = __rdtsc();
&nbsp; &nbsp;&nbsp;int&nbsp;x =&nbsp;0;
&nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;i =&nbsp;0; i <&nbsp;100; i++) {
&nbsp; &nbsp; &nbsp; &nbsp; x += i;
&nbsp; &nbsp; }
&nbsp; &nbsp; DWORD64 end = __rdtsc();

&nbsp; &nbsp;&nbsp;if&nbsp;(end - start >&nbsp;1000) {
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;TRUE;
&nbsp; &nbsp; }
&nbsp; &nbsp;&nbsp;return&nbsp;FALSE;
}

2.3 实战案例分析

2.3.1 案例1:多层级反沙箱检测

攻击场景:恶意软件需要确保不在沙箱环境中执行,避免被自动化分析系统检测。


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:安全分析与研究 pandazhengzheng pandazhengzheng《反检测技术(上)——反沙箱与反调试》

评论:0   参与:  0