Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python wpa_passphrase (linux binary) implementation generates only part of the psk

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?


1 Answers

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"))
like image 178
yoonghm Avatar answered Oct 17 '25 05:10

yoonghm