Skip to content

Commit

Permalink
refactor: rename match class
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Cesarato committed Jul 15, 2021
1 parent 5e174e6 commit 932a490
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 99 deletions.
Binary file modified dist/scanner
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Match.php → src/CodeMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace AMWScan;

class Match
class CodeMatch
{
const DANGEROUS = 'danger';
const WARNING = 'warn';
Expand Down
2 changes: 1 addition & 1 deletion src/Deobfuscator.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function deobfuscate($str)
*/
public function decode($code)
{
$matchesPhp = Match::getCode($code);
$matchesPhp = CodeMatch::getCode($code);
foreach ($matchesPhp as $matchPhp) {
$str = preg_replace("/(<\?(php)?)(.*?)(?!\B\"[^\"]*)(\?>|$)(?![^\"]*\"\B)/si", '$1$3$4', @$matchPhp[0]);

Expand Down
156 changes: 78 additions & 78 deletions src/Exploits.php

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions src/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ public function scanFile($info)
$type = 'exploit';
$lastMatch = $match[0];
$patternFoundKey = $type . $key;
$lineNumber = Match::getLineNumber($lastMatch, $contentRaw);
$lineNumber = CodeMatch::getLineNumber($lastMatch, $contentRaw);
if ($lineNumber !== null) {
$patternFoundKey .= $lineNumber;
}
Expand All @@ -946,7 +946,7 @@ public function scanFile($info)
'type' => $type,
'key' => $key,
'level' => $exploit['level'],
'output' => Match::getText($type, $key, $exploit['description'], $lastMatch, $lineNumber),
'output' => CodeMatch::getText($type, $key, $exploit['description'], $lastMatch, $lineNumber),
'description' => $exploit['description'],
'line' => $lineNumber,
'pattern' => $pattern,
Expand Down Expand Up @@ -980,7 +980,7 @@ public function scanFile($info)
$key = hash('crc32b', $key);
$lastMatch = $match[0];
$patternFoundKey = $type . $key;
$lineNumber = Match::getLineNumber($lastMatch, $contentRaw);
$lineNumber = CodeMatch::getLineNumber($lastMatch, $contentRaw);
if ($lineNumber !== null) {
$patternFoundKey .= $lineNumber;
}
Expand All @@ -990,8 +990,8 @@ public function scanFile($info)
$patternFound[$patternFoundKey] = [
'type' => $type,
'key' => $key,
'level' => Match::DANGEROUS,
'output' => Match::getText($descriptionPrefix, $key, $description, $lastMatch, $lineNumber),
'level' => CodeMatch::DANGEROUS,
'output' => CodeMatch::getText($descriptionPrefix, $key, $description, $lastMatch, $lineNumber),
'description' => $description,
'line' => $lineNumber,
'pattern' => $regexPattern,
Expand Down Expand Up @@ -1023,7 +1023,7 @@ public function scanFile($info)
$checkFunction = function (
$match,
$pattern,
$level = Match::WARNING,
$level = CodeMatch::WARNING,
$descriptionPrefix = '',
$functionType = ''
) use ($contentRaw, $funcRaw, &$patternFound) {
Expand All @@ -1032,10 +1032,10 @@ public function scanFile($info)
if (!empty($functionType)) {
$suffix = '_' . $functionType;
}
$lastMatch = Match::cleanFunctionResult($match[0]); // Clean match
$lastMatch = CodeMatch::cleanFunctionResult($match[0]); // Clean match
$funcKey = $funcRaw . $suffix;
$patternFoundKey = $type . $funcKey;
$lineNumber = Match::getLineNumber($lastMatch, $contentRaw);
$lineNumber = CodeMatch::getLineNumber($lastMatch, $contentRaw);
if ($lineNumber !== null) {
$patternFoundKey .= $lineNumber;
}
Expand All @@ -1045,7 +1045,7 @@ public function scanFile($info)
'type' => trim($type . ' ' . $functionType),
'key' => $funcKey,
'level' => $level,
'output' => Match::getText($type, $funcRaw, $description, $lastMatch, $lineNumber),
'output' => CodeMatch::getText($type, $funcRaw, $description, $lastMatch, $lineNumber),
'description' => $description,
'line' => $lineNumber,
'pattern' => $pattern,
Expand All @@ -1064,19 +1064,19 @@ public function scanFile($info)
'base64_decode',
'strrev',
];
$regexPattern = Match::patternFunction($func);
$regexPattern = CodeMatch::patternFunction($func);
foreach ($contents as $contentType => $content) {
$codeParts = Match::getCode($content);
$codeParts = CodeMatch::getCode($content);
foreach ($codeParts as $codePart) {
/**
* Raw functions.
*/
if (@preg_match_all($regexPattern, $codePart[0], $matches, PREG_OFFSET_CAPTURE)) {
foreach ($matches[0] as $match) {
$descriptionPrefix = 'Potentially dangerous function';
$severity = Match::WARNING;
$severity = CodeMatch::WARNING;
if ($contentType === 'decoded') {
$severity = Match::DANGEROUS;
$severity = CodeMatch::DANGEROUS;
$descriptionPrefix = 'Encoded Function';
}
$checkFunction(
Expand Down Expand Up @@ -1105,7 +1105,7 @@ public function scanFile($info)
$checkFunction(
$match,
$regexPatternEncoded,
Match::DANGEROUS,
CodeMatch::DANGEROUS,
'Encoded Function',
$encoder
);
Expand All @@ -1126,8 +1126,8 @@ public function scanFile($info)
$patternFound[$key] = [
'type' => $type,
'key' => $key,
'level' => Match::DANGEROUS,
'output' => Match::getText($type, $key, $description, ''),
'level' => CodeMatch::DANGEROUS,
'output' => CodeMatch::getText($type, $key, $description, ''),
'description' => $description,
'line' => '',
'pattern' => '',
Expand Down
6 changes: 3 additions & 3 deletions src/Templates/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace AMWScan\Templates;

use AMWScan\Match;
use AMWScan\CodeMatch;
use AMWScan\Path;
use AMWScan\Scanner;

Expand Down Expand Up @@ -122,11 +122,11 @@ protected function saveHTML($output)

if (!empty($item['level'])) {
switch ($item['level']) {
case Match::WARNING:
case CodeMatch::WARNING:
$warnings++;
$badges[] = '<span class="badge badge-pill badge-warning py-1 px-2 ml-1 shadow-none">Warning</span>';
break;
case Match::DANGEROUS:
case CodeMatch::DANGEROUS:
$dangerous++;
$badges[] = '<span class="badge badge-pill badge-danger py-1 px-2 ml-1 shadow-none">Dangerous</span>';
break;
Expand Down

0 comments on commit 932a490

Please sign in to comment.