Advertisement
Guest User

Slightly better formatting; replaced curly double quotes

a guest
Jul 10th, 2017
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # removed odd 40-space indent of entire script
  2. # replaced curly open/close double quotes with normal double quotes
  3.  
  4. #Second Delay
  5. sleep -Seconds 1
  6.  
  7. #Looks in event log.
  8. $RansomwareEvents = Get-Winevent -FilterHashtable @{logname='Application';ProviderName="SRMSVC"; ID=8215}
  9. $username = ($RansomwareEvents.message).split()[1]
  10. $username = $username -replace ".*\\"
  11.  
  12. #Blocks SMB shares access for user but not network
  13. Get-SmbShare | Where-Object currentusers -gt 0 | Block-SmbShareAccess -AccountName $username -force
  14.  
  15. #get name of computer and domain name for email message
  16. $computername = Hostname
  17. $domain = (Get-WmiObject win32_computersystem).domain
  18.  
  19. #Send Email Report
  20.                                        
  21. $SMTPPort= "25"
  22. $SMTPUsername = "test"
  23. $SMTPPassword= "test"
  24. $SMTPServer= "192.168.3.150"
  25. $SMTPFrom = "test@mydomain"
  26. $SMTPto = "test@mydomain"
  27.  
  28. $client = hostname
  29. $messageSubject = "SERVER $computername on the domain $domain IS INFECTED AND BEING ATTACKED BY RANSOMEWARE"
  30. $messagebody= "The User $username has infected the server. They have been denied access to all file shares. CALL USER NOW TURN OFF COMPUTER OR SERVER NOW! AFTER DAMAGE CONTROL. Once they have been disinfected, run the following powershell command on the server $computername to unblock the user from file shares: get-smbshare | where-object Name -notlike *$ | unblock-smbshareaccess -account $username -force "
  31. $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
  32. $message.Subject = $messageSubject
  33. $message.IsBodyHTML = $true
  34. $message.Body = $messagebody
  35. $smtp = New-Object Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
  36. $SMTP.EnableSsl= $false
  37. $smtpCreds = New-Object System.Net.NetworkCredential($SMTPUsername, $SMTPPassword)
  38. $smtp.Send($message)
  39.  
  40. # Restart FSRM services to allow script to re-trigger.
  41.                                        
  42. restart-service "File Server Resource Manager" -force
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement