| 1 | + | use windows_sys::Win32::{System::{Diagnostics::Debug::{CONTEXT, IMAGE_NT_HEADERS64, RtlCaptureContext}, Threading::{CreateEventW, CreateTimerQueue, CreateTimerQueueTimer, WT_EXECUTEINTIMERTHREAD}, LibraryLoader::{GetProcAddress, GetModuleHandleA}, SystemServices::IMAGE_DOS_HEADER}, Foundation::{HANDLE, UNICODE_STRING}}; |
| 2 | + | use std::{mem::zeroed, ptr::null_mut, ffi::c_void}; |
| 3 | + | |
| 4 | + | pub fn ekko(sleep_time: u32) { |
| 5 | + | let ctx_thread: CONTEXT = unsafe { zeroed::<CONTEXT>() }; |
| 6 | + | let rop_prot_rw: CONTEXT = unsafe { zeroed::<CONTEXT>() }; |
| 7 | + | let rop_mem_enc: CONTEXT = unsafe { zeroed::<CONTEXT>() }; |
| 8 | + | let rop_delay: CONTEXT = unsafe { zeroed::<CONTEXT>() }; |
| 9 | + | let rop_mem_dec: CONTEXT = unsafe { zeroed::<CONTEXT>() }; |
| 10 | + | let rop_prot_rx: CONTEXT = unsafe { zeroed::<CONTEXT>() }; |
| 11 | + | let rop_set_evt: CONTEXT = unsafe { zeroed::<CONTEXT>() }; |
| 12 | + | |
| 13 | + | //let h_timer_queue: HANDLE = 0; |
| 14 | + | let mut h_new_timer: HANDLE = 0; |
| 15 | + | //let h_event: HANDLE = 0; |
| 16 | + | //let image_base: *mut c_void = null_mut(); |
| 17 | + | //let image_size: u32 = 0; |
| 18 | + | let old_protect = 0; |
| 19 | + | |
| 20 | + | // This can be a randomly generated key |
| 21 | + | let key_buf: [i8; 16] = [0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55]; |
| 22 | + | let key: UNICODE_STRING = unsafe { zeroed::<UNICODE_STRING>() }; |
| 23 | + | let img: UNICODE_STRING = unsafe { zeroed::<UNICODE_STRING>() }; |
| 24 | + | |
| 25 | + | //let nt_continue: *mut c_void = null_mut(); |
| 26 | + | //let sys_func032: *mut c_void = null_mut(); |
| 27 | + | |
| 28 | + | let h_event = unsafe { CreateEventW(null_mut(), 0, 0, null_mut()) }; |
| 29 | + | let h_timer_queue = unsafe { CreateTimerQueue() }; |
| 30 | + | |
| 31 | + | let nt_continue = unsafe { GetProcAddress(GetModuleHandleA("ntdll".as_ptr()), "NtContinue".as_ptr()) }; |
| 32 | + | let sys_func032 = unsafe { GetProcAddress(GetModuleHandleA("Ntdll".as_ptr()), "SystemFunction032".as_ptr()) }; |
| 33 | + | |
| 34 | + | let image_base = unsafe { GetModuleHandleA(null_mut()) }; |
| 35 | + | let dos_header = image_base as *mut IMAGE_DOS_HEADER; |
| 36 | + | let nt_headesr = unsafe { (*dos_header).e_lfanew as *mut IMAGE_NT_HEADERS64 }; |
| 37 | + | let image_size = unsafe { (*nt_headesr).OptionalHeader.SizeOfImage }; |
| 38 | + | |
| 39 | + | key.Buffer = key_buf.as_mut_ptr() as *mut u16; |
| 40 | + | key.Length = key_buf.len() as _; // 16 |
| 41 | + | key.MaximumLength = key_buf.len() as _; // 16 |
| 42 | + | |
| 43 | + | img.Buffer = image_base as *mut u16; |
| 44 | + | |
| 45 | + | type fnRtlCaptureContext = unsafe extern "system" fn(contextrecord: *mut CONTEXT); |
| 46 | + | let sucesss = unsafe { |
| 47 | + | CreateTimerQueueTimer(&mut h_new_timer, h_timer_queue, Some(fnRtlCaptureContext), &ctx_thread as *const _ as *const _, 0, 0, WT_EXECUTEINTIMERTHREAD) |
| 48 | + | }; |
| 49 | + | |
| 50 | + | if (sucesss != 0) { |
| 51 | + | |
| 52 | + | } |
| 53 | + | } |