Research by: Siddartha Sharma and Adhokshaj Mishra
In our previous blog, we discussed the common utilities in Linux which are generally used by threat actors in the attack chain. This blog discusses the common defense evasion techniques which are mostly used in malicious shell scripts and how Uptycs detects them.
Attackers use malicious shell scripts as an initial vector to download malicious payloads to the victim system. In the earlier days, base64 and other common encoding schemes were used to evade defensive parameters. But nowadays, threat actors are adopting newer techniques that include commands to disable firewalls, monitoring agents etc.
The common evasive techniques which we identified in the malicious shell scripts are as follows:
We will be using the hash (39ac019520a278e350065d12ebc0c24201584390724f3d8e0dc828664fee6cae) to demonstrate and explain in brief about these techniques.
Monitoring agents are the softwares that regularly monitors the activities going on in the system related to process and network. Various logs are also created by the monitoring agents which helps as an aid during any incident investigation.
The malicious script, we found in our inhouse osquery based sandbox tries to:
Uninstall BCM client management agent which is generally installed on Endpoints for risk mitigation.
Figure 1: Script Uninstalling monitoring agents
Most of the systems and servers deploy firewalls as a defense mechanism.In the malicious script, attackers try to disable the firewall i.e., uninterrupted firewall (ufw) as a defense evasive tactic.. Along with that attackers also remove iptables rules (iptables -F) because it is widely used for managing the firewall rules on linux systems and servers.(see figure 2)
Figure 2: Script Disabling Firewall
Attackers also used the commands to disable non-maskable Interrupt(nmi).Watchdog is basically a configurable timer mechanism which generates interrupt at a particular given condition and time.In case of the system freeze, the nmi watchdog interrupt handler would kill the task which is responsible for the system freeze.To evade this defense mechanism, attackers disable watchdog feature using sysctl command or temporarily disabling it by setting the value to ‘0’.(see figure 3)
Figure 3: Script Disabling kernel watchdog
The malicious shell script also disables Linux security modules like SElinux, Apparmor. These modules are designed to implement mandatory access control(MAC) policies. A server administrator could simply configure these modules to provide the users restricted access to the installed or running applications in the system.
AppArmour is a security feature in linux which is used to lock down applications like firefox for increased security. A user can restrict an application in Ubuntu’s default configuration by giving limited permission to a certain application.
Figure 4: Commands disabling AppArmour
SElinux is another security feature in linux systems by which a security administrator could apply security context on certain applications and utilities. On some web servers the shell is disabled or restricted so for RCE(Remote Code Execution) adversaries usually bypass/disable this:
Figure 5: Commands disabling SElinux
ACLs or Access control Lists contain the rules by which permissions on files and utilities are being granted. Filesystem ACLs tell operating systems which users can access the system, and what privileges the users are allowed. Setfacl utility in linux is used to modify, remove the ACL, in the script we can see the usage of setfacl which sets permissions of chmod for the user:
Figure 6: ACL modification
Chattr in linux is used to set/unset certain attributes of a file, more on chattr utility here . Adversaries use this for their own dropped files or to make their files immutable so that a user cannot delete it:
Figure 7.1: Chattr usage for dropped malicious file
Another scenario:
Figure 7.2: Making the keys file immutable
One of the malicious scripts (d7c4693f4c36d8c06a52d8981827245b9ab4f63283907ef8c3947499a37eedc8) also contained common utilities like wget,curl used with different names. These utilities are generally used to download files from the remote IP. Attackers use these utilities to download malicious files from C2.Some of the security solutions whose detection rules monitor the exact names of the utilities might not trigger the download event if wget,curl are used under different names.
Figure 8: Utilities getting renamed in the script
Figure 9: Usage of renamed common utilities
Uptycs endpoints detection and response (EDR) armed with YARA process scanning detected these malicious scripts with a threat score of 10/10.
Figure 10: chattr and setfacl usage
Figure 11:Toolkit data showing attribution
Alongside the detections, Uptycs EDR also records all the events we mentioned above in the process_events table. Using the queries below, incident response analysts can easily identify such malicious events:
As attackers are using more sophisticated and novel methods for evasion, it becomes increasingly important to monitor and record the activities happening in the system. Uptycs EDR offers the added benefit of taking a deep dive into the events logged, providing more insights of an attack. The reactive nature of Uptycs’ EDR helps to log everything whatever goes on in the system.
We recommend the following measures: