While I was trying to think up creative names for the theme of this article, I Google’d the very generic term “hedgehog defense”. It turns out this is an actual military tactic that employs the use of “mutually supportive” strongpoints. I was surprised how well the description of this strategy lends itself to the idea of cybersecurity and wholly convinced to use the term after I saw wikipedia describe it as a “defense in depth” strategy. Nailed it.
So, in this series, I’ll be detailing defensive tactics that you can utilize in your environment that will help thwart threat actors and stop them in their tracks. My aim is for many of these tactics to be relatively easy to implement with little to no risk, but high value in slowing down or even outright preventing malicious attacks.
Why?
Threat actors use all sorts of different file types for a myriad of reasons. Most of the time, it’s to try and get around endpoint security or to confuse a user into doing something that they shouldn’t.Most typical users do not have a business need to be launching vbscript files on their computer, so why not prevent them from being able to do so? Sure, there may still be ways to launch these files, but security is all about layers. Preventing a user from being able to double click to run certain files may make them think twice aboutlaunching the file in the first place or may even force them to reach out to the help desk for assistance.
In fact, the particular strategy I’m going to demonstrate is common enough to have its own Mitre designation, known as a “Double File Extension” which is a sub-technique of Masquerading.
So how does changing default app associations help in situations like this? By default, Windows is configured to see a vbscript and want to run it as a script. To prevent this from happening, we tell Windows that we would rather have it open with a text editor. This small change prevents automatic execution of the vbscript file and stops the attack flow in its tracks.
The most reliable way of accomplishing this is via a Group Policy Object. The primary benefit of using GPO is that it continuously applies to every domain-joined workstation. This means if a default app setting is reset by an app or user, it will eventually be synced up and reset to the app set in the GPO policy.
Another method to achieve the same results is to use the built-in Windows tool, DISM, to perform an export of a machine’s default app associations and then import on another machine. This is also a handy method if you just want to export and audit existing associations on an endpoint.
DISM /Online /Export-DefaultAppAssociations:<output_path>
Example:
DISM /Online /Export-DefaultAppAssociations:C:\Temp\AppAssociations.xml
DISM /Online /Import-DefaultAppAssociations:<output_path>
Example:
DISM /Online /Import-DefaultAppAssociations:C:\Temp\AppAssociations.xml
BONUS! – If (…when) you happen to mess up default app associations and want to clear your (…or someone else’s) default app associations, use the command:
Dism.exe /Online /Remove-DefaultAppAssociations
This will remove any custom set associations and restore everything to default. I also want to note that I had some trouble getting the DISM method to work consistently. Exporting works no problem, but importing or resetting seem to be a little hit or miss. This could just be something with my lab, but just wanted to forewarn and suggest your mileage may vary with this method. Plenty of guides online suggest this method works fine so I’m just going to assume I’m the problem.
Obviously there are quite a few ways you could automate this method too (deploying via an RMM is the first that comes to my mind), but you get the idea. These are certainly not the only ways, so don’t feel discouraged if GPO or DISM are not options for you. Just do some research and find a way that works in your environment.
Video – before default app modifications:
Video – after default app modifications:
In my demo, I will use the common Command and Control platform, Sliver, to generate an executable to deploy my implant on the victim endpoint and create a Sliver session. This executable will be hosted on my malicious server alongside a fake pdf file. I have created a simple vbscript file that will download and run the malicious beacon executable as well as open the pdf. This way, the victim gets what they were expecting (a pdf) while my malware loads in the background and establishes a foothold on the victim endpoint. Another tactic I abuse here is renaming my vbscript file and ending it with ‘.pdf’. In windows, when file extensions are hidden, this makes it look like the file ends with the ‘.pdf’ extension. I tried my best to emulate an actual attack pattern that would be similar to strategies observed by real threat actors.
After Implementing GPO to Change Default App Associations:
Once implemented, the attack flow stops right when the user tries to launch the vbscript file. Instead of being able to launch the file as a script, it will launch with notepad. This prevents the execution of the script and stops the attack from completing and establishing a Sliver session.
Of course, this still opens the file, just in a way that strips it of its fangs. I chose notepad just as an example, feel free to play around and see if there is a different application you would prefer to open with or would work better for your environment. The end goal is just to set it to open with something that will prevent the script from running as a script.
And that’s it! This is a great low-risk change you can make to your environment with potential for a high reward. Again, this isn’t designed to catch everything, we just want to hit the low-hanging fruit, like when would a user ever need to legitimately auto-execute a vbscript or javascript file? This article from HowToGeek shows a lot of file extensions to consider creating a policy for.
Lastly, this is a good training opportunity for your users as well. To combat the double extension tactic, Mitre specifically calls out disabling the feature to hide file extensions and training users to identify suspicious files by their double extension. Even with some basic training, users should be able to spot this nefarious attempt before even downloading or executing the file.
Want to learn about other techniques that threat actors use to deceive their victims? Take a look at this article written by Amanda Berlin that’s all about the topic!