Search code examples
pythonauthenticationhashfreeradius

Unable to compute FREERADIUS CHAP response based on ID + Password + Challenge in Python


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.


Solution

  • 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()