Skip to content

Commit

Permalink
Revert "Atomic sudo" (#193)
Browse files Browse the repository at this point in the history
* Revert "Atomic sudo"

* fix linting issues

---------

Co-authored-by: Hare Sudhan <code@0x6c.dev>
  • Loading branch information
clr2of8 and cyberbuff authored Apr 27, 2024
1 parent dbce611 commit da0cc4e
Show file tree
Hide file tree
Showing 10 changed files with 1,125 additions and 1,194 deletions.
197 changes: 98 additions & 99 deletions Invoke-AtomicRedTeam.psd1
Original file line number Diff line number Diff line change
@@ -1,99 +1,98 @@
@{

# Script module or binary module file associated with this manifest.
RootModule = 'Invoke-AtomicRedTeam.psm1'

# Version number of this module.
ModuleVersion = '2.1.0'

# ID used to uniquely identify this module
GUID = '8f492621-18f8-432e-9532-b1d54d3e90bd'

# Author of this module
Author = 'Casey Smith @subTee, Josh Rickard @MSAdministrator, Carrie Roberts @OrOneEqualsOne, Matt Graeber @mattifestation'

# Company or vendor of this module
CompanyName = 'Red Canary, Inc.'

# Copyright statement for this module
Copyright = '(c) 2021 Red Canary. All rights reserved.'

# Description of the functionality provided by this module
Description = 'A PowerShell module that runs Atomic Red Team tests from yaml definition files.'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @('powershell-yaml')

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# AtomicClassSchema.ps1 needs to be present in the caller's scope in order for the built-in classes to surface properly.
ScriptsToProcess = @('Private\AtomicClassSchema.ps1', 'Public\config.ps1')

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @(
'Invoke-AtomicTest',
'Get-AtomicTechnique',
'New-AtomicTechnique',
'New-AtomicTest',
'New-AtomicTestInputArgument',
'New-AtomicTestDependency',
'Start-AtomicGUI',
'Stop-AtomicGUI',
'Set-Sudo'
'Invoke-SetupAtomicRunner',
'Invoke-GenerateNewSchedule',
'Invoke-RefreshExistingSchedule',
'Invoke-AtomicRunner',
'Get-Schedule',
'Invoke-KickoffAtomicRunner',
'Get-PreferredIPAddress'
)

# Variables to export from this module
VariablesToExport = '*'

NestedModules = @(
"Public\Default-ExecutionLogger.psm1",
"Public\Attire-ExecutionLogger.psm1",
"Public\Syslog-ExecutionLogger.psm1",
"Public\WinEvent-ExecutionLogger.psm1"
)

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('Security', 'Defense')

# A URL to the license for this module.
LicenseUri = 'https://github.com/redcanaryco/invoke-atomicredteam/blob/master/LICENSE.txt'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/redcanaryco/invoke-atomicredteam'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = @'
1.0.2
-----
* Add support for custom execution loggers
1.0.1
-----
* Adding 'powershell-yaml' to RequiredModules in the module manifest
1.0.0
-----
* Initial release for submission to the PowerShell Gallery
'@

} # End of PSData hashtable

} # End of PrivateData hashtable
}
@{

# Script module or binary module file associated with this manifest.
RootModule = 'Invoke-AtomicRedTeam.psm1'

# Version number of this module.
ModuleVersion = '2.1.0'

# ID used to uniquely identify this module
GUID = '8f492621-18f8-432e-9532-b1d54d3e90bd'

# Author of this module
Author = 'Casey Smith @subTee, Josh Rickard @MSAdministrator, Carrie Roberts @OrOneEqualsOne, Matt Graeber @mattifestation'

# Company or vendor of this module
CompanyName = 'Red Canary, Inc.'

# Copyright statement for this module
Copyright = '(c) 2021 Red Canary. All rights reserved.'

# Description of the functionality provided by this module
Description = 'A PowerShell module that runs Atomic Red Team tests from yaml definition files.'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @('powershell-yaml')

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# AtomicClassSchema.ps1 needs to be present in the caller's scope in order for the built-in classes to surface properly.
ScriptsToProcess = @('Private\AtomicClassSchema.ps1', 'Public\config.ps1')

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @(
'Invoke-AtomicTest',
'Get-AtomicTechnique',
'New-AtomicTechnique',
'New-AtomicTest',
'New-AtomicTestInputArgument',
'New-AtomicTestDependency',
'Start-AtomicGUI',
'Stop-AtomicGUI',
'Invoke-SetupAtomicRunner',
'Invoke-GenerateNewSchedule',
'Invoke-RefreshExistingSchedule',
'Invoke-AtomicRunner',
'Get-Schedule',
'Invoke-KickoffAtomicRunner',
'Get-PreferredIPAddress'
)

# Variables to export from this module
VariablesToExport = '*'

NestedModules = @(
"Public\Default-ExecutionLogger.psm1",
"Public\Attire-ExecutionLogger.psm1",
"Public\Syslog-ExecutionLogger.psm1",
"Public\WinEvent-ExecutionLogger.psm1"
)

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('Security', 'Defense')

# A URL to the license for this module.
LicenseUri = 'https://github.com/redcanaryco/invoke-atomicredteam/blob/master/LICENSE.txt'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/redcanaryco/invoke-atomicredteam'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = @'
1.0.2
-----
* Add support for custom execution loggers
1.0.1
-----
* Adding 'powershell-yaml' to RequiredModules in the module manifest
1.0.0
-----
* Initial release for submission to the PowerShell Gallery
'@

} # End of PSData hashtable

} # End of PrivateData hashtable
}
110 changes: 55 additions & 55 deletions Private/AtomicClassSchema.ps1
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
class AtomicDependency {
[String] $description
[String] $prereq_command
[String] $get_prereq_command
}

class AtomicInputArgument {
[String] $description
[String] $type
[String] $default
}

class AtomicExecutorBase {
[String] $name
[Bool] $elevation_required

# Implemented to facilitate improved PS object display
[String] ToString() {
return $this.Name
}
}

class AtomicExecutorDefault : AtomicExecutorBase {
[String] $command
[String] $cleanup_command
}

class AtomicExecutorManual : AtomicExecutorBase {
[String] $steps
[String] $cleanup_command
}

class AtomicTest {
[String] $name
[String] $auto_generated_guid
[String] $description
[String[]] $supported_platforms
# I wish this didn't have to be a hashtable but I don't
# want to change the schema and introduce a breaking change.
[Hashtable] $input_arguments
[String] $dependency_executor_name
[AtomicDependency[]] $dependencies
[AtomicExecutorBase] $executor

# Implemented to facilitate improved PS object display
[String] ToString() {
return $this.name
}
}

class AtomicTechnique {
[String[]] $attack_technique
[String] $display_name
[AtomicTest[]] $atomic_tests
}
class AtomicDependency {
[String] $description
[String] $prereq_command
[String] $get_prereq_command
}

class AtomicInputArgument {
[String] $description
[String] $type
[String] $default
}

class AtomicExecutorBase {
[String] $name
[Bool] $elevation_required

# Implemented to facilitate improved PS object display
[String] ToString() {
return $this.Name
}
}

class AtomicExecutorDefault : AtomicExecutorBase {
[String] $command
[String] $cleanup_command
}

class AtomicExecutorManual : AtomicExecutorBase {
[String] $steps
[String] $cleanup_command
}

class AtomicTest {
[String] $name
[String] $auto_generated_guid
[String] $description
[String[]] $supported_platforms
# I wish this didn't have to be a hashtable but I don't
# want to change the schema and introduce a breaking change.
[Hashtable] $input_arguments
[String] $dependency_executor_name
[AtomicDependency[]] $dependencies
[AtomicExecutorBase] $executor

# Implemented to facilitate improved PS object display
[String] ToString() {
return $this.name
}
}

class AtomicTechnique {
[String[]] $attack_technique
[String] $display_name
[AtomicTest[]] $atomic_tests
}
13 changes: 3 additions & 10 deletions Private/Invoke-ExecuteCommand.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
function Invoke-ExecuteCommand ($finalCommand, $executor, $elevationreq, $can_sudo, $executionPlatform, $TimeoutSeconds, $session = $null, $interactive) {
function Invoke-ExecuteCommand ($finalCommand, $executor, $executionPlatform, $TimeoutSeconds, $session = $null, $interactive) {
$null = @(
if ($null -eq $finalCommand) { return 0 }
$finalCommand = $finalCommand.trim()
Write-Verbose -Message 'Invoking Atomic Tests using defined executor'
if ($executor -eq "command_prompt" -or $executor -eq "sh" -or $executor -eq "bash") {
if (($executor -eq "sh" -or $executor -eq "bash") -and ($elevationreq -eq $true) -and ($can_sudo -eq $true)) {
$execExe = "$(which sudo)"
$execPrefix = "$(which $executor) -c"
}
else {
$execExe = $executor
$execPrefix = "-c"
}

$execPrefix = "-c"
$execExe = $executor
if ($executor -eq "command_prompt") {
$execPrefix = "/c";
$execExe = "cmd.exe";
Expand Down
1 change: 0 additions & 1 deletion Public/Get-PreferredIPAddress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ function Get-PreferredIPAddress($isWindows) {
return ''
}
}

Loading

0 comments on commit da0cc4e

Please sign in to comment.