Obfuscation (software)
In software development, obfuscation is the practice of creating source or machine code that is intentionally difficult for humans or computers to understand. Similar to obfuscation in natural language, code obfuscation may involve using unnecessarily roundabout ways to write statements. Programmers may obfuscate code to conceal its purpose, logic, or embedded values. The primary reasons for doing so are to prevent tampering, deter reverse engineering, or to create a puzzle or recreational challenge to deobfuscate the code, a challenge often included in crackmes. While obfuscation can be done manually, it is more commonly performed using obfuscators.
Overview
The architecture and characteristics of some languages may make them easier to obfuscate than others. C, C++, and the Perl programming language are some examples of languages easy to obfuscate. Haskell is also quite obfuscatable despite being quite different in structure.The properties that make a language obfuscatable are not immediately obvious.
Techniques
Types of obfuscations include simple keyword substitution, use or non-use of whitespace to create artistic effects, and self-generating or heavily compressed programs.According to Nick Montfort, techniques may include:
- naming obfuscation, which includes naming variables in a meaningless or deceptive way;
- data/code/comment confusion, which includes making some actual code look like comments or confusing syntax with data;
- double coding, which can be displaying code in poetry form or interesting shapes.
Payload encoding for malware evasion
In XOR obfuscation, an attacker chooses a secret key and applies the XOR bitwise operation to the malware binary. This transforms the executable into what looks like random data. Function names in the import table vanish, PE headers become corrupted, and the entire file loses its structure. The obfuscated payload then gets embedded into a dropper, which is a normal-looking executable that contains the hidden malware as a resource or data section. When a user runs the dropper, it performs the XOR operation again with the same key to reconstruct the original malware, then either executes it directly from memory or writes it to disk before running it.
This process removes several indicators that antivirus software relies on. The MZ header, which marks the beginning of every Windows executable, gets completely obscured by the XOR operation. Security programs frequently scan for this two-byte signature when searching for embedded executables. Base64 encoding achieves similar results through a different method. It converts binary data into ASCII text, so an executable file ends up looking like plain text rather than a program.
Research from the 2020 Machine Learning Security Evasion Competition showed that these methods can bypass modern detection systems. Participants used combinations of XOR encoding, Base64 encoding, and dead code insertion to evade all three competition models with fewer than five attempts per sample. Entropy-based detection also failed, and in some cases Base64 encoding actually lowered the entropy compared to the original malware files.
The simplicity of these techniques is what makes them particularly dangerous. XOR and Base64 encoding require only basic programming skills to implement, yet they proved effective against advanced machine learning classifiers. This has pushed security researchers toward new defenses, including automated XOR key recovery tools and deeper analysis of embedded resources in executable files.
Automated tools
A variety of tools exist to perform or assist with code obfuscation. These include experimental research tools developed by academics, hobbyist tools, commercial products written by professionals, and open-source software. Additionally, deobfuscation tools exist, aiming to reverse the obfuscation process.While most commercial obfuscation solutions transform either program source code or platform-independent bytecode, portable code, some also work directly on compiled binaries.
- Some Python examples can be found in the and elsewhere.
- The movfuscator C compiler for the x86_32 ISA uses only the mov instruction in order to obfuscate.
Recreational
Short obfuscated Perl programs may be used in signatures of Perl programmers. These are JAPHs.
Cryptographic
Cryptographers have explored the idea of obfuscating code so that reverse-engineering the code is cryptographically hard. This is formalized in the many proposals for indistinguishability obfuscation, a cryptographic primitive that, if possible to build securely, would allow one to construct many other kinds of cryptography, including completely novel types that no one knows how to make.Disadvantages of obfuscation
- While obfuscation can make reading, writing, and reverse-engineering a program difficult and time-consuming, it will not necessarily make it impossible.
- It adds time and complexity to the build process for the developers.
- It can make debugging issues after the software has been obfuscated extremely difficult.
- Once code is no longer maintained, hobbyists may want to maintain the program, add mods, or understand it better. Obfuscation makes it hard for end users to do useful things with the code.
- Certain kinds of obfuscation can degrade performance and/or require Internet.
Notifying users of obfuscated code
Mozilla and Google disallow browser extensions containing obfuscated code in their add-ons store.