1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| from Crypto.Cipher import AES from Crypto.Util.number import long_to_bytes from datetime import datetime, timedelta from pickle import loads from hashlib import md5 from requests import * from math import floor from libnum import n2s import time A = md5(b'A').hexdigest()[:16] B = md5(b'B').hexdigest()[:16] S = md5(b'S').hexdigest()[:16] delta_8_hours = timedelta(hours=8) url = 'http://8.147.131.163:15917' token_A = A token_B = B
def regist(url,token): print(f'[+] use token : {token}') prefix = '/register' params = {'token':token} result = get(url+prefix,params) print(result.text) cur_key = eval(result.text)["key_to_server"] print(f'[+] get key : {cur_key}') return cur_key
def send_msg(url,token,target_token,target,cur_key_token): prefix = '/send_message' timestamp_minus_8_hours = datetime.fromtimestamp(time.time()) - delta_8_hours t = timestamp_minus_8_hours.timestamp() t = n2s(int(t)).rjust(16, b'0') source = bytes.fromhex(target_token) key = b'\x00' * 16 pad = b'\x00' * 8 msg = t + source + key + pad
Cipher = AES.new(bytes.fromhex(cur_key_token), AES.MODE_ECB) message = Cipher.encrypt(msg) payload = message.hex() assert len(payload) == 16 * 3 * 2 if not len(payload) == 16 * 3 * 2:print('?') params = {'token':token,'to':target,'message':payload} result = get(url+prefix,params) return result.text
def send_flag(url,token): prefix = '/send_flag' params = {'token':token} result = get(url+prefix,params) return result.text
def exchange(url,token): prefix = '/A_and_B' params = {'token':token} result = get(url+prefix,params) return result.text
def view_history(url,token): prefix = '/view_history' params = {'token':token} result = get(url+prefix,params) return(result.text)
''' #打法一,直接伪造A对B的发信密钥,让A和B交换一次会话密钥,用发信密钥解密,之后通话就随便监听了
A_key = regist(url,A) #B_key = regist(url,B)
print(f'A_key={A_key}') #print(f'B_key={B_key}')
exchange(url,A) #view_history(A) send_flag(url,A) print(view_history(url,A)) ''' ''' #打法二,利用send_message函数去控制双方的会话密钥,强行让他们相等 A_key = regist(url,A) send_msg(url,A,B,'A',A_Key) send_msg(url,A,A,'B',A_Key) send_flag(url,A) print(view_history(url,A)) #凭记忆写的,可能流程不太对,大致这个思路能过,好处是直接一次性拿下会话密钥。 '''
''' print(A) key = '5fa11352bb62df887404c4da9a8357c9' Cipher = AES.new(bytes.fromhex(key),AES.MODE_ECB) orin_key_cipher = 'ad6c4e00649df28c1e89ea2c19ed49c8257e4cf9d66ed7b76fc76b17254fd5859c10b0c5983f4b3d35e78ac8d2649594' print(bytes.fromhex(orin_key_cipher)) key_ = Cipher.decrypt(bytes.fromhex(orin_key_cipher)) print(key_) print(key_[32: 48].hex())
key0 = 'b5768d25a0c3a76516136dc81e852300' Cipher = AES.new(bytes.fromhex(key0),AES.MODE_ECB) orin_cipher = '90ceb8ced60d9ed6d244edb9345505273ec51c9e32ff15bfd4bba14b0b1cbefdeb699c3a18affbf5fab5b91051f893f6' flag = Cipher.decrypt(bytes.fromhex(orin_cipher)) print(flag) '''
|