Skip to content

Commit

Permalink
fix: deobfuscator php string detection
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Dec 31, 2020
1 parent 62eb024 commit a876561
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Deobfuscator.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function deobfuscate($str)
*/
public function decode($code)
{
preg_match_all("/<\?php(.*?)(?!\B\"[^\"]*)(\?>|$|)(?![^\"]*\"\B)/si", $code, $matchesPhp);
preg_match_all("/<\?php(.*?)(?!\B\"[^\"]*)(\?>(?=([^\"]*\"[^\"]*\")*[^\"]*$)|$)/si", $code, $matchesPhp);
foreach ($matchesPhp as $matchPhp) {
$matchPhp = preg_replace("/<\?php(.*?)(?!\B\"[^\"]*)(\?>|$)(?![^\"]*\"\B)/si", '$1', @$matchPhp[0]);
$str = preg_replace("/(\\'|\\\")[\s\r\n]*\.[\s\r\n]*('|\")/si", '', $matchPhp); // Remove "ev"."al"
Expand Down Expand Up @@ -114,13 +114,14 @@ public function decode($code)
// Check decode functions
$regexPattern = '/((' . implode('|', $patternDecoder) . ')[\s\r\n]*\((([^()]|(?R))*)?\))/si';
preg_match($regexPattern, $str, $match);

// Get value inside function
if ($recursiveLoop && isset($match[0]) && preg_match('/(\((?:\"|\\\')(([^\\\'\"]|(?R))*?)(?:\"|\\\')\))/si', $match[0], $encodedMatch)) {
$value = $encodedMatch[3];
$value = $encodedMatch[2];
$decodersFound = array_reverse(explode('(', $match[0]));
foreach ($decodersFound as $decoder) {
if (in_array($decoder, $decoders) && (is_string($value) && !empty($value))) {
$value = $decoder($value); // Decode
$value = @$decoder($value); // Decode
}
}
if (is_string($value) && !empty($value)) {
Expand Down

0 comments on commit a876561

Please sign in to comment.