Malware Packers
❓ When an attacker thinks about how to hide themselves or make their malware difficult to detect, they turn to certain techniques that help them achieve this.
One of these techniques is Packing or Packer Software 📦
1️⃣ What is a Packer?
Definition: A Packer is a program used by developers to encrypt their programs or reduce their size. What the packer does is hide or compress a part of the program’s code and store it in a format called an “unpacking stub”.
Usage: In the past, developers struggled with the download size of their programs, so they started using packers to reduce the size, the most famous being UPX PACKER. Additionally, nowadays, mostly in games, developers try to protect their games from cracking and reverse engineering, so they use packers like VMPROTECT or THEMIDA for this purpose.
2️⃣ Why are Packers used in Malware? 🌟
When developers used packers for protection, another group emerged that used them for harm and to achieve their goals by hiding their malware from detection.
When a hacker or malware developer starts writing their program or even using tools like msfvenom to create a payload to compromise targets, this type is often detected because its pattern (hash value) is known to security programs. To prevent detection or reduce the likelihood of the program being exposed, we use a packer to change the hash of this program. As a result, it won’t be easily detected and will bypass some security programs. Also, the size reduction feature helps send the payload in the smallest size to the victim, aiding in spread and impact.
3️⃣ The Impact of using Packers 😈
The packer increases the difficulty of detection as well as analysis because it encrypts a part of the malware. Consequently, it will spread faster since visibility for some security programs will be almost non-existent because a part of it is hidden.
4️⃣ Detecting packed programs
First, if we want to know whether a program is packed or not, we use the following methods:
1- Import Address Table (IAT) This table contains all the functions the program needs to run. If there are very few (e.g., 3-5), this is strong evidence that the program is packed.
Image 1 shows a normal program without any packing… Notice the IAT here contains all available functions the program needs without hiding ✅💻
Image 2 shows a packed program as it appears in the IAT, where not all functions used by the program are present 📦☠️
2- Entropy Analysis This is a measure of randomness. Programs that are packed add an extra layer, increasing what is called entropy or complexity. If the entropy is high, the program is packed; if it’s low, it’s normal. The threshold for being packed or not ranges between 5-7. Above 7 or at 7 is generally considered packed.
Image 1: Normal entropy.
Image 2: Packed entropy.
Notice also when we calculate the entropy for a packed program and an unpacked one, we find that the packed program has high entropy. This is an indicator for the analyst if they want to verify whether the program is packed or not ⚛️💻. Detect It Easy is an excellent tool for this 📖.
3- Suspicious Sections and Size Differences
Other methods include suspicious sections inside the program like .UPX or .aspack, and also the difference between RawSize and VirtualSize.
- 💾 RawSize: The size of the program when it is stored on the Disk (before the program is run or executed).
- 😄 VirtualSize: The size of the program when it is loaded into memory (the program has started executing).
If the VirtualSize is larger than the RawSize, this means the program is packed, because its size on disk is small compared to its execution time. When the program is executed or run, it won’t stay packed; it will be unpacked in memory to retrieve the base code it needs to function. As a result, its full size will appear and be larger than what’s on the disk.
5️⃣ Examples of packers
- UPX (Ultimate Packer for Executables): This is the simplest and most commonly used type. As an analyst, you can easily unpack it via a simple command. (Security bypass rate: Weak, Usage: Easy)
- Themida / VMProtect: One of the strongest types of packers ever. Using them is very expensive and provides very strong protection for programs, whether for a legitimate developer or a malware developer. (Security bypass rate: Very High, Usage: Medium-Complex)
There are other programs, but these are the most common.