I got this crackme from one of my readers, who asked me for the help in understanding how to solve it. As he wrote in the e-mail, it comes “from last year competition by the CheckPoint company”. I promised to make a writeup, so here it is :). I hope it will benefit others also.
The crackme is for the beginners, so don’t expect any fireworks ;). But it was relaxing and fun to solve.
This is how the application looks:
When we run in, it asks for a username:
And when we give an invalid one, it responds with a text:
“Go away, you are not me”
The first important step in solving the crackme, is noticing how exactly was it made and what tools are to be applied. As the icon hints, it seems to be an application written in Python and converted into EXE. But let’s confirm it by looking inside. The main process runs another instance of itself:
Let’s attach the debugger to the child process and see the loaded modules:
We can find that indeed Python2.7 is loaded to interpret the code (the module is marked red on the picture).
At this moment we can confirm that this EXE is in reality a wrapper for a Python script. There are several applications that allows to achieve it. Depending on which application produced the wrapping, the output has a bit different format and requires a different decompiler.
- PyInstallerExtractor – allows to unwrap an EXE created by PyIntaller
- The resulting .pyc files need to be decompiled by an appropriate Python decompiler. Depending on the Python version you may use i.e.: Easy Python Decompiler, (for Python > 3.4 use i.e. https://python-decompiler.com/ ) or uncompyle6
Step 1 – Unwrapping the exe
Unpacking the EXE is easy with the appropriate tool. In this case I used PyInstallerExtractor, written in Python.
python pyinstxtractor.py pycrackme.exe
This is the output:
[*] Processing pycrackme.exe
[*] Pyinstaller version: 2.1+
[*] Python version: 27
[*] Length of package: 2604972 bytes
[*] Found 20 files in CArchive
[*] Beginning extraction...please standby
[+] Possible entry point: pyiboot01_bootstrap
[+] Possible entry point: black_box
[*] Found 196 files in PYZ archive
[*] Successfully extracted pyinstaller archive: pycrackme.exe
You can now use a python decompiler on the pyc files within the extracted directory
The script directly hints, that the next step will be to use a Pyhon decompiler and turn the obtained
pyc files into Python scripts.
It also hints about the possible entry point of the application. This information helps us to find where the code of our interest is located.
Step 2 – Decompiling the pyc
The produced output is stored in the directory corresponding to the name of the input executable. We can see there multiple modules extracted, but the interesting one seems to be the file called “black_box”:
The black_box is a
pyc file with a magic number removed, so we can just copy this part from some other
pyc file that we found in the extracted set, i.e.
Let’s paste it at the beginning of the black_box:
After this step we are ready to save it as
black_box.pyc and decompile:
And here is the result:
|# File: b (Python 2.7)|
|from time import sleep|
|from random import sample, getrandbits, randrange|
|from string import ascii_letters, digits|
|from hashlib import sha256|
|f = 'kukuriku'|
|k = 'elvis presley'|
|g = 'lsdjfiownv9037la1sdf10'|
|p = 'byebye'|
The file got decompiled properly, and at this point we can rename it to py and run like any other Python script. We can see the same prompt as it was in the EXE:
Looking at the code we can see that is is mildly obfuscated. The important part is hidden in the variable “c” that is obfuscated by ROT13 and compressed by ZLIB:
To understand it better what happens here, we should dump the content after the deobfuscation, rather than executing it. In order to do so, I slightly modified the script. I removed the code responsible for executing the second stage, and substituted it with the function that writes the decompressed result into a file. This is my modified version:
Now, once we execute this script, we get the next stage dumped. And this is how it looks:
from hashlib import sha256 from time import sleep import socket, sys PASSWORD = "36949" HASH = sha256(PASSWORD).hexdigest() USER = 'Nigel' CODE = "807290" IPADDR = '220.127.116.11' PORT = 587 def login(): print "" username = raw_input("Enter First Name: ") if username.rstrip(' \n\t') != USER: print "Go away! You are not me..." sys.exit() print "Hello %s, Good to see you!" % USER while True: password_guess = raw_input("Enter 5-digit password: ") print "[DEBUG]: calculating sha-256 hash" print "[DEBUG]: comparing with %s's hash: %s" % (USER, HASH) print "[DEBUG]: performing anti-brute-force delay..." sleep(5) if sha256(password_guess).hexdigest() == HASH: print "Password OK!" break else: print "Wrong password!" while True: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) s.connect((IPADDR, PORT)) s.send(str(CODE).decode('hex')) s.close() print "%s, two-factor authentication is required. A one-time code was sent to your email address" % USER code_guess = raw_input("Enter code: ") sleep(5) if code_guess == CODE: print "Success! The code is what you're looking for :)" break else: print "Wrong code!" login()
The script is not further obfuscated.
Once we read it, it’s pretty straight-forward what to do next. So, the username was Nigel. Then, we have to give his password that is 36949 and finaly his code: 807290. This was my final conversation with the crackme confirming that the code is valid.
Enter First Name: Nigel
Hello Nigel, Good to see you!
Enter 5-digit password: 36949
[DEBUG]: calculating sha-256 hash
[DEBUG]: comparing with Nigel's hash: 6912863904dab1ddc332a928bf6df7f365bf1131906f3424aa931c6c85595c34
[DEBUG]: performing anti-brute-force delay...
Nigel, two-factor authentication is required. A one-time code was sent to your email address
Enter code: 807290
Success! The code is what you're looking for :
Exactly the same results we get when we talk with the original EXE:
So, the final answer is 807290.
This crackme can be solved very easily if we know the few tricks. The most important was to find what are the proper tools to be applied. Once we got them, we could easily decompile the code and read the answer.
- “TelegramRAT evades traditional defenses via the cloud” – example of a malware using similar packaging