# T1222.002 - File and Directory Permissions Modification: FreeBSD, Linux and Mac File and Directory Permissions Modification

## Description from ATT&CK

> 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: <code>chown</code> (short for change owner), and <code>chmod</code> (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](https://attack.mitre.org/techniques/T1546/004) or tainting/hijacking other instrumental binary/configuration files via [Hijack Execution Flow](https://attack.mitre.org/techniques/T1574).(Citation: 20 macOS Common Tools and Techniques)

[Source](https://attack.mitre.org/techniques/T1222/002)

## Atomic Tests

- [Atomic Test #1: chmod - Change file or folder mode (numeric mode)](#atomic-test-1-chmod---change-file-or-folder-mode-numeric-mode)
- [Atomic Test #2: chmod - Change file or folder mode (symbolic mode)](#atomic-test-2-chmod---change-file-or-folder-mode-symbolic-mode)
- [Atomic Test #3: chmod - Change file or folder mode (numeric mode) recursively](#atomic-test-3-chmod---change-file-or-folder-mode-numeric-mode-recursively)
- [Atomic Test #4: chmod - Change file or folder mode (symbolic mode) recursively](#atomic-test-4-chmod---change-file-or-folder-mode-symbolic-mode-recursively)
- [Atomic Test #5: chown - Change file or folder ownership and group](#atomic-test-5-chown---change-file-or-folder-ownership-and-group)
- [Atomic Test #6: chown - Change file or folder ownership and group recursively](#atomic-test-6-chown---change-file-or-folder-ownership-and-group-recursively)
- [Atomic Test #7: chown - Change file or folder mode ownership only](#atomic-test-7-chown---change-file-or-folder-mode-ownership-only)
- [Atomic Test #8: chown - Change file or folder ownership recursively](#atomic-test-8-chown---change-file-or-folder-ownership-recursively)
- [Atomic Test #9: chattr - Remove immutable file attribute](#atomic-test-9-chattr---remove-immutable-file-attribute)
- [Atomic Test #10: chflags - Remove immutable file attribute](#atomic-test-10-chflags---remove-immutable-file-attribute)
- [Atomic Test #11: Chmod through c script](#atomic-test-11-chmod-through-c-script)
- [Atomic Test #12: Chmod through c script (freebsd)](#atomic-test-12-chmod-through-c-script-freebsd)
- [Atomic Test #13: Chown through c script](#atomic-test-13-chown-through-c-script)
- [Atomic Test #14: Chown through c script (freebsd)](#atomic-test-14-chown-through-c-script-freebsd)

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

**auto_generated_guid:** `34ca1464-de9d-40c6-8c77-690adf36a135`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| numeric_mode | Specified numeric mode value | integer | 755|
| file_or_folder | Path of the file or folder | path | /tmp/AtomicRedTeam/atomics/T1222.002|

#### Attack Commands: Run with `sh`!

```sh
chmod #{numeric_mode} #{file_or_folder}
```

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

**auto_generated_guid:** `fc9d6695-d022-4a80-91b1-381f5c35aff3`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| symbolic_mode | Specified symbolic mode value | string | a+w|
| file_or_folder | Path of the file or folder | path | /tmp/AtomicRedTeam/atomics/T1222.002|

#### Attack Commands: Run with `sh`!

```sh
chmod #{symbolic_mode} #{file_or_folder}
```

### Atomic Test #3: chmod - Change file or folder mode (numeric mode) recursively

Changes a file or folder's permissions recursively using chmod and a specified numeric mode.

**Supported Platforms:** Linux, macOS

**auto_generated_guid:** `ea79f937-4a4d-4348-ace6-9916aec453a4`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| numeric_mode | Specified numeric mode value | integer | 755|
| file_or_folder | Path of the file or folder | path | /tmp/AtomicRedTeam/atomics/T1222.002|

#### Attack Commands: Run with `sh`!

```sh
chmod -R #{numeric_mode} #{file_or_folder}
```

### Atomic Test #4: chmod - Change file or folder mode (symbolic mode) recursively

Changes a file or folder's permissions recursively using chmod and a specified symbolic mode.

**Supported Platforms:** Linux, macOS

**auto_generated_guid:** `0451125c-b5f6-488f-993b-5a32b09f7d8f`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| symbolic_mode | Specified symbolic mode value | string | a+w|
| file_or_folder | Path of the file or folder | path | /tmp/AtomicRedTeam/atomics/T1222.002|

#### Attack Commands: Run with `bash`!

```bash
chmod -R #{symbolic_mode} #{file_or_folder}
```

### Atomic Test #5: chown - Change file or folder ownership and group

Changes a file or folder's ownership and group information using chown.

**Supported Platforms:** macOS, Linux

**auto_generated_guid:** `d169e71b-85f9-44ec-8343-27093ff3dfc0`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| owner | Username of desired owner | string | root|
| file_or_folder | Path of the file or folder | path | /tmp/AtomicRedTeam/atomics/T1222.002/T1222.002.yaml|
| group | Group name of desired group | string | root|

#### Attack Commands: Run with `bash`!

```bash
chown #{owner}:#{group} #{file_or_folder}
```

### Atomic Test #6: chown - Change file or folder ownership and group recursively

Changes a file or folder's ownership and group information recursively using chown.

**Supported Platforms:** macOS, Linux

**auto_generated_guid:** `b78598