Skip to content

Commit

Permalink
Cleaned up complier error and test inconsistency. (#125)
Browse files Browse the repository at this point in the history
* Cleaned up complier error and test inconsistency.

* Increase wait for DLL inject.

* Improved proc assert.

* sleep time is const.

* Unknown user is const.

* Cleanup compiler warn.
  • Loading branch information
hulto authored Mar 17, 2023
1 parent ecfbc00 commit dd4a1c9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion implants/eldritch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ input_params
file.download("https://www.google.com/", "{path}")
"#);
let test_res = thread::spawn(|| { eldritch_run("test.tome".to_string(), test_content, None) });
let test_val = test_res.join();
let _test_val = test_res.join();

assert!(tmp_file.as_file().metadata().unwrap().len() > 5);

Expand Down
23 changes: 16 additions & 7 deletions implants/eldritch/src/process/list_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use anyhow::{Result};
use sysinfo::{ProcessExt,System,SystemExt,PidExt,User,UserExt};
use sysinfo::{ProcessExt,System,SystemExt,PidExt};
use std::fmt;
#[cfg(not(target_os = "windows"))]
use sysinfo::{User,UserExt};

pub struct ProcessRes {
pid: u32,
Expand Down Expand Up @@ -37,11 +39,14 @@ pub fn list() -> Result<Vec<String>> {
Pleases see sysinfo docs for a full list of supported systems.
https://docs.rs/sysinfo/0.23.5/sysinfo/index.html#supported-oses\n\n"));
}
#[cfg(target_os = "windows")]
const UNKNOWN_USER: &str = "???";

let mut res : Vec<String> = Vec::new();
let mut sys = System::new();
sys.refresh_processes();
sys.refresh_users_list();
#[cfg(not(target_os = "windows"))]
let user_list = sys.users().clone();

for (pid, process) in sys.processes() {
Expand All @@ -51,7 +56,7 @@ pub fn list() -> Result<Vec<String>> {
}

#[cfg(target_os = "windows")]
let mut tmp_username = String::from("???");
let tmp_username = String::from(UNKNOWN_USER);
#[cfg(not(target_os = "windows"))]
let tmp_username = uid_to_username(process.uid, user_list);

Expand All @@ -71,6 +76,7 @@ pub fn list() -> Result<Vec<String>> {
Ok(res)
}

#[cfg(not(target_os = "windows"))]
fn uid_to_username(username: u32, user_list: &[User]) -> String {
for user in user_list {
if *user.uid() == username {
Expand All @@ -87,17 +93,20 @@ mod tests {

#[test]
fn test_process_list() -> anyhow::Result<()>{
let child = Command::new("sleep")
#[cfg(not(target_os = "windows"))]
let sleep_str = "sleep";
#[cfg(target_os = "windows")]
let sleep_str = "timeout";

let child = Command::new(sleep_str)
.arg("5")
.spawn()?;

let res = list()?;
let searchstring = String::from(format!("pid:{}", child.id()));
for proc in res{
if proc.as_str().contains(&searchstring) {
if proc.as_str().contains("command:\\\"sleep 5\\\"") {
assert_eq!(true, true);
}
assert_eq!(true, true);
return Ok(())
}
}
Expand Down
3 changes: 2 additions & 1 deletion implants/eldritch/src/sys/dll_inject_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ mod tests {

#[test]
fn test_dll_inject_simple() -> anyhow::Result<()>{
const DLL_EXEC_WAIT_TIME: u64 = 5;
// Get unique and unused temp file path
let tmp_file = NamedTempFile::new()?;
let path = String::from(tmp_file.path().to_str().unwrap()).clone();
Expand All @@ -109,7 +110,7 @@ mod tests {
// Run our code.
let _res = dll_inject(test_dll_path.to_string_lossy().to_string(), target_pid);

let delay = time::Duration::from_secs(1);
let delay = time::Duration::from_secs(DLL_EXEC_WAIT_TIME);
thread::sleep(delay);

// Test that the test file was created
Expand Down
4 changes: 3 additions & 1 deletion implants/eldritch/src/sys/exec_impl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use anyhow::Result;
use std::process::{Command, exit};
use std::process::Command;
use std::str;
#[cfg(any(target_os = "linux", target_os = "macos"))]
use nix::{sys::wait::waitpid, unistd::{fork, ForkResult}};
#[cfg(any(target_os = "linux", target_os = "macos"))]
use std::process::exit;

// https://stackoverflow.com/questions/62978157/rust-how-to-spawn-child-process-that-continues-to-live-after-parent-receives-si#:~:text=You%20need%20to%20double%2Dfork,is%20not%20related%20to%20rust.&text=You%20must%20not%20forget%20to,will%20become%20a%20zombie%20process.

Expand Down

0 comments on commit dd4a1c9

Please sign in to comment.