Skip to content

Commit

Permalink
rootshell: use seteuid/setegid instead
Browse files Browse the repository at this point in the history
This is also what sshell does.
  • Loading branch information
wgreenberg committed Jul 23, 2024
1 parent a6dfef3 commit a29e7e4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
with:
targets: armv7-unknown-linux-gnueabihf
- name: Install cross-compilation dependencies
Expand Down
35 changes: 31 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rootshell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
nix = { version = "0.29.0", features = ["user"] }
2 changes: 0 additions & 2 deletions rootshell/rust-toolchain.toml

This file was deleted.

14 changes: 4 additions & 10 deletions rootshell/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
#![feature(setgroups)]

//! a simple shell for uploading to the orbic device.
//!
//! It literally just runs bash as UID/GID 0
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();
}

0 comments on commit a29e7e4

Please sign in to comment.