def guess_bute(k): results = [] plaintexts = [ '\x00' * (k) + chr(i) + '\x00' * (15-k) for in xrange(2,256)] ciphertexts = [encrypt(t) for t in plaintexts] keys = [chr(i) * 16 for i in xrange(0,256)] for k in keys: cands
def test_encrypt_message_length_multiple_of_block_size(self): block_size = 16 key = 'K' * block_size init_vector = 'I' * block_size message = 'M' * (block_size * 2) padder = '-' encrypted = client.encrypt(message, block_size, padder, key, init_vector) obj = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_CBC, init_vector) padded_message = obj.decrypt(encrypted) new_message = padded_message.lstrip(padder) self.assertEqual(padded_message, message) self.assertEqual(new_message, message)
def test_encrypt_message_length_less_than_block_size(self): block_size = 16 offset = 7 key = 'K' * block_size init_vector = 'I' * block_size message = 'M' * (block_size - offset) padder = '-' encrypted = client.encrypt(message, block_size, padder, key, init_vector) obj = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_CBC, init_vector) padded_message = obj.decrypt(encrypted) padding = padded_message[:offset] for char in padding: self.assertEqual(char, padder) new_message = padded_message[offset:] self.assertEqual(new_message, message)
client = session.Session(secret_key) client_nonce = client.send_plaintext_nonce() s.send(client_nonce) data = s.recv(BUFFER_SIZE) clients_nonce_encrypted_by_server = data clients_nonce_and_servers_remainder_decrypted_by_client, servers_nonce = client.decrypt_nonce( clients_nonce_encrypted_by_server) servers_nonce_encrypted_by_client = client.encrypt_nonce(servers_nonce) s.send(servers_nonce_encrypted_by_client) client.set_session_key( clients_nonce_and_servers_remainder_decrypted_by_client) #Server Challenge Client data = s.recv(BUFFER_SIZE) challenge_plaintext = data.decode('utf-8') challenge_cryptotext = client.encrypt(challenge_plaintext) s.send(challenge_cryptotext) data = s.recv(BUFFER_SIZE) auth_response = data.decode('utf-8') #Client Challenge Server chars = string.ascii_letters + string.digits + string.punctuation pwdSize = 8 random_client_challenge = ''.join( (random.choice(chars)) for x in range(pwdSize)) s.send(random_client_challenge.encode('utf-8')) server_challenge_response = s.recv(BUFFER_SIZE) client_cryptotext = client.encrypt(random_client_challenge) if server_challenge_response == client_cryptotext:
from client import encrypt_request, encrypt, get_encrypted_flag import itertools # candidates = [[0,1,2],[0,3],...] # for key in itertools.product(*candidates) plaintexts = [ chr(i) + '\x00' * 15 for i in xrange(0,256) ] ciphertexts = [encrypt(t) for t in plaintexts] def xor(key, text): [chr(ord(k) ^ ord(t)) for (k, t) in zip(key, text)] def guess_bute(k): results = [] plaintexts = [ '\x00' * (k) + chr(i) + '\x00' * (15-k) for in xrange(2,256)] ciphertexts = [encrypt(t) for t in plaintexts] keys = [chr(i) * 16 for i in xrange(0,256)] for k in keys: cands
def ask_server(msg): print("Ask: {}".format(msg)) print(encrypt(msg))
for j in xrange(0, 16): res.append(''.join((chr(i), chr(j + 1), chr(1)))) return res def generate_A_pairs(): res = [] for i in xrange(0, 256): for j in xrange(0, 16): res.append(''.join((chr(1), chr(16 + j), chr(i)))) return res pairs_A = generate_A_pairs() pairs_B = generate_B_pairs() left_pool = {} right_pool = {} for p_a in pairs_A: c_a = encrypt(p_a) right_pool[right(c_a)] = (p_a, c_a) for p_b in pairs_B: c_b = encrypt(p_b) left_pool[left(c_b)] = (p_b, c_b) if left(c_b) in left_pool: print(right_pool(left(c_b))) print(p_b, c_b)
#Authentication print("Starting Authentication") client = session.Session(secret_key) client_nonce = client.send_plaintext_nonce() s.send(client_nonce) data = s.recv(BUFFER_SIZE) clients_nonce_encrypted_by_server = data clients_nonce_and_servers_remainder_decrypted_by_client, servers_nonce = client.decrypt_nonce(clients_nonce_encrypted_by_server) servers_nonce_encrypted_by_client = client.encrypt_nonce(servers_nonce) s.send(servers_nonce_encrypted_by_client) client.set_session_key(clients_nonce_and_servers_remainder_decrypted_by_client) #Server Challenge Client data = s.recv(BUFFER_SIZE) challenge_plaintext = data.decode('utf-8') challenge_cryptotext = client.encrypt(challenge_plaintext) s.send(challenge_cryptotext) data = s.recv(BUFFER_SIZE) auth_response = data.decode('utf-8') #Client Challenge Server chars = string.ascii_letters + string.digits + string.punctuation pwdSize = 8 random_client_challenge = ''.join((random.choice(chars)) for x in range(pwdSize)) s.send(random_client_challenge.encode('utf-8')) server_challenge_response = s.recv(BUFFER_SIZE) client_cryptotext = client.encrypt(random_client_challenge) if server_challenge_response == client_cryptotext: s.send("AUTHENTICATION SUCCESSFUL".encode('utf-8'))