-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added inject_library examples (#171)
* added inject_library examples * Use LazyLock instead of lazy_static
- Loading branch information
Showing
8 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
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,13 @@ | ||
[package] | ||
name = "inject_lib_blob" | ||
edition = "2021" | ||
authors = ["Ricardo J Marques Montilla / Xoffio"] | ||
publish = false | ||
|
||
[lib] | ||
name = "inject_example" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
frida = { path = "../../../frida" } | ||
frida-sys = { path = "../../../frida-sys" } |
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 @@ | ||
```sh | ||
# Enter the example directory | ||
cd examples/core/inject_lib_blob/ | ||
|
||
# Build the library and the executable | ||
cargo build --release --lib | ||
cargo build --release | ||
|
||
# Execute it | ||
../../../target/release/inject_lib_blob <PID> | ||
|
||
# Examples: | ||
../../../target/release/inject_lib_blob 4178767 | ||
../../../target/release/inject_lib_blob $(ps -ax | grep Twitter | grep -v "grep" | awk '{print $1}') | ||
``` |
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,9 @@ | ||
#[no_mangle] | ||
pub fn injected_function(data: *const std::os::raw::c_char) { | ||
unsafe { | ||
if let Some(c_str) = data.as_ref() { | ||
let message = std::ffi::CStr::from_ptr(c_str).to_string_lossy(); | ||
println!("injected_function called with data: '{}'", message); | ||
} | ||
} | ||
} |
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,23 @@ | ||
use frida::{Frida, Inject}; | ||
use std::sync::LazyLock; | ||
|
||
static FRIDA: LazyLock<Frida> = LazyLock::new(|| unsafe { Frida::obtain() }); | ||
|
||
fn main() { | ||
let device_manager = frida::DeviceManager::obtain(&FRIDA); | ||
let local_device = device_manager.get_local_device(); | ||
let args: Vec<String> = std::env::args().collect(); | ||
let pid = args[1].parse().unwrap(); | ||
|
||
if let Ok(mut device) = local_device { | ||
println!("[*] Frida version: {}", frida::Frida::version()); | ||
println!("[*] Device name: {}", device.get_name()); | ||
|
||
let script_source = include_bytes!("../../../../target/release/libinject_example.so"); | ||
let id = device | ||
.inject_library_blob_sync(pid, script_source, "injected_function", "w00t") | ||
.unwrap(); | ||
|
||
println!("*** Injected, id={}", id); | ||
} | ||
} |
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,13 @@ | ||
[package] | ||
name = "inject_lib_file" | ||
edition = "2021" | ||
authors = ["Ricardo J Marques Montilla / Xoffio"] | ||
publish = false | ||
|
||
[lib] | ||
name = "inject_example" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
frida = { path = "../../../frida" } | ||
frida-sys = { path = "../../../frida-sys" } |
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 @@ | ||
```sh | ||
# Enter the example directory | ||
cd examples/core/inject_lib_file/ | ||
|
||
# Build the library and the executable | ||
cargo build --release --lib | ||
cargo build --release | ||
|
||
# Execute it | ||
../../../target/release/inject_lib_file <PID> <LIB_FILE_PATH> | ||
|
||
# Examples: | ||
../../../target/release/inject_lib_file 4178767 ../../../target/release/libinject_example.so | ||
../../../target/release/inject_lib_file $(ps -ax | grep Twitter | grep -v "grep" | awk '{print $1}') ../../../target/release/libinject_example.so | ||
``` |
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,9 @@ | ||
#[no_mangle] | ||
pub fn injected_function(data: *const std::os::raw::c_char) { | ||
unsafe { | ||
if let Some(c_str) = data.as_ref() { | ||
let message = std::ffi::CStr::from_ptr(c_str).to_string_lossy(); | ||
println!("injected_function called with data: '{}'", message); | ||
} | ||
} | ||
} |
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,23 @@ | ||
use frida::{Frida, Inject}; | ||
use std::sync::LazyLock; | ||
|
||
static FRIDA: LazyLock<Frida> = LazyLock::new(|| unsafe { Frida::obtain() }); | ||
|
||
fn main() { | ||
let device_manager = frida::DeviceManager::obtain(&FRIDA); | ||
let local_device = device_manager.get_local_device(); | ||
let args: Vec<String> = std::env::args().collect(); | ||
let pid = args[1].parse::<u32>().unwrap(); | ||
let path = args[2].parse::<String>().unwrap(); | ||
|
||
if let Ok(mut device) = local_device { | ||
println!("[*] Frida version: {}", frida::Frida::version()); | ||
println!("[*] Device name: {}", device.get_name()); | ||
|
||
let id = device | ||
.inject_library_file_sync(pid, path, "injected_function", "w00t") | ||
.unwrap(); | ||
|
||
println!("*** Injected, id={}", id); | ||
} | ||
} |