<commit_before><#
.SYNOPSIS
This script will iterate over the Atomic Red Team yaml files, create objects for each test.
The aim is to allow defenders to excercise MITRE ATT&CK Techniques to test defenses.

Function: Invoke-AtomicRedTeam
Author: <NAME> @subTee
License:  http://opensource.org/licenses/MIT
Required Dependencies: powershell-yaml , Install-Module powershell-yaml #https://github.com/cloudbase/powershell-yaml
Optional Dependencies: None
Version: 1.0

.DESCRIPTION
Create Atomic Tests from yaml files described in Atomic Red Team. https://github.com/redcanaryco/atomic-red-team

.EXAMPLE
Convert Single Yaml File to Technique Object
$T1117 = Get-AtomicTechnique -Path ..\..\atomics\T1117\T1117.yaml
.EXAMPLE
Generate the Atomic Tests For A Given Technique, don't execute.
Invoke-AtomicTest $T1117 -GenerateOnly
.EXAMPLE
Execute the Atomic Tests For A Given Technique
$T1117 = Get-AtomicTechnique -Path ..\..\atomics\T1117\T1117.yaml
Invoke-AtomicTest $T1117
.NOTES
This script converts Atomic Tests Expressed in YAML into PowerShell Objects.

.LINK
Blog: http://subt0x11.blogspot.com/2018/08/invoke-atomictest-automating-mitre-att.html
Github repo: https://github.com/redcanaryco/atomic-red-team

#>

function Confirm-Dependencies {

    if (Get-Module -ListAvailable -Name 'powershell-yaml') {
        Write-Host "PowerShell-Yaml Module Exists. Good To Go." -Foreground Green
    }
    else {
        $Title = "PowerShell-Yaml Is Not Installed"
        $Message = "Do you want to Install?"
        $Yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Y-Yes", "Yes"
        $No = New-Object System.Management.Automation.Host.ChoiceDescription "&N-No", "No"
        $Options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No)
        $Result = $Host.ui.PromptForChoice($Title, $Message, $Options, 0)

        switch ($Result) {
            0 { Install-Module -Name powershell-yaml }
            1 { exit }
        }
    }
}

function Get-AtomicTechnique {
    [CmdletBinding()]
    Param(
        [string]
        $Path
    )
    # Returns A HashTable For Each File Passed In
    BEGIN { }
    PROCESS {
        foreach ($File in $Path) {
            $parsedYaml = (ConvertFrom-Yaml (Get-Content $File -Raw ))
            Write-Output $parsedYaml
        }
    }
    END { }
}

function Invoke-AtomicTest {
    [CmdletBinding()]
    Param(
        [System.Collections.Hashtable]
        $AtomicTechnique,

        [switch]<commit_msg>Fix Error Message<commit_after><#
.SYNOPSIS
This script will iterate over the Atomic Red Team yaml files, create objects for each test.
The aim is to allow defenders to excercise MITRE ATT&CK Techniques to test defenses.

Function: Invoke-AtomicRedTeam
Author: <NAME> @subTee
License:  http://opensource.org/licenses/MIT
Required Dependencies: powershell-yaml , Install-Module powershell-yaml #https://github.com/cloudbase/powershell-yaml
Optional Dependencies: None
Version: 1.0

.DESCRIPTION
Create Atomic Tests from yaml files described in Atomic Red Team. https://github.com/redcanaryco/atomic-red-team

.EXAMPLE
Convert Single Yaml File to Technique Object
$T1117 = Get-AtomicTechnique -Path ..\..\atomics\T1117\T1117.yaml
.EXAMPLE
Generate the Atomic Tests For A Given Technique, don't execute.
Invoke-AtomicTest $T1117 -GenerateOnly
.EXAMPLE
Execute the Atomic Tests For A Given Technique
$T1117 = Get-AtomicTechnique -Path ..\..\atomics\T1117\T1117.yaml
Invoke-AtomicTest $T1117
.NOTES
This script converts Atomic Tests Expressed in YAML into PowerShell Objects.

.LINK
Blog: http://subt0x11.blogspot.com/2018/08/invoke-atomictest-automating-mitre-att.html
Github repo: https://github.com/redcanaryco/atomic-red-team

#>

function Confirm-Dependencies {

    if (Get-Module -ListAvailable -Name 'powershell-yaml') {
        Write-Host "PowerShell-Yaml Module Exists. Good To Go." -Foreground Green
    }
    else {
        $Title = "PowerShell-Yaml Is Not Installed"
        $Message = "Do you want to Install?"
        $Yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Y-Yes", "Yes"
        $No = New-Object System.Management.Automation.Host.ChoiceDescription "&N-No", "No"
        $Options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No)
        $Result = $Host.ui.PromptForChoice($Title, $Message, $Options, 0)

        switch ($Result) {
            0 { Install-Module -Name powershell-yaml }
            1 { Write-Host "Atomic Red Team Requires PowerShell-Yaml Exiting" }
        }
    }
}

function Get-AtomicTechnique {
    [CmdletBinding()]
    Param(
        [string]
        $Path
    )
    # Returns A HashTable For Each File Passed In
    BEGIN { }
    PROCESS {
        foreach ($File in $Path) {
            $parsedYaml = (ConvertFrom-Yaml (Get-Content $File -Raw ))
            Write-Output $parsedYaml
        }
    }
    END { }
}

function Invoke-AtomicTest {
    [CmdletBinding()]
    Param(
        [System.Collections.Hashtable]
        $AtomicTechnique,

        [switch]
{'fraction_non_alphanumeric': 0.10662422916252239, 'fraction_numerical': 0.01830117366222399, 'mean_word_length': 3.084484159220146, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4441553', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1548, 'n_words': 429}