-
Notifications
You must be signed in to change notification settings - Fork 44
/
libmhyprot.h
163 lines (144 loc) · 4.99 KB
/
libmhyprot.h
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
/*
* MIT License
*
* Copyright (c) 2020 Kento Oki
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#pragma once
#include <Windows.h>
//
// needed to prepare binary from memory to disk
//
#include <fstream>
#include <vector>
//
// +---------------------------------------------------------------------------+
// | |
// | libmhyprot |
// | A wrapper for the vulnerable driver to execute mhyprot exploits |
// | |
// +---------------------------------------------------------------------------+
// | |
// | what it does: |
// | the binary of mhyprot.sys will be loaded our memory to disk. |
// | please note that there is an possibility that the driver will remain |
// | on your system if you did not unload the library properly, or |
// | somethings fails on the our processes. |
// | |
// +---------------------------------------------------------------------------+
//
typedef struct _MHYPROT_THREAD_INFORMATION
{
uint64_t kernel_address;
uint64_t start_address;
bool unknown;
} MHYPROT_THREAD_INFORMATION, * PMHYPROT_THREAD_INFORMATION;
namespace libmhyprot
{
//
// initialization of this library
//
extern bool mhyprot_init();
//
// uninitialization of this library
// note: if you did not call this, the driver will remains on your system.
//
extern void mhyprot_unload();
//
// read any memory on the kernel
// privilege level: kernel (ring-0)
//
extern bool read_kernel_memory(
const uint64_t& address, void* buffer, const size_t& size
);
//
// template definition of reading kernel memory above
//
template<class T> T read_kernel_memory(const uint64_t& address)
{
T buffer;
read_kernel_memory(address, &buffer, sizeof(T));
return buffer;
}
//
// read any process memory by specific process id
// without process handle which granted permission by system
// privilege level: kernel (ring-0)
//
extern bool read_process_memory(
const uint32_t& process_id,
const uint64_t& address, void* buffer, const size_t& size
);
//
// template definition of reading user memory above
//
template<class T> T read_process_memory(
const uint32_t& process_id, const uint64_t& address
)
{
T buffer;
read_process_memory(process_id, address, &buffer, sizeof(T));
return buffer;
}
//
// write any memory to the process by specific process id
// without process handle which granted permission by system
// privilege level: kernel (ring-0)
//
extern bool write_process_memory(
const uint32_t& process_id,
const uint64_t& address, void* buffer, const size_t& size
);
//
// template definition of writing user memory above
//
template<class T> bool write_process_memory(
const uint32_t& process_id,
const uint64_t& address, const T& value
)
{
return write_process_memory(process_id, address, (void*)&value, sizeof(T));
}
//
// get a number of modules that loaded in the target process
//
extern bool get_process_modules(
const uint32_t& process_id, const uint32_t max_count,
std::vector< std::pair<std::wstring, std::wstring> >& result
);
//
// get all of threads that registered in the target process
// kernel_address is a pointer to the _ETHREAD object in kernel
//
extern bool get_process_threads(
const uint32_t& process_id, const uint32_t& owner_process_id,
std::vector<MHYPROT_THREAD_INFORMATION>& result
);
//
// get a system uptime by seconds
//
extern uint32_t get_system_uptime();
//
// terminate specific process by process id
// this eventually calls ZwTerminateProcess in the driver context
//
extern bool terminate_process(const uint32_t process_id);
}