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.(Citation: Hybrid Analysis Icacls1 June 2018)(Citation: Hybrid Analysis Icacls2 May 2018) 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.(Citation: 20 macOS Common Tools and Techniques)
Atomic Tests#
Atomic Test #1 - chmod - Change file or folder mode (numeric mode)Changes a file or folder’s permissions using chmod and a specified numeric mode.#
Supported Platforms: linux, macos#### Attack Commands: Run with sh
chmod 755 /tmp/AtomicRedTeam/atomics/T1222.002
Invoke-AtomicTest T1222.002 -TestNumbers 1
Atomic Test #2 - chmod - Change file or folder mode (symbolic mode)Changes a file or folder’s permissions using chmod and a specified symbolic mode.#
Supported Platforms: linux, macos#### Attack Commands: Run with sh
chmod a+w /tmp/AtomicRedTeam/atomics/T1222.002
Invoke-AtomicTest T1222.002 -TestNumbers 2
Atomic Test #3 - chmod - Change file or folder mode (numeric mode) recursivelyChanges a file or folder’s permissions recursively using chmod and a specified numeric mode.#
Supported Platforms: linux, macos#### Attack Commands: Run with sh
chmod -R 755 /tmp/AtomicRedTeam/atomics/T1222.002
Invoke-AtomicTest T1222.002 -TestNumbers 3
Atomic Test #4 - chmod - Change file or folder mode (symbolic mode) recursivelyChanges a file or folder’s permissions recursively using chmod and a specified symbolic mode.#
Supported Platforms: linux, macos#### Attack Commands: Run with bash
chmod -R a+w /tmp/AtomicRedTeam/atomics/T1222.002
Invoke-AtomicTest T1222.002 -TestNumbers 4
Atomic Test #5 - chown - Change file or folder ownership and groupChanges a file or folder’s ownership and group information using chown.#
Supported Platforms: macos, linux#### Attack Commands: Run with bash
chown root:root /tmp/AtomicRedTeam/atomics/T1222.002/T1222.002.yaml
Invoke-AtomicTest T1222.002 -TestNumbers 5
Atomic Test #6 - chown - Change file or folder ownership and group recursivelyChanges a file or folder’s ownership and group information recursively using chown.#
Supported Platforms: macos, linux#### Attack Commands: Run with bash
chown -R root:root /tmp/AtomicRedTeam/atomics/T1222.002
Invoke-AtomicTest T1222.002 -TestNumbers 6
Atomic Test #7 - chown - Change file or folder mode ownership onlyChanges a file or folder’s ownership only using chown.#
Supported Platforms: linux, macos#### Attack Commands: Run with sh
chown root /tmp/AtomicRedTeam/atomics/T1222.002/T1222.002.yaml
Invoke-AtomicTest T1222.002 -TestNumbers 7
Atomic Test #8 - chown - Change file or folder ownership recursivelyChanges a file or folder’s ownership only recursively using chown.#
Supported Platforms: macos, linux#### Attack Commands: Run with bash
chown -R root /tmp/AtomicRedTeam/atomics/T1222.002
Invoke-AtomicTest T1222.002 -TestNumbers 8
Atomic Test #9 - chattr - Remove immutable file attributeRemove’s a file’s immutable
attribute using chattr
.#
This technique was used by the threat actor Rocke during the compromise of Linux web servers.
Supported Platforms: macos, linux#### Attack Commands: Run with sh
chattr -i /var/spool/cron/root
Invoke-AtomicTest T1222.002 -TestNumbers 9
Atomic Test #10 - chflags - Remove immutable file attributeRemove’s a file’s immutable
attribute using chflags
.#
This technique was used by the threat actor Rocke during the compromise of Linux web servers.
Supported Platforms: linux#### Attack Commands: Run with sh
touch /tmp/T1222.002.txt
chflags simmutable /tmp/T1222.002.txt
chflags nosimmutable /tmp/T1222.002.txt
Invoke-AtomicTest T1222.002 -TestNumbers 10
Atomic Test #11 - Chmod through c script#
chmods a file using a c script
Supported Platforms: macos, linux
Dependencies: Run with sh
!#
Description: Compile the script from (#{source_file}). Destination is #{compiled_file}#
Check Prereq Commands:#
gcc PathToAtomicsFolder/T1222.002/src/T1222.002.c -o /tmp/T1222002
Get Prereq Commands:#
gcc PathToAtomicsFolder/T1222.002/src/T1222.002.c -o /tmp/T1222002
Invoke-AtomicTest T1222.002 -TestNumbers 11 -GetPreReqs
Attack Commands: Run with sh
#
/tmp/T1222002 /tmp/ T1222002
Invoke-AtomicTest T1222.002 -TestNumbers 11
Atomic Test #12 - Chmod through c script (freebsd)#
chmods a file using a c script
Supported Platforms: linux
Dependencies: Run with sh
!#
Description: Compile the script from (#{source_file}). Destination is #{compiled_file}#
Check Prereq Commands:#
cc PathToAtomicsFolder/T1222.002/src/T1222.002.c -o /tmp/T1222002
Get Prereq Commands:#
cc PathToAtomicsFolder/T1222.002/src/T1222.002.c -o /tmp/T1222002
Invoke-AtomicTest T1222.002 -TestNumbers 12 -GetPreReqs
Attack Commands: Run with sh
#
/tmp/T1222002 /tmp/ T1222002
Invoke-AtomicTest T1222.002 -TestNumbers 12
Atomic Test #13 - Chown through c script#
chowns a file to root using a c script
Supported Platforms: macos, linux
Elevation Required (e.g. root or admin)
Dependencies: Run with sh
!#
Description: Compile the script from (#{source_file}). Destination is #{compiled_file}#
Check Prereq Commands:#
gcc PathToAtomicsFolder/T1222.002/src/chown.c -o /tmp/T1222002own
Get Prereq Commands:#
gcc PathToAtomicsFolder/T1222.002/src/chown.c -o /tmp/T1222002own
Invoke-AtomicTest T1222.002 -TestNumbers 13 -GetPreReqs
Attack Commands: Run with sh
#
sudo /tmp/T1222002own PathToAtomicsFolder/T1222.002/src/chown.c
Invoke-AtomicTest T1222.002 -TestNumbers 13
Atomic Test #14 - Chown through c script (freebsd)#
chowns a file to root using a c script
Supported Platforms: linux
Elevation Required (e.g. root or admin)
Dependencies: Run with sh
!#
Description: Compile the script from (#{source_file}). Destination is #{compiled_file}#
Check Prereq Commands:#
cc PathToAtomicsFolder/T1222.002/src/chown.c -o /tmp/T1222002own
Get Prereq Commands:#
cc PathToAtomicsFolder/T1222.002/src/chown.c -o /tmp/T1222002own
Invoke-AtomicTest T1222.002 -TestNumbers 14 -GetPreReqs
Attack Commands: Run with sh
#
/tmp/T1222002own PathToAtomicsFolder/T1222.002/src/chown.c
Invoke-AtomicTest T1222.002 -TestNumbers 14
Detection#
Monitor and investigate attempts to modify ACLs and file/directory ownership. 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
.(Citation: 20 macOS Common Tools and Techniques)
Consider enabling file/directory permission change auditing on folders containing key binary/configuration files.