Reputation: 137
I'm struggling to compute the response hash based on the CHAP ID + Plaintext Password + Challenge Hash.
Following is my code thus far :
def computeResponse(id_hex,password, challenge):
#id_hex_result = id_hex.encode("hex")
result = id_hex+password+challenge
print result
response = hashlib.md5(result).hexdigest()
print "Generated: ",response
print "Captured : ef53ae181830c4822f14ca826054cc8c"
computeResponse("1","SantaCruzpass","c8ec74267d0bbff78fe49abf756c211d")
The response generated was different as shown below the results :
Generated: e6d0a07960e4d15153caf37fd06cdc8e
Captured : ef53ae181830c4822f14ca826054cc8c
Generated hash is the response computed by the program while the Captured hash is the actual response hash captured during authentication between HQ and Freeradius.
Am i doing it wrongly here ? The CHAP Id captured was "0x01" which yields the hexadecimal value of 1.
Upvotes: 0
Views: 1165
Reputation: 26
I had the same problem. My solution is:
def check_chap_password(clear_text_password, chap_challenge, chap_password):
chap_id = chap_password[0:2]
check_chap_password = chap_id + hashlib.md5(bytearray.fromhex(chap_id) + password + bytearray.fromhex(chap_challenge)).hexdigest()
return check_chap_password == chap_password
Example:
check_chap_password('hello', '2d8f0e32ee566a4f26a9dc46eefeafc0', '6db35db7cf22ecc964ccbb9e6fa8afef')
Upvotes: 0
Reputation: 74
Your password is already in binary form.
Try the following:
Just binascii.unhexlify the id_hex and challenge and you will get what you need.
def computeResponse(id_hex,password, challenge):
id_hex = binascii.unhexlify(id_hex)
challenge = binascii.unhexlify(challenge)
result = id_hex+password+challenge
print result
response = hashlib.md5(result).hexdigest()
Upvotes: 1