数据库
首页 > 数据库> > 利用Python Sqlite3模块提起Firefox Cookie数据库信息

利用Python Sqlite3模块提起Firefox Cookie数据库信息

作者:互联网

  由于Firefox利用Sqlite存储各种上网数据,比如表单数据,Cookie数据,历史记录等,因此可用Python第三方模块Sqlite3对数据库进行操作,提取出响应的表的信息。

 1 import sqlite3
 2 import optparse
 3 import sys
 4 import os
 5 
 6 class FirefoxCookies:
 7     def __init__(self) -> None:
 8         self.filename = self.get_params()
 9         self.tablename = 'moz_cookies'
10 
11     def get_params(self):
12         parser = optparse.OptionParser('Usage: <Program> -f sqlite db filename')
13         parser.add_option('-f', '--filename', dest='filename', type='string', help='Specify database filenamme')
14         options, args = parser.parse_args()
15         if options.filename is None:
16             print(parser.usage)
17             sys.exit(0)
18         if not os.path.exists(options.filename):
19             print('[-] The file does not exist')
20             sys.exit(0)
21         return options.filename
22     
23     def cookie_extractor(self):
24         try:
25             conn = sqlite3.connect(self.filename)
26             cursor = conn.cursor()
27             sql = 'select name,value from {};'.format(self.tablename)
28             cursor.execute(sql)
29             for row in cursor:
30                 print(row[0],":", row[1])
31         except Exception as e:
32             print(e)
33             sys.exit()
34 
35 
36 if __name__ == "__main__":
37     fc = FirefoxCookies()
38     fc.cookie_extractor()

 

标签:__,Firefox,Python,self,filename,Cookie,print,import,options
来源: https://www.cnblogs.com/jason-huawen/p/16298599.html