Vertinet

Cryptography - 140 Points

Welcome to Vertinet.

This problem follows the same specifications as the previous Verticode problem, except that you have to solve many of them by developing a client to communicate with the server available at problems1.2016q1.sctf.io:50000. Good luck.

Writeup

Once solved the Verticode, this Challenge was pretty straightforward.

I tried to connect with nc and the server was printing an HTML page like this

<html><img src='data:image/png;base64,BASE64_HERE'></img><br><br>

And wait for our response (the solution for that Verticode). So I edited the previous script with some Networking and Base64 Library. Done.

#!/usr/bin/env python

import os, sys
import base64
from io import BytesIO
import Image
from socket import socket
import re

def parse_bin(r,g,b):
	 if r+g+b == 0:
	  	return 1
	 else:
	  	return 0 # white is the new black 0

def parse_color(r,g,b):
	 if r == 255 and g == 0 and b == 0: #Red
	 	 return 0
	 if r == 128 and g == 0 and b == 128: #Purple
	    return 1
	 if r == 0 and g == 0 and b == 255: #Blue
	  	return 2
	 if r == 0 and g == 128 and b == 0: #Green
	  	return 3
	 if r == 255 and g == 255 and b == 0: #Yellow
	  	return 4
	 if r == 255 and g == 165 and b == 0: #Orange
		  return 5

def main():
	 sock = socket()
	 sock.connect(('problems1.2016q1.sctf.io', 50000))
	 while 1:
	 	 text = ""
	 	 while True:
	 	  	c = sock.recv(1024)
	 	  	print c
	 	  	text += c
	 	  	if "</img>" in text:
 		   		break
 			  if "sctf" in text:
 			   	exit(0)
 		 with open("out.txt", "a") as text_file:
 			  text_file.write(text+"\n")
 		 r = re.compile(r"base64,(.+?)'>")
 		 img = r.findall(text)[0]
 		 im = Image.open(BytesIO(base64.b64decode(img)))
 		 pix = im.load()
 		 m = 12
 		 data = ""
 		 key = ""
 		 for i in xrange(im.size[1]/m): # Row
 		  	color = 0
 			  for j in xrange(im.size[0]/m): # Col
 				   if j == 0:
 				  	r,g,b = pix[0,i*m]
 					  color = parse_color(r,g,b)
 			 	if j>=7:			
 				  	r,g,b = pix[j*m,i*m]
 				  	data += str(parse_bin(r,g,b))
 				 if j==13:
 				  	key += chr(int(data, 2)-color)
 				  	data = ""
 		 print key
 		 sock.send(key)

	 sock.close()
	 return 0

if __name__ == '__main__':
 	main()

A Lot of Verticode later…

sctf{y0ub34tth3v3rt1c0d3}