Using File Server Resource Manager To Screen For Ransomware
Using File Server Resource Manager To Screen For Ransomware
Altaro VM Backup
eBooks
I have created a script that will set up and con gure all of this
within minutes. The script performs the following actions:
access to all shared les on the le server and sends an email message
More info
to whatever email speci ed.
Windows Server 2012 – in order to use the cmdlet that blocks SMB Of ce 365
share access. Backup
Mail Relay Server – Used to con gure email alert.
Update- Edited script to restart FSRM service after blocking SMB permissions.
Ran into issue where the task was only triggering once.
1 function Install-FSRMRansomware {
Start 30-day trial
2 <#
3 .SYNOPSIS
4 Installs the File Server Resource Manager role if not instal More info
led and then configured a file screen on all drives other th
5 an C.
The file screen screens for possible ransomware infections a
6 nd then deny's SMB access to the user who trigged the scree
7
n.
.PARAMETER SMTPServer
8
Specify the address of an email relay server. This is used t
Hyper-V Dojo
9
10
o send the alert emails that generate when the file screen i Forum
11 s triggered.
12 .PARAMETER EmailTO
13 Specify the email address to send the alerts to.
14 .PARAMETER EmailFrom
15 Specify the email address that the email alerts are sent fro
16 m.
17 #>
18 [CmdletBinding()]
19 param(
20 [Parameter(Mandatory=$True,
21 HelpMessage="Please input the address fo
22 r an accessible email relay server.")]
23
[String]$SMTPServer,
24
25 [Parameter(Mandatory=$True,
26 HelpMessage="Please input a valid Email a
27 ddress to send the email alerts to.")]
[String]$EmailTo, Your training
28
29 [Parameter(Mandatory=$True, continues on the
30 HelpMessage="Please specify an email addr
31 ess to recieve alerts from.")] Dojo Forums!
32 [String]$EmailFrom Browse topics, ask
33
34 questions, read
35 )
36 answers from
37 Process{ fellow IT pros and
38
39 post your own
40 #add the FSRM role if it doesnt exist
41 If ((Get-WindowsFeature fs-resource-manager).ins replies.
42 talled -like "False"){
43 Write-Verbose "Installing File Server Resour
44 ce Manage Role"
45 Install-WindowsFeature fs-resource-manager
46 } Enter the Dojo
47 If ((Get-WindowsFeature RSAT-FSRM-Mgmt).installe Forum
48 d -like "False"){
49 Write-Verbose "Installed FSRM RSAT Tools"
50 install-windowsfeature RSAT-FSRM-Mgmt
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 2/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
51 }
52 Learn more
53
54 #Create File Group for FSRM
55 New-FsrmFileGroup -name "Ransomware Files" -Incl
56 udePattern @( "*DECRYPT_INSTRUCTION.HTML*",
57 "*HELP_DECRYPT.HTML*",
58
"*decrypt all files*.bmp*",
59
"*.ecc",
Categories
60
61 "*.ezz",
62 "*.exx",
63 "*.zzz", STORAGE
64 "*.xyz",
65 "*.aaa",
66 "*.abc",
SECURITY
67 "*.ccc",
68 "*.vvv",
69 "*.xxx",
70 "*.ttt", SCRIPTS & TOOLS
71 "*.micro",
72
"*.encrypted",
73
"*.locked", NETWORKING
74
75 "*.crypto"
76 "*_crypt",
77 "*.crinf",
TROUBLESHOOTING
78 "*.r5a",
79 "*.XRNT",
80 "*.XTBL", & PERFORMANCE
81 "*.crypt",
82 "*.R16M01D05",
83 POWERSHELL &
"*.pzdc",
84 "*.good",
85 "*.LOL!", AUTOMATION
86 "*.OMG*",
87
"*.RDM",
88 WINDOWS SERVER
"*.RRK",
89
"*.encryptedRSA",
90
91 "*.crjoker",
"*.EnCiPhErEd", ALTARO
92
93 "*.LeChiffre",
94 "*.keybtc@inbox_com",
95 "*.0x0",
"*.bleep",
"*.1999",
"*.vault",
"*.HA3",
"*.toxcrypt",
"*.magic",
"*.SUPERCRYPT",
"*.CTBL",
"*.CTB2",
"*.locky" )
96
97
98
99
100
101 #Create FSRM Template xml file and import templa
102 te then remove xml file
103 $FSRMTemplate = @"
104 <?xml version="1.0" ?><Root ><Header DatabaseVersion = '2.0'
></Header><QuotaTemplates ></QuotaTemplates><DatascreenTempl
105 ates ><DatascreenTemplate Name = 'RansomwareCheck' Id = '{12
106 2F5AB4-9DF0-4F09-B89E-0F7BDC9D46CC}' Flags = '1' Description
107 = '' ><BlockedGroups ><FileGroup FileGroupId = '{82D08F60-73
108 19-4BE2-8621-066DB91A958E}' Name = 'Ransomware%sFiles' ></Fi
109 leGroup></BlockedGroups><FileGroupActions ><Action Type="1"
110 Id="{73AFB339-FF17-42DC-B9B9-E7C9A8E7C9A9}" EventType="2" M
essageText="User%s[Source%sIo%sOwner]%sattempted%sto%ssave%s
111
[Source%sFile%sPath]%sto%s[File%sScreen%sPath]%son%sthe%s[Se
rver]%sserver.%sThis%sfile%sis%sin%sthe%s[Violated%sFile%sGr
112
oup]%sfile%sgroup,%swhich%sis%snot%spermitted%son%sthe%sserv
113
er." /><Action Type="3" Id="{D0B80CC5-E6DD-481C-9534-19944A8
114
115 51A72}" ExecutablePath="C:\Windows\System32\WindowsPowerShel
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 3/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
116 l\v1.0\powershell.exe" Arguments=""C:\Scripts\ScriptToD
enyPermissions.PS1"" WorkingDirectory="C:\Windows\Syste
117 m32\WindowsPowerShell\v1.0\" Account="3" MonitorCommand="0"
118 KillTimeOut="0" LogResult="1" CurrentSid="S-1-5-21-34682808
119 91-3112941812-1175424509-500" /></FileGroupActions></Datascr
120 eenTemplate></DatascreenTemplates><FileGroups ></FileGroups>
121 </Root>
122
"@
123
$FSRMTemplate | Out-File -FilePath C:\users\publ
124
ic\FSRMTemplate.xml
125
128
129 #Creates Script Block to perform email message a
130 nd block SMB Permissions. Exports script block to a PS1 for
131 the File Screen Template.
132 $DenyPermissionsScript = @"
133
134 #One second delay to
135 give script enough time to grab newest event logs
136 sleep -Seconds 1
137
138
139 #Looks in event log
140 for the custom event message generated by the file screen a
141 udit. Input's username of the offender into a variable.
142 `$RansomwareEvents =
143 get-eventlog -logname Application -message "*ransomware*" -n
144 ewest 50 | where {`$_.eventid -eq 8215}
145 `$username = (`$Rans
146 omwareEvents.message).split()[1]
147 `$username = `$usern
ame -replace ".*\\"
148
149 #Blocks SMB share ac
150 cess for user
151
Get-SmbShare | Where
152
-Object currentusers -gt 0 | Block-SmbShareAccess -AccountNa
153
154 me `$username -force
155
156 #get name of compute
157 r and domain name for email message
158 `$computername = Hos
159 tname
160 `$domain = (Get-WmiO
bject win32_computersystem).domain
`$client = hostname
`$messageSubject =
"Server `$computername on the domain `$domain is Infected b
eing attacked by Ransomware"
`$messagebody= "The
User `$username has infected the server. They have been den
ied access to all file shares. Please open a ticket to disin
fect their machine. Once they have been disinfected, run the
following powershell command on the server `$computername to
unblock the user from file shares: get-smbshare | unblock-sm
bshareaccess -accountname `$username -force "
`$message = New-Obje
ct System.Net.Mail.MailMessage "$EmailFrom", "$EmailTo"
`$message.Subject =
`$messageSubject
`$message.IsBodyHTML
= `$true
`$message.Body = `
$messagebody
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 4/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
`$smtp = New-Object
Net.Mail.SmtpClient("$smtpserver")
`$smtp.Send(`$messag
e)
"@
New-FSRMFILEScreen -
path "$DRIVE\" -template "RansomwareCheck"
}
Install-FSRMRansomware -SMTPServer InsertValidMailRelayServe
r -EmailTo InsertEmailToSendAlertsTo -EmailFrom InsertEmailT
oSendEmailFrom
Once you have inserted your own parameters, save the script. To
execute the script, hold down SHIFT and RIGHT CLICK on the
.ps1 le. Select COPY AS PATH:
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 5/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
The script will start to run, if the File Server Resource Manager
role is not installed it will begin installing.Once the script nishes,
we can look at what was done by opening up Server Manager and
clicking on Tools and then selecting File Server Resource
Manager:
If we select the File Groups in the left window pane, we can see
our newly created le group called “Ransomware les” that
contains all of our known ransomware extensions to screen for:
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 6/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
If we select the Command tab we can see that the script has been
created in the C:\Scripts directory on the server. This is the script
that performs the SMB blocking action and sends the alert email
through the email relay server speci ed in the script parameters:
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 7/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 8/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
Name
Luke Orellana
Luke Orellana has been immersed in the realm of
Information Technology since 2005. As a System
Administrator for a Managed IT Services Provider,
he supports and maintains the IT Infrastructure of
many businesses through technologies such as
VMware, Hyper-V, Windows Server, Exchange,
SQL, and PowerShell. Luke’s objective is to
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 10/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
Sparky Henderson
July 11, 2019 at 10:18 pm
Reply
Jim
December 6, 2016 at 6:01 pm
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 11/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
Reply
Dariusz
November 28, 2016 at 5:11 pm
Hi
Reply
Dariusz
November 28, 2016 at 5:11 pm
Hi
Reply
Luke Orellana
November 28, 2016 at 9:56 pm
Reply
Aaron
November 3, 2016 at 9:13 pm
Reply
Aaron
November 3, 2016 at 9:13 pm
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 13/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
Reply
Myke
October 24, 2016 at 3:54 pm
Reply
Myke
October 24, 2016 at 3:54 pm
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 14/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
Reply
Luke Orellana
November 28, 2016 at 10:01 pm
Reply
Bill
September 18, 2016 at 6:58 am
Reply
Luke Orellana
November 28, 2016 at 10:05 pm
Reply
Wouter Kokshoorn
September 12, 2016 at 4:17 pm
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 15/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
Reply
John Albrektson
September 9, 2016 at 9:29 pm
Reply
Luke Orellana
September 12, 2016 at 4:12 pm
Reply
Paul Passingham
September 8, 2016 at 6:35 pm
Hi Luke,
Great Article, Will be implementing this across all our our
2012 servers. As our relay server listens on a non standad
port and requires authentication would you be able to
modify the script to accomodate this.
Many thanks
Paul
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 16/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
Reply
Luke Orellana
September 12, 2016 at 4:47 pm
$SMTPPort= “587”
$SMTPUsername = “username”
$SMTPPassword= “password”
$SMTPServer= “smtp.myrelay.com”
$SMTPFrom = “[email protected]”
$SMTPto = “[email protected]”
$client = hostname
$messageSubject = “Server $computername on the
domain $domain is Infected being attacked by
Ransomware”
$messagebody= “The User $username has infected the
server. They have been denied access to all le shares.
Please open a ticket to disinfect their machine. Once
they have been disinfected, run the following powershell
command on the server $computername to unblock the
user from le shares: get-smbshare | unblock-
smbshareaccess -accountname $username -force ”
$message = New-Object System.Net.Mail.MailMessage
$smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true
$message.Body = $messagebody
$smtp = New-Object Net.Mail.SmtpClient($SMTPServer,
$SMTPPort)
$SMTP.EnableSsl= $true
$smtpCreds = New-Object
System.Net.NetworkCredential($SMTPUsername,
$SMTPPassword)
$smtp.Send($message)
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 17/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
Reply
Previous
Next
Find us on
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 18/19
11/4/2019 Using File Server Resource Manager to Screen for Ransomware
https://www.altaro.com/hyper-v/using-file-server-resource-manager-screen-ransomware/ 19/19