-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from EFForg/bootstrap
Add bootstrapping support
- Loading branch information
Showing
10 changed files
with
330 additions
and
77 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,7 @@ | |
members = [ | ||
"lib", | ||
"bin", | ||
"serial", | ||
"rootshell", | ||
] | ||
resolver = "2" |
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,34 @@ | ||
cd serial | ||
cargo build_pc | ||
cd .. | ||
cd rootshell | ||
cargo build --release | ||
cd .. | ||
# Force a switch into the debug mode to enable ADB | ||
target/x86_64-unknown-linux-gnu/debug/serial AT | ||
echo -n "adb enabled, waiting for reboot" | ||
until adb shell true 2> /dev/null | ||
do | ||
echo -n . | ||
sleep 1 | ||
done | ||
echo | ||
echo "it's alive!" | ||
adb push target/armv7-unknown-linux-gnueabihf/release/rootshell /tmp/ | ||
target/x86_64-unknown-linux-gnu/debug/serial "AT+SYSCMD=mv /tmp/rootshell /bin/rootshell" | ||
sleep 1 | ||
target/x86_64-unknown-linux-gnu/debug/serial "AT+SYSCMD=chown root /bin/rootshell" | ||
sleep 1 | ||
target/x86_64-unknown-linux-gnu/debug/serial "AT+SYSCMD=chmod 4755 /bin/rootshell" | ||
echo "we have root!" | ||
adb shell /bin/rootshell -c id | ||
adb shell '/bin/rootshell -c "mkdir /data/rayhunter"' | ||
adb push config.toml.example /data/rayhunter/config.toml | ||
adb push scripts/rayhunter_daemon /tmp/rayhunter_daemon | ||
adb push scripts/misc-daemon /tmp/misc-daemon | ||
adb shell '/bin/rootshell -c "mv /tmp/rayhunter_daemon /etc/init.d/rayhunter_daemon"' | ||
adb shell '/bin/rootshell -c "mv /tmp/misc-daemon /etc/init.d/misc-daemon"' | ||
adb shell '/bin/rootshell -c "chmod 755 /etc/init.d/rayhunter_daemon"' | ||
adb shell '/bin/rootshell -c "chmod 755 /etc/init.d/misc-daemon"' | ||
./make.sh | ||
adb shell '/bin/rootshell -c "/etc/init.d/rayhunter_daemon start"' |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cargo build --release | ||
adb push target/armv7-unknown-linux-gnueabihf/release/rayhunter /data/rayhunter/rayhunter | ||
adb shell '/bin/rootshell -c "/etc/init.d/rayhunter_daemon restart"' |
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,8 @@ | ||
[package] | ||
name = "rootshell" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
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,15 @@ | ||
use std::process::Command; | ||
use std::os::unix::process::CommandExt; | ||
use std::env; | ||
|
||
fn main() { | ||
let mut args = env::args(); | ||
|
||
// discard argv[0] | ||
let _ = args.next(); | ||
Command::new("/bin/bash") | ||
.args(args) | ||
.uid(0) | ||
.gid(0) | ||
.exec(); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#! /bin/sshell | ||
#! /bin/bash | ||
|
||
set -e | ||
|
||
|
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,10 @@ | ||
[package] | ||
name = "serial" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rusb = "0.9.3" | ||
|
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,127 @@ | ||
use std::str; | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
|
||
use rusb::{ | ||
Context, DeviceHandle, UsbContext, | ||
}; | ||
|
||
fn main() { | ||
let args: Vec<String> = std::env::args().collect(); | ||
|
||
if args.len() < 2 { | ||
println!("usage: {0} <command>", args[0]); | ||
return; | ||
} | ||
|
||
match Context::new() { | ||
Ok(mut context) => match open_orbic(&mut context) { | ||
Some(mut handle) => { | ||
send_command(&mut handle, &args[1]) | ||
}, | ||
None => panic!("No Orbic device found"), | ||
}, | ||
Err(e) => panic!("Failed to initialize libusb: {0}", e), | ||
} | ||
} | ||
|
||
fn send_command<T: UsbContext>( | ||
handle: &mut DeviceHandle<T>, | ||
command: &str, | ||
) { | ||
let mut data = String::new(); | ||
data.push_str("\r\n"); | ||
data.push_str(command); | ||
data.push_str("\r\n"); | ||
|
||
let timeout = Duration::from_secs(1); | ||
let mut response = [0; 256]; | ||
|
||
// Set up the serial port appropriately | ||
handle.write_control(0x21, 0x22, 3, 1, &[], timeout).expect("Failed to send control request"); | ||
|
||
// Send the command | ||
handle.write_bulk(0x2, data.as_bytes(), timeout).expect("Failed to write command"); | ||
|
||
// Consume the echoed command | ||
handle.read_bulk(0x82, &mut response, timeout).expect("Failed to read submitted command"); | ||
|
||
// Read the actual response | ||
handle.read_bulk(0x82, &mut response, timeout).expect("Failed to read response"); | ||
|
||
let responsestr = str::from_utf8(&response).expect("Failed to parse response"); | ||
if !responsestr.starts_with("\r\nOK\r\n") { | ||
println!("Received unexpected response{0}", responsestr) | ||
} | ||
} | ||
|
||
fn switch_device<T: UsbContext>( | ||
handle: &mut DeviceHandle<T>, | ||
) { | ||
// Send a command to switch the device into generic mode, exposing serial | ||
let timeout = Duration::from_secs(1); | ||
|
||
if let Err(e) = handle.write_control(0x40, 0xa0, 0, 0, &[], timeout) { | ||
// If the device reboots while the command is still executing we | ||
// may get a pipe error here | ||
if e == rusb::Error::Pipe { | ||
return | ||
} | ||
panic!("Failed to send device switch control request: {0}", e) | ||
} | ||
} | ||
|
||
fn open_orbic<T: UsbContext>( | ||
context: &mut T, | ||
) -> Option<DeviceHandle<T>> { | ||
// Device after initial mode switch | ||
if let Some(handle) = open_device(context, 0x05c6, 0xf601) { | ||
return Some(handle) | ||
} | ||
|
||
// Device with rndis enabled as well | ||
if let Some(handle) = open_device(context, 0x05c6, 0xf622) { | ||
return Some(handle) | ||
} | ||
|
||
// Device in out-of-the-box state, need to switch to diag mode | ||
match open_device(context, 0x05c6, 0xf626) { | ||
Some(mut handle) => switch_device(&mut handle), | ||
None => panic!("No Orbic device detected") | ||
} | ||
|
||
for _ in 1..10 { | ||
if let Some(handle) = open_device(context, 0x05c6, 0xf601) { | ||
return Some(handle) | ||
} | ||
sleep(Duration::from_secs(10)) | ||
} | ||
panic!("No Orbic device detected") | ||
} | ||
|
||
fn open_device<T: UsbContext>( | ||
context: &mut T, | ||
vid: u16, | ||
pid: u16, | ||
) -> Option<DeviceHandle<T>> { | ||
let devices = match context.devices() { | ||
Ok(d) => d, | ||
Err(_) => return None, | ||
}; | ||
|
||
for device in devices.iter() { | ||
let device_desc = match device.device_descriptor() { | ||
Ok(d) => d, | ||
Err(_) => continue, | ||
}; | ||
|
||
if device_desc.vendor_id() == vid && device_desc.product_id() == pid { | ||
match device.open() { | ||
Ok(handle) => return Some(handle), | ||
Err(e) => panic!("device found but failed to open: {}", e), | ||
} | ||
} | ||
} | ||
|
||
None | ||
} |