-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_malicious_dataset.ps1
274 lines (234 loc) · 12.6 KB
/
generate_malicious_dataset.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<# Examples:
%comspec% /b /cl start /b /min powershell -nop -w hidden -encodedcommand ZgByAGEAYwBhAHMAbgBlAGcAbABpAGcAZQBuAHQAcwBwAGwAZQBuAGUAdABpAGMAcgB1AGYAZgBpAGEAbgA=
%windir%\R5sLXSuKf.exe
rundll32.exe C:\Users\<random>\AppData\Local\Temp\LYwsGF9ehrvd5.dll
cmd.exe /C start %COMSPEC% /C 'timeout /t 3 >nul&&echo ikrqD \\.\pipe\ikrqD'
cmd.exe /c 'echo ikrqD > \\.\pipe\ikrqD'
\\127.0.0.1\$ADMIN\91kNx.exe
#>
function Get-RandomPrivateIPAddress {
# Define the private IP address ranges
$ranges = @(
@{ Base = "10."; Octet2Range = 0..255; Octet3Range = 0..255; Octet4Range = 1..254 },
@{ Base = "172."; Octet2Range = 16..31; Octet3Range = 0..255; Octet4Range = 1..254 },
@{ Base = "192.168."; Octet3Range = 0..255; Octet4Range = 1..254 }
)
# Select a random range
$range = Get-Random -InputObject $ranges
# Ensure the selected range is not null or empty
if ($range -eq $null) {
Write-Error "No valid range selected."
return
}
# Generate random octets within the selected range
$octet1 = $range.Base
$octet2 = if ($range.ContainsKey("Octet2Range")) { Get-Random -InputObject $range.Octet2Range } else { "" }
$octet3 = Get-Random -InputObject $range.Octet3Range
$octet4 = Get-Random -InputObject $range.Octet4Range
# Ensure none of the octets are empty
if ($octet1 -eq $null -or $octet3 -eq $null -or $octet4 -eq $null -or ($octet2 -eq $null -and $range.ContainsKey("Octet2Range"))) {
Write-Error "Failed to generate a valid IP address."
return
}
# Format the IP address
if ($range.Base -eq "192.168.") {
return -join "$octet1$octet3.$octet4"
} else {
return -join "$octet1$octet2.$octet3.$octet4"
}
}
function CreateService
{
param ([string]$svcexe,[string]$svcname)
write-host $svcname $svcexe
& c:\windows\system32\sc.exe create $svcname binPath= "$svcexe" type= own
start-sleep -Seconds 2
& c:\windows\system32\sc.exe delete $svcname
}
function powershell_service
{
$ps_template1 = "%comspec% /b /c start /b /min powershell -nop -w hidden -encodedcommand '<random>'"
$ps_template2 = "powershell -nop -w hidden -noni -c '$s=New-Object IO.MemoryStream(,[Convert]::FromBase64String(`"<random>`"))IEX (New-Object IO.StreamReader(New-Object IO.Compression.GzipStream($s,[IO.Compression.CompressionMode]::Decompress))).ReadToEnd();'"
$ps_templates = @($ps_template1,$ps_template2)
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
foreach($template in $ps_templates)
{
$randomLength = Get-Random -Minimum 30 -Maximum 201
$randomString = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($randomString)
$randomb64 =[Convert]::ToBase64String($Bytes)
$servicebin = $template.replace("<random>",$randomb64)
$randomLength = Get-Random -Minimum 6 -Maximum 10
$randomString = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
CreateService -svcexe $servicebin -svcname $randomString
}
}
function rundll32_service
{
$names = get-content .\names.txt
$rundll_template1 = "rundll32.exe C:\Users\<randomname>\AppData\Local\Temp\<random>.dll,StartW"
$rundll_template2 = "rundll32.exe %windir%\<random>.dll,StartW"
$rundll_template3 = "rundll32.exe %programdata\<random>.dll,DllMain"
$rundll_template4 = "rundll32.exe %public%\<random>.dll,StartW"
$rundll_templates = @($rundll_template1,$rundll_template2,$rundll_template3,$rundll_template4)
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
foreach($template in $rundll_templates)
{
if($template -like "*AppData*")
{
$username = ((Get-Random -InputObject $names -Count 1) + "." +(Get-Random -InputObject $names -Count 1)).ToString()
$template = $template.replace("<randomname>",$username)
}
$randomLength = Get-Random -Minimum 6 -Maximum 12
$randomString = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$servicebin = $template.replace("<random>",$randomString)
#& c:\windows\system32\sc.exe create $randomString binPath= "$servicebin" type= own
#start-sleep -Seconds 2
#& c:\windows\system32\sc.exe delete $randomString
CreateService -svcexe $servicebin -svcname $randomString
}
}
function adminshare_service
{
$adminshare_template1 = "\\127.0.0.1\<randomshare>\<random>.exe"
$adminshare_template2 = "\\localhost\<randomshare>\<random>.exe"
$adminshare_template3 = "\\<randomip>\<randomshare>\<random>.exe"
$adminshare_templates = @($adminshare_template1,$adminshare_template2,$adminshare_template3)
$adminshares= @("`$ADMIN","C$","IPC$")
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
foreach ($template in $adminshare_templates)
{
if($template -like "*<randomip>*")
{
[string]$randomIP = Get-RandomPrivateIPAddress
$template = $template.Replace("<randomip>",$randomIP)
}
[string]$randomshare = $adminshares[(Get-Random -Minimum 0 -Maximum 2)]
$template = $template.replace("<randomshare>",$randomshare)
$randomLength = Get-Random -Minimum 6 -Maximum 12
$randomString = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$servicebin = $template.replace("<random>",$randomString)
#& c:\windows\system32\sc.exe create $randomString binPath= "$servicebin" type= own
#start-sleep -Seconds 2
#& c:\windows\system32\sc.exe delete $randomString
CreateService -svcexe $servicebin -svcname $randomString
}
}
function namedpipe_service
{
$namedpipe_template1 = "cmd.exe /C start %COMSPEC% /C 'timeout /t 3 >nul&&echo <random> \\.\pipe\<random>'"
$namedpipe_template2 = "cmd.exe /c 'echo <random> > \\.\pipe\<random>'"
$namedpipe_template3 = "cmd.exe /c 'echo <randomname> > \\.\pipe\<random>'"
$namedpipe_templates= @($namedpipe_template1,$namedpipe_template2,$namedpipe_template3)
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
foreach($template in $namedpipe_templates)
{
if($template -like "*<randomname>*")
{
$randomLength = Get-Random -Minimum 6 -Maximum 8
$servicename = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$template = $template.Replace("<randomname>",$servicename)
}
$randomLength = Get-Random -Minimum 6 -Maximum 8
$randomString = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$servicebin = $template.replace("<random>",$randomString)
#& c:\windows\system32\sc.exe create $randomString binPath= "$servicebin" type= own
#start-sleep -Seconds 2
#& c:\windows\system32\sc.exe delete $randomString
CreateService -svcexe $servicebin -svcname $randomString
}
}
function windir_service
{
$windir_template1 = "%windir%\<random>.exe"
$windir_template2 = "%programdata\<random>.exe"
$windir_template3 = "%public%\<random>.exe"
$windir_templates= @($windir_template1,$windir_template2,$windir_template3)
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
foreach($template in $windir_templates)
{
$randomLength = Get-Random -Minimum 6 -Maximum 8
$randomservicename = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$randomLength = Get-Random -Minimum 6 -Maximum 8
$randomString = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$servicebin = $template.replace("<random>",$randomString)
#echo $servicebin
# & c:\windows\system32\sc.exe create $randomservicename binPath= "$servicebin" type= own
# start-sleep -Seconds 2
# & c:\windows\system32\sc.exe delete $randomservicename
CreateService -svcexe $servicebin -svcname $randomString
}
}
function rmm_service
{
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
$psexec_name = "PSEXESVC"
$psexec_template = "%SytemRoot%\PSEXESVC.exe"
#& c:\windows\system32\sc.exe create $psexec_name binPath= "$psexec_template" type= own
#start-sleep -Seconds 2
#& c:\windows\system32\sc.exe delete $psexec_name
CreateService -svcexe $psexec_template -svcname $psexec_name
$sc_name = "ScreenConnect Client (<randomname>)"
$randomLength = Get-Random -Minimum 14 -Maximum 16
$randomname = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$servicename = $sc_name.Replace("<randomname>",$randomname)
$sc_template1 = "'C:\Program Files (x86)\ScreenConnect Client (<randomname>)\ScreenConnect.ClientService.exe'"
$servicebin = $sc_template1.replace("<randomname>",$randomname)
#write-host $servicebin
#& c:\windows\system32\sc.exe create $servicename binPath= "$servicebin" type= own
#start-sleep -Seconds 2
#& c:\windows\system32\sc.exe delete $servicename
CreateService -svcexe $servicebin -svcname $servicename
$sc_template2 = "C:\Users\<randomuser>\AppData\Local\Apps\2.0\<randompath>\ScreenConnect.ClientService.exe `"?e=Support&y=Guest&h=instance-<randomdomain>.screenconnect.com&p=443&s=<guid>&k=<randomkey>%20Axline`" `"1`""
$names = get-content .\names.txt
$username = ((Get-Random -InputObject $names -Count 1) + "." +(Get-Random -InputObject $names -Count 1)).ToString()
$servicebin = $sc_template2.Replace("<randomuser>",$username)
$randomLength = Get-Random -Minimum 6 -Maximum 9
$randompath = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$servicebin = $servicebin.Replace("<randompath>",$randompath)
$randomLength = Get-Random -Minimum 3 -Maximum 6
$randomdomain = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$servicebin = $servicebin.Replace("<randomdomain>",$randomdomain)
$guid = new-guid
$servicebin = $servicebin.Replace("<guid>",$guid)
$randomLength = Get-Random -Minimum 30 -Maximum 50
$randomkey = -join ((1..$randomLength) | ForEach-Object { $characters[(Get-Random -Minimum 0 -Maximum $characters.Length)] })
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($randomkey)
$randomkey =[Convert]::ToBase64String($Bytes)
$servicebin = $servicebin.Replace("<randomkey>",$randomkey)
#write-host $servicebin
#& c:\windows\system32\sc.exe create $sc_name binPath= "$servicebin" type= own
#start-sleep -Seconds 2
#& c:\windows\system32\sc.exe delete $sc_name
CreateService -svcexe $servicebin -svcname $servicename
$splashtop_name = "SplashtopRemoteService"
$splashtop = "C:\Program Files (x86)\Splashtop\Splashtop Remote\Server\SRManager.exe"
#& c:\windows\system32\sc.exe create $splashtop_name binPath= "$splashtop" type= own
#start-sleep -Seconds 2
#& c:\windows\system32\sc.exe delete $splashtop_name
CreateService -svcexe $splashtop -svcname $splashtop_name
$teamviewer_name = "TeamViewer"
$teamviewer_template1 = "C:\Program Files\TeamViewer\TeamViewer_Service.exe"
$teamviewer_template2 = "C:\Program Files (x86)\TeamViewer\TeamViewer_Service.exe"
CreateService -svcexe $teamviewer_template1 -svcname $teamviewer_name
CreateService -svcexe $teamviewer_template2 -svcname $teamviewer_name
#& c:\windows\system32\sc.exe create $teamviewer_name binPath= "$teamviewer_template1" type= own
#start-sleep -Seconds 2
#& c:\windows\system32\sc.exe delete $teamviewer_name
#start-sleep -Seconds 2
#& c:\windows\system32\sc.exe create $teamviewer_name binPath= "$teamviewer_template2" type= own
#start-sleep -Seconds 2
#& c:\windows\system32\sc.exe delete $teamviewer_name
$anydesk_name = "AnyDesk"
$anydesk_template = "C:\Program Files (x86)\AnyDesk\AnyDesk.exe"
CreateService -svcexe $anydesk_template -svcname $anydesk_name
}
for ($i = 1; $i -le 100; $i++)
{
powershell_service
rundll32_service
adminshare_service
namedpipe_service
windir_service
rmm_service
}