From 532621cbe60a3eefec793b5d51c887ef79dd1271 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Wed, 17 Jul 2019 16:04:07 +0200 Subject: [PATCH] WIP(ptrace): Test ptrace security --- src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 6ce4224..d89f480 100644 --- a/src/main.rs +++ b/src/main.rs @@ -132,7 +132,8 @@ pub fn ptrace() -> Result<(), String> { } } - println!("Waiting until child is ready to be traced..."); + println!("My PID: {}", e(syscall::getpid())?); + println!("Waiting until child (pid {}) is ready to be traced...", pid); let mut status = 0; e(syscall::waitpid(pid, &mut status, syscall::WUNTRACED))?; @@ -245,6 +246,15 @@ pub fn ptrace() -> Result<(), String> { assert!(syscall::wifexited(status)); assert_eq!(syscall::wexitstatus(status), 123); + println!("Trying to do illegal things..."); + for id in 0..=1_000_000 { + let err = File::open(format!("proc:{}/regs/int", id)).map(|_| None).unwrap_or_else(|err| err.raw_os_error()); + assert!( + err == Some(syscall::EPERM) || err == Some(syscall::ESRCH), + "The cops ignored that I tried to illegally open PID {}: {:?}", id, err + ); + } + println!("All done and tested!"); Ok(())