Resources

Malicious PowerShell Attacks – Why They Will Soon be the Least of Your Problems

Written by: Joseph Sarkisian, GWAPT

Introduction to SilentTrinity

Over the past year, Marcello Salvati (@byt3bl33d3r) of Black Hills InfoSec has been quietly working on aย tool that is likely to become a paradigm shift for hackingโ€”white and black hat alike. When attacking Windows environments, Windows PowerShell has been the tool of choice, but Microsoft has become hip to this tactic and has added significant protections that help mitigate the use of malicious PowerShell scripts from running. What we now have is a cat-and-mouse game where hackers find ever-more-creative ways of bypassing these controls, only to have Microsoft and other โ€œblue teamโ€ types fill the gap.

That game is about to end.

In Marcelloโ€™s words:

โ€œSILENTTRINITY is a modern, asynchronous, multiplayer and multiserver C2/post-exploitation framework powered by Python 3 and .NETs DLR. It’s the culmination of an extensive amount of research into using embedded third-party .NET scripting languages to dynamically call .NET API’s, a technique the author coined as BYOI (Bring Your Own Interpreter). The aim of this tool and the BYOI concept is to shift the paradigm back to PowerShell-style-like attacks (as it offers much more flexibility over traditional C# tradecraft) only without using PowerShell in any way.โ€

What this really means is that the tool allows hackers to bypass the use of PowerShell, thus going largely undetectedโ€”especially given that Microsoft has focused the majority of its protections and alerting on PowerShell, not the lesser known .NET languages (like BooLang) that SilentTrinity utilizes.

The tool allows multiple users to log in to a central server where compromised machines can be manipulated. Once a server is started (called a โ€œlistenerโ€), the hacker generates malicious code (a โ€œstagerโ€), and the victim runs the malicious code, thereby opening a session (โ€œhackingโ€ session) on the attackerโ€™s SilentTrinity server. From there, many different modules can be run against the victim host that include things like information gathering and enumeration, privilege escalation, disabling endpoint protection, creating persistence, dumping credentials, changing/downloading registry keys, and more. All of these modules, such as IronPython and Python, are written in BooLang, which has few, if any, protections when run.

How it Works

The following examples will demonstrate how a hacker could use SilentTrinity to attack your system.

In the image below, we have started an http listener on our attacking host at port 80 and named the listener โ€œhttp:โ€

Next, we generate a stager that, when executed, will call back to this listener. Letโ€™s use an MSBuild stager that we can execute on a victim host using the Microsoft .NET compiler:

Once this stager is dropped on a host machine, we can compile it with msbuild.exe from the command prompt, PowerShell or a similar program. For simplicity, letโ€™s use a PowerShell script example to run msbuild.exe on the stager.xml file we have placed on the disk. Notice that we arenโ€™t executing malicious PowerShell scripts or executables, only a known, verified Microsoft application:

And on our attacking host, our new session:

Now weโ€™re ready to use some modules to further compromise our victim machine, all of which are likely to go unnoticed given their usage of BooLang. Letโ€™s try a fun one firstโ€”pop-up box. First, we set our text for the box:

And on our victim machine, voilร โ€ฆ

Now, letโ€™s get scarier. Letโ€™s phish for some plaintext credentials using the CredPhisher module. After executing, we can see a pop-up box appear on the victim host that looks convincing asking for our Windows credentials:

Once we provide credentials, hereโ€™s what we get on our attacking SilentTrinity server:

Finally, letโ€™s privilege escalate to SYSTEM using the โ€œgetsystemโ€ module:

Conclusion

As of now, there are very few mitigations to deal with this threat, and that will likely become the new normal for hackers everywhere as PowerShell security becomes increasingly robust. A few options are:

โ€ข Process monitoring for a BooLang interpreter

โ€ข Advanced host/network monitoring for suspicious C2 traffic originating from MSBuild

โ€ข Updating to .NET 4.8 as soon as possible because it integrates with Microsoftโ€™s Antimalware Scan Interface (AMSI)