The Dark Times Writeup

By
Nash N Sulthan
Published on
20 Sep 2020
4 min read
DOMECTF2020

Story

Elysium faced a ransomware attack and all the server data got encrypted by the adversary. They’re asking a big ransom to carry out their plan. We’re not willing to pay the ransom but we need to get the data back.

Solution

The challenge is to decrypt the given files. In order to decrypt, you need to find a private key.

dark-times1

The key part of this challenge is the bitcoin address and the email id. The provided email is a temporary email address. By searching “toritmp” you can find the website that provides those temporary emails.

By accessing the mail you can see the following emails in it.

dark-times

Those are BIP39 Split Mnemonic. BIP39 Mnemonic phrase is a list of words that store all the information needed for the recovery of a Bitcoin wallet. With that you can get the public key and private key of the bitcoin address.

dark-times3

Using the site https://iancoleman.io/bip39/ will provide you the list of addresses, private key and password.

dark-times4

Now, we have the public key and the private key of the address.

Elliptic Curve Digital Signature Algorithm or ECDSA is a cryptographic algorithm used by bitcoin to ensure that funds can only be spent by their rightful owners.

Elliptic Curve Cryptography (ECC) can do public key encryption. Encrypted files are encrypted using ECC with the public key of the bitcoin Address. For decrypting, the private key of the bitcoin address can be used. The hint was a new generation of ransomware. Searching the hint on google will give a hint of ECC.

Using the eccrypto node module these files can be decrypted with given script:

        var eccrypto = require("eccrypto");
        var fs = require('fs');

        async function decrypt(encryptedFileName, decryptedFileName, privateKey) {
        try{
            let encrypted = JSON.parse(fs.readFileSync(encryptedFileName, 'utf8'))
            for (let key in encrypted) {
            encrypted[key] = Buffer.from(encrypted[key],'hex')
            }
            let plaintext = await eccrypto.decrypt(Buffer.from(privateKey, 'hex'), encrypted)
            fs.writeFileSync(decryptedFileName, plaintext);
        }
        catch(err){
            console.log(err);
        };
        };

        (async function () {
            var myArgs = process.argv.slice(2);
            // simple input sanity check
            if (myArgs.length != 3) {
                console.log("Usage: node decrpyt.js encryptedFileName decrptedFileName privateKey ")
                process.exit(1);
            }
            await decrypt(myArgs[0], myArgs[1], myArgs[2])
            console.log(" ")
            console.log("Successfully decrypted ", myArgs[0], " into ", myArgs[1])
        })()

    

Using the bitcoin-tool, convert the private key to hex format. You will get it as “fee3e9d84f96d14f5eec439924229be51945cf608810a118e3dd8489d1257dc9”

dark-times5

Finally, it’s time to decrypt the flag!

dark-times6
Automated human-like penetration testing for your web apps & APIs
Teams using Beagle Security are set up in minutes, embrace release-based CI/CD security testing and save up to 65% with timely remediation of vulnerabilities. Sign up for a free account to see what it can do for you.

Written by
Nash N Sulthan
Nash N Sulthan
Cyber Security Lead Engineer
Find website security issues in a flash
Improve your website's security posture with proactive vulnerability detection.
Free website security assessment
Experience the power of automated penetration testing & contextual reporting.