The attached Delphi source code is a detector for hidden processes. It has several listing methods to detect processes, making use of native apis and kernel mode drivers (The screenshot details complete available options). The article shows how the author of Process Hunter, Ms-Rem, created the application, describing the concepts used in detail alongside code executing those concepts.
Full source code of Process Hunter is attached at the bottom of the page.
Compiled: Delphi 2007
Operating System: Windows 2000 & Windows XP
Detection of hidden processes.
Article written by Ms-Rem and translated by kao from Russian to English
Many users have got used that Windows NT Task Manager shows all processes, and many consider that it is impossible to hide a process from Task Manager. Actually, process hiding is incredibly simple. There are lots of methods available for such a purpose and there are source codes available. It still amazes me that there are only a few trojans using these methods. Literally only 1 trojan from a 1000 is hidden. I think that trojan authors are lazy, since it requires extra work to hide the process and it is always easier to use ready-made sources and copy-paste them. Therefore we should expect hidden trojan processes in a near future.
Naturally, it is necessary to have protection against hidden processes. Manufacturers of antiviruses and firewals lagging behind as their products are not able to find hidden processes. For this purpose there are only a few utilities from which free-of-charge is only Klister (works only on Windows 2000). All other companies demand considerable money (kao - not true. BlackLight Beta from FSecure is free.). Furthermore, all these utilities can be easily avoided.
All programs available now, use one method for hidden process detection, therefore we have 2 choices:
* think up a method of concealment from a certain principle of detection,
* think up a method of concealment from a certain program, which is much easier.
The user who bought the commercial program cannot change it, and therefore the binding to the concrete program works reliably enough. Therefore the latter method is used in commercial rootkits (for example hxdef Golden edition). The only solution is creation free-of-charge Opensource program for detection of hidden processes. Such program shall employ several detection methods, and therefore would defeat programs concealed from one certain method. Each user can protect against binding to a certain program, it is necessary to take source codes of the program and to alter them to his own liking.
In this article I will discuss the basic methods of detection of hidden processes, show examples of a code using these methods, and to create working program for detection of hidden processes which would meet all above-stated requirements.
Detection in User Mode (ring3)
For the beginning we shall consider simple methods of detection which can be applied in 3 ring, without use of drivers. They are based on fact, that each process generates certain traces of the activity. Based on these traces we can detect hidden process. Such traces include handles opened by process, windows and created system objects. It is simple to avoid from such detection techniques, but for this purpose it is necessary to consider ALL traces left by process. Such stealth mode is not realized in any of public rootkits (unfortunately private versions are not available to me). Usermode methods are simple in implementation, safe to use, and can give a positive effect, therefore their usage should not be neglected.
For the beginning we shall be define data returned by search function, let it be linked lists:
Acquiring the list of processes by using ToolHelp API
We shall define reference function receiving the list of processes, we shall compare these results to results obtained by all other means:
It is obvious that any hidden process will not be found, therefore this function will be used as a reference for hidden process detection.
Acquiring the list of processes by using Native API
The next scanning level will be acquisition a list of processes through ZwQuerySystemInformation (Native API). It is improbable that something will be found out at this level but we should check it anyway.
Acquiring the list of processes by using list of opened handles.
Many hidden processes do not hide handles opened by them, hence we can construct the list of processes by enumerating opened handles using ZwQuerySystemInformation.
At this stage it is already possible to find out something. But we should not rely on result of such check as hiding handles is as easy as hiding processes, although some persons forget to do it.
Acquiring the list of processes by using list of the windows created by them.
It is possible to construct the list of processes having windows by building a list of all windows registered in the system and calling GetWindowThreadProcessId for each of them.
Almost no one is hiding windows, therefore this check also allows to detect some processes, but we should not rely on this check very much.
Acquiring the list of processes by use of a direct system call.
To hide a process in user mode, one usually uses code-injection techniques and intercepts ZwQuerySystemInformation from ntdll.dll in all processes.
Functions in ntdll actually are thunks to corresponding functions in a system kernel, and contain system calls (Int 2Eh in Windows 2000 or sysenter in XP), therefore the most simple and effective way to detect processes hidden from Usermode API, will be the direct use of system calls and not using API.
Function replacing ZwQuerySystemInformation for Windows XP looks like this:
Due to different system call mechanism, for Windows 2000 this code will look differently.
Now it is necessary to enumerate processes using above mentioned functions, not ntdll. Here is a code that does it:
This method detects almost 100% of user mode rootkits, for example all versions of hxdef (including Golden).
Acquiring the list of processes by analyzing handles related to them.
There is another method based on handle enumeration. The essence of method consists not in finding handles opened by process in question but in finding handles in other processes related to this process. It might be handle of the process or handle of the thread. When handle of process is found, we can find process PID using ZwQueryInformationProcess. For a thread it is possible to use ZwQueryInformationThread and obtain Id of process. All processes existing in system have been started by someone, hence parent processes will have handles of them (unless they have closed these handles), also handles of all existing processes are available to a server of Win32 subsystem (csrss.exe). Additionally, Windows NT is using Job objects actively, which allows to unite processes (for example all processes by certain user, or certain services), hence when finding handle of Job object, we should use opportunity to obtain IDs of all processes incorporated in it. It can be done by using function QueryInformationJobObject with a class of the information - JobObjectBasicProcessIdList. The code acquiring the list of processes by analyzing handles related to them looks like this:
Unfortunately, some of the above-stated methods allow to acquire only ProcessId, but not a name of process. Hence, we need to be able to get a name of process for PID. Of course, we should not use ToolHelp API for this purpose as this process might be hidden. Therefore we shall open process memory for reading and get a name from its PEB. PEB address can be acquired by using ZwQueryInformationProcess function. Here is a code that does all this:
Naturally, usermode detection methods do not end here. It is possible to think up some new methods with a little effort (for example, loading of the Dll in accessible processes by use of SetWindowsHookEx with the subsequent analysis of the list of processes where our Dll has been loaded) but for now we will settle with above mentioned methods. Advantages of these methods are that they are simple in programming, and they allow to detect processes hidden in User Mode, or poorly hidden Kernel Mode processes.. For really reliable detection of hidden processes we should write a driver and work with Windows kernel internal structures.
Kernel Mode detection
Congratulation, we made til kernel-mode hidden process detection. The main difference between these methods and usermode methods is that all lists of processes are created bypassing API calls and directly using scheduler (?) structures. It is much harder to hide from these detection methods,because these methods are based on same principles as Windows kernel and removing process from all scheduler structures will effectively disable this process altogether.
What is the process inside the kernel? Each process has the address space, descriptors, threads, etc. There are structures in the kernel related to these things. Each process is described by EPROCESS structure, structures of all processes are connected in the circular doubly-linked list. One of methods of process hiding consists in changing of pointers so that enumeration skips hidden process. Not being enumerated does not influence process' ability to function. However, EPROCESS structure always should exist, it is required for a process to function. The majority of methods of detection of hidden processes in Kernel Mode are somehow connected with detection of this structure.
Again we shall define format how received process information will be stored. This format should be convenient for data transfer from the driver (in the appendix). Let it will the following structure:
Let these structures occupy contiguous chunk of memory, and in the last structure Present flag will not be set.
Acquiring the list of processes by using ZwQuerySystemInformation in a kernel.
We shall begin as always with the simplest way, acquiring reference list of processes by using ZwQuerySystemInformation:
Let this function be our reference function as any Kernel Mode hidden processes will not be detected. But all user mode root-kits like hxdef will be detected.
In this code we use function GetInfoTable to obtain information easily. To avoid questions about what is that, here is complete code of function:
I think that it will be easy to understand what this function does..
Acquiring list of processes using doubly-linked list of EPROCESS structures.
So, we go further. Following step will be acquiring the list of processes by iterating through the doubly-linked list of EPROCESS structures. The list begins with a header - PsActiveProcessHead, therefore for correct enumeration of processes we need to find this not exported symbol. For this purpose we will use a fact that System process is the first process in the list of processes. While being in DriverEntry we need to obtain pointer to current process by using PsGetCurrentProcess (drivers loaded using SC Manager API or ZwLoadDriver are always loaded in a context of process System), and BLink at offset ActiveProcessLinks will point to PsActiveProcessHead. It looks like this:
Now it is possible to iterate through doubly-linked list and create the list of processes:
To obtain a name of process, its Process Id and ParrentProcessId, we use offsets of those fields in structure EPROCESS (pIdOffset, ppIdOffset, NameOffset, ActPsLink). These offsets differ in various versions Windows, therefore their acquisition is done in separate function which you can see in a source code of program Process Hunter (in the appendix).
Any concealment of process by API interception method, will be revealed in the above-stated way. But if process is hidden by means of DKOM (Direct Kernel Object Manipulation)method, this way will not help because such processes are removed from the list of processes.
Acquiring the list of processes using lists of threads in the scheduler.
One of methods of detection of such concealment (kao - the original text is ambiguous. Author probably meant "detection of processes hidden using DKOM method") consists in obtaining the list of processes from list of threads in the scheduler. There are three doubly-linked lists of threads (KiWaitInListHead, KiWaitOutListHead, KiDispatcherReadyListHead) available in Windows 2000. Former two lists contain threads waiting for certain events, and the latter contains threads ready for execution. When processing these lists and substracting offset of the thread list in structure ETHREAD, we will obtain pointer to ETHREAD of a thread (kao - this sentence is very hard to understand in original. I hope I got it right). This structure contains several pointers to the process related to this stream, namely - struct _KPROCESS *Process (0x44, 0x150) and struct _EPROCESS *ThreadsProcess (0x22C, offsets are specified for Windows 2000). First two pointers do not have any influence on functionality of a thread, and therefore can be easily modified to hide a process. On the contrary, third pointer is used by the scheduler when switching address spaces, therefore it cannot be changed. We shall use it to recognize which process owns a thread.
This detection method is used in the program klister, whose main disadvantage is that it works only under Windows 2000 (it fails to work with certain Service Packs, though). Such problem is caused by fact that Klister uses hardcoded addresses of thread lists, but these addresses are different in all Service Packs.
Hardcoding addresses in the program is poor solution as it makes software useless when new OS updates are released and makes it possible to avoid this detection method. Therefore it is necessary to search for list addresses dynamically, by analysing code of kernel functions in which these lists are used.
For the beginning we shall try to find KiWaitItListHead and KiWaitOutListHead in Windows 2000. Addresses of these lists are used in function KeWaitForSingleObject in the following code:
To obtain these addresses we should use length-disassembler (we shall use LDasm written by me) on KeWaitForSingleObject function. When the index (pOpcode) will point to a command "mov ecx, KiWaitInListHead", (pOpcode + 5) will point to "test al, al", and (pOpcode + 24) - to "mov ecx, KiWaitOutListHead". After that we can obtain KiWaitItListHead and KiWaitOutListHead addresses from (pOpcode + 1) and (pOpcode + 25) accordingly. The code which searches for these addresses looks like this:
KiDispatcherReadyListHead in Windows 2000 is found in a similar fashion, by searching function KeSetAffinityThread for the following code:
Here is function that will search for KiDispatcherReadyListHead:
Unfortunately, Windows XP kernel differs very much from Windows 2000 kernel. The scheduler in XP does not have three, but only two lists of threads: KiWaitListHead and KiDispatcherReadyListHead. It is possible to find KiWaitListHead by scanning function KeDelayExecutionThread for the following code:
Such search is carried out by a following code:
The most difficult problem is to find KiDispatcherReadyListHead. A problem lies infact that KiDispatcherReadyListHead address is not present in any of exported functions. Therefore it is necessary to use more complicated search algorithm for its calculation. We shall start our search from function KiDispatchInterrupt and there is only one place of interest in it containing a following code:
The First call in this code points to function in which there is a reference to KiDispatcherReadyListHead. However, search for the KiDispatcherReadyListHead address becomes more complicated because the relevant code in this function is different in Windows XP SP1 and SP2. In SP2 it looks like this:
And in SP1:
Search for only one instruction "lea" is unreliable, therefore we shall check also that after "lea" command there is a command with rel32 displacement (function IsRelativeCmd in LDasm). The full code that searches for KiDispatcherReadyListHead will look like this:
After a finding address of thread list, we can easily enumerate their processes by using the following function:
CollectProcess is a utility function that adds process to the list, if it is not there yet.
Acquiring the list of processes by intercepting system calls.
Any working process cooperates with system through API, and the majority of these inquiries turn into references to a kernel through the interface of system calls. Certainly, process can exist without using any API calls, but then it cannot carry out any useful (or harmful) deed. In general, the idea consists in intercepting system calls by using our handler, and obtaining pointer to EPROCESS of current process in our handler. The list of pointers shall be collected during collect certain period of time, and it will not include processes that did not carry out any system calls while this information was gathered (for example, processes whose threads are in a waiting state).
Interrupt 2Eh is used to make a system call in windows 2000, therefore we need to change a descriptor of corresponding interrupt in idt to intercept system calls. For this purpose we need to detect location of idt in memory by using sidt command. This command returns following structure:
The code for changing interrupt vector 2Eh will look like this:
Of course it is necessary to restore everything before unloading the driver:
Windows XP uses commands sysenter/sysexit (which have appeared in processors Pentium 2) to perform system calls. Functionality of these commands is controlled by model-specific registers (MSR). Address of a system call handler is set in MSR register SYSENTER_EIP_MSR (number 0x176). Reading MSR of the register is carried out by rdmsr command, and we need to set ECX = number of the register to be read, and the result is located in pair of registers EDX:EAX. In our case, SYSENTER_EIP_MSR register is 32 bit register, therefore EDX will be 0, and EAX will contain address of system call handler. Similarly, we can write into MSR register by using wrmsr instruction. There is one thing to note: when writing into 32-bit MSR register, EDX should be nulled, otherwise it will cause exceptions and will lead to immediate crash of system.
By taking all this into account, the code replacing system call handler will look like this:
And code restoring old system call handler looks like this:
One more Windows XP feature is that system call can be made both through sysenter, and through int 2Eh, therefore we need to replace both handlers with ours.
Our new system call handler should obtain pointer to EPROCESS of the current process and if it is new process, it should add this process into our list.
Accordingly, new system call handler will look like this:
To obtain full list of processes this code should work for some period of time and therefore we have the following problem: if process contained in the list will be removed, at the subsequent iteration through the list we will obtain invalid pointer, as a result we will either falsely detect a hidden process or will generate BSOD. The solution to this situation is - using PsSetCreateProcessNotifyRoutine to register our Callback function which will be called when creating or terminating a process. When process is being terminated, it should be deleted from our list. Callback function has the following prototype:
Installation of callback routine is performed like this:
And removal like this:
Here is one problem, Callback function is always called in a context of process to be terminated, hence it is impossible to delete process from lists directly in this callback function. For this purpose we shall use system work items, first we shall allocate memory for a work item by using IoAllocateWorkItem, and then we shall place the task in queue of a working thread by using of IoQueueWorkItem (kao - not sure about this sentence.. ). In handler procedure we will not only delete terminated processes from the list but also will add freshly created processes. Here is a code for handler:
This is rather reliable way of hidden process detection, as no process can manage without system calls, but some processes can be in a waiting state for a long time and will not carry out system calls during long period of time. Such processes will not be detected.
If desired, it is easy to bypass this method of detection. For this purpose it is necessary to change a method of performing system calls in hidden processes (redirect to another interrupt or callgate in GDT). It is especially easy to do so in Windows XP as it is enough to patch KiFastSystemCall in ntdll.dll and to create a corresponding gate for a system call. In Windows 2000 it is a little bit more difficult, as calls to int 2E are scattered throughout ntdll, but it is not so complex to find and patch all these places too, therefore it is not smart to rely on results of this check.
Acquiring the list of processes by iterating through handle table list.
If you have ever tried to hide process by removing it from list of PsActiveProcesses, perhaps you have noticed that when you enumerate handles by using ZwQuerySystemInformation, handles of hidden process are also enumerated and it is possible to detect their ProcessId. It is because for convenience of handle enumaration, all handle tables are incorporated in doubly-linked list HandleTableList. Offset of this list in HANDLE_TABLE structure for Windows 2000 is equal 0x054, and for Windows XP - 0x01C, this list with begins HandleTableListHead. HANDLE_TABLE structure contains pointer to process owning it (QuotaProcess), offset of this pointer in Windows 2000 is equal 0x00C, and in Windows XP - 0x004. By iterating through the list of handle tables we can build process list.
First we need to find HandleTableListHead. Kernel disassembly has shown that references to it are located deeply in the functions, therefore code disassembly method which we used earlier, cannot be used here. To find HandleTableListHead it is possible to use fact that HandleTableListHead is a global kernel variable and therefore it is located in one of kernel file sections and all other elements of HandleTableList are located in dynamically allocated memory and consequently always will be behind kernel address space limits. From this follows, that we need to acquire pointer to HandleTable of any process, and to iterate through linked-list until we find an element that is located in the kernel address space. This element will be HandleTableListHead.
To calculate imagebase and size of system kernel we will use ZwQuerySystemInformation with class SystemModuleInformation. It will return a table of descriptors for all loaded modules and first element always is "system". Taking into account all aforementioned, code that searches for HandleTableListHead looks like this:
This code is rather universal as it works in any Windows NT version, and can be applied not only to search for HandleTableListHead, but also for any other lists having similar structure.
After acquiring address of HandleTableListHead we can traverse through handle tables and construct list of processes based on this information:
This method of detection is used in F-Secure Black Light and in the last version KProcCheck. I think you will easily find a way to fool this detection method.
Acquiring list of processes by scanning PspCidTable.
There is one interesting thing to note - if process is removed from PsActiveProcesses list, it does not prevent opening process by using a call to OpenProcess. There is a method of hidden process detection that tries to detect processes by bruteforcing Pid and calling OpenProcess. I am not present this method, as it does not have any advantages, I would even say that it is "through-the-ass" method. But the fact of its existence means that in system there is one more list of processes besides PsActiveProcesses which is used by OpenProcess. When bruteforcing ProcessId we will certainly note that one process can be opened using a several different Pid, and it suggests that the second list of processes is something like HANDLE_TABLE. To verify this guess, we shall glance in function ZwOpenProcess:
As you see, this code copies given pointers in the safe way, checking if they point to user addresses, checks access rights and presence of the privilege "SeDebugPrivilege", then extracts ProcessId from CLIENT_ID structure and passes it to PsLookupProcessByProcessId function whose purpose is to obtain EPROCESS based on ProcessId. Remaining part of function is useless to us, therefore we should glance in PsLookupProcessByProcessId now:
What we see here, confirms presence of the second table of the processes organized as HANDLE_TABLE. The table is called PspCidTable and contains lists of processes and threads, and is also being used in functions PsLookupProcessThreadByCid and PsLookupThreadByThreadId. As we can see, handle and pointer to handle table is passed to function ExMapHandleToPointer, which (if handle is valid) returns pointer to an element of the table describing given handle - HANDLE_TABLE_ENTRY. After we process ntoskrnl.pdb with PDBdump and dig through obtained log, it is possible to figure out the following:
What's the use of it? First of all, we are interested into contents of Object field, which is the sum of the pointer to object described by this handle and a usage flag of the given element of the table (I will explain this in more details a little bit later). Field GrantedAccess, which specifies permitted access rights to the object from this handle, is rather interesting. For example, it is possible to open a file for reading, modify field GrantedAccess and to write to this file. Such method can be used for reading/writing of files which may not be opened with required access rights (for example - files locked by another process). But we shall return to our problem - to obtain the list of processes by analyzing PspCidTable.
For this purpose we need to understand handle table format, in order to iterate through this list. There is a serious difference between Windows 2000 and Windows XP here. Handle table formats a significantly different and we should analyze each OS separately.
For the beginning we shall analyze handle table in Windows 2000 as it is much easier to understand this format. For the beginning we shall glance in a code of function ExMapHandleToPointer:
Here we call ExMapHandleToPointer function which performs search on HANDLE_TABLE, and call ExLockHandleTableEntry which sets Lock Bit. To understand internals of handle table we should disassemble both these functions. We shall begin with ExpLookupHandleTableEntry:
In addition to it, I shall show HANDLE_TABLE structure obtained from ntoskrnl.pdb:
Based on these data we can recover structure of the handle table:
Considering all of the above it is obvious, that handle value consists of three parts which are indexes in the three-level table of objects. Now we shall look in function ExLockHandleTableEntry:
This code checks 31st bit in Object element of HANDLE_TABLE_ENTRY structure, sets it and, if it is set - waits for HandleContentionEvent in HANDLE_TABLE. For us only the fact of setting TABLE_ENTRY_LOCK_BIT in important, as it is a part of the object address, and if flag is not set, we shall obtain invalid address. Now that we have understood format of the handle table, it is possible to write a code that iterates through objects in the table:
This code processes all objects in the table and calls ProcessObject function for each of them. ProcessObject detects object type and processes it in appropriate way. Here a code of this function:
OK, we have understood table of objects in Windows 2000, now it is time to start analysis in Windows XP. We shall begin with disassembling ExpLookupHandleTableEntry function:
Now we shall look at structure HANDLE_TABLE from ntoskrnl.pdb:
We can recover format of _XP_HANDLE_TABLE structure based on this information:
From the code above, it is obvious that function ExpLookupHandleTableEntry gets TableCode value from HANDLE_TABLE structure and based on its two low-order bits, calculates number of levels of the table. The remaining bits are pointer to the first level table. Hence HANDLE_TABLE in Windows XP can have from one up to three levels, thus the size of the table at any level is equal 1FFh. When quantity of records in the table increases, the system can automatically increase a level count. It is obvious, that the table will have the second level when quantity of records exceeds 0x200, and the third level - at quantity greater 0x40000. It is not known whether the system reduces of number of levels to the table when freeing (kao - releasing?) objects, I did not notice such behaviour.
Function ExLockHandleTableEntry does not exist in Windows XP, therefore the code blocking an element of the table is located in function ExMapHandleToPointer. Lest disassemble this function and look what it does:
When ExpLookupHandleTableEntry function returns pointer to HANDLE_TABLE_ENTRY, we check low-order bit of Object field and, if it is set, it is cleared (kao - there is typo in original here... Hopefully I got it right...) and, if it is not set, we wait until it is set. Hence when obtaining the address of object we should not set the high-order bit (as in Windows 2000), but clear low-order bit. In view of the aforesaid, we can make a code that scans the table of objects:
So we have understood format of object tables. Now to enumerate processes we need to obtain PspCidTable address. As you have probably guessed, we shall search for it in function PsLookupProcessByProcessId, first call in it will contain PspCidTable address. Here a code:
Now we know how to process PspCidTable. It is easily possible to view all objects in tables of all processes in a similar fashion, and to analyze objects which belong to hidden processes, in the same way as we did in UserMode. If you have understood with all aforementioned, I think you can do it.
If the system has a process, then sootvestsvenno it will have its threads. If we can catch the thread switching, it will be possible from the data to build a list of processes. To begin with a brief look at the mechanism of switching streams. At regular intervals (10-15 ms) system timer generates an interrupt that causes the scheduler, and if the time slice associated with the current thread has expired, the thread switch occurs. Needless thread switching is performed non-exported kernel functions SwapContext, which nevertheless can be found in the debug symbols for ntoskrnl.exe. This function is called by the scheduler at the end of time quantum flux, or while waiting for the flow of any event. In the first case, this function is called from KiDispatchInterrupt, in the second case of non-exported functions located deep within the nucleus, which in turn is called from KeWaitForSingleObject, KeDelayExecutionThread and KeWaitForMultipleObjects. SwapContext function parameters are passed in registers and have the following assignment: cl - defines the processing mode APC, edi - a pointer to the stream returns control, esi - a pointer to a thread gets control, ebx - a pointer to the PCR. We are only interested in pointers to switching currents passed in registers esi and edi. First we need to find the address of the function SwapContext. To do this we will disassemble and look KiDispatchInterrupt code like:
From this site we will retrieve the address SwapContext. This search method is very reliable and versatile as it allows to find SwapContext in any Windows, since it is 2000, and ending with 2003 server including all service pack. And here is the code performs search SwapContext:
After finding the address SwapContext we need to hook it. The only possible way in this case - it is a splicing code. To do this, copy the first few instructions to the intercepted function in the buffer at its end put jmp to continue, but the beginning of its function is replaced by jmp on his handler. In this case, if the copied code into the buffer we will meet the team containing relative offset, then you need to correct, otherwise we get the inevitable BSOD. For installation and removal of such hooks, we use the following code:
The method of splicing certainly easy and convenient, but when used incorrectly it can create quite a lot of problems. The hazards of the time of installation and removal of hooks, as on a multiprocessor system (either on a system with Hiperthreading processor) to another thread can call the intercepted function in the patch when its code is not yet complete. Let's make a rough estimate of this probability. The average frequency of calling this function on a dual Pentium April 2400 was equal to 785 calls per second. Assume that the patch beginning of the function is 0.01 microseconds (actually much less), while we get the probability of equal zeal 0.00000785, ie to 127,380 starts, one drop of the system. For such a program as a rootkit detector (which is also rarely run), it is quite reasonable value, but if this method will be used to permanently apply the program (eg antivirus software), then use the splice should only once (for the installation of hooks without their withdrawal) and only at boot (the boot driver). In this case, the probability of a crash so close to zero that it can never be taken into account. So far I have not seen a single case of a crash because of this reason. But there is another, far more than the real cause of instability of splicing (and any other methods of hooks too). If the driver admits unloading and unloading removes the hooks, then unloading can occur when a thread is inside the handler interception. The probability of this depends on the alignment of the content handler to intercept and on the frequency of calls intercepted functions. Experience has shown that the probability of a crash when unloading the driver is large enough and put up with it did not, but this can be avoided if the sync driver unload with a handler function. And even better - make the driver nonpaged, that will save us from the brakes when you synchronize. As you see, when properly used splicing can be absolutely safe, although lack of understanding of his work may lead to very nonweak glitch, so use, but with caution.
All of the above methods of detecting hidden processes implemented in my program Process Hunter. Bypass all the description of the method of detection would be very difficult, but probably the authors of rootkits implement its circumvention by intercepting IOCTL from application to the driver. Reliable protection against such circumvention is to use a private version of the detector. Since the program comes with source code, you can decide to change all that apply to IOCTL, names of modules, windows, etc.
Only Delphi source code is included in the archive.
Delphi Basics - Free Delphi Source Code - Ultimate Programming Resource > Delphi Basics Projects >