Skip to content

Commit 6f355f4

Browse files
committed
Fixed bug with "invoke, inject" keywords & obfuscation detection
1 parent 949d683 commit 6f355f4

3 files changed

Lines changed: 3 additions & 68 deletions

File tree

src/detection.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::collections::HashSet;
22

33
pub const NAME_LENGTH_THRESHOLD: usize = 100;
44
pub const ENTROPY_THRESHOLD: f64 = 7.2;
5-
pub const SUSPICIOUS_CHAR_THRESHOLD: usize = 3;
65

76
lazy_static::lazy_static! {
87
pub static ref SAFE_STRING_CACHE: std::sync::Mutex<std::collections::HashSet<String>> = {
@@ -27,30 +26,6 @@ lazy_static::lazy_static! {
2726
};
2827
}
2928

30-
pub fn is_obfuscated_name(name: &str) -> bool {
31-
if name.len() <= 2 && name != "of" && name != "to" && name != "at" && name != "id" {
32-
return true;
33-
}
34-
35-
let chars: Vec<_> = name.chars().collect();
36-
if chars.len() >= 3 {
37-
let repeats = chars
38-
.windows(3)
39-
.filter(|w| w[0] == w[1] && w[1] == w[2])
40-
.count();
41-
if repeats > 0 {
42-
return true;
43-
}
44-
}
45-
46-
name.contains("$_")
47-
|| name.contains("$$")
48-
|| name.contains("III")
49-
|| name.contains("lll")
50-
|| name.contains("OOO")
51-
|| name.matches('$').count() > 2
52-
}
53-
5429
pub fn is_cached_safe_string(s: &str) -> bool {
5530
if let Ok(cache) = SAFE_STRING_CACHE.lock() {
5631
return cache.contains(s);

src/scanner.rs

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::config::SYSTEM_CONFIG;
22
use crate::database::GOOD_LINKS;
33
use crate::detection::{
4-
cache_safe_string, calculate_detection_hash, is_cached_safe_string, is_obfuscated_name,
5-
ENTROPY_THRESHOLD, NAME_LENGTH_THRESHOLD, SUSPICIOUS_CHAR_THRESHOLD, SUSPICIOUS_DOMAINS,
4+
cache_safe_string, calculate_detection_hash, is_cached_safe_string,
5+
ENTROPY_THRESHOLD, NAME_LENGTH_THRESHOLD, SUSPICIOUS_DOMAINS,
66
};
77
use crate::errors::ScanError;
88
use crate::parser::parse_class_structure;
@@ -35,7 +35,6 @@ pub struct CollapseScanner {
3535
suspicious_domains: HashSet<String>,
3636
crypto_regex: Regex,
3737
malicious_pattern_regex: Regex,
38-
suspicious_consecutive_chars_regex: Regex,
3938
ignored_suspicious_keywords: HashSet<String>,
4039
ignored_crypto_keywords: HashSet<String>,
4140
pub options: ScannerOptions,
@@ -105,8 +104,7 @@ impl CollapseScanner {
105104
url_regex: Regex::new(r#"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»""'']))"#).unwrap(),
106105
suspicious_domains: SUSPICIOUS_DOMAINS.clone(),
107106
crypto_regex: Regex::new(r"(?i)\b(aes|des|rsa|md5|sha[1-9]*-?\d*|blowfish|twofish|pgp|gpg|cipher|keystore|keygenerator|secretkey|password|encrypt|decrypt|hash|salt|ivParameterSpec|SecureRandom)\b").unwrap(),
108-
malicious_pattern_regex: Regex::new(r"(?i)\b(backdoor|exploit|inject|payload|shellcode|bypass|rootkit|keylog|rat\b|trojan|malware|spyware|meterpreter|cobaltstrike|powershell|cmd\.exe|Runtime\.getRuntime\(\)\.exec|ProcessBuilder|loadLibrary|download|upload|socket\(|bind\(|connect\(|URL\(|URLConnection|Class\.forName|defineClass|getMethod|invoke|unsafe|jndi|ldap|rmi|base64|decode)\b").unwrap(),
109-
suspicious_consecutive_chars_regex: Regex::new(&format!(r"[^a-zA-Z0-9_$/.]{{{},}}", SUSPICIOUS_CHAR_THRESHOLD)).unwrap(),
107+
malicious_pattern_regex: Regex::new(r"(?i)\b(backdoor|exploit|payload|shellcode|bypass|rootkit|keylog|rat\b|trojan|malware|spyware|meterpreter|cobaltstrike|powershell|cmd\.exe|Runtime\.getRuntime\(\)\.exec|ProcessBuilder|loadLibrary|download|upload|socket\(|bind\(|connect\(|URL\(|URLConnection|Class\.forName|defineClass|getMethod|unsafe|jndi|ldap|rmi|base64|decode)\b").unwrap(),
110108
ignored_suspicious_keywords,
111109
ignored_crypto_keywords,
112110
options,
@@ -787,14 +785,6 @@ impl CollapseScanner {
787785
return;
788786
}
789787

790-
if is_obfuscated_name(name) {
791-
findings.push((
792-
FindingType::ObfuscationChars,
793-
format!("{} '{}'", context, name),
794-
));
795-
return;
796-
}
797-
798788
let name_char_count = name.chars().count();
799789

800790
if name.contains('/')
@@ -816,21 +806,6 @@ impl CollapseScanner {
816806
));
817807
}
818808

819-
let simple_name_to_check = get_simple_name(name);
820-
if self
821-
.suspicious_consecutive_chars_regex
822-
.is_match(simple_name_to_check)
823-
{
824-
findings.push((
825-
FindingType::ObfuscationChars,
826-
format!(
827-
"Consecutive Symbols: {} '{}'",
828-
context,
829-
truncate_string(name, 20)
830-
),
831-
));
832-
}
833-
834809
let non_ascii_count = name.chars().filter(|&c| !c.is_ascii()).count();
835810
if non_ascii_count > 0 {
836811
findings.push((
@@ -1029,9 +1004,6 @@ impl CollapseScanner {
10291004
let obfuscation_count = type_counts
10301005
.get(&FindingType::ObfuscationLongName)
10311006
.unwrap_or(&0)
1032-
+ type_counts
1033-
.get(&FindingType::ObfuscationChars)
1034-
.unwrap_or(&0)
10351007
+ type_counts
10361008
.get(&FindingType::ObfuscationUnicode)
10371009
.unwrap_or(&0);
@@ -1155,15 +1127,6 @@ impl CollapseScanner {
11551127
}
11561128
}
11571129

1158-
if let Some(obfuscated) = by_type.get(&FindingType::ObfuscationChars) {
1159-
if !obfuscated.is_empty() {
1160-
explanations.push(
1161-
"Uses obfuscated code, which may be trying to hide malicious functionality."
1162-
.to_string(),
1163-
);
1164-
}
1165-
}
1166-
11671130
if let Some(high_entropy) = by_type.get(&FindingType::HighEntropy) {
11681131
if !high_entropy.is_empty() && resource_info.is_some() {
11691132
let ri = resource_info.unwrap();

src/types.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub enum FindingType {
2121
Crypto,
2222
SuspiciousKeyword,
2323
ObfuscationLongName,
24-
ObfuscationChars,
2524
ObfuscationUnicode,
2625
HighEntropy,
2726
}
@@ -36,7 +35,6 @@ impl std::fmt::Display for FindingType {
3635
FindingType::Crypto => write!(f, "Crypto Keyword"),
3736
FindingType::SuspiciousKeyword => write!(f, "Suspicious Keyword"),
3837
FindingType::ObfuscationLongName => write!(f, "Obfuscation (Long Name)"),
39-
FindingType::ObfuscationChars => write!(f, "Obfuscation (Unusual Chars)"),
4038
FindingType::ObfuscationUnicode => write!(f, "Obfuscation (Unicode Name)"),
4139
FindingType::HighEntropy => write!(f, "High Entropy"),
4240
}
@@ -52,7 +50,6 @@ impl FindingType {
5250
FindingType::Crypto => ("🔒", "bright_yellow"),
5351
FindingType::SuspiciousKeyword => ("❗", "red"),
5452
FindingType::ObfuscationLongName => ("📏", "bright_magenta"),
55-
FindingType::ObfuscationChars => ("❓", "magenta"),
5653
FindingType::ObfuscationUnicode => ("㊙️ ", "magenta"),
5754
FindingType::HighEntropy => ("🔥", "yellow"),
5855
}

0 commit comments

Comments
 (0)