This is a writeup of the reversing challenge 'REG EX' from PlaidCTF 2015.
The challenge provided two files: a python server program and a crazy-huge regex (see regex.txt
). The python server is very basic: it simply listens for a connection, prompts for a 'key', and then checks whether the key matches the regex. It will then send the flag, but only if the provided key did NOT match the regex.
After the initial shock of looking at many screenfulls of regex, it actually breaks down into simple chunks. The regex consists of a single group which must match the entire string (^(...)$
), containing a number of alternatives. Because we need to find a string which does not match the regex, we need to ensure that none of the alternatives match our string. The first alternative (.*[^plaidctf].*
) will match any string which contains any character not in 'plaidctf', so we know our solution will contain only those characters. The second two alternatives (.{,170}|.{172,}
) will match any string