File and Directory Permissions Modification: Linux and Mac File and Directory Permissions Modification

ID Name
T1222.001 Windows File and Directory Permissions Modification
T1222.002 Linux and Mac File and Directory Permissions Modification

Adversaries may modify file or directory permissions/attributes to evade access control lists (ACLs) and access protected files.[1][2] File and directory permissions are commonly managed by ACLs configured by the file or directory owner, or users with the appropriate permissions. File and directory ACL implementations vary by platform, but generally explicitly designate which users or groups can perform which actions (read, write, execute, etc.).

Most Linux and Linux-based platforms provide a standard set of permission groups (user, group, and other) and a standard set of permissions (read, write, and execute) that are applied to each group. While nuances of each platform’s permissions implementation may vary, most of the platforms provide two primary commands used to manipulate file and directory ACLs: chown (short for change owner), and chmod (short for change mode).

Adversarial may use these commands to make themselves the owner of files and directories or change the mode if current permissions allow it. They could subsequently lock others out of the file. Specific file and directory modifications may be a required step for many techniques, such as establishing Persistence via Unix Shell Configuration Modification or tainting/hijacking other instrumental binary/configuration files via Hijack Execution Flow.[3]

ID: T1222.002
Sub-technique of:  T1222
Tactic: Defense Evasion
Platforms: Linux, macOS
Version: 1.2
Created: 04 February 2020
Last Modified: 14 August 2023

Procedure Examples

ID Name Description
G0050 APT32

APT32's macOS backdoor changes the permission of the file it wants to execute to 755.[4]

S1070 Black Basta

The Black Basta binary can use chmod to gain full permissions to targeted files.[5]

S0482 Bundlore

Bundlore changes the permissions of a payload using the command chmod -R 755.[3]

S0281 Dok

Dok gives all users execute permissions for the application using the command chmod +x /Users/Shared/AppStore.app.[6]

S0599 Kinsing

Kinsing has used chmod to modify permissions on key files for use.[7]

S0402 OSX/Shlayer

OSX/Shlayer can use the chmod utility to set a file as executable, such as chmod 777 or chmod +x.[3][8][9]

S0352 OSX_OCEANLOTUS.D

OSX_OCEANLOTUS.D has changed permissions of a second-stage payload to an executable via chmod.[10]

S0598 P.A.S. Webshell

P.A.S. Webshell has the ability to modify file permissions.[11]

S0587 Penquin

Penquin can add the executable flag to a downloaded file.[12]

G0106 Rocke

Rocke has changed file permissions of files so they could not be modified.[13]

G0139 TeamTNT

TeamTNT has modified the permissions on binaries with chattr.[14][15]

S0658 XCSSET

XCSSET uses the chmod +x command to grant executable permissions to the malicious file.[3]

Mitigations

ID Mitigation Description
M1026 Privileged Account Management

Ensure critical system files as well as those known to be abused by adversaries have restrictive permissions and are owned by an appropriately privileged account, especially if access is not required by users nor will inhibit system functionality.

M1022 Restrict File and Directory Permissions

Applying more restrictive permissions to files and directories could prevent adversaries from modifying the access control lists.

Detection

ID Data Source Data Component Detects
DS0017 Command Command Execution

Many of the commands used to modify ACLs and file/directory ownership are built-in system utilities and may generate a high false positive alert rate, so compare against baseline knowledge for how systems are typically used and correlate modification events with other indications of malicious activity where possible. Commonly abused command arguments include chmod +x, chmod -R 755, and chmod 777.[3]

DS0022 File File Metadata

Monitor and investigate attempts to modify ACLs and file/directory ownership. Consider enabling file/directory permission change auditing on folders containing key binary/configuration files.

Adversaries sometimes modify object access rights at the operating system level. There are varying motivations behind this action - they may not want some files/objects to be changed on systems for persistence reasons and therefore provide admin only rights; also, they may want files to be accessible with lower levels of permissions.

Windows environment logs can be noisy, so we take the following into consideration:

  • We need to exclude events generated by the local system (subject security ID "NT AUTHORITY\SYSTEM") and focus on actual user events.
  • When a permission modification is made for a folder, a new event log is generated for each subfolder and file under that folder. It is advised to group logs based on handle ID or user ID.
  • The Windows security log (event ID 4670) also includes information about the process that modifies the file permissions. It is advised to focus on uncommon process names, and it is also uncommon for real-users to perform this task without a GUI.
  • Pseudocode Event ID is for Windows Security Log (Event ID 4670 - Permissions on an object were changed).
  • Windows Event ID 4719 (An Attempt Was Made to Access An Object) can also be used to alert on changes to Active Directory audit policy for a system.

Linux environment logs can be more noisy than the Windows-specific implementation, although Linux does not generate logs for system triggered activities like in Windows. In addition, it may be necessary to whitelist cron jobs that regularly run and execute chmod.

Analytic 1 : Access Permission Modification for Windows

file_dacl_events = filter log_events where (event_id == "4670" ANDobject_type == "File" ANDsubject_security_id != "NT AUTHORITY\SYSTEM")

Analytic 2 - Access Permission Modification for Linux

chmod_processes = filter processes where command_line == "chmod *"

DS0009 Process Process Creation

Monitor for newly executed processes that may modify file or directory permissions/attributes to evade access control lists (ACLs) and access protected files.[1][2]

References