-
Notifications
You must be signed in to change notification settings - Fork 0
/
Accessibility_Defender.vbs
125 lines (111 loc) · 4.91 KB
/
Accessibility_Defender.vbs
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
Option Explicit
dim oShell, oFSO, dangerousExes, exe, cmdHardCodedHash, cmdDynamicHash, strComputerName, strUserName, strLogFilePath, strSafeDate, _
strSafeTime, strDateTime, strLogFileName, strEventInfo, objLogFile, cmdHashCache, objCmdHashCache, dangerHashCache, _
dangerHashData, mailFile, objDangerHashCache, oFile, strAppFilePath
'----------
'Environment Specific Variables
strLogFilePath = "\\server\Logs"
strAppFilePath = "\\server\scripts"
'----------
Set oShell = WScript.CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
dangerousExes = Array("Magnify.exe", "Narrator.exe", "osk.exe", "sapisvr.exe", "control.exe", "utilman.exe")
cmdHardCodedHash = "db 06 c3 53 49 64 e3 fc 79 d2 76 31 44 ba 53 74 2d 7f a2 50 ca 33 6f 4a 0f e7 24 b7 5a af f3 86"
cmdDynamicHash = ""
strComputerName = oShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
strUserName = oShell.ExpandEnvironmentStrings("%USERNAME%")
strSafeDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
strDateTime = strSafeDate & "-" & strSafeTime
strLogFileName = strLogFilePath & "\" & strComputerName & "-" & strDateTime & "-Accessibility_Defender.txt"
cmdHashCache = "C:\cmdHashCache.dat"
dangerHashCache = "C:\dangerHashCache.dat"
mailFile = "C:\Accessibility_Defender_Warning.mail"
'A function to clear the previous dangerCache and create a new one.
Function clearCache()
If oFSO.FileExists(dangerHashCache) Then
oFSO.DeleteFile(dangerHashCache)
End If
If Not oFSO.FileExists(dangerHashCache) Then
oFSO.CreateTextFile(dangerHashCache)
End If
End Function
'A function to create the CMD Hash Cache file.
Function getCmdHash()
If oFSO.FileExists("C:\Windows\System32\cmd.exe") Then
oShell.run "cmd /c CertUtil -hashfile ""C:\Windows\System32\cmd.exe"" SHA256 | find /i /v ""SHA256"" | find /i /v ""certutil"" > " & cmdHashCache, 0, TRUE
End If
End Function
'A function to hash each of the hardcoded files and cache the value.
Function getDangerHash()
For Each exe In dangerousExes
If oFSO.FileExists("C:\Windows\System32\" & exe) Then
oShell.run "cmd /c CertUtil -hashfile ""C:\Windows\System32\" & exe & """ SHA256 | find /i /v ""SHA256"" | find /i /v ""certutil"" >> " & dangerHashCache, 0, TRUE
End If
Next
End Function
'A function to read the CMD hash cache.
Function cmdHashData()
If oFSO.FileExists(cmdHashCache) Then
Set objCmdHashCache = oFSO.OpenTextFile(cmdHashCache)
cmdHashData = objCmdHashCache.ReadAll()
objCmdHashCache.close
End If
End Function
'A function to read the Danger hash cache and compare it to the CMD hash cache and hardcoded CMD hash.
Function hashMatch()
hashMatch = FALSE
If oFSO.FileExists(dangerHashCache) Then
Set objDangerHashCache = oFSO.OpenTextFile(dangerHashCache)
Do While Not objDangerHashCache.AtEndOfStream
dangerHashData = objDangerHashCache.ReadLine()
If dangerHashData = cmdHashData() Or dangerHashData = cmdHardCodedHash Then
hashMatch = TRUE
End If
loop
objDangerHashCache.close
End If
End Function
'A function to create a log file.
Function createLog(strEventInfo)
If Not (strEventInfo = "") Then
Set objLogFile = oFSO.CreateTextFile(strLogFileName, True)
objLogFile.WriteLine(strEventInfo)
objLogFile.Close
End If
End Function
Function createEmail()
If oFSO.FileExists(mailFile) Then
oFSO.DeleteFile(mailFile)
End If
If Not oFSO.FileExists(mailFile) Then
oFSO.CreateTextFile(mailFile)
End If
Set oFile = oFSO.CreateTextFile(mailFile, True)
oFile.Write "To: [email protected]" & vbNewLine & "From: [email protected]" & vbNewLine & _
"Subject: COMPANY Accessibility Defender Warning!!!" & vbNewLine & _
"This is an automatic email from the COMPANY Network to notify you that a workstation was defended from Accessibility Tools exploitation." & _
vbNewLine & vbNewLine & "Please log-in and verify that the equipment listed below is secure." & vbNewLine & _
vbNewLine & "USER NAME: " & strUserName & vbNewLine & "WORKSTATION: " & strComputerName & vbNewLine & _
"This check was generated by " & strComputerName & " and is performed when Windows boots." & vbNewLine & vbNewLine & _
"Script: ""Accessibility_Defender.vbs"""
oFile.close
End Function
'A function for running SendMail.
Function sendEmail()
oShell.run "cmd /c " & strAppFilePath & "\sendmail.exe " & mailFile, 0, TRUE
End Function
'A function to display a warning message to the user and kill the machine after a specified time.
Function killWorkstation()
oShell.Run "cmd /c C:\windows\system32\shutdown.exe", 0, false
End Function
clearCache()
getCmdHash()
getDangerHash()
hashMatch()
If hashMatch = TRUE Then
createLog("The machine " & strComputerName & " just attempted to execute an Accessibility Tools exploitation!")
createEmail()
sendEmail()
killWorkstation()
End If