Six Malicious Linux Shell Scripts Used to Evade Defenses and How to Stop Them | Threatpost

Siddartha Sharma and Adhokshaj Mishra

Evasive techniques used by attackers, date back to the earlier days, when base64 and other common encoding schemes were used. Today, attackers are adopting new Linux shell script tactics and techniques to disable firewalls, monitoring agents and modifying access control lists (ACLs).

In previous Uptycs Threat Research posts, we discussed the common utilities in Linux, which are generally used by threat actors in the attack chain. In this report, we highlight those common defense evasion techniques, which are common in malicious Linux shell scripts. And then, we outline how Uptycs spots and mitigates against them.

In this post, we cover common evasive shell-script techniques as:

The hash 39ac019520a278e350065d12ebc0c24201584390724f3d8e0dc828664fee6cae will be used to demonstrate and explain these techniques.

Technique 1: Uninstalling monitoring Agents

Monitoring agents are the software components that regularly monitor 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 in-house osquery based sandbox tries to:

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 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:

Another scenario:

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:


Want to Learn More About How Uptycs Can Help Secure Your Linux Environments? Watch A 15-Minute Demo!