Created
December 26, 2018 14:36
-
-
Save Hanaasagi/8cbbd022e5f87d535e7ffd2dae56d568 to your computer and use it in GitHub Desktop.
hijacking write call in Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use libc; | |
use std::ffi::CString; | |
use std::mem::transmute; | |
use std::os::raw::c_char; | |
use std::os::raw::c_int; | |
use std::os::raw::c_void; | |
#[no_mangle] | |
extern "C" fn strcmp(s1: *const c_char, s2: *const c_char) -> c_int { | |
println!("strcmp"); | |
return 0; | |
} | |
#[no_mangle] | |
extern "C" fn write(fd: c_int, buf: *const c_void, count: libc::size_t) -> libc::ssize_t { | |
let name = CString::new("write").expect("CString::new failed"); | |
let ptr = unsafe { libc::dlsym(libc::RTLD_NEXT, name.as_ptr()) }; | |
let msg = "hijacking\n"; | |
let handler: fn(c_int, *const c_void, libc::size_t) -> libc::ssize_t = | |
unsafe { transmute(ptr) }; | |
//let b: c_void = unsafe { transmute(msg) }; | |
handler(fd, msg as *const _ as *const c_void, 10); | |
return count as libc::ssize_t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment