Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/DLLHijackAuditKit/audit.js
Views: 11766
/* DLLHijackAuditKit (C) 2010 Rapid7, Inc */12function print_status(msg) {3try {4WScript.StdOut.WriteLine("[*] "+ msg);5} catch(e) {}6}78function process_list() {9var res = new Array();10var wbemFlagReturnImmediately = 0x10;11var wbemFlagForwardOnly = 0x20;12var oWMI = GetObject("winmgmts:\\\\localhost\\root\\CIMV2");13var cPID = oWMI.ExecQuery("SELECT * FROM Win32_Process", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);14var enumItems = new Enumerator(cPID);15for (; !enumItems.atEnd(); enumItems.moveNext()) {16var p = enumItems.item();17if (p.ExecutablePath && p.ExecutablePath.toLowerCase().indexOf("taskmgr") != -1) continue;18res.push(p.ProcessId);19}20return res;21}22232425var pause_interval = 100000;2627var oFso = new ActiveXObject("Scripting.FileSystemObject");28var oShl = new ActiveXObject("WScript.Shell");29var oLoc = new ActiveXObject("WbemScripting.SWbemLocator");30var oSvc = oLoc.ConnectServer(null, "root\\default");31var oReg = oSvc.Get("StdRegProv");3233var oCWD = oShl.CurrentDirectory + "";3435var oMethod = oReg.Methods_.Item("EnumKey");36var oInParam = oMethod.InParameters.SpawnInstance_();37oInParam.hDefKey = 0x80000002;38oInParam.sSubKeyName = "Software\\Classes";3940var oOutParam = oReg.ExecMethod_(oMethod.Name, oInParam);41var aNames = oOutParam.sNames.toArray();424344try { oFso.CreateFolder("DLLAudit"); } catch(e) { }45try { oFso.CreateFolder("DLLAudit\\ext"); } catch(e) { }464748if (! oFso.FileExists("procmon.exe")) {49print_status("Downloading procmon.exe from \\\\live.sysinternals.com ...")50try { oFso.CopyFile("\\\\live.sysinternals.com\\Tools\\procmon.exe", "procmon.exe"); } catch(e) {}51}5253if (! oFso.FileExists("procmon.exe")) {54print_status("Failed to download procmon.exe, copy here manually.");55WScript.Quit();56}575859print_status("Starting the process monitor...");60oShl.Run("procmon.exe /AcceptEULA /Quiet /LoadConfig DLLAudit.pmc", 10);61WScript.Sleep(5000);6263var total = 0;64print_status("Creating test cases for each file extension...");6566for (var i = 0; i < aNames.length; i++) {67if (aNames[i].substr(0,1) != ".") continue;68var ext = aNames[i].substr(1,32).toLowerCase();6970if (ext == "com") continue;71if (ext == "pif") continue;72if (ext == "exe") continue;73if (ext == "bat") continue;74if (ext == "scr") continue;75if (ext == "dos") continue;76if (ext == "386") continue;77if (ext == "cpl") continue;78if (ext == "sys") continue;79if (ext == "dll") continue;80if (ext == "drv") continue;81if (ext == "rb") continue;82if (ext == "py") continue;83if (ext == "pl") continue;84if (ext == "crds") continue;85if (ext == "crd") continue;86if (ext == "pml") continue;87if (ext == "pmc") continue;8889try { oFso.CreateFolder("DLLAudit\\ext\\" + ext); } catch(e) { }90try {91var a = oFso.CreateTextFile("DLLAudit\\ext\\" + ext + "\\exploit." + ext);92a.WriteLine("HOWDY!");93a.Close();94} catch(e) { }9596total++;97}9899print_status("Created " + total + " test cases");100var procs = process_list();101print_status("Protecting " + procs.length + " processes");102103var tries = 0;104105var base = oFso.GetFolder("DLLAudit\\ext");106var subs = new Enumerator(base.SubFolders);107for (; !subs.atEnd(); subs.moveNext()) {108var path = subs.item() + "";109var bits = path.split("\\");110var ext = bits[bits.length - 1];111112print_status("Auditing extension: " + ext);113oShl.CurrentDirectory = path + "\\";114115oShl.Run("cmd.exe /c start exploit." + ext, 0);116WScript.Sleep(500);117118var nprocs = process_list();119var cnt = 0;120while(nprocs.length == procs.length && cnt < 2) {121cnt++;122WScript.Sleep(500);123nprocs = process_list();124}125126// If an application spawned, give it three seconds127// This helps with ProcMon memory usage as well128if (nprocs.length > procs.length) {129WScript.Sleep(3000);130}131132var killer = "taskkill /F ";133for (var i=0; i < nprocs.length; i++) {134var found = false;135for (var x=0; x < procs.length; x++) {136if (nprocs[i] == procs[x]) {137found = true;138break;139}140}141if (found) continue;142killer = killer + "/PID " + nprocs[i] + " ";143}144oShl.Run(killer, 0, true);145146tries++;147148if (tries % pause_interval == 0) {149print_status("Completed " + tries + " extensions, hit enter to continue.")150WScript.Stdin.ReadLine();151print_status("Continuing...")152}153}154155print_status("Data collection phase complete, export Logfile.CSV from ProcMon.")156157158159