在windows上使用linux Cookie时出现解密问题

2024-03-29 10:32:42 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图在Linux(Ubuntu)和Windows上使用Cookies文件(sqlite fomated)时,我遇到了解密“加密值”的麻烦。有没有机会让Cookies文件兼容两个系统?在

基本上,selenium驱动程序使用Cookies文件进行各种用途,并且一切都在Linux上运行。有时需要我的操作,所以我想把这个Cookies文件放在桌面上,在Windows上运行,但是当我直接下载它并复制粘贴到我的配置文件目录时,我的chromedriver会记录错误:

[4708:4884:0604/082853.607:错误:os_crypt_win.cc(61)]解密失败:参数不正确。(0x57)

我假设“encrypted_value”列解密存在一些问题,但我无法解决此问题。在

我使用selenium for python这是一个片段,我在其中为我的webdriver创建选项:

def create_options_for_webdriver(session_directory):
    print('Creating options for webdriver!')
    options = Options()
    options.add_argument("user-data-dir=my_userdir")
    options.add_argument("user-agent=my_useragent")
    options.add_argument('--disable-background-networking ')
    options.add_argument('--disable-client-side-phishing-detection')
    options.add_argument('--disable-default-apps')
    options.add_argument('--disable-hang-monitor')
    options.add_argument('--disable-popup-blocking')
    options.add_argument('--disable-prompt-on-repost')
    options.add_argument('--disable-sync')
    options.add_argument('--disable-web-resources')
    options.add_argument('--enable-automation')
    options.add_argument('--enable-blink-features=ShadowDOMV0')
    options.add_argument('--force-fieldtrials=SiteIsolationExtensions/Control')
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--no-first-run')
    options.add_argument('--password-store=basic')
    options.add_argument('--use-mock-keychain')
    return options

在创建选项之前,我创建一个最小的目录结构,它看起来像我的\u userdir/Default/,并将Cookies文件下载到默认文件夹中。在


Tags: 文件addformylinuxwindows选项selenium
2条回答

回来更新! 似乎,正如@jww所提到的,这个过程比较复杂,但只是有一点:)

为了使Cookies与任何操作系统完全兼容,必须进行一些特殊处理。在

在我的例子中,我使用pickle库创建兼容文件。要实现这一目标,需要做如下工作:

from selenium.webdriver import Chrome
import pickle
driver = Chrome()
####here you do some job which generate cookies like FB login or whatever
input("Press any key to close session") #you cant simply close browser, in order to make it work browser have to be closed in console so the rest of script will execute
pickle.dump(driver.get_cookies(), open('cookies.pkl',"wb"))
driver.quit()
print("Session closed!")

这将创建饼干.pkl可以在任何操作系统下访问的文件:

^{pr2}$

正如我提到的,这种cookies文件在任何操作系统下都可以工作,遗憾的是它迫使我使用selenium,但这比什么都不做要好:)

... when I download it directly and copy-paste it to my profile directory, my chromedriver logs error:

[... ERROR:os_crypt_win.cc(61)] Failed to decrypt: The parameter is incorrect. (0x57)

看来这是不可能的。或者也许你不可能这么做。这需要额外的努力。在

问题Decrypting Chrome's cookies on windows有一个指向^{}的链接。os_crypt_win.cc使用DPAPI,这是旧的WinCrypt齿轮。DPAPI将加密绑定到用户的Windows登录。DPAPI还将MAC放在加密数据上。我相信MAC是您看到消息的原因:“参数不正确”。DPAPI发现MAC上加密的数据是错误的,它会给你一般的错误消息。在

因此,如果您真的想在Windows上使用Linux cookie,您需要使用Linux规范对其进行解密,然后使用Windows规范重新加密它

如果你要追求它,那么你可能想要访问这个黑帽演讲:Reversing dpapi and stealing windows secrets offline。它允许您在Linux for Windows上加密用户的数据。在

相关问题 更多 >