Add-Persistence bugfix

When file paths were specified, they were not being properly validated.
This commit is contained in:
mattifestation
2014-11-17 08:24:54 -05:00
parent 956e4c968a
commit dc1a5e519f
2 changed files with 23 additions and 11 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
ModuleToProcess = 'Persistence.psm1'
# Version number of this module.
ModuleVersion = '1.1.0.0'
ModuleVersion = '1.1.1.0'
# ID used to uniquely identify this module
GUID = '633d0f10-a056-41da-869d-6d2f75430195'
+22 -10
View File
@@ -417,11 +417,9 @@ function Add-Persistence
[String]
$PersistenceScriptName = 'Update-Windows',
[ValidateNotNullOrEmpty()]
[String]
$PersistentScriptFilePath = "$PWD\Persistence.ps1",
[ValidateNotNullOrEmpty()]
[String]
$RemovalScriptFilePath = "$PWD\RemovePersistence.ps1",
@@ -446,35 +444,49 @@ function Add-Persistence
throw 'You provided invalid user-level persistence options.'
}
$Path = Split-Path $PersistentScriptFilePath -ErrorAction Stop
$Result = Get-Item $PersistentScriptFilePath -ErrorAction SilentlyContinue
if ($Result -and $Result.PSIsContainer)
{
throw 'You must provide a file name with the PersistentScriptFilePath option.'
}
$Result = Get-Item $RemovalScriptFilePath -ErrorAction SilentlyContinue
if ($Result -and $Result.PSIsContainer)
{
throw 'You must provide a file name with the RemovalScriptFilePath option.'
}
$PersistentPath = Split-Path $PersistentScriptFilePath -ErrorAction Stop
$Leaf = Split-Path $PersistentScriptFilePath -Leaf -ErrorAction Stop
$PersistentScriptFile = ''
$RemovalScriptFile = ''
if ($Path -eq '')
if ($PersistentPath -eq '')
{
# i.e. Only a file name was provided implying $PWD
$PersistentScriptFile = "$($PWD)\$($Leaf)"
}
else
{
$PersistentScriptFile = "$($Path)\$($Leaf)"
$PersistentScriptFile = "$(Resolve-Path $PersistentPath)\$($Leaf)"
}
$Path = Split-Path $RemovalScriptFilePath -ErrorAction Stop
$RemovalPath = Split-Path $RemovalScriptFilePath -ErrorAction Stop
$Leaf = Split-Path $RemovalScriptFilePath -Leaf -ErrorAction Stop
if ($Path -eq '')
if ($RemovalPath -eq '')
{
# i.e. Only a file name was provided implying $PWD
$RemovalScriptFile = "$($PWD)\$($Leaf)"
}
else
{
$RemovalScriptFile = "$($Path)\$($Leaf)"
$RemovalScriptFile = "$(Resolve-Path $RemovalPath)\$($Leaf)"
}
if ($PSBoundParameters['FilePath'])
{
Get-ChildItem $FilePath -ErrorAction Stop
$Script = [IO.File]::ReadAllText((Resolve-Path $Path))
$null = Get-ChildItem $FilePath -ErrorAction Stop
$Script = [IO.File]::ReadAllText((Resolve-Path $FilePath))
}
else
{