Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
ex0dus-0x committed Mar 7, 2024
1 parent bcc1bda commit 25d30bf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/check/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ impl Analyze for Elf<'_> {

// find symbols for stack canary and FORTIFY_SOURCE
for _sym in self.syms.iter() {
let _symbol = self.strtab.get(_sym.st_name);
if let Some(Ok(symbol)) = _symbol {
let _symbol = self.strtab.get_at(_sym.st_name);
if let Some(symbol) = _symbol {
if symbol == "__stack_chk_fail" {
stack_canary = true;

Expand All @@ -132,19 +132,19 @@ impl Analyze for Elf<'_> {
mitigate_map
}

fn instrumentation(&self) -> Option<GenericMap> {
fn instrumentation(&self) -> GenericMap {
let mut instr_map: GenericMap = GenericMap::new();
for _sym in self.syms.iter() {
let _symbol = self.strtab.get(_sym.st_name);
if let Some(Ok(symbol)) = _symbol {
let _symbol = self.strtab.get_at(_sym.st_name);
if let Some(symbol) = _symbol {

// /__ubsan\w+\d+/
if symbol.starts_with("__ubsan") {
instr_map.insert("Address Sanitizer (ASAN)".to_string(), json!(true));
instr_map.insert("Undefined Behavior Sanitizer (UBSAN)".to_string(), json!(true));

// /_ZN\w+__asan\w+\d+/
} else if symbol.starts_with("__asan") {
instr_map.insert("Undefined Behavior Sanitizer (UBSAN)".to_string(), json!(true));
instr_map.insert("Address Sanitizer (ASAN)".to_string(), json!(true));

// /__afl\w+\d+/
} else if symbol.starts_with("__afl") {
Expand All @@ -156,6 +156,6 @@ impl Analyze for Elf<'_> {
}
}
}
unimplemented!();
instr_map
}
}
2 changes: 1 addition & 1 deletion src/check/mach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Analyze for MachO<'_> {
mitigate_map
}

fn instrumentation(&self) -> Option<GenericMap> {
fn instrumentation(&self) -> GenericMap {
unimplemented!();
}
}
2 changes: 1 addition & 1 deletion src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ pub trait Analyze {
/// To be implemented for each specific binary format
fn compilation(&self, bytes: &[u8]) -> BinResult<GenericMap>;
fn mitigations(&self) -> GenericMap;
fn instrumentation(&self) -> Option<GenericMap>;
fn instrumentation(&self) -> GenericMap;
}
2 changes: 1 addition & 1 deletion src/check/pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Analyze for PE<'_> {
mitigation_checks
}

fn instrumentation(&self) -> Option<GenericMap> {
fn instrumentation(&self) -> GenericMap {
unimplemented!();
}
}
16 changes: 8 additions & 8 deletions src/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use crate::check::{Analyze, GenericMap};
use crate::errors::{BinError, BinResult};
use crate::rules;

use goblin::mach::Mach;
use goblin::Object;
Expand All @@ -22,7 +21,7 @@ pub struct Detector {
basic: GenericMap,
compilation: GenericMap,
mitigations: GenericMap,
instrumentation: Option<GenericMap>,
instrumentation: GenericMap,
}

impl Detector {
Expand Down Expand Up @@ -93,7 +92,7 @@ impl Detector {
},
compilation: pe.compilation(&data)?,
mitigations: pe.mitigations(),
instrumentation: None,
instrumentation: pe.instrumentation(),
}),
Object::Mach(Mach::Binary(mach)) => Ok(Self {
basic: {
Expand All @@ -102,22 +101,23 @@ impl Detector {
},
compilation: mach.compilation(&data)?,
mitigations: mach.mitigations(),
instrumentation: None,
instrumentation: mach.instrumentation(),
}),
_ => Err(BinError::new("unsupported filetype for analysis")),
}
}

/// Output all the finalized report collected on the specific executable, writing to
/// JSON path if specificed not as `-`.
pub fn output(&self, json: Option<&str>) -> serde_json::Result<()> {
pub fn output(&self, json: Option<&str>) -> BinResult<()> {
if let Some(_path) = json {
let output: &str = &serde_json::to_string_pretty(self)?;
if _path == "-" {
println!("{}", output);
return Ok(());
} else {
todo!()
fs::write(_path, output)?;
return Ok(());
}
}

Expand All @@ -127,8 +127,8 @@ impl Detector {
Detector::table("EXPLOIT MITIGATIONS", self.mitigations.clone());

// get instrumentation if any are set
if let Some(instrumentation) = &self.instrumentation {
Detector::table("INSTRUMENTATION", instrumentation.clone());
if !self.instrumentation.is_empty() {
Detector::table("INSTRUMENTATION", self.instrumentation.clone());
}
Ok(())
}
Expand Down

0 comments on commit 25d30bf

Please sign in to comment.