Skip to content

Instantly share code, notes, and snippets.

@mratsim
Created November 27, 2016 12:21
Show Gist options
  • Save mratsim/fcf82f332755451231d62d3b041f45f9 to your computer and use it in GitHub Desktop.
Save mratsim/fcf82f332755451231d62d3b041f45f9 to your computer and use it in GitHub Desktop.
Extract cookies from Firefox
#!/bin/bash
#extract_cookies.sh $HOME/.mozilla/firefox/*/cookies.sqlite > /tmp/cookies.txt
#wget --load-cookies=/tmp/cookies.txt http://mysite.com
# OR
#curl --cookie /tmp/cookies.txt http://mysite.com
function cleanup {
rm -f $TMPFILE
exit 1
}
trap cleanup SIGHUP SIGINT SIGTERM
# This is the format of the sqlite database:
# CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER);
# We have to copy cookies.sqlite, because FireFox has a lock on it
TMPFILE=`mktemp /tmp/cookies.sqlite.XXXXXXXXXX`
cat $1 >> $TMPFILE
sqlite3 -separator ' ' $TMPFILE << EOF
.mode tabs
.header off
select host,
case substr(host,1,1)='.' when 0 then 'FALSE' else 'TRUE' end,
path,
case isSecure when 0 then 'FALSE' else 'TRUE' end,
expiry,
name,
value
from moz_cookies;
EOF
cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment