Reputation: 101
I'm trying to decrypt the Windows wireless password stored in the profile xml file using Python. I came across a blog post giving an example of how to do it calling Windows CryptUnprotectData using Python's win32crypt module. My problem is I get the Key not valid for use in specified state
error and need to run it using LocalSystem.
You will get that error even if you run cmd.exe as an administrator. Here's where you need to know a bit about Windows that, as a Windows n00b, I didn't know: the LocalSystem account is different from the administrator privilege. In order to run cmd.exe with the LocalSystem account, you need to install a Microsoft package called PsTools. Inside PsTools a program called PsExec, which is a little bit like sudo on Un*x. Just download the zip linked at the bottom of the Microsoft TechNet page above and unzip it somewhere where you can find it.
To use PsExec, open cmd.exe as an administrator (open the start menu in the bottom-left of your screen, type cmd.exe into the search box, and press Ctrl+Shift+Enter to run it as an admin). Hit "continue" on the User Account Control dialog box that opens. In the command shell that opens, navigate to the directory where you unzipped PsTools. Now run "psexec.exe /s /i cmd.exe". After you agree to PsTools's EULA, PsTools should open a new cmd.exe shell window running as LocalSystem.
Is there a way around this error without using psexec.exe
as the blog post states? Perhaps using CryptoPy or PyCrypto?
For reference, the encrypted password I retrieve is the keyMaterial key from the Windows Vista profile xml file.
The code I'm using:
import win32crypt
mykey='01000000D08C9DDF.....' # 308 characters long
binout = []
for i in range(len(mykey)):
if i % 2 == 0:
binout.append(chr(int(mykey[i:i+2],16)))
pwdHash=''.join(binout)
output = win32crypt.CryptUnprotectData(pwdHash,None,None,None,0)
print "hex:", "".join(["%02X" % ord(char) for char in output[1]])
print "ascii:", output[1]
Thanks in advance.
Upvotes: 3
Views: 2715
Reputation: 43533
Wht not ask your system administrator to give you LocalSystem privileges, if that is what you need?
BTW, don't bother with the complex conversion from hex to binary. Just do:
In [5]: '01000000D08C9DDF'.decode('hex')
Out[5]: '\x01\x00\x00\x00\xd0\x8c\x9d\xdf'
Upvotes: 1