HackVent 2023 - [HV23.20] Santa's Candy Cane Machine
Difficulty: Hard
Category: Reverse Engineering
Author: keep3r
As Santa wanted to start producing Candy Canes for this years christmas season, his machine wouldn’t work anymore. All he got was some error message about an “expired license”. Santa tried to get support from the manufacturer. Unfortunately, the company is out of business since many years. One of the elves already tried his luck but all he got out of the machine was a
.dll
! Can you help Santa license his Candy Cane machine and make all those kids happy for this years christmas?
We get a .dll
file that we can open in Avalonia ILSpy.
Instead of trying to reverse the algorithm by hand, we can use Save code ...
to store the disassembled code in a .cs
file.
I’ve added the following code to brute-force a valid key:
public static String RandomChar() {
String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random = new Random();
return chars[random.Next(chars.Length)].ToString();
}
public static String RandomFiveChars() {
String result = "";
for (int i = 0; i < 5; i++) {
result += RandomChar();
}
return result;
}
public static String RandomProductKey() {
String key = RandomFiveChars() + "-" + RandomFiveChars() + "-" + RandomFiveChars() + "-" + RandomFiveChars() + "-" + RandomFiveChars();
return key;
}
public static void Main() {
while (true) {
// generate random key
String productKey = RandomProductKey();
// decode product key
CandyCaneLicense candyCane = CandyCaneLicense.Create(productKey);
if (candyCane != null) {
Console.WriteLine(productKey);
Console.WriteLine("Product key is valid");
Console.WriteLine("Expiration date: " + candyCane.ExpirationDate.ToString());
// product key is valid
break;
}
}
}
After submitting one of the keys with a valid expiry date, we get the flag:
HV23{santas-k3ygen-m4ster}