[WordPress Security] Know Your Malware Part Two – Hacky Obfuscation Techniques

From: Wordfence <list_at_wordfence.com>
Date: Wed, 1 Nov 2023 09:46:53 -0700

A deep dive into common malware obfuscation techniques that rely on abusing native PHP features intended for other purposes.

Wordfence-Logo.png (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKLx3prCCW6N1vHY6lZ3nhW4lrhrt7zKL2JN5XSdgDxY596W50ccgL7ppKKzN4qn8KV6SQ8tW2mlmSd78Qjc6W4SSmtD1wff_jW8sBpGk1n9710W652mQb2wRp7hN8dN71WXXjvGW49MXtW7ny876N6v-H0DMRRLRW64M6f96Jn9zLW7dY4523JWKd8W8hVHmZ9lLcHSW5cz6nh5sWjsGN3YJjY_XS4mZW3KThcr4HYVJlW7vpsd52VpVDCW5rZ0dR4g4Mk5W817QJ_4BMPf1N16zZFNMJj2tW73SzG-6Pn9fgdfVmX604 )

FeaturedImage_Wordfence_51.03 (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

In the first post in this series, we covered common PHP encoding techniques and how they’re used by malware to hide from security analysts and scanners. In today’s post, we’re going to dive a little bit deeper into other obfuscation techniques that make use of other features available in PHP.

CONTINUE READING ON THE BLOG
(https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

Obfuscation Redux

In the first post in this series, we defined Obfuscation as the process of concealing the purpose or functionality of code or data so that it evades detection and is more difficult for a human or security software to analyze, but still fulfills its intended purpose. One of the main contributing factors to the popularity of PHP is its ease of use, but the same functionality that makes it easy to use also makes it easy to abuse, often in ways that were never intended.

The techniques covered in this post are often simpler and “hackier” than the ones listed in the previous article, and most of them are less reliable as indicators of malicious activity individually, as several of them typically need to be combined in order to achieve sufficient obfuscation. These techniques are also often easier for a human analyst to spot, but they are also more difficult to detect using scanning tools due to the wide variety of permutations available. Such simpler obfuscation methods can also be creatively combined with encoding techniques, granting malware authors a formidable array of tactics to avoid detection.

While it is not practical to cover every possible technique in active use, this article will detail the more commonly found methods, and help illustrate the wide range of possibilities when decoding obfuscated malware. Several of the methods we will cover today, such as comment abuse, can be combined into almost infinite variations with minute changes, thus rendering them completely undetectable to traditional hash-based malware scanning and even partially slowing down regular expression-based scanning of the type used by Wordfence.

Fortunately, while these methods do make analysis more difficult, and can slow down scanning, their presence in certain combinations is a strong signal of malicious activity, and the malware detection signatures used by the Wordfence plugin and Wordfence CLI are tuned to detect these combinations with astoundingly few false positives. Wordfence CLI (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKM63prCCW7Y8-PT6lZ3mlV-Rgt9222pJNW8BLTtT7_KfJjW5v2Xv39lGzsYVM1-gr63_373VZTfTc4_HCvQW9kRBY33NDWz3W5YWTKw2Q-PZBW2tJbBT2SRymxW1-nCyV3_JzmGW4Bpv2z2mDznhW9jnNV59g6Jz5W9c221d7tr5ZBW5607tw8GyyKnW603bWb3nqrjvW1GVjw74LzdMKN5LH-n_QMzLdVhwzSQ2gyvFZW9743L51-Hd-QVLs_Mz6Yf7lCW8d6pjD3QXpvgW7TCZwq5xFfyJN5CbK88CxJpMW4NstqL5sJR-xW2yTZNx7Zh9q7W44f7QJ6ncRhFVzv-pQ2nwgfpf6wkjFd04 ) in particular is useful in these cases, as it is highly performant and can run multithreaded jobs, compensating for any speed penalties imposed by these techniques.

Comment Abuse

PHP has several methods of adding code comments that you may already be familiar with. Well-commented code is considered a best practice, as it makes it much easier to maintain software and pay off technical debt, but comments can also be used for illicit purposes.

PHP uses three styles of comments:

//, denoting a single line comment that ends on the next line.

#, likewise a single line comment that ends on the next line, though this is less common than ‘//’.

/*, the beginning of a multiline comment, which can only closed with */.

Multiline comments are particularly useful to malware authors because they are ignored by PHP, and do not have to extend over multiple lines. This means that an attacker can “break up” their code to evade scanners using comments. For instance, the following code block prints “Hello, World!”:

ray-so-export (3) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

While this is a very basic example, more complicated examples can be found in real malware, such as the following snippet, which makes use of several additional obfuscation techniques, including octal escape sequences and invisible null bytes:

ray-so-export (4) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

While we’re not going to fully analyze this malware today, it already presents problems for many scanners. For instance, a scanner searching for the very first line of code, function ed_ixpn() would fail to find it because of the comments. While detection using regular expressions, such as the ones used by the Wordfence Plugin scanner and Wordfence CLI are capable of detecting malware of this type, it still imposes a performance penalty on detection due to the enormous number of possible variations.

Concatenation Catastrophe

PHP makes string concatenation very simple via the dot . operator. This allows programmers to join two separate strings with minimal hassle. For instance, the following code outputs “Hello, World!”:

ray-so-export (5) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

There are a large number of legitimate use cases for string concatenation, so it’s generally only an indicator of malicious activity when combined with several other obfuscation techniques. The malware sample we shared earlier provides a good example of this, with octal encoding concatenated with the return values of various functions, which we’ll get to in a later section.

Index Fun

PHP, like most languages, stores text strings as arrays of characters, each with a defined position or index. This makes it possible to assemble arbitrary commands and data from a string containing the required characters, using the array index of each character and the concatenation operator. For instance, the following code prints “Hello, World!”:

ray-so-export (6)-1 (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

PHP arrays start with an index of 0, meaning that $string[0] in the example above would be “W”, the first letter of “Wow, what a cool Helpful research device!”. By concatenating letters from different parts of that text string, it’s possible to assemble an entirely different text string.

This method can be very helpful for hiding the underlying text being assembled from human researchers and security scan tools alike, and though it does have the occasional legitimate use in selecting chunks of text, when used extensively it is a strong indicator of malicious activity, though it typically needs to be combined with additional techniques such as evaluating the resulting string or passing it to a function.

Math, Not Even Once

PHP allows mathematical operations within other functionality. One of the interesting features in the malware snippet – $disdcrxh_(564-452) – demonstrates this, with it turning out as $disdcrxh_112 due to the subtraction of 564 and 452 in the parenthesis. This functionality can likewise be combined with the string index technique mentioned above. For example, the following code prints out “Hello, World!”:

ray-so-export (7)-1 (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

This adds an additional obfuscation layer that can make it even more difficult to determine the code’s functionality without executing it. However, it is incredibly rare for this type of code to be used legitimately, so the presence of this technique is typically an indicator of malicious activity.

String Reversals

One of the most basic functions in PHP’s text string manipulation libraries is strrev, which is used to reverse strings of text. For instance, the following code snippet prints out “Hello, World!”:

ray-so-export (8) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

While not particularly effective at obfuscation on its own, it can be combined with the techniques in this article as well as nearly all of the techniques in our previous article on encoding to make it even more difficult to decode malicious functionality. While it has a number of legitimate use cases, the presence of strrev alongside two or more additional encoding or obfuscation techniques is often a reliable indicator of compromise.

Variable, Dynamic, and Anonymous Functions

PHP has the ability to use variables to store function names as variables and then invoke those functions using the variable. This is widely used by legitimate software, but can also be combined with several other techniques, such as string concatenation, in which case it is often an indicator of malicious activity. For instance, the following code snippet prints out “Hello, World!”:

ray-so-export (9) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

This can also be combined with dynamic function invocation using methods such as call_user_func, which accepts a function for its first parameter and any arguments to be passed to that function in subsequent parameters. As with variable function names, this is widely used in legitimate code, but it can still make analysis more difficult, especially for automated tools looking primarily for more basic function call syntax. For example, the following code snippet prints out “Hello, World!”:

ray-so-export (10) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

Finally, PHP also allows for anonymous functions, which are exactly what they sound like – functions without a name. These can be combined with variable assignment as shown:

ray-so-export (11) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

While anonymous functions are widely used in legitimate code, it is possible to use them in combination with other features to make it more difficult for automated scanning tools or human analysts to keep track of code flow and as such are useful for obfuscation.

We’ve begun to combine obfuscation layers in our examples to provide a better picture of the type of obfuscation often found in the wild, and there’s still more to come.

GOTO Labels

One of the oldest and most basic code functions is the goto statement. While some legitimate software still uses GOTO statements, the functionality is considered poor coding practice and is not widely used, though it reflects how the code operates at a fundamental level far more accurately than more modern syntax. Its primary use in obfuscation is similar to comment abuse in that it breaks up the code so that it is more difficult to determine the control flow.

For example, the following code snippet prints out “Hello, World!” if and only if $_GET['input'] is present and set to ‘hello’, otherwise it prints “Sorry”:

ray-so-export (12) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

Include/Require of non-PHP files

PHP uses the include and require functions to include and execute code located in a separate file. This is almost universally used, and occasionally the .inc extension is used instead of PHP for files to be included. However, one particular feature that is ripe for abuse is that PHP will include files with any extension and execute them as code. This allows attackers to upload the bulk of their malicious code as a file with an allowed extension, often an image extension such as .ico or .png, and then simply include that file from a loader file with a PHP extension. Inclusion of files without a .php or .inc extension is thus almost always an indicator of malicious activity.

For instance, take the following set of files:

ray-so-export (13) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

ray-so-export (14) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

This will print out “Hello, World” when loader.php is executed, even though hello.ico does not have a PHP extension and would not run as PHP if accessed directly.

Putting it All Together

Here’s an example that makes use of everything we’ve learned today apart from including files:

ray-so-export (15) (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKKF5m_5PW50kH_H6lZ3mMVvHtQf67BSD6VSJmPg9jm43JW3gwCrC2qRQMhW2-jVH05dBjvjW8CyWh64kMQwNW6j1FrK7K3YmbW7j6fTK6dvJwVVM0TrV5_Rlp1W32pW0C152rr2W44Ly846KWbDRW39bdkC1TBGGzW6MZ0qn4ZpyLRW2p6wGQ7RFWs2W85y7fy1jrzyqW8pYDy37jvX0SW2KwsfQ7WTysyN7nGlsPrLlzgW7zP8cv37KZ5nW48JsBW1V9Nj4W2_N8cJ4Sr6HTW1j-NzJ2PGkWWW5lzZHM6RryL2Vxf-bw9f4YybW835w6k1KxvYTN4p6r019d0XcV1N78R4SlfXrW3fxmMG7fmWfcW3bf6sx3yX-fZW1yDrWx1jBp3RW6svS71282L-BW8TMDm64v7FHCV5060c8gBr82f3rKlq-04 )

It begins with comments breaking up the code as well as the concatenation and string indexing techniques we covered earlier, which assigns “Hello, World!” in reverse, or “!dlroW ,olleH” to the $mashed variable.

A quick glance at the code might lead you to believe that it outputs “That didn’t work!” but thanks to the goto statement that line of code is skipped – such misleading uses are par for the course with malware that uses goto statements.

In the dostuff section, we use call_user_func to call the echostring function, which really just does the same thing as echo but serves as an additional layer of obfuscation to untangle, especially if the function were to be given a less friendly name. The echostring function is fed the output of the anonymous function assigned to the $rev variable, which again simply performs a str_rev on the input. The result is that $mashed is reversed and echoed out as “Hello, World!”. While we have kept the function and variable names relatively relevant for this example, there’s nothing preventing a malware author from naming these functions whatever they want, and indeed, misleading or nonsensical function names are more common than meaningful or useful function names in PHP malware.

Conclusion

In today’s post, we covered a number of the more creative, or “hacky” malware obfuscation techniques in widespread use, and showed examples of how they can be combined to make it difficult to analyze code functionality. All of these techniques can also be combined with the techniques in our previous post on malware obfuscation to make life even more difficult for analysts and security scanners.

These two posts cover the most popular obfuscation methods used by PHP malware, but there are even more advanced and sophisticated techniques, including genuine encryption, which we will cover in our next article, alongside less commonly-used functionality.

PHP malware is constantly evolving, and our malware analysts release dozens of detection signatures every month, which can be used by the Wordfence scanner as well as by Wordfence CLI (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKM63prCCW7Y8-PT6lZ3mlV-Rgt9222pJNW8BLTtT7_KfJjW5v2Xv39lGzsYVM1-gr63_373VZTfTc4_HCvQW9kRBY33NDWz3W5YWTKw2Q-PZBW2tJbBT2SRymxW1-nCyV3_JzmGW4Bpv2z2mDznhW9jnNV59g6Jz5W9c221d7tr5ZBW5607tw8GyyKnW603bWb3nqrjvW1GVjw74LzdMKN5LH-n_QMzLdVhwzSQ2gyvFZW9743L51-Hd-QVLs_Mz6Yf7lCW8d6pjD3QXpvgW7TCZwq5xFfyJN5CbK88CxJpMW4NstqL5sJR-xW2yTZNx7Zh9q7W44f7QJ6ncRhFVzv-pQ2nwgfpf6wkjFd04 ) . While the vast majority of new signatures will only be made available to Wordfence Premium (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKM63prCCW7Y8-PT6lZ3mKVk-N1Q2v-B4_W7thJcq2_PMD6W8gTHbk7Hqq1ZW2gKvxg347tdwW6YgdKn4j5_NgW1H6XwD1BgXqyN6nsr-XB4nx7N4Nnt5vVNqnGVttXw631rw3GVQ37nq2lc7tLW3XCwmp5DSbQxW1sSYsw9b_8gCW3hH4p32zQm7xW7jcz3F5C1_KsVqC-kk4rq92_W7k6yqq2Ccr55N7Ll1l3TPCFJW79ylmY6cVGdGW6zVL3g842H87W6gdqw87Mh7f3W1Mx6NF47tKCDN5R0KQzPzqKwVqgc4j5mC1f-W4rtNk998VsG5W5mmpjl5DBvlTW37-5rf89-txsf69Fnbn04 ) , Wordfence Care (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKM63prCCW7Y8-PT6lZ3kvW7P8gYw78-b3yVcZRrS31xYt7W3hxWcd5xJ9BgW4TQrhB5whxqQW7vqqwx8FV0lGW5dxY6m4V_6GZVzMpfv6gmfw5N6SNwQCd3lkbW53R5g36Yl-J2N5-KL6cgQr0PW7JtPQZ7KKX1TW8w0p-P3P5hHXW1M8LYQ2_YQGpW3K98js37Zdf_W9dsv472m0KxRW6qZyZM52LL1rW4WFGz75vgLs3W3lcVYm8mnck8V77y3_1cf3xRN67dFfmTWgJmW3h9yLv8jr3FgW8qcvKl5bmS6NW2HDNd380zlyCW5hgCsR62ZcnRVr8QZ27RhDlcN25Bkcr7mcylf2Jwhpz04 ) , Wordfence Response (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKM63prCCW7Y8-PT6lZ3psW934y1q7gwr9dW5hCqS_39ZL7SW5vLYbs612YtxW3X261Y86D9DhW10jBDy7qSl8-W7jjpt28vCxfDW7zZV7m68y_tTW8Bbj1M1KvMsKW83M_Jm10dGvzW9lm6h64rbCglW4c98V97M48h6W9cFWxb6V_PTBW24XWYq184zzwW5ZFY1131GnJyW1G76JH8x_W0DW47y3Np2LVqF4W2mdL8L30r0DNW6M9yTl7xlNZBW4yG-WH29fC85W2TJ2KF6C0HKVW5lLm8f5bwkZXW85wHBY4BhXqkMLRNFHfwT6PW7fwZNQ5jdsC9W5-XkgJ85QBSpW1fzKSx1XLYcbf301b4804 ) , and the Paid Wordfence CLI Tiers, the free version of Wordfence and Wordfence CLI still offer excellent detection capabilities, and include our broadest signature set, which in our testing detects at least one indicator of compromise on more than 90% of infected sites. We also plan to periodically update our free signature set with signatures that detect the most widespread malware from our full signature set.

Once again, we encourage readers who want to learn more about this to experiment with the various code snippets we have presented. As always, be sure to be careful with any actual malware samples you find and only execute them in a hardened virtual environment, as even PHP malware can be used for local privilege escalation on vulnerable machines.

For security researchers looking to disclose vulnerabilities responsibly and obtain a CVE ID, you can submit your findings to Wordfence Intelligence (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKLR3prCCW7lCdLW6lZ3kXW6SFNMZ1PjZVRW3GKNvs8KG3WpVzWrcz3BmRFtN192kTZrnGrMW2X83dr40VRMKN25K3gY4l3N9W3XmkJS5hrKP0VHdXQz1KWT08W838Dr35HJddwW4PfPZQ4NffS1W5dKVKT34DcLqW3kh5Bx8bDTNzW8mL_5N1q6hgTMgsZMjnNK6mVdJ_zc7Ffb9rW4pPPZG8g86sPW7gX_JD6lqPytW4MCLg25Hy_1xW2wh5Vj3BmbP5N4-5Ft7WmKG8W8Z7w2f1VhKNHVRPQCw3sNqF2W76Jdrc6WqCp1W353bg75xxW64f2np0Vz04 ) and potentially earn a spot on our leaderboard (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKMq3prCCW8wLKSR6lZ3kvW3fVWbs12lvX6W2SKlwb5P58mnW82PTSy3CxT3mVB2-2h1TPKXdW8wtKd27wV1LrVY5bCg1zYPt4W6pK7vm8C8V_-W3qgvZ55yKLrcN2kggDwkpbpJW5rg2bb1LRm71W8HkDTD5q5WpJW580Djc7X-MdpW4KMgNl2r9Y2vW7-nSSq3LySJ6N4J3Kr9XMKJMW22l_2y4q2NRvW2J2wX345RkPKW6Fr-s84ggsJXW7nJpFD41hQvxW8QVpYH7P35vVW79JXx51TcRfxW7jpwrC5frmC2W2xqGgR4l_jBVMpyYtFYbbsQW4SnmBW7-bCTZW3xmNyQ48jrzWW7_4vH472gvfKW792x9m6j4TwKf2WHmtT04 ) .

The Full Product Lineup

wf-stacked-free-1 (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKM63prCCW7Y8-PT6lZ3nCW4Wn5Hq90g6njW1JZRyj1JkvTJW2kftHp7Zg3TZW5_Czj39fr0tmW1HVMLh5Qn3lGW278zbQ2PMsNQW551LKq1KXvF3W4-Kxbs2rmrnPW4-jYc32rrn0PW7rcq485PzhBCVswxCM9ch0PbW2GfyjR8GQfy8W3fK1SB5Ny1BqW53F53783-Vp2W8qZ47-8rBdKzW7Vtkdx4g6l4qW1xJQsN6XSCxMW57kKNH4MPdVxT2fqT5ZjTP4W1j8hYn3F8ZD9W5mvQfX65YXqxW3f50VP2r34mvW3J-D0Q6LtmkKVlj_lD4bzfx-W7L7X8_8q8p_NW7KKmpR6ZtZ3sf5nfbC004 )

wf-stacked-premium-1 (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKM63prCCW7Y8-PT6lZ3kHW5WLmsZ6mj-3_W5MQX_c4NT6zVW8jKxh33Jc8GqW8h8SDV5Z5PBCN4dCHNNCl-qbN3MrW8nNZtxmW1gjl5w3T27kHW81npdd8Y7lNwW3vX1dp35yQhVW5KF_XJ4GBXm6N1m_m4NKdfzVW16WKcl8nKl2RW7qsLwv76B_04W1sMnXR789bNvN54P8RNHxbnsW4m0Hhp7G9XJhW4B7kdr3J0KRGW8W4R2S1gSm9HW87ZsQN6tBht0W7z9NYm2GncxgW6PRQhX96gS8tW1Fc01w97p4hVW3CWRfR3gpMxMW1bsYnF4XjkT-W2C7QZ963Rf9jW5J417N38-vsWf32PSFj04 )

wf-stacked-care-3 (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKM63prCCW7Y8-PT6lZ3krW4yq5DK67wm83W6KVXB52DdtgMW4sBbbs35xxG4V9rKjh8y_pgqW7F2Wz96QflSZW6QR1DT8fZhqsW4THSwM1KqxflW4Z_f-J2Cm0GnW7tkX4B9gzCgvW2hWhNf7mM_TwW82NJws5kRslFW4MZhkM6sWHXwW8WDrnt8B1nBSN37WSqFt0HwMW7DBk9V7k_BLkW1gQJSH7gp9tPW6gppXP1HDlDdW6BTTn7178MMnW3ttTrv6m1h9GW4vPZc12mvGn3W20Vkty3LhhPlW7N7n9p3bgqHrW2qLpPD6dpHlQN1W-JFHHXL1yW3YP7j07HSpQNW2XWQ-z31f_zQf1w2kx-04 )

wf-stacked-response-2 (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKM63prCCW7Y8-PT6lZ3psW934y1q7gwr9dW5hCqS_39ZL7SW5vLYbs612YtxW3X261Y86D9DhW10jBDy7qSl8-W7jjpt28vCxfDW7zZV7m68y_tTW8Bbj1M1KvMsKW83M_Jm10dGvzW9lm6h64rbCglW4c98V97M48h6W9cFWxb6V_PTBW24XWYq184zzwW5ZFY1131GnJyW1G76JH8x_W0DW47y3Np2LVqF4W2mdL8L30r0DNW6M9yTl7xlNZBW4yG-WH29fC85W2TJ2KF6C0HKVW5lLm8f5bwkZXW85wHBY4BhXqkMLRNFHfwT6PW7fwZNQ5jdsC9W5-XkgJ85QBSpW1fzKSx1XLYcbf301b4804 )

wf-stacked-cli (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKM63prCCW7Y8-PT6lZ3mlV-Rgt9222pJNW8BLTtT7_KfJjW5v2Xv39lGzsYVM1-gr63_373VZTfTc4_HCvQW9kRBY33NDWz3W5YWTKw2Q-PZBW2tJbBT2SRymxW1-nCyV3_JzmGW4Bpv2z2mDznhW9jnNV59g6Jz5W9c221d7tr5ZBW5607tw8GyyKnW603bWb3nqrjvW1GVjw74LzdMKN5LH-n_QMzLdVhwzSQ2gyvFZW9743L51-Hd-QVLs_Mz6Yf7lCW8d6pjD3QXpvgW7TCZwq5xFfyJN5CbK88CxJpMW4NstqL5sJR-xW2yTZNx7Zh9q7W44f7QJ6ncRhFVzv-pQ2nwgfpf6wkjFd04 )

wf-stacked-intelligence (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKLR3prCCW7lCdLW6lZ3lVW8J1KrL1sJYfDW754Vq-6PklNzW81cS9Q3hT5YNW7zvNgs19qwHPW8XKL8J8LzLzhN73XStLKy6-xW3WS8Rc316_knW3v80FY7S3h7mW2c4kvh8wJlvDW7vZ7JR1Gp_5zW1gt5Nk25cDcCW7PhPbq1J0ZrGN8Q5-5qPpDt9W5mLXkJ4mFZ1YW8VkLZV53V9pbW3ZwSdB1k94jvVzk1Ln2N88GbW8CYQ3S8lm5wdW4FkMmz4nbJLtW5J9nwr3n57P9W7ztWqK1ZsJ3yW134NJC5gCJBXW3RyLtH2G21fZN4hYLQSRM01pf3N61z804 )

logo-defiant (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKLx3prCCW6N1vHY6lZ3q3W29FgVW8NPmjQN786w_DmHdhWW1m8ngD2-CxYbN5BqR70SkmqdW68ZBBQ6-qk-_TmRpm4k89csW5srsd3661C4rW8HHHr_95SlNhW1QwWlY20hnnwVm4Q_n7PX9C_V3RyVR679TZmW4fdQsS4Q-L9gW7Cq9Vt4sY1XvW78zWZk15BbqXW1Nvj_H633_67N2VJwxBfkwHxW31B5BW8t6n22W7vh7-d7jDhgvN16qCcg9cFmrW3wG6JD19mCvqW5NWtXx8TVs9hW7CJcnV1spPGxf2cKznj04 )

Defiant, Inc., 1700 Westlake Ave N STE 200

Seattle, WA 98109 United States

Unsubscribe (https://email.wordfence.com/hs/manage-preferences/unsubscribe-all?languagePreference=en&d=Vn9bTK892TtnVsxx1M3JN_XyW41Rcn-4h29fmN6J4V3XmWFfnW64Xz3D6cdKSyV25w_Z8S89Y0N4T5RlSXjRb4N85tpWqXk_7QVbv-s98K1CPcW6KTV955LlCJdw6LnhB814S2&v=3&_hsenc=p2ANqtz-9BitUcZ4w15fcZAHFSDNG4oz5em-HZmCxBwQ7_oD8GVfgmWHpwvKQkhXJQGaIxjk7-b39ZhzYJCodesHNUoM0__y-iIA&_hsmi=280787118 ) Manage Preferences (https://email.wordfence.com/hs/manage-preferences/unsubscribe?languagePreference=en&d=Vn9bTK892TtnVsxx1M3JN_XyW41Rcn-4h29fmN6J4V3XmWFfnW64Xz3D6cdKSyV25w_Z8S89Y0N4T5RlSXjRb4N85tpWqXk_7QVbv-s98K1CPcW6KTV955LlCJdw6LnhB814S2&v=3&_hsenc=p2ANqtz-9BitUcZ4w15fcZAHFSDNG4oz5em-HZmCxBwQ7_oD8GVfgmWHpwvKQkhXJQGaIxjk7-b39ZhzYJCodesHNUoM0__y-iIA&_hsmi=280787118 )

ISO_27001 (https://email.wordfence.com/e3t/Ctc/GC+113/cwG7R04/MWpBrG5g5qbW71SvGQ2HvNLJW2K0rfL55l56JN4zFKLx3prCCW6N1vHY6lZ3mvW4HxQwH3vhcFgW4YvZ9x7Wpxr3W3qVsHq7Bt8z4W7FMFmp2mRNX7W4Q6G385RhsWTW4mk55m9k9WklW6Bs8Gx35dfKSW4vbRQ41-sjdLN87jfLL9DcR3W3HRWmD5H8bvQN2Mg1RVQtzrTW346Htz1ysVdqN8tfQm4GgRKtW3dpqFW7lnrwFMHbysrDLjvbW44yxv87BGYSlW4qpTvv4s8vGRW4qsg1p8fS-_RN5KKGF0xYbFgW4f7-hf7j856XW8t4VzP5LmDynW2v1SZf19HS6Mf6PV45v04 )

You're receiving this email because you signed up to the Wordfence WordPress security mailing list.
Received on Wed Nov 01 2023 - 17:46:57 CET

This archive was generated by hypermail 2.3.0 : Wed Nov 01 2023 - 17:53:14 CET