When you get tricked by a phishing mail and open a document attachment that has a malicious macro or a link to a malicious site, or you download an infected application, there’s a file that antivirus software can scan as it’s saved to or opened from disk, and there’s a trail of file activity that you can look back at if you’re trying to review the damage done. To get around those protections, attackers are starting to use ‘fileless’ malware where the attacks run directly in memory or use system tools that are already installed to run malicious code without saving files that antivirus software can scan. (Note: This article about fileless malware is available as a free PDF download.)
That could mean tricking a user into running a script that executes a .NET binary directly from memory, like Sharpshooter which downloads the malware payload via the text records of DNS queries. Or it could mean sending malicious network packets that exploit the EternalBlue vulnerability and install the DoublePulsar backdoor in kernel memory. It could mean storing the malicious payload in the Registry as a handler for a file extension so it runs when you open a normal file with that extension. Kovter, for example, used that to download Mimikatz and steal credentials, putting the payload in a DLL that’s encoded into a string and run with a PowerShell command, installing a malicious PowerShell comment in the WMI repository and configuring it to run at regular intervals. The malicious code could even be in device firmware or a peripheral like BadUSB; that way, the payload can run in memory and keep coming back even if you reboot, reinstall Windows or reformat the disk.
SEE: Special report: Cyberwar and the future of cybersecurity (free PDF) (TechRepublic)
Fileless techniques can be extremely advanced, and they are harder for traditional antivirus software to detect. But not every advanced malware attack is fileless and throwing the term around doesn’t help organisations defend against it, Tanmay Ganacharya told TechRepublic. Ganacharya runs the Microsoft Defender threat research team, which analyses new threats and builds models to detect them. “Fileless is such an overused term, and it has gone from the truly fileless threats, to now people wanting to call almost everything that is even slightly advanced fileless and making it slightly buzzwordy,” he says.
To demystify the term, the threat research team started categorising fileless attacks based on how they get onto a PC and where they’re hosted. There are more than a dozen combinations of those ‘entry points’ and malware hosts being used for fileless attacks — some of which are very sophisticated and are rarely used for targeted attacks, and some of which have been commoditised and are showing up more often for common attacks like trying to run a coin miner on your system. But they fall into three broad groups.
“Type one is truly fileless, where the attack is delivered on the network or from a device, the payload is handled in memory and almost nothing touches the disk at all,” says Ganacharya. EternalBlue and BadUSB are truly fileless attacks — and they’re rare. “These are truly the most advanced attacks out there, but most of the attacks that get called fileless don’t belong in this group. This kind of attack and exploitation has been getting harder and harder, so it’s difficult for these to become commoditised.”
That’s called ‘living off the land’, and it’s hard to detect with standard antivirus tools because those legitimate tools don’t trigger warnings and the files malware does save are obfuscated and full of junk data that’s easy to change to create a new attack. You can’t clean it up by deleting files either, because you can’t just delete key parts of Windows like the Registry and the WMI repository.
The most common fileless attacks actually do use files, but they don’t run the attacks from those files directly. “Type three clearly start with a file whether it’s a document file with a macro in it, or a Java file, or Flash file, and sometimes even EXE files that drop certain files, but then persistence is fileless,” Ganacharya says. “So once the payload is dropped, the payload achieves persistence by either staying just in memory or staying in the registry and running from there.”
Many of those Type three attacks come from email, but the file attachments won’t show up as obviously malicious if an antivirus scans the files. “You don’t generally attach an EXE file, you attach a document with a macro and that links to another file and then that file goes and downloads the payload,” Ganacharya explains. VBA code doesn’t have a binary that antivirus software can scan, but it can load PowerShell scripts that download and run attacks.
How to detect fileless attacks
Since you can’t scan files to detect fileless attacks, you have to rely on scanning memory and spotting malicious behaviour. “You have to be able to scan injected modules in memory, because nothing ever touches the disk, and you have to be able to see as things get loaded into memory, whether it is a payload or shell code,” Ganacharya says. “You have to be able to see it, stop it and then kill the associated processes.” Extending that to cover the boot sector protects against boot sector attacks.
Behaviour monitoring spots malware that does malicious things, which includes all three types of fileless malware. Ganacharya: “Behaviour monitoring really applies across the board, right because anything that is fileless — whether it is fileless end to end or whether it has achieved fileless persistence — will have behaviour that indicates malicious activity. If it’s ransomware, it has to encrypt files, otherwise it’s not true ransomware, if it’s an info stealer it will have to steal some files or some information. So there will always be behaviours [to detect].”
To detect fileless attacks that rely on scripts, look for products like Microsoft Defender that use the Windows 10 Antimalware Scan Interface (AMSI) to check script behaviour at runtime.
Any antivirus software can hook into AMSI and see that sequence — and as of September 2018 that includes Office macros.
SEE: The Dark Web: A guide for business professionals (free PDF) (TechRepublic)
Defender also stopped a more recent and highly sophisticated attack using the Asteroth info stealer this summer, which was targeted at South America and attempted to steal credentials, keystrokes and other sensitive information using only existing tools in Windows in a sequence that’s hard even to follow with a diagram.
Defender has behavioural detections for all the techniques used in this attack. “We actually blocked these attacks at the very first stage, but to show that not only do we detect the first stage, we detect all stages, we put the AV in audit mode and let it run and we saw that every single stage had a behaviour detection,” Ganacharya says. “We ended up saving every single machine that was targeted by this attack that was running Windows Defender, starting from patient zero.”
Endpoint detection and response tools like Defender are stopping fileless attacks, and you can see how attacks get detected using Microsoft Defender Advanced Threat Protection. But you should also be setting up attack surface reduction rules to disable functionality that you’re not using — like allowing Office apps to inject code into other processes, which is something a lot of ransomware exploits.
“Having Office apps create child processes is not common behaviour. There are a small handful of enterprises out there writing really complex macro code [that needs this] — and they should stop doing that!” Ganacharya warns. “But most organisations do not need this functionality enabled, especially not for departments like sales and HR and marketing where you don’t have a lot of engineers.”
The Locky ransomware used an email message with an Office attachment with a hidden formula that ran PowerShell to infect systems. “If you have just enabled the attack surface reduction rule that said block Office apps from creating child processes, you don’t have to worry that your solution has to be able to deal with all the things that are happening in these latter three stages — you will just stop the attack very early on, minimising damage in your network,” Ganacharya says.
“Just enabling attack surface reduction rules stops most of the zero days that were identified in the last year or so.”
- How to prevent destructive malware attacks on your business: 7 tips (TechRepublic)
- How to become a cybersecurity pro: A cheat sheet (TechRepublic)
- 10 dangerous app vulnerabilities to watch out for (TechRepublic download)
- Windows 10 security: A guide for business leaders (TechRepublic Premium)
- Online security 101: Tips for protecting your privacy from hackers and spies (ZDNet)
- The best password managers of 2019 (CNET)
- Cybersecurity and cyberwar: More must-read coverage (TechRepublic on Flipboard)