-
Notifications
You must be signed in to change notification settings - Fork 3
/
protein.ps1
815 lines (680 loc) · 72.1 KB
/
protein.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
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
# File Monitor for Creation RANSOMWARE
# Check if new ransomware is infecting our system, check docx docs.
# If detect new ransomware, or one of blacklist, then disable de account of the user to
# block any access to our system.
# Author : Amador Pérez Trujillo aka @c0p3rn1c0
# 2016
#TO_DO: Disable network adapter after ransomware detected
# Multiple paths for monitor
# Disable USB hdd
# Change buffer size 4k 48
# Creation different extension in spite of .docx _AntiRansomware
# NEXT VERSION:
# Show message DANGER on client..........................DONE!
# SNMP to server to log on siem
# Detect filetype not based on extension
# Convert to service
$folder_tolog = ""
if ($args.Count -ne 1) {
#help
Clear-Host
Write-Host "
_____ ______ ____ ________ _____ _____ __ _
( __ \ ( __ \ / __ \ (___ ___) / ___/ (_ _) / \ / )
) )_) ) ) (__) ) / / \ \ ) ) ( (__ | | / /\ \ / /
( ___/ ( __/ ( () () ) ( ( ) __) | | ) ) ) ) ) )
) ) ) \ \ _ ( () () ) ) ) ( ( | | ( ( ( ( ( (
( ( ( ( \ \_)) \ \__/ / ( ( \ \___ _| |__ / / \ \/ /
/__\ )_) \__/ \____/ /__\ \____\ /_____( (_/ \__/
"
Write-Host "PROTEcting your INformation - AntiRansomware"
Write-Host "____________________________________________"
Write-Host " "
Write-Host " "
Write-Host ".SYNOPSIS"
Write-Host " - This script is an actively monitoring for files in a repository to search for known or unknown ransomware."
Write-Host " - PROTEIN captures the action of creation new files, analyzing them and determining whether they are valid or not for the corporation."
Write-Host " - PROTEIN Identifies known files (whitelist), potential threats (blacklist) likewise unknown files for further processing."
Write-Host ""
Write-Host " - PROTEIN logs every creation action on files on your server."
Write-Host " - Possibility to email alerts to an administrator when a new ransomware is detected."
Write-Host " - PROTEIN alerts, via messagebox on the user's computer, when a new ransomware is detected."
Write-Host " - PROTEIN disables domain's user affected by the ransomware, preventing the access to the repository by the ransomware or other critical system objects."
Write-Host " - PROTEIN disables the NIC on the user's computer affected by the ransomware, to block the access to the network."
Write-Host " "
Write-Host ".REQUIREMENTS"
Write-Host " - Run this script as an administrator to control computers and domain users remotely."
Write-Host " "
Write-Host " .INSTALATION"
Write-Host " - ./protein.ps1 --install"
Write-Host " - ./protein.ps1 --configure"
Write-Host ""
Write-Host ".NOTES"
Write-Host " - Author : Amador Pérez Trujillo"
Write-Host " - Twitter : @c0p3rnic0"
Write-Host " - Company : http://www.newvisionsoftlan.com"
Write-Host ""
Write-Host ".PARAMETER --install"
Write-Host " - Set the path to folder to monitor, path and filename for storage logs and email of the adminsitrator to alert of a risk."
Write-Host ".PARAMETER --monitor"
Write-Host " - Start monitoring the Folders... Start the Game!!!"
Write-Host ".PARAMETER --configure"
Write-Host " - Re-configure path of folders to monitor and storage the logs, email address..."
Write-Host ".PARAMETER --path"
Write-Host " - Echo by console the configuration files for checking purposing."
Write-Host ".PARAMETER --logs"
Write-Host " - Echo by console the log file."
Write-Host ""
Write-Host ""
Write-Host ""
Break
}
if ($args -eq "--install")
{
Clear-Host
Write-Host "
_____ ______ ____ ________ _____ _____ __ _
( __ \ ( __ \ / __ \ (___ ___) / ___/ (_ _) / \ / )
) )_) ) ) (__) ) / / \ \ ) ) ( (__ | | / /\ \ / /
( ___/ ( __/ ( () () ) ( ( ) __) | | ) ) ) ) ) )
) ) ) \ \ _ ( () () ) ) ) ( ( | | ( ( ( ( ( (
( ( ( ( \ \_)) \ \__/ / ( ( \ \___ _| |__ / / \ \/ /
/__\ )_) \__/ \____/ /__\ \____\ /_____( (_/ \__/
"
Write-Host "PROTEcting your INformation - AntiRansomware"
Write-Host "____________________________________________"
Write-Host " "
Write-Host " "
Write-Host "INTALATION:"
Write-Host "==========="
$question = Read-Host -Prompt 'Do you really want to install the application (Y/N)?'
$question.ToUpper()
$first_time = 0 #Create file of dir only 1 time
if ($question -eq "Y" ) {
Write-Host "Path to File Server Folder to monitor?"
$object = New-Object -comObject Shell.Application
$folder = $object.BrowseForFolder(0, "Path to File Server Folder to monitor", 0, 0)
$folder_toinstall = $folder.self.Path
if ($folder_toinstall.length -gt 3) {
Write-Host "d3"
$folder_toinstall.ToUpper()
$folder_toinstall += "\_AntiRansomware"
New-Item -ItemType Directory -Force -Path $folder_toinstall
Copy-Item "C:\Anti_malware_config\docs\_1.docx" $folder_toinstall
Copy-Item "C:\Anti_malware_config\docs\_2.docx" $folder_toinstall
Copy-Item "C:\Anti_malware_config\docs\_3.docx" $folder_toinstall
$question = Read-Host -Prompt 'Add another folder(Y/N)?'
$question.ToUpper()
$config_file = "C:\Anti_malware_config\fake_dirs.config"
if ($first_time -eq 0) { #Check if file is created or not
New-Item $config_file -type file -force
Add-Content -Path $config_file -Value $folder_toinstall
$first_time = 1
}
else
{
Add-Content -Path $config_file -Value $folder_toinstall
}
}
else {
$question = "N"
Write-Host "d4"
}
}
}
if ($args -eq "--logs")
{
$lines_config = Get-Content C:\Anti_malware_config\setup.config
$next = "0"
foreach ($line_data in $lines_config) {
if ($line_data -notlike '*#*') {
#Isn't a comment
switch ($next)
{
"folder" {
$folder = $line_data
$next = "null"
}
"logs" {
$folder_logs = $line_data + "\config_changes.txt"
$next = "null"
}
"from" {
$FROM = $line_data
$next = "null"
}
"email" {
$To = $line_data
$next = "null"
}
"server" {
$smtp = $line_data
$next = "null"
}
}
if ($line_data -like '%Path_Repository*') { # Enter the root path you want to monitor.
$next = "folder"
}
if ($line_data -like '%Path_File*'){ # Enter the path you want to storage logs.
$next = "logs"
}
if ($line_data -like '%To*') { # Enter the path you want to storage logs.
$next = "email"
}
if ($line_data -like '%Smtp*') { # Enter the path you want to storage logs.
$next = "server"
}
if ($line_data -like '%From*') { # Enter the path you want to storage logs.
$next = "from"
}
}
}
Clear-Host
Write-Host "
_____ ______ ____ ________ _____ _____ __ _
( __ \ ( __ \ / __ \ (___ ___) / ___/ (_ _) / \ / )
) )_) ) ) (__) ) / / \ \ ) ) ( (__ | | / /\ \ / /
( ___/ ( __/ ( () () ) ( ( ) __) | | ) ) ) ) ) )
) ) ) \ \ _ ( () () ) ) ) ( ( | | ( ( ( ( ( (
( ( ( ( \ \_)) \ \__/ / ( ( \ \___ _| |__ / / \ \/ /
/__\ )_) \__/ \____/ /__\ \____\ /_____( (_/ \__/
"
Write-Host "PROTEcting your INformation - AntiRansomware"
Write-Host "____________________________________________"
Write-Host " "
Write-Host " "
Write-Host "LOGS:"
Write-Host "====="
$lines_config = Get-Content $folder_logs
foreach ($line in $lines_config)
{
write-host $line
}
}
if ($args -eq "--path")
{
Clear-Host
Write-Host "
_____ ______ ____ ________ _____ _____ __ _
( __ \ ( __ \ / __ \ (___ ___) / ___/ (_ _) / \ / )
) )_) ) ) (__) ) / / \ \ ) ) ( (__ | | / /\ \ / /
( ___/ ( __/ ( () () ) ( ( ) __) | | ) ) ) ) ) )
) ) ) \ \ _ ( () () ) ) ) ( ( | | ( ( ( ( ( (
( ( ( ( \ \_)) \ \__/ / ( ( \ \___ _| |__ / / \ \/ /
/__\ )_) \__/ \____/ /__\ \____\ /_____( (_/ \__/
"
Write-Host "PROTEcting your INformation - AntiRansomware"
Write-Host "____________________________________________"
Write-Host " "
Write-Host " "
Write-Host "SETUP CONFIGURATION:"
Write-Host "===================="
$lines_config = Get-Content C:\Anti_malware_config\setup.config
foreach ($line in $lines_config)
{
write-host $line
}
Write-Host "FOLDERS CONFIGURATION:"
Write-Host "===================="
$lines_config = Get-Content C:\Anti_malware_config\folder_config.config
foreach ($line in $lines_config)
{
write-host $line
}
Write-Host""
#Pause
Break
}
if ($args -eq "--configure")
{
Clear-Host
Write-Host "
_____ ______ ____ ________ _____ _____ __ _
( __ \ ( __ \ / __ \ (___ ___) / ___/ (_ _) / \ / )
) )_) ) ) (__) ) / / \ \ ) ) ( (__ | | / /\ \ / /
( ___/ ( __/ ( () () ) ( ( ) __) | | ) ) ) ) ) )
) ) ) \ \ _ ( () () ) ) ) ( ( | | ( ( ( ( ( (
( ( ( ( \ \_)) \ \__/ / ( ( \ \___ _| |__ / / \ \/ /
/__\ )_) \__/ \____/ /__\ \____\ /_____( (_/ \__/
"
Write-Host "PROTEcting your INformation - AntiRansomware"
Write-Host "____________________________________________"
Write-Host " "
Write-Host " "
Write-Host "SETUP CONFIGURATION:"
Write-Host "===================="
$question = Read-Host -Prompt 'Do you really want to re-configure the paths for the application (Y/N)?'
$question.ToUpper()
if ($question -eq "Y" ) {
$object = New-Object -comObject Shell.Application
$folder = $object.BrowseForFolder(0, "Path to File Server Folder to monitor", 0, 0)
$folder_toinstall = $folder.self.Path
if ($folder_toinstall.length -gt 3) {$folder_toinstall.ToUpper()}
Write-Host "Path to File Server Activity Log?"
$object = New-Object -comObject Shell.Application
$folder = $object.BrowseForFolder(0, "Path to File Server Folder to monitor", 0, 0)
$folder_logs = $folder.self.Path
if ($folder_logs.length -gt 3) {$folder_logs.ToUpper()}
$FROM = Read-Host -Prompt "Email address (From:) for alerts?"
if ($FROM.length -gt 3) {$FROM.ToUpper()}
$To = Read-Host -Prompt "Email address (To:) for alerts?"
if ($To.length -gt 3) {$To.ToUpper()}
$smtp = Read-Host -Prompt "SMTP Server for alerts?"
if ($smtp.length -gt 3) {$smtp.ToUpper()}
# Make Config file
$config_file = "C:\Anti_malware_config\fake_dirs.config"
New-Item $config_file -type file -force
$fake_foldertoinstall = $folder_toinstall+ "\_AntiRansomware"
Add-Content -Path $config_file -Value $fake_foldertoinstall
$config_file = "C:\Anti_malware_config\setup.config"
New-Item $config_file -type file -force
Add-Content -Path $config_file -Value "# You need to specify Path (Root path...) to active monitoring for File Server"
Add-Content -Path $config_file -Value "# And Path where store a log file for this monitoring."
Add-Content -Path $config_file -Value ""
Add-Content -Path $config_file -Value "%Path_Repository_to_Check:"
Add-Content -Path $config_file -Value $folder_toinstall
Add-Content -Path $config_file -Value ""
Add-Content -Path $config_file -Value "%Path_File_Server_Activity_Log:"
Add-Content -Path $config_file -Value $folder_logs
Add-Content -Path $config_file -Value ""
Add-Content -Path $config_file -Value "#Email_account"
Add-Content -Path $config_file -Value "%From:"
Add-Content -Path $config_file -Value $FROM
Add-Content -Path $config_file -Value "%To:"
Add-Content -Path $config_file -Value $To
Add-Content -Path $config_file -Value "%Smtp_Server:"
Add-Content -Path $config_file -Value $SMTP
}
}
if ($args -eq "--monitor")
{ # ARGS PASSED. START!!!!
Clear-Host
Try
{
Unregister-Event AntiRansomware
}
Catch
{
Clear-Host
}
#Start Reading file configuration setup.config
Write-Host "Loading configuration file..." -foregroundcolor red -backgroundcolor white
Write-Host ""
Write-Host ""
Write-Host ""
$lines_config = Get-Content C:\Anti_malware_config\setup.config
$next = "0"
foreach ($line_data in $lines_config) {
if ($line_data -notlike '*#*') {
#Isn't a comment
switch ($next)
{
"folder" {
$folder = $line_data
$next = "null"
}
"logs" {
$folder_tolog = $line_data + "\config_changes.txt"
$next = "null"
}
"from" {
$FROM = $line_data
$next = "null"
}
"email" {
$To = $line_data
$next = "null"
}
"server" {
$smtp = $line_data
$next = "null"
}
}
if ($line_data -like '%Path_Repository*') { # Enter the root path you want to monitor.
$next = "folder"
}
if ($line_data -like '%Path_File*'){ # Enter the path you want to storage logs.
$next = "logs"
}
if ($line_data -like '%To*') { # Enter the path you want to storage logs.
$next = "email"
}
if ($line_data -like '%Smtp*') { # Enter the path you want to storage logs.
$next = "server"
}
if ($line_data -like '%From*') { # Enter the path you want to storage logs.
$next = "from"
}
}
}
Write-Host "Loaded... Checking Configuration..." -foregroundcolor red -backgroundcolor white
# Check parameters
# Check that all variables have values
if ( ($folder) -and ($folder_tolog) -and ($To) -and ($smtp) ) {
$whitelist = Get-Content -Path C:\Anti_malware_config\white_list.config
$blacklist = Get-Content -Path C:\Anti_malware_config\ransomware_list.config
$fake_dirs = Get-Content -Path C:\Anti_malware_config\Fake_dirs.config
$filter = '*.*' # You can enter a wildcard filter here.
# In the following line, you can change 'IncludeSubdirectories to $true if required.
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $true;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
################################################################################################################################
# #
# REGISTER_EVENTS_TO_MONITOR #
# #
################################################################################################################################
Register-ObjectEvent $fsw Created -SourceIdentifier AntiRansomware -Action {
$whitelist = Get-Content -Path C:\Anti_malware_config\white_list.config
$blacklist = Get-Content -Path C:\Anti_malware_config\ransomware_list.config
$fake_dirs = Get-Content -Path C:\Anti_malware_config\Fake_dirs.config
$lines_config = Get-Content C:\Anti_malware_config\setup.config
####################
#LOAD CONFIGURATION#
####################
$next = "0"
foreach ($line_data in $lines_config) {
if ($line_data -notlike '*#*') {
switch ($next)
{
"folder" {
$folder = $line_data
$next = "null"
}
"logs" {
$folder_tolog = $line_data + "\config_changes.txt"
$next = "null"
}
"from" {
$FROM = $line_data
$next = "null"
}
"email" {
$To = $line_data
$next = "null"
}
"server" {
$smtp = $line_data
$next = "null"
}
}
if ($line_data -like '%Path_Repository*') { # Enter the root path you want to monitor.
$next = "folder"
}
if ($line_data -like '%Path_File*'){ # Enter the path you want to storage logs.
$next = "logs"
}
if ($line_data -like '%To*') { # Enter the path you want to storage logs.
$next = "email"
}
if ($line_data -like '%Smtp*') { # Enter the path you want to storage logs.
$next = "server"
}
if ($line_data -like '%From*') { # Enter the path you want to storage logs.
$next = "from"
}
}
}
##########################
# ANALYZE EVENT CAPTURED #
##########################
$name = $Event.SourceEventArgs.Name
$path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
$datestamp = get-date -uformat "%Y-%m-%d@%H-%M-%S"
$Computer = get-content env:computername
$Body = " $path on $Computer was $changeType at $timeStamp"
$PIECES=$path.split("\")
$newfolder=$PIECES[-2]
$user = (get-acl $path).owner
################################
# find extension in white list #
################################
$founded=""
$pos = $name.IndexOf(".")
$leftPart = $name.Substring(0, $pos)
$rightPart = $name.Substring($pos+1)
$founded=""
$pos = $name.IndexOf(".")
$leftPart = $name.Substring(0, $pos)
$rightPart = $name.Substring($pos+1)
###############################
# CHECK IF EXTENSION IS KNOWN #
###############################
if ($whitelist -like '*.' + $rightPart) {
$founded = ""
}
else {
$founded = ", File is not recognized"
}
######################################
# CHECK IF EXTENSION IS A RANSOMWARE #
######################################
$danger = ""
if ($blacklist -like '*.' +$rightPart) {
$infected = "and was INFECTED!!!!!"
$danger = "DANGER! DANGER! NEW RANSOMWARE FOUNDED AND WORKING. BLOCKING..."
$Messages_count++;
################
#GETCOMPUTERNAME
################
Import-Module ActiveDirectory
$m= (Get-AdComputer -Filter *) | measure
$total = $m.count
$modelinfo=@()
(Get-ADComputer -Filter *) |
ForEach-Object {
Try
{
$count = $count + 1
$computername= $_.dnshostname
$user_temp = Get-WmiObject win32_computersystem -Computer $computername | Select-Object -ExpandProperty username
if ($user_temp -like $user) {
$computer = $computername
}
}
Catch {
}
}
###################
# Disable user AD #
###################
Write-Host "Disabling user : $user"
$Danger += "Disabling user :"+ $user + "."
$pos = $user.IndexOf("\")
$user_to_disable= $user.Substring($pos+1)
Disable-ADAccount -Identity $user_to_disable
Write-Host "Disabled!"
###########################
# ALERTO TO ADMINISTRATOR #
###########################
#Send-MailMessage -From $FROM -To $To -Subject "File Infected!!!" -Body $messageBody -SmtpServer $smtp
$messageBody = "File `"$Name`" was infected!"
######################################
#Sending message to user and computer#
######################################
Invoke-WmiMethod -Class win32_process -ComputerName $computer -Name create -ArgumentList "c:\windows\system32\msg.exe * DANGER! RANSOMWARE DETECTED.USER AND COMPUTER DISABLED.`n `nPLEASE PUT IN CONTACT WITH YOU SYSTEM ADMINISTRATOR."
#####################################################
#Disable ETHERNET NETWORK ADAPTER for a computername#
#####################################################
Write-Host "Disabling NIC on : $computer" -ErrorAction Stop | ? { $_.NetConnectionStatus -eq 2 }
$danger += ". Disabling NIC on:" + $computer + "."
if(Test-Connection -ComputerName $computer -Count 1 -ErrorAction 0) {
try {
$nics = Get-wmiobject win32_NetworkAdapter -ComputerName $computer -ErrorAction Stop| Where-Object {($_.Name -like "*Ethernet*") -and ($_.NetConnectionStatus -eq 2) }
Write-Host "NICs DETECTED: $nics"
}
catch {
Write-Error "Failed to connect for network adapters on $computer"
Continue
}
foreach($nic in $nics) {
try {
Write-Host "Disabling $nic ..."
$retval = $nic.disable()
}
catch {
"Error occurred while disabling {0}" -f $nic.Name
continue
}
Write-Host "Disabled!"
}
}
else {
Write-Verbose "$computer is offline"
}
Write-Host " "
Write-Host "$path on $Computer was $changeType at $timeStamp by $user $founded $infected $danger"
Out-File -FilePath $folder_tolog -Append -InputObject " $path on $Computer was $changeType at $timeStamp by $user $founded $infected $danger"
#Send-MailMessage -To "email@domain.com" -From "email@domain.com" -Subject $Body -SmtpServer "192.168.#.##" -Body " "
}
else {
$infected = ""
}
# Let's check if is a new ransomware..
foreach ($fake in $fake_dirs) {
#Files to check if exists
$file1 = $fake + "\_1.docx"
$file2 = $fake + "\_2.docx"
$file3 = $fake + "\_3.docx"
if ( ( (Test-Path $file1) -and (Test-Path $file2) -and (Test-Path $file3) ) -or ( ($path -like "*_3.docx") -or ($path -like "*_2.docx") -or ($path -like "*_1.docx") ) )
{
#All fine!
Write-Host "NO NEW RANSOMWARE FOUNDED! on $fake"
}
else {
Write-Host "DETECTED HONEYPOT $path on $fake"
####################################################################
# RANSOMWARE FAKE DELETE FILES!!!!! OR RENAME TO UNKOWN EXTERNSION #
####################################################################
$infected = ""
$danger = "DANGER! DANGER! NEW RANSOMWARE FOUNDED AND WORKING ON $fake. BLOCKING..."
#######################################
# FIND NEW FILES IN THIS FAKE FOLDER #
#######################################
$fake_files_new = Get-ChildItem -Path $fake -Exclude _1.docx,_2.docx,_3.docx
if ($fake_files_new) {
#Detect the user who has ransomware by creation new files
$user = (get-acl $fake_files_new[0]).owner
################
#GETCOMPUTERNAME
################
Import-Module ActiveDirectory
$m= (Get-AdComputer -Filter *) | measure
$total = $m.count
$modelinfo=@()
(Get-ADComputer -Filter *) |
ForEach-Object {
Try
{
$count = $count + 1
$computername= $_.dnshostname
$user_temp = Get-WmiObject win32_computersystem -Computer $computername | Select-Object -ExpandProperty username
if ($user_temp -like $user) {
$computer = $computername
}
}
Catch {
}
}
###################
# Disable user AD #
###################
Write-Host "Disabling user : $user ..."
$Danger += "Disabling user :"+ $user + "."
$pos = $user.IndexOf("\")
$user_to_disable= $user.Substring($pos+1)
Disable-ADAccount -Identity $user_to_disable
Write-Host "Disabled!"
###########################
# ALERTO TO ADMINISTRATOR #
###########################
#Send-MailMessage -From $FROM -To $To -Subject "File Infected!!!" -Body $messageBody -SmtpServer $smtp
$messageBody = "File `"$Name`" was infected!"
######################################
#Sending message to user and computer#
######################################
Invoke-WmiMethod -Class win32_process -ComputerName $computer -Name create -ArgumentList "c:\windows\system32\msg.exe * DANGER! RANSOMWARE DETECTED.USER AND COMPUTER DISABLED.`n `nPLEASE PUT IN CONTACT WITH YOU SYSTEM ADMINISTRATOR."
#######################################################
# Disable ETHERNET NETWORK ADAPTER for a computername #
#######################################################
Write-Host "Disabling NIC on : $computer" -ErrorAction Stop | ? { $_.NetConnectionStatus -eq 2 }
$danger += ". Disabling NIC on:" + $computer + "."
if(Test-Connection -ComputerName $computer -Count 1 -ErrorAction 0) {
try {
$nics = Get-wmiobject win32_NetworkAdapter -ComputerName $computer -ErrorAction Stop| Where-Object {($_.Name -like "*Ethernet*") -and ($_.NetConnectionStatus -eq 2) }
}
catch {
Write-Error "Failed to connect for network adapters on $computer"
Continue
}
foreach($nic in $nics) {
try {
$retval = $nic.disable()
if($retval.returnvalue -eq 0) {
"{0} network card disabled successfully" -f $nic.Name
}
else {
"{0} network card disable failed" -f $nic.Name
}
}
catch {
"Error occurred while disabling {0}" -f $nic.Name
continue
}
}
}
else {
Write-Verbose "$computer is offline"
}
Write-Host "Disabled!"
Write-Host "$path on $Computer was $changeType at $timeStamp by $user $founded $infected $danger"
Out-File -FilePath $folder_tolog -Append -InputObject " $path on $Computer was $changeType at $timeStamp by $user $founded $infected $danger"
#############################################
# REMOVE ALL ITEMS AND COPY NEW IN HONEYPOT #
#############################################
Write-Host " Restoring fake files to $fake"
$restore = $fake +"\*.*"
Write-Host " Remove $restore"
Remove-Item $restore
Write-Host " And Copy"
$restore = $fake +"\"
Copy-Item "C:\Anti_malware_config\docs\_1.docx" $restore
Copy-Item "C:\Anti_malware_config\docs\_2.docx" $restore
Copy-Item "C:\Anti_malware_config\docs\_3.docx" $restore
Write-Host " Restored!"
} #end if fake_files_new
}#end else
}
}
Clear-Host
Write-Host "
_____ ______ ____ ________ _____ _____ __ _
( __ \ ( __ \ / __ \ (___ ___) / ___/ (_ _) / \ / )
) )_) ) ) (__) ) / / \ \ ) ) ( (__ | | / /\ \ / /
( ___/ ( __/ ( () () ) ( ( ) __) | | ) ) ) ) ) )
) ) ) \ \ _ ( () () ) ) ) ( ( | | ( ( ( ( ( (
( ( ( ( \ \_)) \ \__/ / ( ( \ \___ _| |__ / / \ \/ /
/__\ )_) \__/ \____/ /__\ \____\ /_____( (_/ \__/
"
Write-Host "PROTEcting your INformation - AntiRansomware"
Write-Host "____________________________________________"
Write-Host " "
Write-Host " "
Write-Host "Configuration Succesful..."
Write-Host "--------------------------"
Write-Host "PATH : $folder"
Write-Host "LOGS: $folder_tolog"
Write-Host "EMAIL : $To SMTP : $smtp"
Write-Host ""
#load black & white lists on arrays and fake directories
}
else { #Error configuration file
Write-Host "CONFIG FILE ERROR"
Write-Host "================="
Write-Host ""
Write-Host "%Path_Repository: "$Folder
Write-Host "%Path_File: "$Folder_tolog
Write-Host "%To: "$To
Write-Host "%%SMTP "$smtp
}
} # End monitor parameter