Skip to content

Instantly share code, notes, and snippets.

@denis-bz
Created January 15, 2016 10:28
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save denis-bz/88611952815b56b5b8b5 to your computer and use it in GitHub Desktop.
List Firefox cookies, in python
#!/usr/bin/env python
''' In: a firefox cookies.sqlite file
default $HOME/Library/Application\ Support/Firefox/Profiles/*/cookies.sqlite
Out: urls in the file, one per line on stdout
modified https://linuxfreelancer.com/decoding-firefox-cookies-sqlite-cookies-viewer
'''
# google python sqlite3 "delete cookies" ? looks mttiw
import glob
import os
import sqlite3
import sys
__version__ = "2016-01-14 jan denis-bz-py t-online de"
def Usage():
print "/.../cookies.sqlite not found"
sys.exit(1)
def dollarstar( filename ):
""" expand $vars, * """
filename = os.path.expandvars( filename ) # e.g. $HOME
names = glob.glob( filename ) # -> [] or [name ...]
return names[0] if len(names) > 0 else filename # 2 or more ?
if len(sys.argv) >= 2:
sqldb = sys.argv[1]
else:
sqldb = dollarstar( "$HOME/Library/Application Support/Firefox/Profiles/*/cookies.sqlite" )
if not os.path.isfile(sqldb):
Usage()
#...............................................................................
# Bind to the sqlite db and execute sql statements
conn = sqlite3.connect(sqldb)
cur = conn.cursor()
try:
data = cur.execute('select * from moz_cookies')
except sqlite3.Error, e:
print 'Error {0}:'.format(e.args[0])
sys.exit(1)
mydata = data.fetchall()
# 0 id
# 1 baseDomain
# 2 appId
# 3 inBrowserElement
# 4 name
# 5 value
# 6 host
# 7 path
# 8 expiry
# 9 lastAccessed
# 10 creationTime
# 11 isSecure
# 12 isHttpOnly
# urls only, no datetimes --
urls = sorted( set([ item[1] for item in mydata ]))
for url in urls:
print url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment