I heard you liked zip codes! Connect via nc c1.easyctf.com 12483 to prove your zip code knowledge.
Connecting to the server we receive some questions like this one:
There are only 4 types of question.
I noted that when you send a wrong answer, the server gives you the right answer and closes the connection.
My first idea was to answer wrong stuff, and then store the right answer sent by the server in a SQLite database. When having the right answer in the database, sending it, and when not, sending random stuff to get and store the right answer.
So I made a ruby script to achieve that:
The script was perfectly working but that was far too long because of several issues:
each wrong answer close the connection so you loose time opening a new one
waiting for 3... 2... 1... Go!
there are thousands of zip code and 4 possible data values for each
Another idea I had before beginning my script was to use a web API but those are rather limited and never contains the wanted information.
So I read the server header again and I saw this: based on the 2010 Census. Using my web browser I found the U.S. Gazetteer Files that is The U.S. Gazetteer Files provide a listing of all geographic areas for selected geographic area types. The files include geographic identifier codes, names, area measurements, and representative latitude and longitude coordinates..
So I downloaded the 2010 ZIP Code Tabulation Areas file and looked at it:
I was pretty sure the author of the challenge was using this file too so I wrote a new ruby script again:
I don't like it when people try to view source on my page. Especially when I put all this effort to put my flag verbatim into the source code, but then people just look at the source to find the flag! How annoying.
This time, when I write my wonderful website, I'll have to hide my beautiful flag to prevent you CTFers from stealing it, dagnabbit. We'll see what you're able to find...
Looking at the source code, we can see a script inside <script></script>:
process(a, b) is just a xor function and flag is the encrypted (xored) flag. The xor key is global.encryptionKey so this is window.encryptionKey that is available in the browser.
I opened Firefox Web Developer toolbar and switched to the Console tab. Then it was easy to reverse the process: