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:
- Technique 1: Uninstalling monitoring Agents
- Technique 2: Disabling Firewalls and Interrupts
- Technique 3: Disabling Linux Security Modules(LSMs)
- Technique 4: Modifying ACLs
- Technique 5: Changing Attributes
- Technique 6: Renaming common Utilities
We will be using the hash (39ac019520a278e350065d12ebc0c24201584390724f3d8e0dc828664fee6cae) to demonstrate and explain in brief about these techniques.
Technique 1: Uninstalling monitoring Agents
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 Cloud related monitoring agent Aegis(Alibaba cloud threat detection agent), stopping the aliyun service.
- Uninstall YunJing which is a host security agent from Tencent.
Uninstall BCM client management agent which is generally installed on Endpoints for risk mitigation.
Technique 2: Disabling Firewalls and Interrupts
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)
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)
Technique 3: Disabling Linux Security Modules (LSMs)
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.
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:
Technique 4: Modifying ACLs
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:
Technique 5: Changing Attributes
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:
Technique 6: Renaming common Utilities
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.
Uptycs EDR Detections
Uptycs EDR armed with YARA process scanning detected these malicious scripts with a threat score of 10/10.
Uptycs EDR queries
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:
- Firewall disabling
- select * from process_events where exe_name = 'ufw';
- ACL modification
- select * from process_events where exe_name = 'setfacl';
- Chattr utility usage
- select * from process_events where exe_name = 'chattr' and cmdline = 'chattr +ia /home/hilde/.ssh/authorized_keys2';
- Checking renamed common utilities (wget,curl)
- select * from process_events where exe_name = 'mv';
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:
- Regularly monitor the suspicious processes, events, and network traffic spawned on the execution of any untrusted binary.
- Keep systems and firmware updated with the latest releases and patches.
Want to Learn More About How Uptycs Can Help Secure Your Linux Environments?
Research and updates from the Uptycs Threat Research team.
Other posts you might be interested in
8 min read | March 24, 2020
Should We Blocklist Newly Registered Domains?Read More
21 min read | May 7, 2021
Linux Commands and Utilities Commonly Used by AttackersRead More
15 min read | October 7, 2021