Created
August 27, 2018 03:45
-
-
Save zelon88/e0cf7f3d4f577e53c59a88b747cdc98e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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%") | |
strLogFilePath = "\\server\Logs" | |
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: IT@COMPANY.com" & vbNewLine & "From: server@COMPANY.com" & vbNewLine & _ | |
"Subject: COMPANY Accessibility Defender Warning!!!" & vbNewLine & _ | |
"This is an automatic email from the Tru Form 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script requires "Fake Sendmail for Windows" by Byron Jones.
https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwjYkJyLqYzdAhXohOAKHaQWD40QFjAAegQICRAB&url=https%3A%2F%2Fwww.glob.com.au%2Fsendmail%2F&usg=AOvVaw1EFXz3aE--b-SKLX8CYH5o