{"id":54149,"date":"2024-10-09T17:11:39","date_gmt":"2024-10-09T09:11:39","guid":{"rendered":"https:\/\/server.hk\/cnblog\/54149\/"},"modified":"2024-10-09T17:11:39","modified_gmt":"2024-10-09T09:11:39","slug":"windows-x86-x64-ring-3-%e5%b1%a4%e6%b3%a8%e5%85%a5-dll-%e7%b8%bd%e7%b5%90","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/54149\/","title":{"rendered":"Windows x86\/x64 Ring 3 \u5c64\u6ce8\u5165 DLL \u7e3d\u7d50"},"content":{"rendered":"<h1 id=\"windows-x86-x64-ring-3-%e5%b1%a4%e6%b3%a8%e5%85%a5-dll-%e7%b8%bd%e7%b5%90-IczqZvihqV\">Windows x86\/x64 Ring 3 \u5c64\u6ce8\u5165 DLL \u7e3d\u7d50<\/h1>\n<p>\u5728 Windows \u64cd\u4f5c\u7cfb\u7d71\u4e2d\uff0cDLL\uff08\u52d5\u614b\u93c8\u63a5\u5eab\uff09\u6ce8\u5165\u662f\u4e00\u7a2e\u5e38\u898b\u7684\u6280\u8853\uff0c\u901a\u5e38\u7528\u65bc\u64f4\u5c55\u6216\u4fee\u6539\u61c9\u7528\u7a0b\u5e8f\u7684\u884c\u70ba\u3002\u9019\u7a2e\u6280\u8853\u5728\u5b89\u5168\u7814\u7a76\u3001\u9006\u5411\u5de5\u7a0b\u548c\u67d0\u4e9b\u5408\u6cd5\u7684\u61c9\u7528\u7a0b\u5e8f\u4e2d\u90fd\u6709\u5176\u7528\u9014\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Windows x86\/x64 \u74b0\u5883\u4e0b\u7684 Ring 3 \u5c64 DLL \u6ce8\u5165\u6280\u8853\uff0c\u4e26\u63d0\u4f9b\u76f8\u95dc\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-dll-%e6%b3%a8%e5%85%a5%ef%bc%9f-IczqZvihqV\">\u4ec0\u9ebc\u662f DLL \u6ce8\u5165\uff1f<\/h2>\n<p>DLL \u6ce8\u5165\u662f\u6307\u5c07\u4e00\u500b DLL \u6587\u4ef6\u52a0\u8f09\u5230\u53e6\u4e00\u500b\u9032\u7a0b\u7684\u5730\u5740\u7a7a\u9593\u4e2d\u3002\u9019\u6a23\uff0c\u6ce8\u5165\u7684 DLL \u53ef\u4ee5\u6514\u622a\u6216\u4fee\u6539\u8a72\u9032\u7a0b\u7684\u884c\u70ba\u3002\u9019\u7a2e\u6280\u8853\u901a\u5e38\u7528\u65bc\u4ee5\u4e0b\u5e7e\u500b\u65b9\u9762\uff1a<\/p>\n<ul>\n<li>\u64f4\u5c55\u61c9\u7528\u7a0b\u5e8f\u529f\u80fd<\/li>\n<li>\u9032\u884c\u5b89\u5168\u6e2c\u8a66\u548c\u6f0f\u6d1e\u5206\u6790<\/li>\n<li>\u9006\u5411\u5de5\u7a0b\u548c\u8abf\u8a66<\/li>\n<\/ul>\n<h2 id=\"windows-%e7%9a%84%e9%80%b2%e7%a8%8b%e5%92%8c%e6%ac%8a%e9%99%90%e5%b1%a4%e7%b4%9a-IczqZvihqV\">Windows \u7684\u9032\u7a0b\u548c\u6b0a\u9650\u5c64\u7d1a<\/h2>\n<p>\u5728 Windows \u64cd\u4f5c\u7cfb\u7d71\u4e2d\uff0c\u9032\u7a0b\u7684\u57f7\u884c\u6b0a\u9650\u5206\u70ba\u5e7e\u500b\u5c64\u7d1a\uff0c\u5176\u4e2d Ring 3 \u662f\u7528\u6236\u6a21\u5f0f\uff0c\u9019\u610f\u5473\u8457\u5b83\u7684\u6b0a\u9650\u76f8\u5c0d\u8f03\u4f4e\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0cRing 0 \u662f\u5167\u6838\u6a21\u5f0f\uff0c\u64c1\u6709\u66f4\u9ad8\u7684\u6b0a\u9650\u3002DLL \u6ce8\u5165\u901a\u5e38\u767c\u751f\u5728 Ring 3 \u5c64\uff0c\u56e0\u70ba\u9019\u662f\u7528\u6236\u61c9\u7528\u7a0b\u5e8f\u904b\u884c\u7684\u74b0\u5883\u3002<\/p>\n<h2 id=\"dll-%e6%b3%a8%e5%85%a5%e7%9a%84%e5%b8%b8%e8%a6%8b%e6%96%b9%e6%b3%95-IczqZvihqV\">DLL \u6ce8\u5165\u7684\u5e38\u898b\u65b9\u6cd5<\/h2>\n<p>\u5728 Windows \u74b0\u5883\u4e2d\uff0c\u6709\u5e7e\u7a2e\u5e38\u898b\u7684 DLL \u6ce8\u5165\u65b9\u6cd5\uff0c\u5305\u62ec\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8-createremotethread-IczqZvihqV\">1. \u4f7f\u7528 CreateRemoteThread<\/h3>\n<p>\u9019\u662f\u4e00\u7a2e\u5e38\u898b\u7684\u6ce8\u5165\u65b9\u6cd5\uff0c\u901a\u904e\u5275\u5efa\u4e00\u500b\u9060\u7a0b\u7dda\u7a0b\u4f86\u52a0\u8f09 DLL\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u6b65\u9a5f\uff1a<\/p>\n<pre><code>\nHANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, targetProcessId);\nLPVOID pDllPath = VirtualAllocEx(hProcess, NULL, strlen(dllPath) + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);\nWriteProcessMemory(hProcess, pDllPath, (LPVOID)dllPath, strlen(dllPath) + 1, NULL);\nHANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, pDllPath, 0, NULL);\n<\/code><\/pre>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8-setwindowshookex-IczqZvihqV\">2. \u4f7f\u7528 SetWindowsHookEx<\/h3>\n<p>\u9019\u7a2e\u65b9\u6cd5\u901a\u5e38\u7528\u65bc\u6514\u622a Windows \u6d88\u606f\uff0c\u4e26\u53ef\u4ee5\u5728\u7279\u5b9a\u4e8b\u4ef6\u767c\u751f\u6642\u52a0\u8f09 DLL\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u78bc\uff1a<\/p>\n<pre><code>\nHHOOK hHook = SetWindowsHookEx(WH_CBT, HookProc, hInstance, 0);\n<\/code><\/pre>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8-appinit_dlls-IczqZvihqV\">3. \u4f7f\u7528 AppInit_DLLs<\/h3>\n<p>\u9019\u662f\u4e00\u7a2e\u8f03\u70ba\u7c21\u55ae\u7684\u6ce8\u5165\u65b9\u6cd5\uff0c\u901a\u904e\u4fee\u6539\u8a3b\u518a\u8868\u4f86\u52a0\u8f09 DLL\u3002\u9019\u7a2e\u65b9\u6cd5\u7684\u7f3a\u9ede\u662f\u9700\u8981\u7cfb\u7d71\u7ba1\u7406\u54e1\u6b0a\u9650\u3002<\/p>\n<h2 id=\"%e5%ae%89%e5%85%a8%e6%80%a7%e8%80%83%e9%87%8f-IczqZvihqV\">\u5b89\u5168\u6027\u8003\u91cf<\/h2>\n<p>\u96d6\u7136 DLL \u6ce8\u5165\u6280\u8853\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\u662f\u5408\u6cd5\u7684\uff0c\u4f46\u5b83\u4e5f\u53ef\u80fd\u88ab\u7528\u65bc\u60e1\u610f\u76ee\u7684\u3002\u56e0\u6b64\uff0c\u8a31\u591a\u5b89\u5168\u8edf\u4ef6\u6703\u6aa2\u6e2c\u548c\u963b\u6b62\u9019\u7a2e\u884c\u70ba\u3002\u958b\u767c\u8005\u5728\u4f7f\u7528\u9019\u7a2e\u6280\u8853\u6642\uff0c\u61c9\u8a72\u9075\u5faa\u6cd5\u5f8b\u6cd5\u898f\uff0c\u4e26\u78ba\u4fdd\u4e0d\u6703\u4fb5\u72af\u4ed6\u4eba\u7684\u6b0a\u76ca\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-IczqZvihqV\">\u7d50\u8ad6<\/h2>\n<p>Windows x86\/x64 Ring 3 \u5c64\u7684 DLL \u6ce8\u5165\u6280\u8853\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u64f4\u5c55\u548c\u4fee\u6539\u61c9\u7528\u7a0b\u5e8f\u7684\u884c\u70ba\u3002\u7121\u8ad6\u662f\u5728\u5b89\u5168\u7814\u7a76\u9084\u662f\u5408\u6cd5\u7684\u61c9\u7528\u958b\u767c\u4e2d\uff0c\u4e86\u89e3\u9019\u4e9b\u6280\u8853\u90fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u7136\u800c\uff0c\u958b\u767c\u8005\u5fc5\u9808\u8b39\u614e\u4f7f\u7528\uff0c\u4e26\u9075\u5faa\u76f8\u95dc\u6cd5\u5f8b\u6cd5\u898f\uff0c\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6cd5\u5f8b\u98a8\u96aa\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u548c\u5176\u4ed6\u4f3a\u670d\u5668\u89e3\u6c7a\u65b9\u6848\u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7e3d\u7d50Windows x86\/x64 Ring 3\u5c64DLL\u6ce8\u5165\u6280\u8853\uff0c\u63a2\u8a0e\u5176\u539f\u7406\u3001\u65b9\u6cd5\u53ca\u61c9\u7528\uff0c\u52a9\u60a8\u6df1\u5165\u7406\u89e3\u7cfb\u7d71\u5b89\u5168\u8207\u653b\u64ca\u9632\u7bc4\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-54149","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/54149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=54149"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/54149\/revisions"}],"predecessor-version":[{"id":54150,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/54149\/revisions\/54150"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=54149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=54149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=54149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}