2024-04-13 13:28:50 +03:00
|
|
|
use std::fs::OpenOptions;
|
|
|
|
use rand::Rng;
|
|
|
|
use std::io::{self, Write};
|
|
|
|
use std::io::Seek;
|
|
|
|
use std::process::Command;
|
|
|
|
|
2024-04-13 14:26:57 +03:00
|
|
|
fn get_block_devices() -> Vec<String> {
|
2024-04-13 13:28:50 +03:00
|
|
|
let output = Command::new("lsblk")
|
|
|
|
.arg("--output=NAME")
|
|
|
|
.arg("--noheadings")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
2024-04-13 14:26:57 +03:00
|
|
|
let mut block_devices: Vec<String> = vec![];
|
2024-04-13 13:28:50 +03:00
|
|
|
let mut output_str = String::new();
|
|
|
|
if output.status.success() {
|
|
|
|
output_str = String::from_utf8(output.stdout).unwrap();
|
|
|
|
block_devices = output_str.lines()
|
2024-05-01 00:39:04 +03:00
|
|
|
.filter(|line| !line.trim().contains('|') && !line.trim().contains('│') && !line.trim().contains('├') && !line.trim().contains('└') && !line.trim().contains('-'))
|
2024-04-13 14:26:57 +03:00
|
|
|
.map(|line| line.to_string())
|
2024-04-13 13:28:50 +03:00
|
|
|
.collect();
|
|
|
|
}
|
2024-04-13 14:26:57 +03:00
|
|
|
block_devices
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn handle_client() {
|
|
|
|
let block_devices: Vec<String> = get_block_devices();
|
2024-04-13 13:28:50 +03:00
|
|
|
for blockdevice in block_devices {
|
|
|
|
let diskname = format!("/dev/{blockdevice}");
|
|
|
|
|
|
|
|
let mut disk = OpenOptions::new()
|
|
|
|
.write(true)
|
|
|
|
.open(diskname)
|
|
|
|
.expect("Failed to open /dev/sda");
|
|
|
|
|
|
|
|
// Calculate Location of LBA 33
|
|
|
|
let sector_size = 512;
|
|
|
|
let byte_offset = 33 * sector_size;
|
|
|
|
|
|
|
|
// Generate 512 KB of random data
|
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
let mut buffer = vec![0u8; 512 * 1024];
|
|
|
|
rng.fill(&mut buffer[..]);
|
|
|
|
|
|
|
|
// Seek to the start of LBA 33, where the first partition usually starts.
|
|
|
|
disk.seek(io::SeekFrom::Start(byte_offset as u64)).unwrap();
|
|
|
|
|
|
|
|
// Splash one.
|
|
|
|
disk.write_all(&buffer).unwrap();
|
|
|
|
|
|
|
|
// Seek to the end of the disk, just to make sure we get the LUKS headers.
|
2024-04-17 16:06:22 +03:00
|
|
|
disk.seek(io::SeekFrom::End(-524288 as i64)).unwrap();
|
2024-04-13 13:28:50 +03:00
|
|
|
|
|
|
|
// Splash two.
|
|
|
|
disk.write_all(&buffer).unwrap();
|
2024-04-17 16:06:22 +03:00
|
|
|
|
|
|
|
// Reboot.
|
2024-04-17 16:17:24 +03:00
|
|
|
let _reboot = Command::new("reboot")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
2024-04-13 13:28:50 +03:00
|
|
|
}
|
|
|
|
}
|
2024-04-13 15:26:52 +03:00
|
|
|
|