rootshell: use seteuid/setegid instead

This is also what sshell does.
This commit is contained in:
Will Greenberg
2024-07-22 17:51:02 -07:00
committed by Cooper Quintin
parent a5b784c259
commit 8e256b6455
5 changed files with 37 additions and 17 deletions
+4 -10
View File
@@ -1,5 +1,3 @@
#![feature(setgroups)]
//! a simple shell for uploading to the orbic device.
//!
//! It literally just runs bash as UID/GID 0
@@ -7,23 +5,19 @@ use std::process::Command;
use std::os::unix::process::CommandExt;
use std::env;
const ANDROID_PARANOID_NETWORK_GROUPS: &[u32] = &[
3001, // AID_BT
3002, // AID_BT_NET
3003, // AID_INET
3004, // AID_NET_RAW
3005, // AID_ADMIN
];
use nix::unistd::{Gid, Uid};
fn main() {
let mut args = env::args();
nix::unistd::setegid(Gid::from_raw(0)).expect("setegid(0) failed");
nix::unistd::seteuid(Uid::from_raw(0)).expect("seteuid(0) failed");
// discard argv[0]
let _ = args.next();
Command::new("/bin/bash")
.args(args)
.uid(0)
.gid(0)
.groups(ANDROID_PARANOID_NETWORK_GROUPS)
.exec();
}