Skip to content

Commit

Permalink
Cleanup main code, better errors for invalid parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane Gittins committed Dec 3, 2019
1 parent 2c66a0c commit 5e3a614
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions Huntress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
.NOTES
Author: Zane Gittins
Last Updated: 2/25/2019
Version 1.0
Last Updated: 11/3/2019
#>

param (
Expand Down Expand Up @@ -92,7 +91,6 @@ class MachineGroup {
}

function Write-Banner {
# Print the Huntress banner.
[CmdletBinding()]
param()
$Banner = "
Expand Down Expand Up @@ -232,27 +230,38 @@ Write-Banner

$AllGroups = @()

# User must provide either a quiver file or taret host.
if($PSBoundParameters.ContainsKey('Quiver') -eq $true -and $Quiver -ne "" -and $Quiver -ne $null) {
$AllGroups = Get-Quiver $Quiver
} elseif ($PSBoundParameters.ContainsKey("TargetHost") -eq $true) {

# User must provide a target group if quiver is specified.
if($PSBoundParameters.ContainsKey('TargetGroup') -eq $true) {
$AllGroups = $AllGroups | Where-Object {$_.Group -eq $TargetGroup}
} else {
Get-Help $MyInvocation.MyCommand.Path
Write-Color -Text "Quiver specified but no TargetGroup given." -Color Red
Exit
}
}
elseif ($PSBoundParameters.ContainsKey("TargetHost") -eq $true) {
$NewGroup = [MachineGroup]::new()
$NewGroup.Group = "SINGLE"
$NewGroup.Members = @()
$NewGroup.Members += $TargetHost
$AllGroups += $NewGroup
} else {
Write-Host "No Quiver file or TargetHost provided."
}
else {
Get-Help $MyInvocation.MyCommand.Path
Write-Color -Text "No Quiver or TargetHost provided." -Color Red
Exit
}

# If user provided Module and did not provide ModuleArguments then set variable to null.
if ($PSBoundParameters.ContainsKey('Module') -eq $true -and $PSBoundParameters.ContainsKey('ModuleArguments') -eq $false) {
$ModuleArguments = $null
}

if($PSBoundParameters.ContainsKey('TargetGroup') -eq $true) {
$AllGroups = $AllGroups | Where-Object {$_.Group -eq $TargetGroup}
}
}

# User must pass credentials or enter credentials at run-time.
$LiveCred = $null
if($PSBoundParameters.ContainsKey('Credential') -eq $true) { $LiveCred = $Credential }
elseif ($PSBoundParameters.ContainsKey('CredentialFile') -eq $true -and $PSBoundParameters.ContainsKey('CredentialUsername')) {
Expand All @@ -261,6 +270,7 @@ elseif ($PSBoundParameters.ContainsKey('CredentialFile') -eq $true -and $PSBound
}
else {$LiveCred = Get-Credential }

# Display groups that Huntress will run against.
Write-Groups $AllGroups

Write-Host ""
Expand All @@ -276,5 +286,6 @@ if ($PSBoundParameters.ContainsKey('Module') -eq $true) {
}
else {
Get-Help $MyInvocation.MyCommand.Path
Write-Color -Text "No Module provided." -Color Red
Exit
}

0 comments on commit 5e3a614

Please sign in to comment.