Add frida log handling

This commit is contained in:
Dimitris Zervas 2023-05-28 02:07:20 +03:00
parent c10945f2e0
commit a21fca1ea1
No known key found for this signature in database
GPG Key ID: 5C27D7C9D1901A30
3 changed files with 68 additions and 5 deletions

16
Cargo.lock generated
View File

@ -226,6 +226,8 @@ dependencies = [
"frida", "frida",
"goblin", "goblin",
"lazy_static", "lazy_static",
"serde",
"serde_json",
"winapi", "winapi",
] ]
@ -854,6 +856,20 @@ name = "serde"
version = "1.0.163" version = "1.0.163"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.163"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.16",
]
[[package]] [[package]]
name = "serde_json" name = "serde_json"

View File

@ -14,10 +14,14 @@ path = "src/main.rs"
# frida = { version = "0.4.0", features = ["auto-download"] } # frida = { version = "0.4.0", features = ["auto-download"] }
frida = { git = "https://github.com/dzervas/frida-rust", features = ["auto-download"] } frida = { git = "https://github.com/dzervas/frida-rust", features = ["auto-download"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"
ctor = "0.2.0" serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.9", features = ["winnt", "libloaderapi"] } winapi = { version = "0.3.9", features = ["winnt", "libloaderapi"] }
[target.'cfg(unix)'.dependencies]
ctor = "0.2.0"
[build-dependencies] [build-dependencies]
goblin = "0.6.1" goblin = "0.6.1"

View File

@ -1,4 +1,5 @@
use frida::{DeviceManager, Frida, ScriptHandler, ScriptOption, ScriptRuntime}; use frida::{DeviceManager, Frida, ScriptHandler, ScriptOption, ScriptRuntime};
use serde::Deserialize;
use lazy_static::lazy_static; use lazy_static::lazy_static;
lazy_static! { lazy_static! {
@ -8,7 +9,7 @@ lazy_static! {
#[no_mangle] #[no_mangle]
pub fn attach(pid: u32) { pub fn attach(pid: u32) {
let frida_code = env!("FRIDA_CODE").to_string(); let frida_code = env!("FRIDA_CODE").to_string();
println!("[*] Injecting into PID: {}", pid); println!("[+] Injecting into PID: {}", pid);
std::thread::spawn(move || { std::thread::spawn(move || {
let device_manager = DeviceManager::obtain(&FRIDA); let device_manager = DeviceManager::obtain(&FRIDA);
@ -23,7 +24,7 @@ pub fn attach(pid: u32) {
println!("[*] Attached"); println!("[*] Attached");
let mut script_option = ScriptOption::new() let mut script_option = ScriptOption::new()
.set_name("frida-deepfreeze-rs") // .set_name("frida-deepfreeze-rs")
.set_runtime(ScriptRuntime::QJS); .set_runtime(ScriptRuntime::QJS);
println!("[*] Script {}", frida_code); println!("[*] Script {}", frida_code);
let script = session let script = session
@ -36,7 +37,7 @@ pub fn attach(pid: u32) {
println!("[*] Script loaded"); println!("[*] Script loaded");
} }
} else { } else {
println!("[!] No device found!"); eprintln!("[!] No device found!");
}; };
}); });
} }
@ -47,10 +48,52 @@ pub fn attach_self() {
attach(0); attach(0);
} }
#[derive(Debug, Deserialize)]
struct LogEntry {
#[serde(rename = "type")]
log_type: LogType,
level: LogLevel,
payload: String,
}
#[derive(Debug, Deserialize)]
enum LogType {
#[serde(rename = "log")]
Log,
}
#[derive(Debug, Deserialize)]
enum LogLevel {
#[serde(rename = "debug")]
Debug,
#[serde(rename = "info")]
Info,
#[serde(rename = "warning")]
Warning,
#[serde(rename = "error")]
Error,
}
struct Handler; struct Handler;
impl ScriptHandler for Handler { impl ScriptHandler for Handler {
fn on_message(&mut self, message: &str) { fn on_message(&mut self, message: &str) {
eprintln!("[<] {message}"); if let Ok(log_entry) = serde_json::from_str::<LogEntry>(message) {
match log_entry.log_type {
LogType::Log => {
match log_entry.level {
LogLevel::Debug => eprint!("[-] "),
LogLevel::Info => eprint!("[i] "),
LogLevel::Warning => eprint!("[!] "),
LogLevel::Error => eprint!("[X] "),
}
}
}
eprintln!("{}", log_entry.payload);
return;
}
eprintln!("{message}");
} }
} }