HACKVent 2020 – Day 2

Challenge – Chinese Animals

I’ve received this note from a friend, who is a Chinese CTF player:

恭喜!收旗爲:HV20{獭慬氭敬敧慮琭扵瑴敲晬礭汯癥猭杲慳猭浵搭桯牳e}

Unfortunately, Google Translate wasn’t of much help: 

I suspect the data has somehow been messed up while transmitting it.

Sadly, I can’t ask my friend about more details. The Great Chinese Firewall is thwarting our attempts to reach each other, and there’s no way I’m going to install WeChat on my phone.

Solution

“I suspect the data has somehow been messed up while transmitting it.” sounds like encoding issues to me. So lets try a bunch, because who knows what encoding was used.

using System;
using System.Text;


Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode;

Console.WriteLine("Input string:");
var origString = Console.ReadLine();

PrintStringFromEncodingInAllEncodings(origString, Encoding.UTF8);
PrintStringFromEncodingInAllEncodings(origString, Encoding.ASCII);
PrintStringFromEncodingInAllEncodings(origString, Encoding.BigEndianUnicode);
PrintStringFromEncodingInAllEncodings(origString, Encoding.Default);
PrintStringFromEncodingInAllEncodings(origString, Encoding.Latin1);
PrintStringFromEncodingInAllEncodings(origString, Encoding.UTF32);
PrintStringFromEncodingInAllEncodings(origString, Encoding.UTF7);
PrintStringFromEncodingInAllEncodings(origString, Encoding.Unicode);

Console.ReadLine();



static void PrintStringFromEncodingInAllEncodings(string s, Encoding encoding)
{
    Span<byte> bytes = encoding.GetBytes(s);
    Console.WriteLine($"From {encoding.EncodingName}");
    PrintBytesInAllEncodings(bytes);
    Console.WriteLine("------------------------");
}


static void PrintBytesInAllEncodings(Span<byte> bytes)
{
    PrintBytesInGivenEncoding(bytes, Encoding.ASCII);
    PrintBytesInGivenEncoding(bytes, Encoding.UTF8);
    PrintBytesInGivenEncoding(bytes, Encoding.BigEndianUnicode);
    PrintBytesInGivenEncoding(bytes, Encoding.Default);
    PrintBytesInGivenEncoding(bytes, Encoding.Latin1);
    PrintBytesInGivenEncoding(bytes, Encoding.UTF32);
    PrintBytesInGivenEncoding(bytes, Encoding.UTF7);
    PrintBytesInGivenEncoding(bytes, Encoding.Unicode);
}

static void PrintBytesInGivenEncoding(Span<byte> bytes, Encoding encoding)
{
    Console.WriteLine($"{encoding.EncodingName}\t{encoding.GetString(bytes)}");
}
The (important) part of the output

Ok, I could have guessed that. Obviously the destination encoding was to be something ASCII compatible. And with the Chinese characters, UTF-16 BE isn’t really surprising either. But hey, here’s the solution:

HV20{small-elegant-butterfly-loves-grass-mud-horse}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *