我正在尝试使用 Python 解密存储在配置文件 xml 文件中的 Windows 无线密码。我遇到了 blog post举例说明如何调用 Windows CryptUnprotectData使用 Python 的 win32crypt 模块。我的问题是我收到 Key not valid for use in specified state
错误,需要使用 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.
有没有如博文所述不使用 psexec.exe
解决此错误的方法?也许使用 CryptoPy 或 PyCrypto?
作为引用,我检索到的加密密码是 Windows Vista 配置文件 xml 文件中的 keyMaterial key 。
我使用的代码:
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]
提前致谢。
最佳答案
如果您需要的话,为什么不让您的系统管理员给您 LocalSystem 权限呢?
顺便说一句,不要为从十六进制到二进制的复杂转换而烦恼。只是做:
In [5]: '01000000D08C9DDF'.decode('hex')
Out[5]: '\x01\x00\x00\x00\xd0\x8c\x9d\xdf'
关于python - 使用 Python 解密 Windows 无线密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11445058/