{"id":1225,"date":"2023-02-20T13:41:43","date_gmt":"2023-02-20T05:41:43","guid":{"rendered":"https:\/\/www.aqwu.net\/wp\/?p=1225"},"modified":"2023-02-20T13:44:17","modified_gmt":"2023-02-20T05:44:17","slug":"%e9%9a%90%e8%97%8f%e5%9c%a8%e4%bc%97%e7%9b%ae%e7%9d%bd%e7%9d%bd%e4%b9%8b%e4%b8%8b-%e9%97%b4%e6%8e%a5%e7%b3%bb%e7%bb%9f%e5%91%bc%e5%8f%ab%e5%b7%b2%e6%ad%bb%ef%bc%81%e8%87%aa%e5%ae%9a%e4%b9%89","status":"publish","type":"post","link":"https:\/\/www.aqwu.net\/wp\/?p=1225","title":{"rendered":"\u9690\u85cf\u5728\u4f17\u76ee\u777d\u777d\u4e4b\u4e0b &#8211; \u95f4\u63a5\u7cfb\u7edf\u547c\u53eb\u5df2\u6b7b\uff01\u81ea\u5b9a\u4e49\u8c03\u7528\u5806\u6808\u4e07\u5c81"},"content":{"rendered":"\n<p>\u6ce8\u610f\uff1a<strong><em>\u8fd9\u662f\u5173\u4e8e\u5806\u6808\u8ddf\u8e2a\u89c4\u907f\u7684\u7b2c\u4e8c\u90e8\u5206\u535a\u5ba2\u3002\u7b2c\u4e00\u90e8\u5206\u53ef\u4ee5<a href=\"https:\/\/www.aqwu.net\/wp\/?p=1222\">\u5728\u8fd9\u91cc<\/a>\u627e\u5230\u3002<\/em><\/strong><\/p>\n\n\n\n<p>\u8fd9\u662f\u6211 3 \u5929\u524d\u5199\u7684\u5173\u4e8e\u4ee3\u7406 DLL \u52a0\u8f7d\u4ee5\u9690\u85cf\u5bfc\u81f4\u7528\u6237\u5206\u914d\u7684 RX \u533a\u57df\u7684\u53ef\u7591\u5806\u6808\u8ddf\u8e2a\u7684\u535a\u5ba2\u7684\u7b2c\u4e8c\u90e8\u5206\u3002\u6211\u4e0d\u4f1a\u6df1\u5165\u8ba8\u8bba\u5806\u6808\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u56e0\u4e3a\u6211\u5df2\u7ecf\u5728\u4e4b\u524d\u7684\u535a\u5ba2\u4e2d\u4ecb\u7ecd\u4e86\u8fd9\u4e00\u70b9\uff0c\u53ef\u4ee5\u4ece\u4e0a\u9762\u7684\u94fe\u63a5\u8bbf\u95ee\u3002\u6211\u4eec\u4e4b\u524d\u770b\u5230\uff0c\u6211\u4eec\u53ef\u4ee5\u64cd\u7eb5 \u548c \u6307\u4ee4\u6765\u8bf7\u6c42\u7a97\u53e3\u56de\u8c03\u4ee5\u8c03\u7528 API \u8c03\u7528\u3002\u4f46\u662f\uff0c\u5806\u6808\u8ddf\u8e2a\u68c0\u6d4b\u8fdc\u8fdc\u8d85\u51fa\u4e86\u641c\u5bfb DLL \u52a0\u8f7d\u7684\u8303\u56f4\u3002\u5c06\u53cd\u5c04 DLL \u6ce8\u5165\u672c\u5730\u6216\u8fdc\u7a0b\u8fdb\u7a0b\u65f6\uff0c\u5fc5\u987b\u8c03\u7528 API \u8c03\u7528\uff0c\u4f8b\u5982 \/\uff0c\u5b83\u95f4\u63a5\u8c03\u7528 \/\u3002\u4f46\u662f\uff0c\u5f53\u60a8\u68c0\u67e5\u5408\u6cd5 API \u8c03\u7528\u7684\u8c03\u7528\u5806\u6808\u65f6\uff0c\u60a8\u4f1a\u6ce8\u610f\u5230\u50cf WINAPI \u8fd9\u6837\u7684\u4e3b\u8981\u7531\u975e Windows DLL \u51fd\u6570\u8c03\u7528\u3002\u5927\u591a\u6570Windows DLL\u5c06\u76f4\u63a5\u8c03\u7528\/\u3002\u4e0b\u9762\u662f\u8c03\u7528 \u65f6\u7684\u8c03\u7528\u5806\u6808\u7684\u5feb\u901f\u793a\u4f8b\u3002<\/p>\n\n\n\n<p>.<code>calljmpLoadLibraryVirtualAllocExVirtualProtectExNtAllocateVirtualMemoryNtProtectVirtualMemoryVirtualAlloc\/VirtualProtectNtAllocateVirtualMemoryNtProtectVirtualMemoryNtProtectVirtualMemoryRtlAllocateHeap<\/code><\/p>\n\n\n\n<p>\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/0xdarkvortex.dev\/hiding-in-plainsight\/<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/0xdarkvortex.dev\/assets\/images\/2023-01-29-Hiding-In-Plainsight\/rtlprotectheap.png\"><img decoding=\"async\" src=\"https:\/\/0xdarkvortex.dev\/assets\/images\/2023-01-29-Hiding-In-Plainsight\/rtlprotectheap.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>\u8fd9\u610f\u5473\u7740\uff0c\u7531\u4e8e ntdll.dll \u4e0d\u4f9d\u8d56\u4e8e\u4efb\u4f55\u5176\u4ed6 DLL\uff0c\u56e0\u6b64 ntdll \u4e2d\u6240\u6709\u9700\u8981\u5bf9\u5185\u5b58\u533a\u57df\u4f7f\u7528\u6743\u9650\u7684\u51fd\u6570\u90fd\u5c06\u76f4\u63a5\u8c03\u7528 NTAPI\u3002\u56e0\u6b64\uff0c\u8fd9\u610f\u5473\u7740\u5982\u679c\u6211\u4eec\u80fd\u591f\u901a\u8fc7 ntdll \u672c\u8eab\u7684\u5e72\u51c0\u5806\u6808\u91cd\u65b0\u8def\u7531\u6211\u4eec\u7684\u8c03\u7528.dll\u6211\u4eec\u6839\u672c\u4e0d\u7528\u62c5\u5fc3\u68c0\u6d4b\u3002\u5927\u591a\u6570\u7ea2\u961f\u4f9d\u9760\u95f4\u63a5\u7cfb\u7edf\u8c03\u7528\u6765\u907f\u514d\u68c0\u6d4b\u3002\u5bf9\u4e8e\u95f4\u63a5\u7cfb\u7edf\u8c03\u7528\uff0c\u60a8\u53ea\u9700\u5728\u4ed4\u7ec6\u521b\u5efa\u5806\u6808\u540e\u8df3\u8f6c\u5230\u6307\u4ee4\u5730\u5740\uff0c\u4f46\u8fd9\u91cc\u7684\u95ee\u9898\u662f\u95f4\u63a5\u7cfb\u7edf\u8c03\u7528\u53ea\u4f1a\u66f4\u6539 ntdll.dll \u4e2d\u7684\u6307\u4ee4\u3002 \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u662f\u7cfb\u7edf\u8c03\u7528\u6307\u4ee4\u5728\u7cfb\u7edf\u8c03\u7528\u5b8c\u6210\u540e\u9700\u8981\u8fd4\u56de\u5230\u7684\u4f4d\u7f6e\u3002\u4f46\u662f\uff0c\u8fd4\u56de\u5730\u5740\u4e0b\u65b9\u7684\u5176\u4f59\u5806\u6808\u5728\u4ece RX \u533a\u57df\u51fa\u73b0\u65f6\u4ecd\u7136\u4f1a\u53d7\u5230\u6000\u7591\u3002\u5982\u679c EDR \u68c0\u67e5 NTAPI \u7684\u5b8c\u6574\u5806\u6808\uff0c\u5219\u53ef\u4ee5\u8f7b\u677e\u8bc6\u522b\u8fd4\u56de\u5730\u5740\u6700\u7ec8\u4f1a\u8fd4\u56de\u5230\u7528\u6237\u5206\u914d\u7684 RX \u533a\u57df\u3002\u8fd9\u610f\u5473\u7740\uff0c\u8fd4\u56de\u5730\u5740\u5230 ntdll.dll \u533a\u57df\uff0c\u4f46\u6e90\u81ea RX \u533a\u57df\u7684\u5806\u6808\u662f 100% \u5f02\u5e38\uff0c\u8bef\u62a5\u7684\u53ef\u80fd\u6027\u4e3a\u96f6\u3002\u5bf9\u4e8e\u5728\u5185\u6838\u4e2d\u4f7f\u7528 ETW \u8fdb\u884c\u7cfb\u7edf\u8c03\u7528\u8ddf\u8e2a\u7684 EDR \u6765\u8bf4\uff0c\u8fd9\u662f\u4e00\u4e2a\u8f7b\u677e\u7684\u80dc\u5229\u3002<code>NtAllocateVirtualMemory<\/code><code>syscall<\/code><code>return address<\/code><code>syscall<\/code><code>Return Address<\/code><\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u6211\u82b1\u4e86\u4e00\u4e9b\u65f6\u95f4\u53cd\u8f6c\u4e86\u51e0\u4e2a ntdll.dll \u51fd\u6570\uff0c\u53d1\u73b0\u53ea\u8981\u6709\u4e00\u70b9\u6c47\u7f16\u77e5\u8bc6\u548c Windows \u56de\u8c03\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u6211\u4eec\u5e94\u8be5\u80fd\u591f\u64cd\u7eb5\u56de\u8c03\u6765\u8c03\u7528\u4efb\u4f55 NTAPI \u51fd\u6570\u3002\u5bf9\u4e8e\u6b64\u535a\u5ba2\uff0c\u6211\u4eec\u5c06\u4ee5\u5176\u4e2d\u4e3a\u4f8b\uff0c\u6211\u4eec\u5c06<a href=\"https:\/\/github.com\/paranoidninja\/Proxy-DLL-Loads\">\u4ece\u6211\u4eec\u7684\u90e8\u5206 I \u535a\u5ba2\u4e2d\u9009\u62e9\u4ee3\u7801<\/a>\u5e76\u5bf9\u5176\u8fdb\u884c\u4fee\u6539\u3002\u6211\u4eec\u5c06\u4ee5\u53ef\u4ee5\u6267\u884c\u56de\u8c03\u51fd\u6570\u7684\u76f8\u540c API \u4e3a\u4f8b\u3002\u4f46\u662f\uff0c\u8fd9\u6b21\u6211\u4eec\u5c06\u4f20\u9012\u6307\u5411\u7ed3\u6784\u7684\u6307\u9488\uff0c\u800c\u4e0d\u662f\u50cf\u5728 Dll \u4ee3\u7406\u7684\u60c5\u51b5\u4e0b\u90a3\u6837\u4f20\u9012\u6307\u5411\u5b57\u7b26\u4e32\u7684\u6307\u9488\u3002\u8fd9\u6b21\u6211\u4eec\u8fd8\u5c06\u901a\u8fc7\u786e\u4fdd\u6240\u6709\u5fc5\u8981\u7684\u4fe1\u606f\u90fd\u5728\u7ed3\u6784\u4e2d\u6765\u907f\u514d\u4efb\u4f55\u5168\u5c40\u53d8\u91cf\uff0c\u56e0\u4e3a\u6211\u4eec\u5728\u7f16\u5199shellcode\u65f6\u4e0d\u80fd\u6709\u5168\u5c40\u53d8\u91cf\u3002\u6839\u636e msdn \u7684\u5b9a\u4e49\u662f\uff1a<code>NtAllocateVirtualMemory<\/code><code>TpAllocWork<\/code><code>NtAllocateVirtualMemory<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">__kernel_entry NTSYSCALLAPI NTSTATUS NtAllocateVirtualMemory(\n  [in]      HANDLE    ProcessHandle,\n  [in, out] PVOID     *BaseAddress,\n  [in]      ULONG_PTR ZeroBits,\n  [in, out] PSIZE_T   RegionSize,\n  [in]      ULONG     AllocationType,\n  [in]      ULONG     Protect\n);<\/pre>\n\n\n\n<p>\u8fd9\u610f\u5473\u7740\uff0c\u6211\u4eec\u9700\u8981\u5c06\u7ed3\u6784\u5185\u7684\u6307\u9488\u53ca\u5176\u53c2\u6570\u4f20\u9012\u7ed9\u56de\u8c03\uff0c\u4ee5\u4fbf\u6211\u4eec\u7684\u56de\u8c03\u53ef\u4ee5\u4ece\u7ed3\u6784\u4e2d\u63d0\u53d6\u8fd9\u4e9b\u4fe1\u606f\u5e76\u6267\u884c\u5b83\u3002\u6211\u4eec\u5c06\u5ffd\u7565\u4fdd\u6301\u9759\u6001\u7684\u53c2\u6570\uff0c\u4f8b\u5982\u54ea\u4e2a\u603b\u662f\u96f6\uff0c\u54ea\u4e2a\u603b\u662f\u5341\u516d\u8fdb\u5236\u4e2d\u7684\u54ea\u4e2a\u662f\u3002\u56e0\u6b64\uff0c\u6dfb\u52a0\u5176\u4f59\u53c2\u6570\uff0c\u7ed3\u6784\u5c06\u5982\u4e0b\u6240\u793a\uff1a<code>NtAllocateVirtualMemory<\/code><code>ULONG_PTR ZeroBits<\/code><code>ULONG AllocationType<\/code><code>MEM_RESERVE|MEM_COMMIT<\/code><code>0x3000<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">typedef struct _NTALLOCATEVIRTUALMEMORY_ARGS {\n    UINT_PTR pNtAllocateVirtualMemory;   \/\/ pointer to NtAllocateVirtualMemory - rax\n    HANDLE hProcess;                     \/\/ HANDLE ProcessHandle - rcx\n    PVOID* address;                      \/\/ PVOID *BaseAddress - rdx; ULONG_PTR ZeroBits - 0 - r8\n    PSIZE_T size;                        \/\/ PSIZE_T RegionSize - r9; ULONG AllocationType - MEM_RESERVE|MEM_COMMIT = 3000 - stack pointer\n    ULONG permissions;                   \/\/ ULONG Protect - PAGE_EXECUTE_READ - 0x20 - stack pointer\n} NTALLOCATEVIRTUALMEMORY_ARGS, *PNTALLOCATEVIRTUALMEMORY_ARGS;<\/pre>\n\n\n\n<p>\u7136\u540e\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u6240\u9700\u7684\u53c2\u6570\u521d\u59cb\u5316\u7ed3\u6784\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u6307\u9488\u4f20\u9012\u7ed9\u5e76\u8c03\u7528\u7528\u6c47\u7f16\u7f16\u5199\u7684\u51fd\u6570\u3002<code>TpAllocWork<\/code><code>WorkCallback<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#include &lt;windows.h&gt;\n#include &lt;stdio.h&gt;\n\ntypedef NTSTATUS (NTAPI* TPALLOCWORK)(PTP_WORK* ptpWrk, PTP_WORK_CALLBACK pfnwkCallback, PVOID OptionalArg, PTP_CALLBACK_ENVIRON CallbackEnvironment);\ntypedef VOID (NTAPI* TPPOSTWORK)(PTP_WORK);\ntypedef VOID (NTAPI* TPRELEASEWORK)(PTP_WORK);\n\ntypedef struct _NTALLOCATEVIRTUALMEMORY_ARGS {\n    UINT_PTR pNtAllocateVirtualMemory;   \/\/ pointer to NtAllocateVirtualMemory - rax\n    HANDLE hProcess;                     \/\/ HANDLE ProcessHandle - rcx\n    PVOID* address;                      \/\/ PVOID *BaseAddress - rdx; ULONG_PTR ZeroBits - 0 - r8\n    PSIZE_T size;                        \/\/ PSIZE_T RegionSize - r9; ULONG AllocationType - MEM_RESERVE|MEM_COMMIT = 3000 - stack pointer\n    ULONG permissions;                   \/\/ ULONG Protect - PAGE_EXECUTE_READ - 0x20 - stack pointer\n} NTALLOCATEVIRTUALMEMORY_ARGS, *PNTALLOCATEVIRTUALMEMORY_ARGS;\n\nextern VOID CALLBACK WorkCallback(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WORK Work);\n\nint main() {\n    LPVOID allocatedAddress = NULL;\n    SIZE_T allocatedsize = 0x1000;\n\n    NTALLOCATEVIRTUALMEMORY_ARGS ntAllocateVirtualMemoryArgs = { 0 };\n    ntAllocateVirtualMemoryArgs.pNtAllocateVirtualMemory = (UINT_PTR) GetProcAddress(GetModuleHandleA(\"ntdll\"), \"NtAllocateVirtualMemory\");\n    ntAllocateVirtualMemoryArgs.hProcess = (HANDLE)-1;\n    ntAllocateVirtualMemoryArgs.address = &amp;allocatedAddress;\n    ntAllocateVirtualMemoryArgs.size = &amp;allocatedsize;\n    ntAllocateVirtualMemoryArgs.permissions = PAGE_EXECUTE_READ;\n\n    FARPROC pTpAllocWork = GetProcAddress(GetModuleHandleA(\"ntdll\"), \"TpAllocWork\");\n    FARPROC pTpPostWork = GetProcAddress(GetModuleHandleA(\"ntdll\"), \"TpPostWork\");\n    FARPROC pTpReleaseWork = GetProcAddress(GetModuleHandleA(\"ntdll\"), \"TpReleaseWork\");\n\n    PTP_WORK WorkReturn = NULL;\n    ((TPALLOCWORK)pTpAllocWork)(&amp;WorkReturn, (PTP_WORK_CALLBACK)WorkCallback, &amp;ntAllocateVirtualMemoryArgs, NULL);\n    ((TPPOSTWORK)pTpPostWork)(WorkReturn);\n    ((TPRELEASEWORK)pTpReleaseWork)(WorkReturn);\n\n    WaitForSingleObject((HANDLE)-1, 0x1000);\n    printf(\"allocatedAddress: %p\\n\", allocatedAddress);\n    getchar();\n\n    return 0;\n}\n<\/pre>\n\n\n\n<p>\u73b0\u5728\u8fd9\u5c31\u662f\u4e8b\u60c5\u53d8\u5f97\u6709\u8da3\u7684\u5730\u65b9\u3002\u5728DLL\u4ee3\u7406\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ea\u7528\u4e00\u4e2a\u53c2\u6570\u6267\u884c\uff0c\u5373\u8981\u52a0\u8f7d\u7684DLL\u7684\u540d\u79f0\uff0c\u8be5\u540d\u79f0\u88ab\u4f20\u9012\u5230\u5bc4\u5b58\u5668\u3002\u4f46\u5728 \u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u603b\u5171\u6709 6 \u4e2a\u53c2\u6570\u3002\u8fd9\u610f\u5473\u7740\u524d\u56db\u4e2a\u53c2\u6570\u8fdb\u5165\u5feb\u901f\u8c03\u7528\u5bc4\u5b58\u5668\uff0c\u5373 \u548c\u3002\u4f46\u662f\uff0c\u5728\u4e3a\u6211\u4eec\u7684 4 \u4e2a\u5bc4\u5b58\u5668\u5206\u914d\u4e00\u4e9b\u5f52\u4f4d\u7a7a\u95f4\u540e\uff0c\u5fc5\u987b\u5c06\u5269\u4f59\u7684\u4e24\u4e2a\u53c2\u6570\u63a8\u9001\u5230\u5806\u6808\u3002\u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u7684\u5806\u6808\u9876\u90e8\u5f53\u524d\u5305\u542b 0ffset 0x130 \u5904\u7684\u5185\u90e8 NTAPI \u51fd\u6570\u7684\u8fd4\u56de\u503c\u3002\u8fd9\u5c31\u662f\u8c03\u7528\u56de\u8c03\u51fd\u6570\u65f6\u8c03\u7528\u5806\u6808\u7684\u6837\u5b50\u3002<code>LoadLibrary<\/code><code>RCX<\/code><code>NtAllocateVirtualMemory<\/code><code>RCX, RDX, R8<\/code><code>R9<\/code><code>TppWorkpExecuteCallback<\/code><code>WorkCallback<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/0xdarkvortex.dev\/assets\/images\/2023-01-29-Hiding-In-Plainsight\/TppStack_1.png\"><img decoding=\"async\" src=\"https:\/\/0xdarkvortex.dev\/assets\/images\/2023-01-29-Hiding-In-Plainsight\/TppStack_1.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/0xdarkvortex.dev\/assets\/images\/2023-01-29-Hiding-In-Plainsight\/TppStack_0.png\"><img decoding=\"async\" src=\"https:\/\/0xdarkvortex.dev\/assets\/images\/2023-01-29-Hiding-In-Plainsight\/TppStack_0.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>\u73b0\u5728\u95ee\u9898\u6765\u4e86\u3002\u5982\u679c\u4f60\u4fee\u6539\u8fd4\u56de\u5730\u5740\u6240\u5728\u7684\u5806\u6808\u9876\u90e8\uff0c\u4e3a 4 \u4e2a\u5bc4\u5b58\u5668\u6dfb\u52a0\u5f52\u4f4d\u7a7a\u95f4\u5e76\u5411\u5176\u6dfb\u52a0\u53c2\u6570\uff0c\u6574\u4e2a\u5806\u6808\u5e27\u5c06\u9677\u5165\u6298\u817e\u548c\u6df7\u4e71\u5806\u6808\u5c55\u5f00\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u5fc5\u987b\u5728\u4e0d\u66f4\u6539\u5806\u6808\u5e27\u672c\u8eab\u7684\u60c5\u51b5\u4e0b\u4fee\u6539\u5806\u6808\uff0c\u800c\u53ea\u9700\u66f4\u6539\u5806\u6808\u5e27\u4e2d\u7684\u503c\u3002\u6bcf\u4e2a\u90fd\u4ece\u4e0a\u56fe\u6240\u793a\u7684\u84dd\u7ebf\u5f00\u59cb\u548c\u7ed3\u675f\u3002\u6211\u4eec\u7684\u5806\u6808\u6846\u67b6\u672c\u8eab\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u6765\u5bb9\u7eb3 6 \u4e2a\u53c2\u6570\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u7684\u4e0b\u4e00\u6b65\u662f\u4ece\u6211\u4eec\u7684\u7ed3\u6784\u4e2d\u63d0\u53d6\u6570\u636e\uff0c\u5e76\u5c06\u5176\u79fb\u52a8\u5230\u76f8\u5e94\u7684\u5bc4\u5b58\u5668\u548c\u5806\u6808\u4e2d\u3002\u5f53\u6211\u4eec\u8c03\u7528\u65f6\uff0c\u6211\u4eec\u5c06\u6307\u5411\u7ed3\u6784\u7684\u6307\u9488\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u8fd9\u610f\u5473\u7740\u6211\u4eec\u6307\u5411\u7ed3\u6784\u7684\u6307\u9488\u73b0\u5728\u5e94\u8be5\u5728\u5bc4\u5b58\u5668\u4e2d\u3002\u6211\u4eec\u7ed3\u6784\u4e2d\u7684\u6bcf\u4e2a\u503c\u4e3a 8 \u4e2a\u5b57\u8282\uff08\u5bf9\u4e8e x64\uff0c\u5bf9\u4e8e x86\uff0c\u5b83\u5c06\u662f 4 \u4e2a\u5b57\u8282\uff09\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u5c06\u4ece\u7ed3\u6784\u4e2d\u63d0\u53d6\u8fd9\u4e9b QWORD \u503c\uff0c\u5e76\u5728\u8c03\u6574\u5f52\u4f4d\u7a7a\u95f4\u540e\u5c06\u5176\u79fb\u52a8\u5230\u5806\u6808\u4e0a\u7684\u5269\u4f59\u503c\u3002\u6839\u636e&nbsp;<a href=\"https:\/\/learn.microsoft.com\/en-us\/cpp\/build\/x64-calling-convention?view=msvc-170\">msdn \u6587\u6863<\/a>\uff0c\u7a97\u53e3\u4e2d x64 \u51fd\u6570\u7684\u8c03\u7528\u7ea6\u5b9a\u4e3a\uff1a<code>stack frame<\/code><code>TppWorkpExecuteCallback<\/code><code>NTALLOCATEVIRTUALMEMORY_ARGS<\/code><code>TpAllocWork<\/code><code>NTALLOCATEVIRTUALMEMORY_ARGS<\/code><code>WorkCallback<\/code><code>RDX<\/code><code>RCX, RDX, R8, R9<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">__kernel_entry NTSYSCALLAPI NTSTATUS NtAllocateVirtualMemory(\n  [in]      HANDLE    ProcessHandle,  \/\/ goes into rcx\n  [in, out] PVOID     *BaseAddress,   \/\/ goes into rdx\n  [in]      ULONG_PTR ZeroBits,       \/\/ goes into r8\n  [in, out] PSIZE_T   RegionSize,     \/\/ goes into r9\n  [in]      ULONG     AllocationType, \/\/ goes to stack after adjusting homing space for 4 arguments\n  [in]      ULONG     Protect         \/\/ goes to stack below the 5th argument after adjusting homing space for 4 arguments\n);\n<\/pre>\n\n\n\n<p>\u5c06\u6b64\u903b\u8f91\u878d\u5408\u5230\u6c47\u7f16\u5c06\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">section .text\n\nglobal WorkCallback\n\nWorkCallback:\n    mov rbx, rdx                ; backing up the struct as we are going to stomp rdx\n    mov rax, [rbx]              ; NtAllocateVirtualMemory\n    mov rcx, [rbx + 0x8]        ; HANDLE ProcessHandle\n    mov rdx, [rbx + 0x10]       ; PVOID *BaseAddress\n    xor r8, r8                  ; ULONG_PTR ZeroBits\n    mov r9, [rbx + 0x18]        ; PSIZE_T RegionSize\n    mov r10, [rbx + 0x20]       ; ULONG Protect\n    mov [rsp+0x30], r10         ; stack pointer for 6th arg\n    mov r10, 0x3000             ; ULONG AllocationType\n    mov [rsp+0x28], r10         ; stack pointer for 5th arg\n    jmp rax\n<\/pre>\n\n\n\n<p>\u8981\u89e3\u91ca\u4e0a\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6211\u4eec\u9996\u5148\u5c06\u6307\u5411\u5bc4\u5b58\u5668\u4e2d\u7ed3\u6784\u7684\u6307\u9488\u5907\u4efd\u5230\u5bc4\u5b58\u5668\u4e2d\u3002\u6211\u4eec\u8fd9\u6837\u505a\u662f\u56e0\u4e3a\u6211\u4eec\u5c06\u7528\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6765\u8e29\u8e0fRDX\u5bc4\u5b58\u5668\uff0c\u5f53\u6211\u4eec\u8c03\u7528\u5b83\u65f6<code>RDX<\/code><code>RBX<\/code><code>NtAllocateVirtualMemory<\/code><\/li>\n\n\n\n<li>\u6211\u4eec\u5c06\u524d 8 \u4e2a\u5b57\u8282\u4ece\u5bc4\u5b58\u5668\u4e2d\u7684\u5730\u5740\uff08\u5373\uff09\u79fb\u52a8\u5230 rax \u5bc4\u5b58\u5668\uff0c\u5728\u8c03\u6574\u53c2\u6570\u540e\u6211\u4eec\u5c06\u8df3\u8f6c\u5230<code>RBX<\/code><code>struct NTALLOCATEVIRTUALMEMORY_ARGS<\/code><code>UINT_PTR pNtAllocateVirtualMemory<\/code><\/li>\n\n\n\n<li>\u6211\u4eec\u5c06\u7b2c\u4e8c\u7ec4 8 \u5b57\u8282 \uff08\uff09 \u4ece\u7ed3\u6784\u79fb\u52a8\u5230<code>HANDLE hProcess<\/code><code>RCX<\/code><\/li>\n\n\n\n<li>\u6211\u4eec\u5c06\u7b2c\u4e09\u7ec4 8 \u4e2a\u5b57\u8282\uff0c\u5373\u6307\u5411\u5b58\u50a8\u5728\u7ed3\u6784\u4e2d\u7684 NULL \u6307\u9488 \uff08\uff09 \u7684\u6307\u9488\u79fb\u52a8\u5230 .\u8fd9\u662f\u6211\u4eec\u5206\u914d\u7684\u5730\u5740\u5c06\u5199\u5165\u7684\u5730\u65b9<code>PVOID* address<\/code><code>RDX<\/code><code>NtAllocateVirtualMemory<\/code><\/li>\n\n\n\n<li>\u6211\u4eec\u5c06\u53c2\u6570\u7684\u5bc4\u5b58\u5668\u6e05\u96f6<code>R8<\/code><code>ULONG_PTR ZeroBits<\/code><\/li>\n\n\n\n<li>\u6211\u4eec\u5c06\u7b2c 6 \u4e2a\u53c2\u6570\uff0c\u5373\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u79fb\u52a8\u5230\u6240\u6709\u53c2\u6570 \uff08\uff09 \u7684\u5e95\u90e8\u5230 r10\uff0c\u7136\u540e\u5c06\u5176\u79fb\u52a8\u5230\u5806\u6808\u6307\u9488\u9876\u90e8\u7684\u504f\u79fb\u91cf\u3002<code>ULONG Protect i.e. PAGE permissions<\/code><code>0x30<\/code>\n<ul class=\"wp-block-list\">\n<li>\u5806\u6808\u9876\u90e8\u6307\u9488 = RSP = \u8fd4\u56de\u5730\u5740\u4e3a 8 \u4e2a\u5b57\u8282<code>TppWorkpExecuteCallback<\/code><\/li>\n\n\n\n<li>4 \u4e2a\u53c2\u6570\u7684\u5f52\u4f4d\u7a7a\u95f4\u5927\u5c0f = 4&#215;8 = 32 \u5b57\u8282<\/li>\n\n\n\n<li>\u7b2c 5 \u4e2a\u53c2\u6570\u7684\u7a7a\u95f4 = 8 \u4e2a\u5b57\u8282<\/li>\n\n\n\n<li>\u56e0\u6b64 32+8 = 40 = 0x28\uff08\u8fd9\u662f\u5012\u6570\u7b2c\u4e8c\u4e2a\u7b2c 5 \u4e2a\u53c2\u6570\u5c06\u51fa\u73b0\u7684\u5730\u65b9\uff09<\/li>\n\n\n\n<li>\u56e0\u6b64 32+8+8 = 48 = 0x30\uff08\u8fd9\u662f\u6700\u540e\u4e00\u4e2a\u7b2c 6 \u4e2a\u53c2\u6570\u5c06\u8981\u53bb\u7684\u5730\u65b9\uff09<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u6211\u4eec\u6700\u540e\u79fb\u52a8\u7b2c 5 \u4e2a\u53c2\u6570\u503c \uff08\uff09\uff0c\u5373 \u5230\u5bc4\u5b58\u5668\uff0c\u7136\u540e\u5c06\u5176\u63a8\u9001\u5230RSP\u504f\u79fb<code>ULONG AllocationType<\/code><code>0x3000 - MEM_COMMIT|MEM_RESERVE<\/code><code>R10<\/code><code>0x28<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u5c06\u5b83\u4eec\u5168\u90e8\u7f16\u8bd1\u5728\u4e00\u8d77\uff0c\u8fd9\u662f\u8df3\u8f6c\u5230\u4e4b\u524d\u7684\u6837\u5b50\uff1a<code>NtAllocateVirtualMemory<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53cd\u6c47\u7f16\u7684\u4ee3\u7801\u663e\u793a\u4e86\u6211\u4eec\u7f16\u5199\u7684 asm \u6307\u4ee4\u3002\u5f53\u524d\u6307\u4ee4\u6307\u9488\u521a\u597d\u5728\u8c03\u6574\u5806\u6808\u4e4b\u540e\uff0c\u8df3\u8f6c\u5230<code>NtAllocateVirtualMemory<\/code><\/li>\n\n\n\n<li>\u5bc4\u5b58\u5668\u663e\u793a\u53c2\u6570<code>NtAllocateVirtualMemory<\/code><\/li>\n\n\n\n<li>\u8f6c\u50a8\u663e\u793a\u5185\u5b58\u4e2d\u7684\u7ed3\u6784\u3002\u6bcf\u4e2a 8 \u5b57\u8282\u7684\u5185\u5b58\u5757\u90fd\u662f\u4e00\u4e2a\u4e0e\u7ed3\u6784\u5185\u5bb9\u76f8\u5173\u7684\u5bf9\u8c61<code>NTALLOCATEVIRTUALMEMORY_ARGS<\/code><\/li>\n\n\n\n<li>\u5806\u6808\u663e\u793a\u8c03\u6574\u540e\u7684\u5806\u6808<code>NtAllocateVirtualMemory<\/code><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/0xdarkvortex.dev\/assets\/images\/2023-01-29-Hiding-In-Plainsight\/finalStack.png\"><img decoding=\"async\" src=\"https:\/\/0xdarkvortex.dev\/assets\/images\/2023-01-29-Hiding-In-Plainsight\/finalStack.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>\u5728\u6267\u884c \u540e\u5feb\u901f\u67e5\u770b\u5806\u6808\u4f1a\u663e\u793a\u4e00\u4e2a\u53ef\u4ee5\u5b8c\u7f8e\u5c55\u5f00\u7684\u6709\u6548\u8c03\u7528\u5806\u6808\u3002\u60a8\u8fd8\u53ef\u4ee5\u770b\u5230\u7cfb\u7edf\u8c03\u7528\u8fd4\u56de\u96f6\uff0c\u8fd9\u610f\u5473\u7740\u8c03\u7528\u6210\u529f\u3002<code>NtAllocateVirtualMemory<\/code><code>NtAllocateVirtualMemory<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/0xdarkvortex.dev\/assets\/images\/2023-01-29-Hiding-In-Plainsight\/stacktrace.png\"><img decoding=\"async\" src=\"https:\/\/0xdarkvortex.dev\/assets\/images\/2023-01-29-Hiding-In-Plainsight\/stacktrace.png\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>\u70df\u56f1\u53c8\u50cf\u6c34\u6676\u4e00\u6837\u6e05\u6670\uff0c\u6ca1\u6709\u4efb\u4f55\u6076\u610f\u7684\u8ff9\u8c61\u3002\u8bf7\u6ce8\u610f\uff0c\u8fd9\u662f\u5806\u53e0\u6b3a\u9a97\uff0c\u56e0\u4e3a\u5728\u6211\u4eec\u7684\u4f8b\u5b50\u4e2d\uff0c\u5806\u6808\u5b8c\u5168\u5c55\u5f00\u800c\u4e0d\u4f1a\u5d29\u6e83\u3002\u8fd8\u6709\u66f4\u591a\u8fd9\u6837\u7684 API \u8c03\u7528\u53ef\u7528\u4e8e\u4ee3\u7406\u5404\u79cd\u51fd\u6570;\u6211\u5c06\u7559\u7ed9\u8bfb\u8005\u4f7f\u7528\u81ea\u5df1\u7684\u521b\u9020\u529b\u3002\u5373\u5c06\u53d1\u5e03\u7684 BRc4 \u5c06\u4f7f\u7528\u7c7b\u4f3c\u7684\u4e1c\u897f\uff0c\u4f46\u5177\u6709\u4e0d\u540c\u7684 API \u8c03\u7528\u96c6\uff0c\u8fd9\u4e9b\u8c03\u7528\u5b8c\u5168\u672a\u8bb0\u5f55\uff0c\u5e76\u4e14\u5c06\u4f4d\u4e8e\u79f0\u4e3a .\u5b8c\u6574\u7684\u4ee3\u7801\u53ef\u4ee5\u5728\u6211\u7684<a href=\"https:\/\/github.com\/paranoidninja\/Proxy-Function-Calls-For-ETwTI\">github\u5b58\u50a8\u5e93<\/a>\u4e2d\u627e\u5230\u3002<code>not<\/code><code>stealth++<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8\u610f\uff1a\u8fd9\u662f\u5173\u4e8e\u5806\u6808\u8ddf\u8e2a\u89c4\u907f\u7684\u7b2c\u4e8c\u90e8\u5206\u535a\u5ba2\u3002\u7b2c\u4e00\u90e8\u5206\u53ef\u4ee5\u5728\u8fd9\u91cc\u627e\u5230\u3002 \u8fd9\u662f\u6211 3 \u5929\u524d\u5199\u7684\u5173\u4e8e\u4ee3\u7406 DLL \u52a0\u8f7d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[102,43],"tags":[304],"class_list":["post-1225","post","type-post","status-publish","format-standard","hentry","category-windows-infoarticle","category-infoarticle","tag-dll"],"views":2048,"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1225"}],"version-history":[{"count":3,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1225\/revisions"}],"predecessor-version":[{"id":1230,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1225\/revisions\/1230"}],"wp:attachment":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}