Today, I am going to write about a Crypto challenge from ABCTF. Although it is just a competition for high school student, it still contains funny stuffs.
In this challange, they give us:
See if you can break this!!
You can connect with nc 107.170.122.6 7765 and the source can be found [here](http://pastebin.com/UTkSDn4H).
#/usr/bin/env pythonfromCrypto.Cipher.AESimportAESCipherimportSocketServer,threading,os,timeimportsignalfromsecret2importFLAG,KEYPORT=7765defpad(s):l=len(s)needed=16-(l%16)returns+(chr(needed)*needed)defencrypt(s):returnAESCipher(KEY).encrypt(pad('ENCRYPT:'+s.decode('hex')+FLAG))classincoming(SocketServer.BaseRequestHandler):defhandle(self):atfork()req=self.requestdefrecvline():buf=""whilenotbuf.endswith("\n"):buf+=req.recv(1)returnbufsignal.alarm(5)req.sendall("Send me some hex-encoded data to encrypt:\n")data=recvline()req.sendall("Here you go:")req.sendall(encrypt(data).encode('hex')+'\n')req.close()classReusableTCPServer(SocketServer.ForkingMixIn,SocketServer.TCPServer):passSocketServer.TCPServer.allow_reuse_address=Trueserver=ReusableTCPServer(("0.0.0.0",PORT),incoming)print"Server listening on port %d"%PORTserver.serve_forever()
As you see, the service receives our message, uses AES Encryption to encrypt the received message, then returns the ciphertext for us.
My favor scripting lannguage is Python.
I use my own lib - (punpwn)[https://github.com/tungpun/punpwn], that was forked from (pwntools lib)[pwntools.readthedocs.org].