python操作谷歌浏览器,python获取chrome cookies

大家好,小编为大家解答python操作谷歌浏览器的问题。很多人还不知道python获取chrome cookies,现在让我们一起来看看吧!

使用Python破解谷歌Chrome浏览器存储密码

目前,谷歌浏览器80以后版本改进了用户存储在本机密码的加密方式,以往的破解密码方法不可行了!以下是博主测试可行的破解方法。

采用Python,安装两个包pywin32和cryptography,可以使用pip install pywin32, pip install cryptographypython简单代码画皮卡丘。具体破解代码如下:

import os,json,base64,sqlite3
from win32crypt import CryptUnprotectData
from cryptography.hazmat.primitives.ciphers.aead import AESGCM 

 
class Chrome:
  def __init__(self):
    self.local_state = os.environ['LOCALAPPDATA'] + r'\Google\Chrome\User Data\Local State'
    self.cookie_path = os.environ['LOCALAPPDATA'] + r"\Google\Chrome\User Data\Default\Login Data"
 
  def get_key(self):
    with open(self.local_state, 'r', encoding='utf-8') as f:
      base64_encrypted_key = json.load(f)['os_crypt']['encrypted_key']
    encrypted_key_with_header = base64.b64decode(base64_encrypted_key)
    encrypted_key = encrypted_key_with_header[5:]
    key_ = CryptUnprotectData(encrypted_key, None, None, None, 0)[1]
    return key_
 
  @staticmethod
  def decrypt_string(key, secret, salt=None): 
    nonce, cipher_bytes = secret[3:15], secret[15:]
    aes_gcm = AESGCM(key)
    return aes_gcm.decrypt(nonce, cipher_bytes, salt).decode('utf-8')
 
 
  def get_password(self):
    sql = "select username_value,password_value,signon_realm from logins"
    with sqlite3.connect(self.cookie_path) as conn:
      cu = conn.cursor()
      res = cu.execute(sql).fetchall()
      cu.close()
      result = []
      key = self.get_key()
 
      for name, encrypted_value,website in res: 
        if encrypted_value[0:3] == b'v10' or encrypted_value[0:3] == b'v11':
          passwd = self.decrypt_string(key, encrypted_value)
        else:
          passwd = CryptUnprotectData(encrypted_value)[1].decode()
        print('网站:{},用户名:{},密码:{}'.format(website,name, passwd))
 
 
if __name__ == '__main__':
  c = Chrome()
  c.get_password()
 

祝大家破解愉快!

  • 23
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Python的Selenium库来清理谷歌浏览器缓存。具体步骤如下: 1. 首先需要导入Selenium库和webdriver模块,以及ChromeOptions类和Options类。 ```python from selenium import webdriver from selenium.webdriver.chrome.options import Options ``` 2. 创建一个ChromeOptions对象,并设置浏览器参数。 ```python options = Options() options.add_argument('--ignore-certificate-errors') options.add_argument('--ignore-ssl-errors') ``` 3. 创建一个WebDriver对象,并使用ChromeOptions对象作为参数来设置浏览器参数。 ```python driver = webdriver.Chrome(chrome_options=options) ``` 4. 打开浏览器,并访问需要清理缓存的网站。 ```python driver.get('https://www.example.com') ``` 5. 使用execute_script()方法执行JavaScript代码来清理缓存。 ```python driver.execute_script('window.localStorage.clear();') driver.execute_script('window.sessionStorage.clear();') driver.execute_script('window.location.reload();') ``` 6. 关闭浏览器。 ```python driver.quit() ``` 完整的代码示例: ```python from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--ignore-certificate-errors') options.add_argument('--ignore-ssl-errors') driver = webdriver.Chrome(chrome_options=options) driver.get('https://www.example.com') driver.execute_script('window.localStorage.clear();') driver.execute_script('window.sessionStorage.clear();') driver.execute_script('window.location.reload();') driver.quit() ``` 注意:这个方法只能清理浏览器缓存,不能清理浏览器历史记录和cookie等其他数据。如果需要清理其他数据,可以使用selenium的delete_all_cookies()方法来删除cookie
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值