Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ntifs.h>
- #define PHNT_MODE PHNT_MODE_KERNEL
- #include <phnt.h>
- #include <ntfill.h>
- #include <bcrypt.h>
- #include <kphapi.h>
- // Memory
- #define PTR_ADD_OFFSET(Pointer, Offset) ((PVOID)((ULONG_PTR)(Pointer) + (ULONG_PTR)(Offset)))
- #define PTR_SUB_OFFSET(Pointer, Offset) ((PVOID)((ULONG_PTR)(Pointer) - (ULONG_PTR)(Offset)))
- // Zero extension and sign extension macros
- #define C_2sTo4(x) ((unsigned int)(signed short)(x))
- // Debugging
- #ifdef DBG
- #define dprintf(Format, ...) DbgPrint("KProcessHacker: " Format, __VA_ARGS__)
- #else
- #define dprintf
- #endif
- typedef struct _KPH_CLIENT
- {
- struct
- {
- ULONG VerificationPerformed : 1;
- ULONG VerificationSucceeded : 1;
- ULONG KeysGenerated : 1;
- ULONG SpareBits : 29;
- };
- FAST_MUTEX StateMutex;
- NTSTATUS VerificationStatus;
- PVOID VerifiedProcess; // EPROCESS (for equality checking only - do not access contents)
- HANDLE VerifiedProcessId;
- PVOID VerifiedRangeBase;
- SIZE_T VerifiedRangeSize;
- // Level 1 and 2 secret keys
- FAST_MUTEX KeyBackoffMutex;
- KPH_KEY L1Key;
- KPH_KEY L2Key;
- } KPH_CLIENT, *PKPH_CLIENT;
- typedef struct _KPH_PARAMETERS
- {
- KPH_SECURITY_LEVEL SecurityLevel;
- } KPH_PARAMETERS, *PKPH_PARAMETERS;
- // main
- extern ULONG KphFeatures;
- extern KPH_PARAMETERS KphParameters;
- NTSTATUS KpiGetFeatures(
- _Out_ PULONG Features,
- _In_ KPROCESSOR_MODE AccessMode
- );
- // devctrl
- _Dispatch_type_(IRP_MJ_DEVICE_CONTROL) DRIVER_DISPATCH KphDispatchDeviceControl;
- NTSTATUS KphDispatchDeviceControl(
- _In_ PDEVICE_OBJECT DeviceObject,
- _Inout_ PIRP Irp
- );
- // dynimp
- VOID KphDynamicImport(
- VOID
- );
- PVOID KphGetSystemRoutineAddress(
- _In_ PWSTR SystemRoutineName
- );
- // object
- PHANDLE_TABLE KphReferenceProcessHandleTable(
- _In_ PEPROCESS Process
- );
- VOID KphDereferenceProcessHandleTable(
- _In_ PEPROCESS Process
- );
- VOID KphUnlockHandleTableEntry(
- _In_ PHANDLE_TABLE HandleTable,
- _In_ PHANDLE_TABLE_ENTRY HandleTableEntry
- );
- NTSTATUS KpiEnumerateProcessHandles(
- _In_ HANDLE ProcessHandle,
- _Out_writes_bytes_(BufferLength) PVOID Buffer,
- _In_opt_ ULONG BufferLength,
- _Out_opt_ PULONG ReturnLength,
- _In_ KPROCESSOR_MODE AccessMode
- );
- NTSTATUS KphQueryNameObject(
- _In_ PVOID Object,
- _Out_writes_bytes_(BufferLength) POBJECT_NAME_INFORMATION Buffer,
- _In_ ULONG BufferLength,
- _Out_ PULONG ReturnLength
- );
- NTSTATUS KphQueryNameFileObject(
- _In_ PFILE_OBJECT FileObject,
- _Out_writes_bytes_(BufferLength) POBJECT_NAME_INFORMATION Buffer,
- _In_ ULONG BufferLength,
- _Out_ PULONG ReturnLength
- );
- NTSTATUS KpiQueryInformationObject(
- _In_ HANDLE ProcessHandle,
- _In_ HANDLE Handle,
- _In_ KPH_OBJECT_INFORMATION_CLASS ObjectInformationClass,
- _Out_writes_bytes_(ObjectInformationLength) PVOID ObjectInformation,
- _In_ ULONG ObjectInformationLength,
- _Out_opt_ PULONG ReturnLength,
- _In_ KPROCESSOR_MODE AccessMode
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement