def recv_msg(self): cipher = self.s.recv(2048) iv = cipher[0:16] cipher = cipher[16:] #print 'iv - ',iv #print 'cipher - ',cipher return chal10.decrypt_CBC(cipher, self.key, iv)
def decrypt_oracle(ciphertext): plaintext = chal10.decrypt_CBC( ciphertext, KEY, iv) #The function will implicitly check for correct padding s_elements = plaintext.split(';') print s_elements if 'admin=true' in s_elements: return True else: return False
g = 2 a = randint(1, p) A = pow(g, a, p) packet = {} packet['p'] = p packet['g'] = g packet['A'] = A c.send(json.dumps(packet)) print "p,g,A sent to B" response = json.loads(c.recv(1024)) B = response['B'] print 'B received' msg = "Hello B" s = pow(B, a, p) hash = SHA1() hash.update(str(s)) key = hash.hexdigest()[0:16] #print key iv = chal11.get_random_bytes(16) #print 'iv - ',iv cipher = chal10.encrypt_CBC(msg, key, iv) cipher = iv + cipher #print cipher c.send(cipher) response = c.recv(1024) cipher = response[16:] iv = response[:16] msg = chal10.decrypt_CBC(cipher, key, iv) print 'Message from B - ', msg c.close()
def recv_msg(self): response = self.c.recv(1024) cipher = response[16:] iv = response[:16] return chal10.decrypt_CBC(cipher, self.key, iv)
def check_CBC_padding_oracle(ciphertext, key, iv): try: palintext = chal10.decrypt_CBC(ciphertext, key, iv) return True except: return False