-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(rsjudge-runner): ✅ add exploit code to verify robustness
- Loading branch information
1 parent
c9aaaa3
commit f144b0a
Showing
6 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::{path::PathBuf, process::Command}; | ||
|
||
use caps::{read, CapSet}; | ||
use rsjudge_runner::{user::builder, RunAs}; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
dbg!(read(None, CapSet::Ambient).unwrap()); | ||
dbg!(read(None, CapSet::Effective).unwrap()); | ||
dbg!(read(None, CapSet::Inheritable).unwrap()); | ||
dbg!(read(None, CapSet::Permitted).unwrap()); | ||
let examples = PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
.parent() | ||
.and_then(|p| p.parent()) | ||
.ok_or_else(|| anyhow::anyhow!("cannot find crate root"))? | ||
.join("target/debug/examples"); | ||
|
||
let exploit_inner = examples.join("exploit-inner"); | ||
|
||
let status = Command::new(exploit_inner).run_as(builder()?).output()?; | ||
assert!(status.status.success()); | ||
println!("{}", String::from_utf8_lossy(&status.stdout)); | ||
println!("{}", String::from_utf8_lossy(&status.stderr)); | ||
|
||
let normal = examples.join("normal"); | ||
let status = Command::new(normal).run_as(builder()?).output()?; | ||
assert!(status.status.success()); | ||
println!("{}", String::from_utf8_lossy(&status.stdout)); | ||
println!("{}", String::from_utf8_lossy(&status.stderr)); | ||
|
||
Ok(()) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use caps::{read, CapSet}; | ||
use nix::unistd::{setuid, Uid}; | ||
|
||
fn main() { | ||
dbg!(read(None, CapSet::Ambient).unwrap()); | ||
dbg!(read(None, CapSet::Effective).unwrap()); | ||
dbg!(read(None, CapSet::Inheritable).unwrap()); | ||
dbg!(read(None, CapSet::Permitted).unwrap()); | ||
eprintln!("Starting setuid syscall."); | ||
let result = setuid(Uid::from_raw(0)).expect_err("Should fail to set UID"); | ||
dbg!(result.desc()); | ||
dbg!(read(None, CapSet::Permitted).unwrap()); | ||
eprintln!("Failed calling setuid, test pass."); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use caps::{read, CapSet}; | ||
|
||
fn main() { | ||
dbg!(read(None, CapSet::Ambient).unwrap()); | ||
dbg!(read(None, CapSet::Effective).unwrap()); | ||
dbg!(read(None, CapSet::Inheritable).unwrap()); | ||
dbg!(read(None, CapSet::Permitted).unwrap()); | ||
println!("Hello, world!"); | ||
} |