{"id":83,"date":"2019-12-13T22:55:31","date_gmt":"2019-12-13T14:55:31","guid":{"rendered":"http:\/\/blog.73007300.xyz\/?p=83"},"modified":"2019-12-14T00:04:22","modified_gmt":"2019-12-13T16:04:22","slug":"create-process-content-injection","status":"publish","type":"post","link":"https:\/\/blog.73007300.xyz\/?p=83","title":{"rendered":"Create Process Context Injection"},"content":{"rendered":"\n<p>\u601d\u8def\uff1a<\/p>\n\n\n\n<p>1.CreateProcess \u521b\u5efa\u8fdb\u7a0b \uff0c\u8fdb\u7a0b\u4fe1\u606f\u653e\u5728 PROCESS_INFORMATION pi \u4e2d\u3002<\/p>\n\n\n\n<p>2. GetSystemInfo \u83b7\u53d6\u5185\u5b58\u4e2d\u7684\u6240\u6709\u6570\u636e\uff0c\u653e\u5728 SYSTEM_INFO sysinfo; \u4e2d\u3002<\/p>\n\n\n\n<p>3.\u4ece sysinfo.lpMinimumApplicationAddress \u5f00\u59cb\uff0c \u6bcf\u4e00\u6b21\u7684\u5927\u5c0f\u4e3a sysinfo.dwPageSize \u5230 sysinfo.lpMaximumApplicationAddress\u7ed3\u675f\uff0c\u904d\u5386\u5185\u5b58\u3002<\/p>\n\n\n\n<p>4.\u6bcf\u6b21\u90fd VirtualQueryEx \u4e00\u6b21\uff0c \u628a\u5f53\u524d\u9875\u7684\u5185\u5b58\u4fe1\u606f\u653e\u5230 MEMORY_BASIC_INFORMATION mbi = {0}\u4e2d\u3002<\/p>\n\n\n\n<p>5.\u5f53 VirtualQueryEx \u51fa\u6765\u7684\u7c7b\u578b\u662f MEM_IMAGE \u65f6\uff0c\u5185\u5b58\u4e2d\u7684\u5730\u5740\u53c8\u662f\u6307\u5b9a\u6587\u4ef6\u540d\u7684\u6620\u5c04\uff0c\u5c31\u4fdd\u5b58\u5e76\u8fd4\u56de\u8fd9\u4e2a\u5730\u5740\u3002<\/p>\n\n\n\n<p>6.\u7528 CImage \u7684 AttachToProcess\u65b9\u6cd5\u8bfb\u53d6\u521a\u521a\u5730\u5740\u7684\u5185\u5b58\u5934\uff0c\u4fdd\u5b58\u5728 PBYTE ImageBase\u4e2d\u3002<\/p>\n\n\n\n<p>7.\u7528 VirtualQueryEx \u51fa\u6765\u7684\u5185\u5b58\u5730\u5740 \u52a0 CImage\u7ed3\u6784\u4f53\u4e2d\u7684m_dwEntryPoint\u957f\u5ea6\uff0c\u5c31\u662f\u7a0b\u5e8f\u5185\u5b58\u4e2d\u7684\u5165\u53e3\u70b9\u3002<\/p>\n\n\n\n<p>8.\u627e\u5230\u6253\u5f00\u7a0b\u5e8f\u7684\u7a0b\u5e8f\u5165\u53e3\u70b9\u7684\u5730\u5740\uff0c\u5c31\u53ef\u4ee5\u51c6\u5907\u8981\u6ce8\u5165\u7684code\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>typedef struct _INJECT_DATA64 \n{\n BYTE ShellCode[0xC0];\n \/*Off=0x0C0*\/HANDLE ModuleHandle; \/\/Dll\u53e5\u67c4\n \/*Off=0x0C8*\/PUNICODE_STRING pDllPath;\/\/PUNICODE_STRING DllPath\n \/*Off=0x0D0*\/ULONG DllCharacteristics;\n \/*Off=0x0D8*\/ULONG_PTR AddrOfLdrLoadDll;\/\/LdrLoadDll\u5730\u5740\n \/*Off=0x0E0*\/ULONG_PTR ProtectBase; \/\/\u7528\u4e8eVirtualMemory\n \/*Off=0x0E8*\/ULONG OldProtect; \/\/\u7528\u4e8eVirtualMemory\n \/*Off=0x0F0*\/SIZE_T ProtectSize;s\n \/*Off=0x0F8*\/ULONG_PTR ExeEntry;\/\/Exe\u5165\u53e3\u70b9\u7684\u5730\u5740\n \/*Off=0x100*\/ULONG_PTR AddrOfZwProtectVirtualMemory;\n \/*Off=0x108*\/BYTE SavedEntryCode[16];\/\/\u4fdd\u5b58exe\u5165\u53e3\u70b9\u7684\u524d16\u5b57\u8282\n \/*Off=0x118*\/UNICODE_STRING usDllPath;\/\/Dll\u8def\u5f84\n \/*Off=0x128*\/WCHAR wDllPath[256];\/\/Dll\u8def\u5f84\uff0c\u4e5f\u5c31\u662fusDllPath\u4e2d\u7684Buffer\n}INJECT_DATA64;\n<\/code><\/pre>\n\n\n\n<p>9.\u7528 VirtualAllocEx \u5206\u914d\u51fa\u4e00\u5757 0x1000 \u5927\u5c0f\u7684\u5185\u5b58\uff0c\u5206\u7ed9 \u4e4b\u524d\u6253\u5f00\u7684\u8fdb\u7a0b\u3002<\/p>\n\n\n\n<p>10.ReadProcessMemory \u8bfb\u53d6\u76ee\u6807\u8fdb\u7a0b\u7684\u524d8\u4e2a\u5b57\u8282\uff0c\u5e76\u5b58\u5230\u53d8\u91cf\u91cc\u3002<\/p>\n\n\n\n<p>11.\u7528 VirtualProtectEx \u4fee\u6539\u76ee\u6807\u8fdb\u7a0b\u7684\u5185\u5b58\u5c5e\u6027\u3002<\/p>\n\n\n\n<p>12.\u627e\u5230\u76ee\u6807\u8fdb\u7a0b\u4e2d32\u4f4d ntdll \u7684\u5730\u5740\u3002<\/p>\n\n\n\n<p>13.\u901a\u8fc7\u8ba1\u7b97\u81ea\u5df1\u5185\u5b58\u91ccntdll\u4e2dZwProtectVirtualMemory\u548cLdrLoadDll\u7684\u504f\u79fb\uff0c\u6765\u63a8\u6d4b\u76ee\u6807\u8fdb\u7a0b\u7684\u76f8\u5173\u51fd\u6570\u7684\u504f\u79fb\u3002<\/p>\n\n\n\n<p>14.\u83b7\u53d6 shellcode\u7684\u5185\u5bb9\uff0c\u5f00\u59cb\u5230\u504f\u79fb\u7684\u5185\u5bb9\u3002\u628a\u5185\u5bb9\u653e\u5230 INJECT_DATA64 \u7ed3\u6784\u4f53\u7684 ShellCode\u4e2d\u3002<\/p>\n\n\n\n<p>15.\u586b\u5145 INJECT_DATA64 \u7ed3\u6784\u4f53\u7684 \u5176\u4ed6\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>16.\u7528 WriteProcessMemory \u628a INJECT_DATA64 \u7ed3\u6784\u4f53\u5199\u9053\u76ee\u6807\u8fdb\u7a0b\u4e2d\uff0c\u4f4d\u7f6e\u662f\u4e4b\u524d\u7528 VirtualAllocEx \u5206\u914d\u7684\u5185\u5b58 \u3002<\/p>\n\n\n\n<p>17.\u7f16\u5199Jmp xxxx\u6307\u4ee4\uff0c\u7528 WriteProcessMemory \u8ba9\u7a0b\u5e8f\u5728\u5f00\u5934\u8df3\u8f6c\u5230 shellcode \u6267\u884c\u3002<\/p>\n\n\n\n<p>18.ResumeThread \u8ba9\u6682\u505c\u7684\u7ebf\u7a0b\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\u53c2\u8003 \u52a0\u5bc6\u89e3\u5bc6 \u968f\u4e66\u5149\u76d8\u4e2d\u7684 \uff1a chap12\\10.CreateProcContextInject\\CreateProcContextInject.cpp<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u601d\u8def\uff1a 1.CreateProcess \u521b\u5efa\u8fdb\u7a0b \uff0c\u8fdb\u7a0b\u4fe1\u606f\u653e\u5728 PROCESS_INFORMATION pi \u4e2d\u3002 2. GetSystemInfo \u83b7\u53d6\u5185\u5b58\u4e2d\u7684\u6240\u6709\u6570\u636e\uff0c\u653e\u5728 SYSTEM_INFO sysinfo; \u4e2d\u3002 3.\u4ece sysinfo.lpMinimumApplicationAddress \u5f00\u59cb\uff0c \u6bcf\u4e00\u6b21\u7684\u5927\u5c0f\u4e3a sysinfo.dwPageSize \u5230 sysinfo.lpMaximumApplicationAddress\u7ed3\u675f\uff0c\u904d\u5386\u5185\u5b58\u3002 4.\u6bcf\u6b21\u90fd VirtualQueryEx \u4e00\u6b21\uff0c \u628a\u5f53\u524d\u9875\u7684\u5185\u5b58\u4fe1\u606f\u653e\u5230 MEMORY_BASIC_INFORMATION mbi = {0}\u4e2d\u3002 5.\u5f53 VirtualQueryEx \u51fa\u6765\u7684\u7c7b\u578b\u662f MEM_IMAGE \u65f6\uff0c\u5185\u5b58\u4e2d\u7684\u5730\u5740\u53c8\u662f\u6307\u5b9a\u6587\u4ef6\u540d\u7684\u6620\u5c04\uff0c\u5c31\u4fdd\u5b58\u5e76\u8fd4\u56de\u8fd9\u4e2a\u5730\u5740\u3002 6.\u7528 CImage \u7684 AttachToProcess\u65b9\u6cd5\u8bfb\u53d6\u521a\u521a\u5730\u5740\u7684\u5185\u5b58\u5934\uff0c\u4fdd\u5b58\u5728 PBYTE ImageBase\u4e2d\u3002 7.\u7528 VirtualQueryEx \u51fa\u6765\u7684\u5185\u5b58\u5730\u5740 \u52a0 CImage\u7ed3\u6784\u4f53\u4e2d\u7684m_dwEntryPoint\u957f\u5ea6\uff0c\u5c31\u662f\u7a0b\u5e8f\u5185\u5b58\u4e2d\u7684\u5165\u53e3\u70b9\u3002 8.\u627e\u5230\u6253\u5f00\u7a0b\u5e8f\u7684\u7a0b\u5e8f\u5165\u53e3\u70b9\u7684\u5730\u5740\uff0c\u5c31\u53ef\u4ee5\u51c6\u5907\u8981\u6ce8\u5165\u7684code\u4e86\u3002 9.\u7528 VirtualAllocEx \u5206\u914d\u51fa\u4e00\u5757 0x1000 \u5927\u5c0f\u7684\u5185\u5b58\uff0c\u5206\u7ed9 \u4e4b\u524d\u6253\u5f00\u7684\u8fdb\u7a0b\u3002 10.ReadProcessMemory \u8bfb\u53d6\u76ee\u6807\u8fdb\u7a0b\u7684\u524d8\u4e2a\u5b57\u8282\uff0c\u5e76\u5b58\u5230\u53d8\u91cf\u91cc\u3002 11.\u7528 VirtualProtectEx [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.73007300.xyz\/index.php?rest_route=\/wp\/v2\/posts\/83"}],"collection":[{"href":"https:\/\/blog.73007300.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.73007300.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.73007300.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.73007300.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=83"}],"version-history":[{"count":4,"href":"https:\/\/blog.73007300.xyz\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":88,"href":"https:\/\/blog.73007300.xyz\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions\/88"}],"wp:attachment":[{"href":"https:\/\/blog.73007300.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.73007300.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.73007300.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}