Created
December 21, 2022 16:14
-
-
Save kamoshi/9836bbaa2819f067fcf41f5f84624ebb to your computer and use it in GitHub Desktop.
Overwrite string length in a fat pointer via /proc on Unix
This file contains hidden or 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
fn main() { | |
use std::fs::OpenOptions; | |
use std::io::{Seek, SeekFrom, Write}; | |
let foo = "hello"; | |
let fat_ptr_ptr = &foo as *const _ as u64; | |
println!("{fat_ptr_ptr}"); | |
println!("before = {foo}"); | |
let mut mem = OpenOptions::new().read(true).write(true).open("/proc/self/mem").unwrap(); | |
//let ptr = foo.as_ptr(); | |
mem.seek(SeekFrom::Start(fat_ptr_ptr as u64 + 8)).unwrap(); | |
let buf = &[2u8]; | |
mem.write(buf).unwrap(); | |
println!("after = {}", foo); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment