Recently, I found several malicious Python scripts that looked the same. They all contained the same strings at the end:
Pretty nifty obfuscation technique because you cannot get any idea of the script’s purpose without executing it in a sandbox or checking deeper. Obfuscation is a crucial element for attackers because they help to bypass classic security controls and they slow down the analysis process by Security Analysts. How does it work? Attackers write their code then they use tools to obfuscate the code. Of course, they are tools available in the underground, but there are also tools publicly available.
One of them is called development-tools.net, which provides a free online Python obfuscation tool:
Here is a simple/fantastic script:
#!/usr/bin/python print "Hello world!"
The obfuscated code is:
import base64, codecs magic = 'IyEvdXNyL2Jpb' love = 'v9jrKEbo24XpU' god = 'JpbnQgIkhlbGx' destiny = 'iVUqipzkxVFVX' joy = 'x72x6fx74x31x33' trust = eval('x6dx61x67x69x63') + eval('x63x6fx64x65x63x73x2ex64x65x63x6fx64x65x28x6cx6fx76x65x2cx20x6ax6fx79x29') + eval('x67x6fx64') + eval('x63x6fx64x65x63x73x2ex64x65x63x6fx64x65x28x64x65x73x74x69x6ex79x2cx20x6ax6fx79x29') eval(compile(base64.b64decode(eval('x74x72x75x73x74')),'','exec'))
But is the obfuscation efficient to make the Python script bypass some AV’s? I selected a classic script (a password stealer). The script has a current score of 4/60 on VT (SHA256:5f9a62e6c09f085ffb60caefbe155e3ead38848d0f5201517ca0c3cccc09ce78). The obfuscated script received a score of 5/60.
Another one (a keylogger) with a score of 10/59 (SHA256:77d1cda4ab39e3e0f0a7af4c3d86a42721b9a0d62ccf2f3112988e518c296af5). The obfuscated version also received a score of 5/60.
As you can see, if the code is really difficult to understand out-of-the-box by an Analyst (goal completed) without proper tools. However, this obfuscation tool does not always improve the detection rate of antivirus tools.
Xavier Mertens (@xme)
Senior ISC Handler – Freelance Cyber Security Consultant
(c) SANS Internet Storm Center. https://isc.sans.edu Creative Commons Attribution-Noncommercial 3.0 United States License.