#*******************************************************************************# # BinaryCookieReader: Written By Satishb3 (http://www.securitylearn.net) # # # # For any bug fixes contact me: satishb3@securitylearn.net # # # # Usage: Python BinaryCookieReader.py Cookie.Binarycookies-FilePath # # # # Safari browser and iOS applications store the persistent cookies in a binary # # file names Cookies.binarycookies.BinaryCookieReader is used to dump all the # # cookies from the binary Cookies.binarycookies file. # # # #*******************************************************************************# import sys from struct import unpack from StringIO import StringIO from time import strftime, gmtime if len(sys.argv)!=2: print "\nUsage: Python BinaryCookieReader.py [Full path to Cookies.binarycookies file] \n" print "Example: Python BinaryCookieReader.py C:\Cookies.binarycookies" sys.exit(0) FilePath=sys.argv[1] try: binary_file=open(FilePath,'rb') except IOError as e: print 'File Not Found :'+ FilePath sys.exit(0) file_header=binary_file.read(4) #File Magic String:cook if str(file_header)!='cook': print "Not a Cookies.binarycookie file" sys.exit(0) num_pages=unpack('>i',binary_file.read(4))[0] #Number of pages in the binary file: 4 bytes page_sizes=[] for np in range(num_pages): page_sizes.append(unpack('>i',binary_file.read(4))[0]) #Each page size: 4 bytes*number of pages pages=[] for ps in page_sizes: pages.append(binary_file.read(ps)) #Grab individual pages and each page will contain >= one cookie print "#*************************************************************************#" print "# BinaryCookieReader: developed by Satishb3: http://www.securitylearn.net #" print "#*************************************************************************#" for page in pages: page=StringIO(page) #Converts the string to a file. So that we can use read/write operations easily. page.read(4) #page header: 4 bytes: Always 00000100 num_cookies=unpack('= one cookie. Fetch cookie starting point from page starting byte page.read(4) #end of page header: Always 00000000 cookie='' for offset in cookie_offsets: page.seek(offset) #Move the page pointer to the cookie starting point cookiesize=unpack('