Extract Data from Chrome Database.

Today we extract data from google-chrome sqllite database using python script.Chrome contain lots of information in its database like history ;cookies; search history ; autofill ;download ;addons and more.Database location are different in different O.S.

In windows C:\\Users\user_name/AppData/Local/Google/Chrome/User Data/Default/

In linux /root/.config/google-chrome/Default

Extract Autofill data script:-

#!/usr/bin/python

import re
import optparse
import os
import sqlite3

def printLoginData(LoginData):
try:
conn = sqlite3.connect(LoginData)
c = conn.cursor()
c.execute(‘SELECT name, value FROM autofill’)

print ‘\n[*] — Found url –‘
for row in c:

print str(row[0]) + ” ” + str(row[1])
except Exception, e:
if ‘encrypted’ in str(e):
print ‘\n[*] Error reading your cookies database.’
print ‘[*] Upgrade your Python-Sqlite3 Library’

def main():
parser = optparse.OptionParser(“usage %prog “+\
“-p ”
)
parser.add_option(‘-p’, dest=’pathName’, type=’string’,\
help=’specify chrome profile path’)

(options, args) = parser.parse_args()
pathName = options.pathName
if pathName == None:
print parser.usage
exit(0)
elif os.path.isdir(pathName) == False:
print ‘[!] Path Does Not Exist: ‘ + pathName
exit(0)
else:
LoginData = os.path.join(pathName, ‘Web Data’)
printLoginData(LoginData)

if __name__ == ‘__main__’:
main()

Extract Cookies from Database:-

#!/usr/bin/python
# -*- coding: utf-8 -*-

import re
import optparse
import os
import sqlite3
def printCookies(cookiesDB):
try:
conn = sqlite3.connect(cookiesDB)
c = conn.cursor()
c.execute(‘SELECT host_key, name, value FROM Cookies’)

print ‘\n[*] — Found Cookies –‘
for row in c:
host = str(row[0])
name = str(row[1])
value = str(row[2])
print ‘[+] Host: ‘ + host + ‘, Cookie: ‘ + name \
+ ‘, Value: ‘ + value
except Exception, e:
if ‘encrypted’ in str(e):
print ‘\n[*] Error reading your cookies database.’
print ‘[*] Upgrade your Python-Sqlite3 Library’
def main():
parser = optparse.OptionParser(“usage %prog “+\
“-p ”
)
parser.add_option(‘-p’, dest=’pathName’, type=’string’,\
help=’specify Chrome profile path’)

(options, args) = parser.parse_args()
pathName = options.pathName
if pathName == None:
print parser.usage
exit(0)
elif os.path.isdir(pathName) == False:
print ‘[!] Path Does Not Exist: ‘ + pathName
exit(0)
else:
cookiesDB = os.path.join(pathName, ‘Cookies’)
if os.path.isfile(cookiesDB):
pass
printCookies(cookiesDB)
else:
print ‘[!] Cookies Db does not exist:’ + cookiesDB

if __name__ == ‘__main__’:
main()

Extract history From Database:-

#!/usr/bin/python
import re
import optparse
import os
import sqlite3
def printCookies(cookiesDB):
try:
conn = sqlite3.connect(cookiesDB)
c = conn.cursor()
c.execute(‘SELECT url, title FROM urls’)

print ‘\n[*] — Found History –‘
for row in c:
host = str(row[0])
name = str(row[1])

print str(row[0]) + ” Title:” + str(row[1])
except Exception, e:
if ‘encrypted’ in str(e):
print ‘\n[*] Error reading your cookies database.’
print ‘[*] Upgrade your Python-Sqlite3 Library’
def main():
parser = optparse.OptionParser(“usage %prog “+\
“-p ”
)
parser.add_option(‘-p’, dest=’pathName’, type=’string’,\
help=’specify chrome profile path’)

(options, args) = parser.parse_args()
pathName = options.pathName
if pathName == None:
print parser.usage
exit(0)
elif os.path.isdir(pathName) == False:
print ‘[!] Path Does Not Exist: ‘ + pathName
exit(0)
else:
cookiesDB = os.path.join(pathName, ‘History’)
if os.path.isfile(cookiesDB):
pass
printCookies(cookiesDB)
else:
print ‘[!] Cookies Db does not exist:’ + cookiesDB

if __name__ == ‘__main__’:
main()

You can also create your script to extract other data from database.

Usage of script:-

chmod +x script_name

./script_name.py -p path of db according to your O.s.

Leave a comment