Skip to content

Instantly share code, notes, and snippets.

@ducnhse130201
Created April 28, 2019 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ducnhse130201/aaee8689ff2fc23a2d9403ea9e405275 to your computer and use it in GitHub Desktop.
Save ducnhse130201/aaee8689ff2fc23a2d9403ea9e405275 to your computer and use it in GitHub Desktop.
crypto2_solve_matess3r4
from telnetlib import *
import json
import hashlib
from Crypto.Util.number import *
from libnum import *
r = Telnet('125.235.240.166', 13337)
def get_key():
data = json.loads(r.read_until("\n").strip())
N, g, k = data['N'], data['g'], data['k']
return N,g,k
def exchanged_key(A, usn):
data = '{"A":%s,"username":"%s"}' % (A, usn)
r.write(data + "\n")
def get_back():
data = json.loads(r.read_until("\n").strip())
salt, B = data['salt'], data['B']
return salt,B
def check_token(token):
data = '{"token":"%s"}' % str(token)
r.write(data + "\n")
r.interact()
def hmac(salt, data, hex):
if hex:
return hashlib.sha512(salt + data).hexdigest()
return hashlib.sha512(salt + data).digest()
def create_key(salt,A,B,k,g,rand_num,N,password):
xH = hmac(str(salt), password, 0)
x = bytes_to_long(xH)
uH = hmac(str(A), str(B), 0)
u = bytes_to_long(uH)
S = pow(B - k * pow(g, x, N), rand_num + u * x, N)
K = hmac('', str(S), 0)
return hmac(K, str(salt), 1)
N,g,k = get_key()
exchanged_key(str(N**2), "peterjson")
salt,B = get_back()
K = hmac('', str(0), 0)
h = hmac(K, str(salt), 1)
print h
check_token(h)
# h = create_key(salt, A, B, k, g, 17, N, "hehe")
# check_token(h,str(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment