Boston Key Party CTF 2014 Crypto 200

MITM II: Electric BoogalooCrypto : 200
Chisa and Arisu are trying to tell each other two halves of a very important secret! They think they're safe, because they know how cryptography works---but can you learn their terrible, terrible secret? They're available as services at 54.186.6.201:12346 and 54.186.6.201:12345 respectively.
http://bostonkeyparty.net/challenges/mitm2-632e4ecc332baba0943a0c6471dec2c6.tar.bz2

没什么可讲的,纯实现题。。。

#!/usr/bin/python
# -*- coding: utf-8 -*-

import base64
import sys
import SocketServer
import mitmlib
import socket

class Person(object):
	def __init__(self, ip, port):
		self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		self.s.connect((ip, port))
		print "connected to %s" % ip
	
	def gen_share(self):
		self.secretshare, self.publicshare = mitmlib.mkshare()

	def send_share(self):
		self.s.sendall(str(self.publicshare[0]) + "," + str(self.publicshare[1]))

	def recv_share(self):
		got = self.s.recv(2048).split(',')
		self.partpubshare = tuple([int(got[0]), int(got[1])])
		self.aeskey = mitmlib.mksecret(self.secretshare, self.partpubshare)
	
	def recv_check(self):
		msg = self.s.recv(400)
		#print msg
		check = mitmlib.decrypt(self.aeskey, msg)
		#print check
		return check

	def send_enc(self, msg):
		self.s.send(mitmlib.encrypt(self.aeskey, msg))


	def recv_secret(self):
		return mitmlib.decrypt(self.aeskey, self.s.recv(400))

	def send_magic(self, magic):
		self.s.send(magic)
	def recv_magic(self):
		magic = self.s.recv(50)
		print magic

if __name__ == '__main__':
	arisu = Person('54.186.6.201', 12345)
	chisa = Person('54.186.6.201', 12346)

	chisa.send_magic("アリスです")
	chisa.recv_magic()

	arisu.recv_magic()
	arisu.send_magic("千佐だよ")

	arisu.gen_share()
	chisa.gen_share()

	arisu.recv_share()
	arisu.send_share()

	chisa.send_share()
	chisa.recv_share()

	cnt = 0
	while cnt < 19:
		cnt += 1
		print cnt
		check_a = arisu.recv_check()
		chisa.send_enc(check_a)
		check_b = chisa.recv_check()
		arisu.send_enc(check_b)
	secret = arisu.recv_secret()
	print secret
	chisa.send_enc(secret)
	print chisa.recv_secret()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值