Baby onion

Table of Contents

No onions

Problem

Ogres are like onions!

Solution

The file is an base64-encoded text file.

After de-base64, it’s hex encoded.

Script:

a.c: De-hexify

#include <stdio.h>

// compiled under WSL

int hex2dec(char raw);

int main(void)
{
    char temp;
    while ((temp = getchar()) != '\n')
    {
        // read two char at a time
        char temp_1 = temp;
        char temp_2 = getchar();
        // 48 ~ 57 '0' ~ '9'
        // 97 ~ 102 'a' ~ 'f'
        char out = hex2dec(temp_1) * 16 + hex2dec(temp_2);
        if (out == '(')
        {
            return 0;
        }
        printf("%c", out);
    }
    return 0;
}

int hex2dec(char raw)
{
    switch (raw)
    {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            return raw - '0';
        default:
            return raw - 'a' + 10;
    }
    return -1;
}
gcc ./a.c

extract_onion.bash: de-base64 and use a.out to dehexify

#!/bin/bash

layer=0
cat baby.onion | ./a.out > $layer.txt
while [ true ]
do
    echo "Layer: $layer"
    if base64 -d $layer.txt > $layer.b64out; then
        let temp=$layer+1
        if cat ./$layer.b64out | ./a.out > $temp.txt; then
            let layer=$layer+1
        else
            exit
        fi
    else
        exit
    fi
done
bash ./extract_onion.bash
cat ./14.b64out

Result

➜  onion cat 14.b64out
DawgCTF{b@by_0n10ns_c@n_$t1ll_Mak3_u_cRy!?!?}
Nemo Xiong avatar
Nemo Xiong
ex-Cybersecurity Executor, now a student in Unimelb
comments powered by Disqus