# T1059.003 - Windows Command Shell
## [Description from ATT&CK](https://attack.mitre.org/techniques/T1059/003)
<blockquote>Adversaries may abuse the Windows command shell for execution. The Windows command shell ([cmd](https://attack.mitre.org/software/S0106)) is the primary command prompt on Windows systems. The Windows command prompt can be used to control almost any aspect of a system, with various permission levels required for different subsets of commands. 

Batch files (ex: .bat or .cmd) also provide the shell with a list of sequential commands to run, as well as normal scripting operations such as conditionals and loops. Common uses of batch files include long or repetitive tasks, or the need to run the same set of commands on multiple systems.

Adversaries may leverage [cmd](https://attack.mitre.org/software/S0106) to execute various commands and payloads. Common uses include [cmd](https://attack.mitre.org/software/S0106) to execute a single command, or abusing [cmd](https://attack.mitre.org/software/S0106) interactively with input and output forwarded over a command and control channel.</blockquote>

## Atomic Tests

- [Atomic Test #1 - Create and Execute Batch Script](#atomic-test-1---create-and-execute-batch-script)

- [Atomic Test #2 - Writes text to a file and displays it.](#atomic-test-2---writes-text-to-a-file-and-displays-it)

- [Atomic Test #3 - Suspicious Execution via Windows Command Shell](#atomic-test-3---suspicious-execution-via-windows-command-shell)


<br/>

## Atomic Test #1 - Create and Execute Batch Script
Creates and executes a simple batch script. Upon execution, CMD will briefly launch to run the batch script then close again.

**Supported Platforms:** Windows


**auto_generated_guid:** 9e8894c0-50bd-4525-a96c-d4ac78ece388





#### Inputs:
| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| command_to_execute | Command to execute within script. | String | dir|
| script_path | Script path. | Path | $env:TEMP&#92;T1059.003_script.bat|


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


```powershell
Start-Process #{script_path}
```

#### Cleanup Commands:
```powershell
Remove-Item #{script_path} -Force -ErrorAction Ignore
```



#### Dependencies:  Run with `powershell`!
##### Description: Batch file must exist on disk at specified location (#{script_path})
##### Check Prereq Commands:
```powershell
if (Test-Path #{script_path}) {exit 0} else {exit 1}
```
##### Get Prereq Commands:
```powershell
New-Item #{script_path} -Force | Out-Null
Set-Content -Path #{script_path} -Value "#{command_to_execute}"
```




<br/>
<br/>

## Atomic Test #2 - Writes text to a file and displays it.
Writes text to a file and display the results. This test is intended to emulate the dropping of a malicious file to disk.

**Supported Platforms:** Windows


**auto_generated_guid:** 127b4afe-2346-4192-815c-69042bec570e





#### Inputs:
| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| file_contents_path | Path to the file that the command prompt will drop. | Path | %TEMP%&#92;test.bin|
| message | Message that will be written to disk and then displayed. | String | Hello from the Windows Command Prompt!|


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


```cmd
echo "#{message}" > "#{file_contents_path}" & type "#{file_contents_path}"
```

#### Cleanup Commands:
```cmd
del "#{file_contents_path}" >nul 2>&1
```





<br/>
<br/>

## Atomic Test #3 - Suspicious Execution via Windows Command Shell
Command line executed via suspicious invocation. Example is from the 2021 Threat Detection Report by Red Canary.

**Supported Platforms:** Windows


**auto_generated_guid:** d0eb3597-a1b3-4d65-b33b-2cda8d397f20





#### Inputs:
| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| output_file | File to output to | String | hello.txt|
| input_message | Message to write to file | String | Hello, from CMD!|


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


```cmd
%LOCALAPPDATA:~-3,1%md /c echo #{input_message} > #{output_file} & type #{output_file}
```






<br/>
