Skip to content

Commit

Permalink
Fix. Common libs. Signature analysis fixed on several equal signature…
Browse files Browse the repository at this point in the history
…s matches.
  • Loading branch information
alexandergull committed Dec 23, 2024
1 parent e9af9d8 commit 4a65bf4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/CleantalkSP/Common/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,23 @@ public static function isRegexp($signature, $delimiters = '#/')
* @param string $signature_body Character position
* @param bool $is_regexp Flag. Is signature is regular expression?
*
* @return int String number
* @return array Array of lines number with needle
*/
public static function getNeedleStringNumberFromFile($file_path, $signature_body, $is_regexp = false)
public static function getNeedleStringsNumberFromFile($file_path, $signature_body, $is_regexp = false)
{
$file = file($file_path);
$out = 1;
$out_line_numbers = array();

foreach ( $file as $number => $line ) {
if (
($is_regexp && preg_match($signature_body, $line)) ||
( ! $is_regexp && strripos($line, stripslashes($signature_body)) !== false)
) {
$out = $number + 1;
$out_line_numbers[] = $out;
}
}

return $out;
return $out_line_numbers;
}
}
14 changes: 10 additions & 4 deletions lib/CleantalkSP/Common/Scanner/SignaturesAnalyser/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,20 @@ function_exists('md5') &&
if (
( $is_regexp && preg_match($signature['body'], $file_content) ) ||
( ! $is_regexp &&
( strripos($file_content, stripslashes($signature['body'])) !== false ||
strripos($file_content, $signature['body']) !== false) )
(
strripos($file_content, stripslashes($signature['body'])) !== false ||
strripos($file_content, $signature['body']) !== false
)
)
) {
$line_number = Helper::getNeedleStringNumberFromFile(
$line_numbers = Helper::getNeedleStringsNumberFromFile(
$root_path . $file_info->path,
$signature['body'],
$is_regexp
);
$verdict['SIGNATURES'][$line_number][] = $signature['id'];
foreach ($line_numbers as $line_number) {
$verdict['SIGNATURES'][$line_number][] = $signature['id'];
}
}
}
}
Expand All @@ -109,6 +114,7 @@ function_exists('md5') &&
$file_info->weak_spots,
true
) : array();

if ( isset($file_info->weak_spots['SIGNATURES']) ) {
unset($file_info->weak_spots['SIGNATURES']);
}
Expand Down

0 comments on commit 4a65bf4

Please sign in to comment.