SRM was another 50 point reverse engineering challenge at SharifCTF 2016. A binary was provided with the following description:
The flag is : The valid serial number.
file reported that the binary was a PE32 for Windows. So I fired up a Win7 VM and pulled up the disassembly in IDA.
Running the binary resulted in a dialog asking for an email address and a serial number.
A few quick test inputs showed that there was some validation of email address field and guesses at the serial resulted in ‘Registration Failure’ responses.
Looking at the file in IDA, DialogProc seems to handle all the logic. The HexRays decompiler failed to recognise the static array that is populated by the user’s input from the textBox.
After fixing the datatype definition to CHAR (Set IVAR Type from the context menu or ‘Y’ hotkey) the checks made later in the code become clear:
if ( strlen(KeyString?) != 0x10 || KeyString? != 'C' || KeyString? != 'X' || KeyString? != 'Z' || KeyString? + KeyString? != 0x9B || KeyString? != '9' || KeyString? + KeyString? != 0x9B || KeyString? != 'd' || KeyString? != '7' || KeyString? != 'm' || KeyString? != 'G' || KeyString? != 'q' || KeyString? + KeyString? != 0xAA || KeyString? != '4' || KeyString? != 'g' || KeyString? != 'c' || KeyString? != '8' )
We can see that much of the desired input is hardcoded. The remaining three items can be derived from the existing data:
KeyString is 0x9b - Keystring (‘Z’ or 0x7a)
Result: 0x41 (‘A’)
Calculating the rest of the derived characters results in the string:
Entering this key with a valid email address results in a ‘Registration Successful’ message and gives the flag for the challenge.