fix: imports and deps

This commit is contained in:
əlemi 2023-03-30 06:12:44 +02:00
parent f8b85e457e
commit da45c7f025
Signed by: alemi
GPG key ID: A4895B84D311642C
6 changed files with 21 additions and 20 deletions

View file

@ -2,14 +2,14 @@ use std::path::PathBuf;
use tracing::{metadata::LevelFilter, info, error}; use tracing::{metadata::LevelFilter, info, error};
use nix::{Result, {sys::{ptrace, wait::waitpid}, unistd::Pid}}; use nix::{sys::{ptrace, wait::waitpid}, unistd::Pid};
use clap::Parser; use clap::Parser;
use rustyneedle::{ use rustyneedle::{rc::{
injector::RemoteOperation, executors::RemoteShellcode, injector::RemoteOperation, executors::RemoteShellcode,
senders::RemoteString, syscalls::RemoteExit, senders::RemoteString, syscalls::RemoteExit,
explorers::step_to_syscall, explorers::step_to_syscall,
}; }, locators::{procmaps::map_addr_path, exec::offset_in_elf}};
mod monitor; mod monitor;
@ -20,7 +20,7 @@ struct NeedleArgs {
pid: i32, pid: i32,
/// shared object to inject into target process /// shared object to inject into target process
#[arg(short, long, default_value = "./target/debug/libtetanus.so")] #[arg(short, long)]
payload: String, payload: String,
/// exact address of dlopen function, calculated with `base + offset` if not given /// exact address of dlopen function, calculated with `base + offset` if not given
@ -48,7 +48,7 @@ struct NeedleArgs {
monitor: bool, monitor: bool,
} }
fn nasty_stuff(args: NeedleArgs) -> Result<()> { fn nasty_stuff(args: NeedleArgs) -> Result<(), Box<dyn std::error::Error>> {
let pid = Pid::from_raw(args.pid); let pid = Pid::from_raw(args.pid);
ptrace::attach(pid)?; ptrace::attach(pid)?;
@ -77,7 +77,9 @@ fn nasty_stuff(args: NeedleArgs) -> Result<()> {
} else { } else {
let (mut calc_base, mut calc_fpath) = (0, "".into()); // rust complains about uninitialized... let (mut calc_base, mut calc_fpath) = (0, "".into()); // rust complains about uninitialized...
if args.path.is_none() || args.base.is_none() { // if user gives both no need to calculate it if args.path.is_none() || args.base.is_none() { // if user gives both no need to calculate it
(calc_base, calc_fpath) = find_libc(pid).expect("could not read proc maps of process"); if let Some((b, p)) = map_addr_path(pid.as_raw(), "libc.so.6")? {
(calc_base, calc_fpath) = (b, p);
}
} }
let base = match args.base { let base = match args.base {
@ -91,8 +93,8 @@ fn nasty_stuff(args: NeedleArgs) -> Result<()> {
}; };
let offset = match args.offset { let offset = match args.offset {
Some(o) => o, Some(o) => o, // TODO catch error if dlopen is not in symbols
None => find_dlopen(&fpath).expect("could not read libc shared object") None => offset_in_elf(&fpath, "dlopen")?.expect("no dlopen symbol available"),
}; };
dlopen_addr = base + offset; dlopen_addr = base + offset;
@ -141,7 +143,7 @@ fn main() {
let monitor = args.monitor; let monitor = args.monitor;
if let Err(e) = nasty_stuff(args) { if let Err(e) = nasty_stuff(args) {
error!("error injecting shared object: {} ({})", e, e.desc()); error!("error injecting shared object: {}", e);
return; return;
} }

View file

@ -1,13 +1,14 @@
use nix::{unistd::Pid, Result, libc::{PROT_READ, MAP_PRIVATE, MAP_ANON, PROT_EXEC}, sys::{ptrace, wait::waitpid}}; use nix::{unistd::Pid, Result, libc::{PROT_READ, MAP_PRIVATE, MAP_ANON, PROT_EXEC}, sys::{ptrace, wait::waitpid}};
use tracing::{debug, info}; use tracing::{debug, info};
use crate::{syscalls::{RemoteMMap, RemoteMUnmap}, senders::write_buffer, injector::RemoteOperation}; use crate::rc::{injector::RemoteOperation, syscalls::{RemoteMMap, RemoteMUnmap}, senders::write_buffer};
pub struct RemoteShellcode<'a> { pub struct RemoteShellcode<'a> {
code: &'a [u8], code: &'a [u8],
ptr: Option<u64>, ptr: Option<u64>,
} }
#[allow(unused)]
impl<'a> RemoteShellcode<'a> { impl<'a> RemoteShellcode<'a> {
pub fn new(code: &'a [u8]) -> Self { pub fn new(code: &'a [u8]) -> Self {
RemoteShellcode { code, ptr: None } RemoteShellcode { code, ptr: None }

View file

@ -1,8 +1,6 @@
use std::{ffi::c_void, path::{Path, PathBuf}, io::{ErrorKind, Error}}; use std::ffi::c_void;
use elf::{ElfBytes, endian::AnyEndian};
use nix::{unistd::Pid, sys::{ptrace, wait::waitpid}}; use nix::{unistd::Pid, sys::{ptrace, wait::waitpid}};
use proc_maps::get_process_maps;
pub fn step_to_syscall(pid: Pid) -> nix::Result<usize> { pub fn step_to_syscall(pid: Pid) -> nix::Result<usize> {
let mut registers; let mut registers;

View file

@ -1,7 +1,7 @@
mod jnjector; pub mod injector;
mod executors; pub mod executors;
mod explores; pub mod explorers;
mod senders; pub mod senders;
mod syscalls; pub mod syscalls;

View file

@ -3,7 +3,7 @@ use std::{ffi::c_void, mem::size_of};
use nix::{Result, unistd::Pid, sys::ptrace, libc::{PROT_READ, PROT_WRITE, MAP_PRIVATE, MAP_ANON}}; use nix::{Result, unistd::Pid, sys::ptrace, libc::{PROT_READ, PROT_WRITE, MAP_PRIVATE, MAP_ANON}};
use tracing::{debug, info}; use tracing::{debug, info};
use crate::{injector::RemoteOperation, syscalls::{RemoteMMap, RemoteMUnmap}}; use crate::rc::{injector::RemoteOperation, syscalls::{RemoteMMap, RemoteMUnmap}};
const WORD_SIZE : usize = size_of::<usize>(); const WORD_SIZE : usize = size_of::<usize>();

View file

@ -1,7 +1,7 @@
use nix::{libc::user_regs_struct, Result, sys::{ptrace, wait::waitpid}, unistd::Pid}; use nix::{libc::user_regs_struct, Result, sys::{ptrace, wait::waitpid}, unistd::Pid};
use tracing::debug; use tracing::debug;
use crate::{injector::RemoteOperation, senders::RemoteString}; use crate::rc::{injector::RemoteOperation, senders::RemoteString};
pub trait RemoteSyscall { pub trait RemoteSyscall {
fn registers(&self, regs: &mut user_regs_struct); fn registers(&self, regs: &mut user_regs_struct);