# Plaid CTF 2016 – Tonnerre解题思路

## 解决方案

• `salt` , 一个随机的127字节字符串

• `verifier` , 一个随机的145字节字符串

``N = ... # a 1024-bit prime number, the group modulus  g = ... # a 671-bit number, a group generator  ...     # generates a key pair     random_server = random.randint(2, N-3)     public_server = pow(g, random_server, N)      # mask the public key with the verifier     residue = (public_server + permitted_users[username][1]) % N      # send salt and masked pubkey     req.sendall(tostr(permitted_users[username][0]) + '/n')     req.sendall(tostr(residue) + '/n')      # compute the session key,     #   masking the client pubkey with the verifier     #   raising to the server's secret exponent     #   hashign the whole thing using SHA-256     session_secret = (public_client * permitted_users[username][1]) % N     session_secret = pow(session_secret, random_server, N)     session_key = H(tostr(session_secret))      # receive a proof from the client..     proof = req.recv(512).strip('/n')      # ..should be a hash of the server's masked pubkey and session key     if (proof != H(tostr(residue) + session_key)):       req.sendall('Sorry, not permitted./n')       req.close()       return      # this is useless for the challenge     our_verifier = H(tostr(public_client) + session_key)     req.sendall(our_verifier + '/n')      # send us the flag!     req.sendall('Congratulations! The flag is ' + flag + '/n')     req.close() ``

``(C * verifier)^s = g^(cs) * verifier^s ``

``random_client = random.randint(2, N-2) public_client = pow(g, random_client, N)  invver = modinv(verifier, N)  public_client2 = invver * public_client % N  if ((public_client2 * verifier) % N) == public_client:     print 'verifier verified'  s.sendall(tostr(public_client2) + '/n')  # get salt and server pubkey salt = int(s.recv(512).strip('/n'), 16) % N residue = int(s.recv(512).strip('/n'), 16) % N public_server = (residue - verifier + N) % N  session_secret = pow(public_server, random_client, N) session_key = H(tostr(session_secret))  proof = H(tostr(residue) + session_key)  s.sendall(proof + '/n') time.sleep(0.5) r = s.recv(512).strip('/n') print r ``

## 获得结果

``python tonnerre_solve.py Welcome to the Tonnerre Authentication System!  verifier verified ca787059bc572bc7902c91d2a168226a32052518073f4c32948ff02826e6be22 Congratulations! The flag is PCTF{SrP_v1_BeSt_sRp_c0nf1rm3d}``

*原文链接： duksctf ，鸢尾编译，转载请注明来自FreeBuf黑客与极客（FreeBuf.COM）