3
wpa_passphrase "testing" "testingpassword"network={
    ssid="testing"
    #psk="testingpassword"
    psk=ae9400eac47807861c32f6b2d52434594fe1f1cbbd5ae0d89d5199ea5e4c79aa
}

I did a python script as this wikipedia article tells me how to compute wpa psk:

https://en.wikipedia.org/wiki/Wi-Fi_Protected_Access#Target_users_.28authentication_key_distribution.29

like this:

import hashlib, binascii
def wpa_psk(ssid, password):
    dk = hashlib.pbkdf2_hmac('sha1', str.encode(password), str.encode(ssid), 4096)
    return (binascii.hexlify(dk))

print((wpa_psk("testing", "testingpassword")))

Output: b'ae9400eac47807861c32f6b2d52434594fe1f1cb'

Which is part of the psk generated by the wpa_passphrase tool. What's missing?

  • I do not see any instruction in that wikipedia article. I think I am confused on what you are trying to accomplish. Are you trying to receive a psk then convert it to a hash value? – Joe Sep 29 '17 at 23:25
  • What's missing is the (nondefault value for) keyword argument dklen described in https://docs.python.org/2/library/hashlib.html#key-derivation – dave_thompson_085 Sep 30 '17 at 00:57

3 Answers3

3

It may be too late now, I came across this question, you could do this:

import hashlib, binascii

def wpa_psk(ssid, password):
    dk = hashlib.pbkdf2_hmac(
        'sha1',
        str.encode(password),
        str.encode(ssid),
        4096,
        256
    )
    return (binascii.hexlify(dk))

print((wpa_psk('testing', 'testingPassword')[0:64].decode('utf8')))

The output is

131e1e221f6e06e3911a2d11ff2fac9182665c004de85300f9cac208a6a80531

You could make this into a script:

import hashlib, binascii
from getpass import getpass

def wpa_psk():
    '''
    Encrypt password using ssid and password for WPA and WPA2
    '''
    ssid=input("SSID: ")
    dk = hashlib.pbkdf2_hmac(
        'sha1', str.encode(getpass("Password: ")),
        str.encode(ssid), 4096, 32
    )
    print(binascii.hexlify(dk).decode("UTF-8"))
yoonghm
  • 4,198
  • 1
  • 32
  • 48
3

The only thing missing was an specifying the dklen parameter when calling hashlib.pbkdf2_hmac(). This parameter should be set to 32.

import hashlib, binascii
def wpa_psk(ssid, password):
    dk = hashlib.pbkdf2_hmac('sha1', str.encode(password), str.encode(ssid), 4096, 32)
    return (binascii.hexlify(dk))

print((wpa_psk("testing", "testingpassword")))
2

After a long Internet search , finally I found psk.py. Able to compute the PSK from SSID and Passphrase. Please check :-)

Veerendra K
  • 2,145
  • 7
  • 32
  • 61