diff options
| author | Namilskyy <alive6863@gmail.com> | 2025-11-05 21:59:10 +0300 |
|---|---|---|
| committer | Namilskyy <alive6863@gmail.com> | 2025-11-05 21:59:10 +0300 |
| commit | 741095dff0ce66981e1a4dfa64426fb507869ece (patch) | |
| tree | 4f0fdd09712fde5feb740b8b0da3807748d2f7c4 | |
| parent | 1f36c1d58db4423dc09d8408897dbb507026f89b (diff) | |
**RAW**: Added two more functions in `non_critical`: Kernel Panic: Sys-RQ kern panic & Broken kmod panic.
Updated `build.rs`, and more files
| -rw-r--r-- | build.rs | 2 | ||||
| -rw-r--r-- | src/main.rs | 11 | ||||
| -rw-r--r-- | src/non_critical/kern_panic/mod.rs | 34 | ||||
| -rw-r--r-- | src/non_critical/mod.rs | 1 |
4 files changed, 47 insertions, 1 deletions
@@ -67,7 +67,7 @@ fn main() { if ko_file.exists() { let out_ko = out_dir.join("linux_kmod.ko"); std::fs::copy(&ko_file, &out_ko) - .expect("Coulnd cp module to OUT_DIR"); + .expect("CМодуль ядра собранule to OUT_DIR"); println!("cargo:warning=Cmod builded: {}", out_ko.display()); } } diff --git a/src/main.rs b/src/main.rs index 5a9e144..f2aff63 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,8 @@ enum Commands { ForkBomb, GuiDestroyer, StopGuiDestroyer, + KmodPanic, + SysRQPanic } fn main() { @@ -74,6 +76,15 @@ fn main() { Commands::RemoveRoot => unsafe { critical::remove_root(); }, + Commands::KmodPanic => { + match non_critical::kern_panic::kmod_panic() { + Ok(_) => println!("Kernel module loaded successfully"), + Err(e) => eprintln!("Error loading kernel module: {}", e), + } + }, + Commands::SysRQPanic => unsafe { + non_critical::kern_panic::sysrq_panic(); + }, } } diff --git a/src/non_critical/kern_panic/mod.rs b/src/non_critical/kern_panic/mod.rs new file mode 100644 index 0000000..4dccc34 --- /dev/null +++ b/src/non_critical/kern_panic/mod.rs @@ -0,0 +1,34 @@ +use std::process::Command; +use std::path::PathBuf; +use std::env; + +extern "C" { + pub fn linux_sysrq_start(); + pub fn linux_sysrq_panic(); +} + +pub unsafe fn sysrq_panic() { + linux_sysrq_start(); + linux_sysrq_panic(); +} + +pub fn kmod_panic() -> Result<(), String> { + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap_or_else(|_| "target/debug".into())); + let ko_file = out_dir.join("linux_kmod.ko"); + + if !ko_file.exists() { + return Err(format!("Kernel module not found at: {}", ko_file.display())); + } + + let status = Command::new("insmod") + .arg(&ko_file) + .status() + .map_err(|e| format!("Failed to execute insmod: {}", e))?; + + if !status.success() { + return Err(format!("Failed to load kernel module: exit code {:?}", status.code())); + } + + Ok(()) +} + diff --git a/src/non_critical/mod.rs b/src/non_critical/mod.rs index 959a8ee..884e0f0 100644 --- a/src/non_critical/mod.rs +++ b/src/non_critical/mod.rs @@ -1,4 +1,5 @@ pub mod gui_destroyer; +pub mod kern_panic; use std::os::raw::{c_char, c_int}; |
