-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdedri.ps1
631 lines (541 loc) · 22.2 KB
/
dedri.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
<#
.SYNPOSIS
Clean Dridex infection from Windows system
.EXAMPLE
PS > .\dedri.ps1
.Notes
Author: LIFARS @mwlac
Date: November 17, 2019
.LINK
https://github.com/Lifars/Dridex-Vaccine
#>
$DedriDir = "C:\ProgramData\Dedri"
$LogFile = "C:\ProgramData\dedri.log"
$ProcHack = "$DedriDir\prochack.exe"
$prochack_base64str = "<PUT BASE64-ENCODED PROCESSHACKER.EXE HERE>"
$procmon_base64str = "<PUT BASE64-ENCODED PROCMON.EXE HERE>"
function Out-HostLogFile
{
param (
[Parameter(ValueFromPipeline = $True)]
[Object]$param
)
echo $param | Out-File $LogFile -Append
echo $param | Out-Host
}
Add-Type -TypeDefinition @"
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
public static class Kernel32
{
public enum ThreadAccess : int
{
TERMINATE = (0x0001),
SUSPEND_RESUME = (0x0002),
GET_CONTEXT = (0x0008),
SET_CONTEXT = (0x0010),
SET_INFORMATION = (0x0020),
QUERY_INFORMATION = (0x0040),
SET_THREAD_TOKEN = (0x0080),
IMPERSONATE = (0x0100),
DIRECT_IMPERSONATION = (0x0200)
}
[DllImport("kernel32.dll")]
public static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);
[DllImport("kernel32.dll")]
public static extern uint GetThreadId(IntPtr hThread);
[DllImport("kernel32.dll")]
public static extern uint SuspendThread(IntPtr hThread);
[DllImport("kernel32.dll")]
public static extern int ResumeThread(IntPtr hThread);
[DllImport("kernel32.dll")]
public static extern int TerminateThread(IntPtr hThread, uint dwExitCode);
[DllImport("kernel32.dll")]
public static extern int CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll")]
public static extern int GetLastError();
}
"@
function Suspend-Thread{
param (
[Parameter(Mandatory = $True)]
[int]$ThreadID
)
if (Get-CimInstance win32_thread -filter “handle = $ThreadID”)
{
$Error = $False
$err = 0
$handle = [Kernel32]::OpenThread([Kernel32+ThreadAccess]::SUSPEND_RESUME, $False, [System.UInt32]$ThreadID)
if ($handle -ne 0)
{
if ([Kernel32]::SuspendThread($handle) -eq 4294967295)
{
$err = [Kernel32]::GetLastError()
$Error = $True
}
else
{
echo " Thread $ThreadID suspended" | Out-HostLogFile
}
[Kernel32]::CloseHandle($handle)
}
else
{
$err = [Kernel32]::GetLastError()
$Error = $True
}
if ($Error)
{
echo " Error $err with native suspending thread" | Out-HostLogFile
echo " Trying ProcesHacker tool" | Out-HostLogFile
if ((Test-Path -Path $ProcHack -PathType Leaf) -eq $False)
{
[IO.File]::WriteAllBytes($ProcHack, [Convert]::FromBase64String($prochack_base64str))
}
& $ProcHack -c -ctype thread -cobject $ThreadID -caction suspend
sleep 5
}
}
else
{
echo " Thread $ThreadID doesn't exist" | Out-HostLogFile
}
}
function Resume-Thread{
param (
[Parameter(Mandatory = $True)]
[int]$ThreadID
)
$handle = [Kernel32]::OpenThread([Kernel32+ThreadAccess]::SUSPEND_RESUME, $False, [System.UInt32]$ThreadID)
if ($handle -ne 0)
{
if ([Kernel32]::ResumeThread($handle) -eq 4294967295)
{
[Kernel32]::GetLastError()
}
else
{
echo "Thread $ThreadID resumed" | Out-HostLogFile
}
[Kernel32]::CloseHandle($handle)
}
else
{
[Kernel32]::GetLastError()
}
}
function Terminate-Thread{
param (
[Parameter(Mandatory = $True)]
[int]$ThreadID
)
if (Get-CimInstance win32_thread -filter “handle = $ThreadID”)
{
$Error = $False
$err = 0
$handle = [Kernel32]::OpenThread([Kernel32+ThreadAccess]::TERMINATE, $False, [System.UInt32]$ThreadID)
if ($handle -ne 0)
{
if ([Kernel32]::SuspendThread($handle) -eq 4294967295)
{
$err = [Kernel32]::GetLastError()
$Error = $True
}
else
{
echo " Thread $ThreadID terminated" | Out-HostLogFile
}
[Kernel32]::CloseHandle($handle)
}
else
{
$err = [Kernel32]::GetLastError()
$Error = $True
}
if ($Error)
{
echo " Error $err with native terminating thread" | Out-HostLogFile
echo " Trying ProcesHacker tool" | Out-HostLogFile
if ((Test-Path -Path $ProcHack -PathType Leaf) -eq $False)
{
[IO.File]::WriteAllBytes($ProcHack, [Convert]::FromBase64String($prochack_base64str))
}
& $ProcHack -c -ctype thread -cobject $ThreadID -caction terminate
sleep 5
}
}
else
{
echo " Thread $ThreadID doesn't exist" | Out-HostLogFile
}
}
function Is-SystemFile
{
param (
[Parameter(Mandatory = $True)]
[System.IO.FileInfo]$File
)
return (Test-Path "$env:windir\System32\$($File.Name)" -PathType Leaf) -or (Test-Path "$env:windir\$($File.Name)" -PathType Leaf)
}
function Is-InfectedCommand()
{
param (
[Parameter(Mandatory = $True)]
[String]$Command,
[Parameter(Mandatory = $True)]
[Object[]]$InfectedDirs
)
$IsInfected = $False;
$ExpandedCommand = [System.Environment]::ExpandEnvironmentVariables($Command)
foreach($InfectedDir in $InfectedDirs)
{
$InfectedDirFullName = $InfectedDir.Fullname
if (($InfectedDirFullName | Select-String "AppData").Matches.Count -gt 0) #AppData dir
{
$AppDataDirIndex = ($InfectedDirFullName | Select-String "AppData").Matches.Index
$AppDataDir = $InfectedDirFullName.Substring($AppDataDirIndex, $InfectedDirFullName.Length - $AppDataDirIndex)
if ($ExpandedCommand -like "*$AppDataDir*")
{
$IsInfected = $True
}
}
else #System dir
{
if ($ExpandedCommand -like "*$InfectedDirFullName*")
{
$IsInfected = $True
}
}
}
return $IsInfected
}
function Detect-InfectedDirs
{
$IsInfected = $False
$WasInfected = $False
$InfectedDirs = @()
$System32SubDirs = Get-ChildItem -Force -Directory "$env:windir\System32"
$AppDataSubDirs = Get-ChildItem -Force -Directory "C:\Users\*\AppData\Roaming\*"
$Dirs = @($System32SubDirs) + @($AppDataSubDirs)
foreach ($Dir in $Dirs)
{
$IsInfectedDir = $True
$IsInfectedDir = $True
$Files = Get-ChildItem -Force -ErrorAction SilentlyContinue $Dir.FullName
$Extensions = ($Files | select -Property Extension) | Group-Object -Property Extension
if ((($Files | measure).Count -le 3) -and (($Extensions | where Name -eq ".exe").Count -eq 1) -and (($Extensions | where Name -eq ".dll").Count -le 1) -and (($Extensions | where Name -ne ".dll" | where Name -NotLike ".x*" | measure).Count -eq 1))
{
foreach ($File in $Files)
{
if ($IsInfectedDir -and (($File.Extension -eq ".dll") -or ($File.Extension -eq ".exe")))
{
$IsSystemFile = Is-SystemFile($File)
$IsInfectedDir = $IsInfectedDir -and $IsSystemFile
}
else
{
if ($File.Extension -notlike ".x*")
{
$IsInfectedDir = $False
}
}
}
}
else
{
$IsInfectedDir = $False
}
If ($IsInfectedDir)
{
$IsInfected = $True
$InfectedDirs = @($InfectedDirs) + @($Dir)
}
}
return $InfectedDirs
}
function Remove-InfectedDirs
{
param (
[Parameter(Mandatory = $True)]
[Object[]]$InfectedDirs
)
echo "Removing infected dirs:" | Out-HostLogFile
foreach ($InfectedDir in $InfectedDirs)
{
echo " $($InfectedDir.FullName)" | Out-HostLogFile
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue -Path $InfectedDir.FullName
}
}
function Detect-InfectedTasks
{
param (
[Parameter(Mandatory = $True)]
[Object[]]$InfectedDirs
)
$ScheduledTasks = schtasks.exe /QUERY /V /FO csv | ConvertFrom-Csv | select -property @{Name="Command";Expression={[System.Environment]::ExpandEnvironmentVariables($_."Task To Run")}}, @{Name="RunAsUser";Expression={$_."Run As User"}}, Taskname
$System32Tasks = $ScheduledTasks | Where-Object {$_.Command -match "system32.*exe"}
$AppDataTasks = $ScheduledTasks | Where-Object {$_.Command -match "appdata.*exe"}
$InfectedTasks = @()
$Tasks = @($System32Tasks) + @($AppDataTasks)
foreach ($Task in $Tasks)
{
$Command = $Task.Command
if (Is-InfectedCommand $Command $InfectedDirs)
{
$InfectedTasks = @($InfectedTasks) + @($Task)
}
}
return $InfectedTasks
}
function Remove-InfectedTasks
{
param (
[Parameter(Mandatory = $True)]
[Object[]]$InfectedTasks
)
echo "Removing tasks:" | Out-HostLogFile
foreach ($InfectedTask in $InfectedTasks)
{
echo " $($InfectedTask.TaskName) -> $($InfectedTask.Command)" | Out-HostLogFile
schtasks.exe /DELETE /TN $($InfectedTask.TaskName) /F
}
}
function Detect-InfectedStartups
{
param (
[Parameter(Mandatory = $True)]
[Object[]]$InfectedDirs
)
$InfectedStartups = @()
$Startups=Get-ChildItem -Force "C:\Users\*\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\*.lnk"
$Shell = New-Object -ComObject WScript.Shell
foreach ($Startup in $Startups)
{
$TargetPath = [System.Environment]::ExpandEnvironmentVariables($shell.CreateShortcut($Startup.Fullname).TargetPath)
if (Is-InfectedCommand $TargetPath $InfectedDirs){
$InfectedStartups = @($InfectedStartups) + @($Startup)
}
}
return $InfectedStartups
}
function Remove-InfectedStartups
{
param (
[Parameter(Mandatory = $True)]
[Object[]]$InfectedStartups
)
echo "Removing startups:" | Out-HostLogFile
foreach ($InfectedStartup in $InfectedStartup)
{
echo " $($InfectedStartup.FullName)" | Out-HostLogFile
Remove-Item -Force -ErrorAction SilentlyContinue -Path $InfectedStartup.FullName
}
}
function Detect-InfectedAutoruns
{
param (
[Parameter(Mandatory = $True)]
[Object[]]$InfectedDirs
)
$InfectedAutoruns = @()
$null = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
$AutorunsKey = "\SOFTWARE\Microsoft\Windows\CurrentVersion\Run*"
$HKLM_AutorunsKey = Get-Item "HKLM:$AutorunsKey"
$HKU_AutorunsKey = Get-Item "HKU:\*\$AutorunsKey"
$AutorunsKeys = @($HKLM_AutorunsKey) + @($HKU_AutorunsKey)
foreach ($AutorunsKey in $AutorunsKeys)
{
$AutorunsProperties = $AutorunsKey.property
foreach ($Property in $AutorunsProperties)
{
$Command = $AutorunsKey.GetValue($Property)
if ($Command)
{
if (Is-InfectedCommand $Command $InfectedDirs){
$InfectedAutoruns = @($InfectedAutoruns) + @(new-object psobject -Property @{RegistryKey=$AutorunsKey;Property=$Property;Value=$Command})
}
}
}
}
$null = Remove-PSDrive -Name HKU
return $InfectedAutoruns
}
function Remove-InfectedAutoruns
{
param (
[Parameter(Mandatory = $True)]
[Object[]]$InfectedAutoruns
)
$null = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
echo "Removing autoruns:" | Out-HostLogFile
foreach ($InfectedAutorun in $InfectedAutoruns)
{
echo " $($InfectedAutorun.RegistryKey):$($InfectedAutorun.Property)" | Out-HostLogFile
$PSPath = $InfectedAutorun.RegistryKey.PSPath
Remove-ItemProperty -PSPath $PSPath -Name $InfectedAutorun.Property
}
$null = Remove-PSDrive -Name HKU
}
function FindInfectedThread
{
$config_base64str = "oAAAABAAAAAgAAAAgAAAAEMAbwBsAHUAbQBuAHMAAAAyAGQAKABJACQAZADIAGQAZABkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAQAAAAKAAAAAQAAABDAG8AbAB1AG0AbgBDAG8AdQBuAHQAAAAKAAAAJAEAABAAAAAkAAAAAAEAAEMAbwBsAHUAbQBuAE0AYQBwAAAAjpwAAHWcAAB2nAAAl5wAAIicAAB3nAAAh5wAAHicAAB5nAAAg5wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AIecAAAFAAAAABIAAAAkAE0AZgB0AE0AaQByAHIAAAAAAAAAAAAAAIecAAAFAAAAABIAAAAkAEwAbwBnAEYAaQBsAGUAAAAAAAAAAAAAAIecAAAFAAAAABAAAAAkAFYAbwBsAHUAbQBlAAAAAAAAAAAAAACHnAAABQAAAAASAAAAJABBAHQAdAByAEQAZQBmAAAAAAAAAAAAAACHnAAABQAAAAAMAAAAJABSAG8AbwB0AAAAAAAAAAAAAACHnAAABQAAAAAQAAAAJABCAGkAdABtAGEAcAAAAAAAAAAAAAAAh5wAAAUAAAAADAAAACQAQgBvAG8AdAAAAAAAAAAAAAAAh5wAAAUAAAAAEgAAACQAQgBhAGQAQwBsAHUAcwAAAAAAAAAAAAAAh5wAAAUAAAAAEAAAACQAUwBlAGMAdQByAGUAAAAAAAAAAAAAAIecAAAFAAAAABAAAAAkAFUAcABDAGEAcwBlAAAAAAAAAAAAAACHnAAABgAAAAAQAAAAJABFAHgAdABlAG4AZAAAAAAAAAAAAAAAkpwAAAAAAAAAFAAAAFAAcgBvAGYAaQBsAGkAbgBnAAAAAAAAAAAAAACSnAAAAAAAAAAQAAAATgBlAHQAdwBvAHIAawAAAAAAAAAAAAAAkpwAAAAAAAAAEgAAAFIAZQBnAGkAcwB0AHIAeQAAAAAAAAAAAAAAMwAAABAAAAAuAAAABQAAAEgAaQBnAGgAbABpAGcAaAB0AFIAdQBsAGUAcwAAAAEAAAAA"
$ProcMon = "$DedriDir\procmon.exe"
$ProcMonCfg = "$DedriDir\config.pmc"
$ProcMonPml = "$DedriDir\procmon.pml"
$ProcMonCsv = "$DedriDir\procmon.csv"
if ((Test-Path $DedriDir) -eq $True)
{
Remove-Procmon
}
$null = New-Item -Path "C:\ProgramData" -Name "Dedri" -ItemType "directory"
[IO.File]::WriteAllBytes($ProcMon, [Convert]::FromBase64String($procmon_base64str))
[IO.File]::WriteAllBytes($ProcMonCfg, [Convert]::FromBase64String($config_base64str))
$InfectedThread = -1
#do
#{
Remove-Item -ErrorAction SilentlyContinue $ProcMonPml
Remove-Item -ErrorAction SilentlyContinue $ProcMonCsv
echo " (ProcMon Tracing running for 70 seconds)" | Out-HostLogFile
& $ProcMon /AcceptEula /LoadConfig $ProcMonCfg /Minimized /Quiet /Runtime 70 /BackingFile $ProcMonPml
#Start-Process -FilePath $ProcMon -ArgumentList "/AcceptEula","/LoadConfig","$ProcMonCfg","/Minimized","/Quiet","/Runtime","120","/BackingFile","$ProcMonPml"
sleep 80
& $ProcMon /AcceptEula /Terminate
sleep 10
echo " (ProcMon convert PML to CSV)" | Out-HostLogFile
& $ProcMon /AcceptEula /LoadConfig $ProcMonCfg /OpenLog $ProcMonPml /Minimized /Quiet /SaveAs $ProcMonCsv /SaveApplyFilter
sleep 20
Stop-Process -Force -ErrorAction SilentlyContinue -Name procmon64
Stop-Process -Force -ErrorAction SilentlyContinue -Name procmon
if (Test-Path -Path $ProcMonCsv -PathType Leaf)
{
$TIDs = (Get-Content $ProcMonCsv | ConvertFrom-Csv | Where-Object -Property Path -eq "C:\Windows\System32\schtasks.exe" | Where-Object -Property Operation -eq "Process Create" | Where-Object -Property "Process Name" -eq "Explorer.exe").TID | Group-Object
}
else
{
$TIDs = @()
echo " (Detection of injected thread via ProcMon failed)" | Out-HostLogFile
}
#} while ($TIDs.Length -le 1)
if ($TIDs.Length -eq 1)
{
$InfectedThread = $TIDs[0].Name
}
return [int]$InfectedThread
}
function Prevent-Infection
{
echo "Prevention:" | Out-HostLogFile
if ((Test-Path "C:\aaa_TouchMeNot_.txt" -PathType Leaf) -eq $False)
{
echo " BitPaymer Prevention created" | Out-HostLogFile
$null= New-Item -Path "C:\aaa_TouchMeNot_.txt" -ItemType File
(Get-Item -Force "C:\aaa_TouchMeNot_.txt").Attributes += "Hidden,ReadOnly"
}
else
{
echo " BitPaymer Prevention already exists" | Out-HostLogFile
}
<#if ((Test-Path -LiteralPath "\\?\C:\Windows ") -eq $False)
{
echo " Dridex Prevention created" | Out-HostLogFile
$null = New-Item -Path "\\?\C:\Windows " -ItemType File -ErrorAction SilentlyContinue
if (Test-Path -LiteralPath "\\?\C:\Windows ")
{
(Get-Item -Force -LiteralPath "\\?\C:\Windows ").Attributes+="Hidden,ReadOnly"
}
}
else
{
echo " Dridex Prevention already exists" | Out-HostLogFile
}#>
}
function Remove-Procmon
{
echo " (Removing temporary files)" | Out-HostLogFile
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue $DedriDir
}
#### MAIN ####
echo "" | Out-HostLogFile
echo "+---------------+" | Out-HostLogFile
echo "| DEDRI Vaccine |" | Out-HostLogFile
echo "+---------------+" | Out-HostLogFile
echo "" | Out-HostLogFile
echo "by LIFARS @mwlac" | Out-HostLogFile
echo "" | Out-HostLogFile
echo "" | Out-HostLogFile
echo "" | Out-HostLogFile
Get-Date | Out-HostLogFile
echo " (Running detection of infected thread)" | Out-HostLogFile
$InfectedThread = -1
## For disabling detection of infected thread, just comment the next line
$InfectedThread = FindInfectedThread
echo "Infected Thread:" | Out-HostLogFile
if ($InfectedThread -ge 0)
{
echo " $($InfectedThread) in Explorer.exe" | Out-HostLogFile
echo "Suspending thread $InfectedThread"
$null = Suspend-Thread $InfectedThread
sleep 5
}
else
{
echo " No Injected Thread detected" | Out-HostLogFile
}
$InfectedDirs = Detect-InfectedDirs
echo "Infected Dirs:" | Out-HostLogFile
foreach ($InfectedDir in $InfectedDirs)
{
echo " $($InfectedDir.FullName)" | Out-HostLogFile
}
if ($InfectedDirs.Count -ge 1)
{
echo "" | Out-HostLogFile
$InfectedTasks = Detect-InfectedTasks $InfectedDirs
echo "Infected Tasks:" | Out-HostLogFile
foreach ($InfectedTask in $InfectedTasks)
{
echo " $($InfectedTask.TaskName) -> $($InfectedTask.Command)" | Out-HostLogFile
}
echo "" | Out-HostLogFile
$InfectedStartups = Detect-InfectedStartups $InfectedDirs
echo "Infected Startups:" | Out-HostLogFile
foreach ($InfectedStartup in $InfectedStartups)
{
echo " $($InfectedStartup.FullName)" | Out-HostLogFile
}
echo "" | Out-HostLogFile
$InfectedAutoruns = Detect-InfectedAutoruns $InfectedDirs
echo "Infected Autoruns:" | Out-HostLogFile
foreach ($InfectedAutorun in $InfectedAutoruns)
{
echo " $($InfectedAutorun.RegistryKey):$($InfectedAutorun.Property) -> $($InfectedAutorun.Value)" | Out-HostLogFile
}
echo "" | Out-HostLogFile
Remove-InfectedDirs $InfectedDirs
if (@($InfectedTasks).Count -ge 1)
{
Remove-InfectedTasks $InfectedTasks
}
if (@($InfectedStartups).Count -ge 1)
{
Remove-InfectedStartups $InfectedStartups
}
if (@($InfectedAutoruns).Count -ge 1)
{
Remove-InfectedAutoruns $InfectedAutoruns
}
}
else
{
echo " Not detected" | Out-HostLogFile
}
if ($InfectedThread -ge 0)
{
echo "Terminating thread $InfectedThread"
$null = Terminate-Thread $InfectedThread
}
Remove-ProcMon
Prevent-Infection
Get-Date | Out-HostLogFile
echo "===========================================================" | Out-HostLogFile