Skip to content

Instantly share code, notes, and snippets.

@JKme
Created September 14, 2023 03:01
Show Gist options
  • Save JKme/ec42e202f652d2147b05cec280617cef to your computer and use it in GitHub Desktop.
Save JKme/ec42e202f652d2147b05cec280617cef to your computer and use it in GitHub Desktop.
用于解密的chrome cookie提取用于Cookie Editor的脚本,方便提取google账号的Cookie
import sqlite3
import sys
import json
def main():
if len(sys.argv) != 3:
print('Usage: python script.py <db_path> <filter_value>')
return
db_path = sys.argv[1]
filter_value = sys.argv[2]
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
query = "SELECT host_key, expires_utc, is_httponly, path, encrypted_value, is_secure, samesite, name FROM cookies WHERE host_key = ?"
cursor.execute(query, (filter_value,))
cookies = []
for row in cursor.fetchall():
cookie = {
"domain": row[0],
"expirationDate": row[1],
"hostOnly": False,
"httpOnly": bool(row[2]),
"name": row[7],
"path": row[3],
"sameSite": "no_restriction" if row[6] == 0 else None,
"secure": bool(row[5]),
"session": False,
"storeId": None,
"value": row[4] # Assuming the encrypted_value is utf-8 encoded
}
if cookie.get("name") == "SEARCH_SAMESITE":
cookie.update({"sameSite": "strict"})
if cookie.get("name") == "AEC":
cookie.update({"sameSite": "lax"})
if cookie.get("name") == "__Secure-OSID":
cookie.update({"hostOnly": True})
if cookie.get("name") == "OTZ":
cookie.update({"hostOnly": True})
if cookie.get("name") == "OSID":
cookie.update({"hostOnly": True})
# cookie.pop("SNID")
# cookie.pop("_ga")
cookies.append(cookie)
with open('tmp2.json', 'a+') as f:
json.dump(cookies, f, indent=4)
f.write(",\n")
print('Finished writing cookies to cookies.json')
conn.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment