NtiIframe. vbs is used to batch clear malicious codes added to files.

Source: Internet
Author: User

AntiIframe. vbs

# This script is the reverse of a batch Trojan program, used to batch clear malicious code added to the file. To open a file in notepad, you can modify the Pattern parameter to specify the file name to be processed. The file names are separated by | (vbs regular expressions are also supported ). Exercise caution when modifying files (it is best to back up files first)
# Usage: CScript AntiIframe. vbs [processing path] [contains files to clear content]
# Example: CScript AntiIframe. vbs d: \ Web d: \ lake2.txtCopy codeThe Code is as follows :'-----------------------
'Anti-Iframe in vbs
'Author: lake2 (http://lake2.0x54.org)
'Date: 2007-2-27
'Version: 1.1
'-----------------------

'-------- Config Start --------------
'Specifies the name of the file to be processed. You can use the vbs regular expression or the enumerated format "(index. asp | index.htm | index.html )".
Pattern = "^. + \. (htm | html | asp | aspx | php) $"
'-------- Config End --------------

Call ShowInfo ()
If WScript. Arguments. Count = 2 Then
If Right (WScript. Arguments. Item (0), 1) = "\" Then
If len (WScript. Arguments. Item (0)> 3 then
ThePath = Mid (WScript. Arguments. Item (0), 1, Len (WScript. Arguments. Item (0)-1)
Else
ThePath = WScript. Arguments. Item (0)
End if
Else
ThePath = WScript. Arguments. Item (0)
End If
Call CheckArg (thePath)
WScript. Echo "start cleaning. Please wait ...... "
Call ShowAllFile (thePath)
WScript. Echo vbcrlf & "cleared! "& Vbcrlf
Else
Call ShowHelp ()
End If

Sub ShowInfo ()
HelpStr = HelpStr & "==========================" & vbcrlf
HelpStr = HelpStr & "===== welcome to leike graph ASP webmaster Security Assistant vbs ====" & vbcrlf
HelpStr = HelpStr & "==== Anti-Batch Trojans ====" & vbcrlf
HelpStr = HelpStr & "===== Author: lake2 ====" & vbcrlf
HelpStr = HelpStr & "==== Email: lake2@mail.csdn.net ====" & vbcrlf
HelpStr = HelpStr & "===== welcome to www.0x54.org for more information ====" & vbcrlf
HelpStr = HelpStr & "==========================" & vbcrlf
HelpStr = HelpStr & vbcrlf
WScript. Echo HelpStr
End Sub

Sub ShowHelp ()
HelpStr = HelpStr & "# usage: CScript AntiIframe. vbs [processed path] [files containing cleared content]" & vbcrlf
HelpStr = HelpStr & "# example: CScript AntiIframe. vbs d: \ Web d: \ lake2.txt" & vbcrlf
HelpStr = HelpStr & vbcrlf
WScript. Echo HelpStr
End Sub

Sub CheckArg (arg)
TmpPath = arg
Set objFSO = WScript. CreateObject ("Scripting. FileSystemObject ")
If Not objFSO. FileExists (WScript. Arguments. Item (1) Then
WScript. Echo "Error: the configuration file" & WScript. Arguments. Item (1) & "is not found )&""! "
WScript. Quit
ElseIf Not objFSO. FolderExists (tmpPath) Then
WScript. Echo "Error: Incorrect path" & tmpPath &""! "
WScript. Quit
End If
Set objFSO = Nothing
End Sub

'Process all files in the path and Its subdirectories through Traversal
Sub ShowAllFile (Path)
Set FSO = CreateObject ("Scripting. FileSystemObject ")
Set g = FSO. GetFile (WScript. Arguments. Item (1 ))
If g. Size> 0 Then
Set ts2 = g. OpenAsTextStream (1,-2)
Filecon = ts2.ReadAll
Ts2.Close
Set ts2 = Nothing
Else
WScript. Echo "Error: configuration file" & WScript. Arguments. Item (1) & "the size is 0! "
WScript. Quit
End If
Set g = Nothing
Set f = FSO. GetFolder (Path)
Set fc2 = f. files
On Error Resume Next
For Each myfile in fc2
If Err Then WScript. Echo "has insufficient permissions, you cannot check the directory" & thePath: exit sub
Set regEx = New RegExp
RegEx. IgnoreCase = True
RegEx. Global = True
RegEx. Pattern = Pattern
If regEx. Test (myfile. name) Then
CheckFile path & "\" & myfile. name, filecon
End If
Set regEx = Nothing
Next
Set fc = f. SubFolders
For Each f1 in fc
ShowAllFile path & "\" & f1.name
Next
Set FSO = Nothing
End Sub

Sub CheckFile (filepath, filecon2)
XSet = GetCharSet (filepath)
Set tStream = CreateObject ("ADODB. Stream ")
TStream. type = 1
TStream. mode = 3
TStream. open
TStream. Position = 0
TStream. LoadFromFile FilePath
If err Then Exit Sub end if
TStream. type = 2
TStream. charset = xSet
Do Until tStream. EOS
Filecon = filecon & LCase (tStream. ReadText (102400 ))
Loop
TStream. close ()
Set tStream = Nothing
If InStr (filecon, filecon2)> 0 Then
Filecon = Replace (filecon, filecon2 ,"")
Set tStream = CreateObject ("ADODB. Stream ")
TStream. type = 2
TStream. mode = 3
TStream. charset = xSet
TStream. open
TStream. Position = 0
TStream. WriteText filecon
TStream. SaveToFile filepath, 2
TStream. close ()
Set tStream = Nothing
WScript. Echo "Repaired files:" & filepath &"..."
End If
End Sub

Function GetCharSet (xPath)
Set tStream = CreateObject ("ADODB. Stream ")
TStream. type = 1
TStream. mode = 3
TStream. open
TStream. Position = 0
TStream. LoadFromFile xPath
Byte1 = ascB (tStream. Read (1 ))
Byte2 = ascB (tStream. Read (1 ))
Byte3 = ascB (tStream. Read (1 ))
TStream. close ()
Set tStream = Nothing
If byte1 = 239 and byte2 = 187 and byte3 = 191 Then
GetCharSet = "UTF-8"
Else
GetCharSet = "GB2312"
End If
End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.