-
Notifications
You must be signed in to change notification settings - Fork 27
/
main.rs
59 lines (50 loc) · 1.45 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
50
51
52
53
54
55
56
57
58
59
const SCRATCH_SIZE: usize = 10 * 1024 * 1024;
const SHELLCODE_SIZE: usize = 1 * 1024 * 1024;
fn main() {
// Scratch space for writing structures
let scratch = unsafe {
libc::mmap(
std::ptr::null_mut(),
SCRATCH_SIZE,
libc::PROT_READ | libc::PROT_WRITE,
libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,
-1,
0,
)
} as usize;
// Clear the data in the scratch memory
let data = [0x0; SCRATCH_SIZE];
unsafe {
std::ptr::copy(data.as_ptr(), scratch as *mut u8, SCRATCH_SIZE);
}
let shellcode = unsafe {
libc::mmap(
std::ptr::null_mut(),
SHELLCODE_SIZE,
libc::PROT_READ | libc::PROT_WRITE | libc::PROT_EXEC,
libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,
-1,
0,
)
} as usize;
// Always return from the shellcode
let data = [0xc3; SHELLCODE_SIZE];
unsafe {
std::ptr::copy(data.as_ptr(), shellcode as *mut u8, SHELLCODE_SIZE);
}
println!(
"SNAPSHOT: Scratch memory {:#x} Length: {SCRATCH_SIZE:#x}",
scratch
);
println!(
"SNAPSHOT: Shellcode: {:#x} Length: {SHELLCODE_SIZE:#x}",
shellcode
);
unsafe {
// Use the qemu_snapshot trigger
std::arch::asm!("int 0x3 ; vmcall");
// Call the shellcode
let func: extern "C" fn() = std::mem::transmute(shellcode);
func();
};
}