Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python:
- import codecs
- import glob
- import sys
- import os
- import json
- def find_files(work_dir):
- dir_pattern = 'Cookies'
- files_pattern = '/**/*'
- extension_pattern = '.log'
- chrome_pattern = 'Chrome'
- list_of_files = []
- list_of_fs_objects = glob.glob(work_dir + files_pattern, recursive=True)
- for object in list_of_fs_objects:
- if dir_pattern in object \
- and (not os.path.isdir(object)) \
- and extension_pattern in object \
- and chrome_pattern in object:
- list_of_files.append(object)
- print('find', len(list_of_files), 'Chrome logs')
- return list_of_files
- def read_file(filename):
- try:
- with codecs.open(filename, 'r', encoding='utf-8', errors='ignore') as file:
- file_data = file.readlines()
- return file_data
- except IOError:
- print("Can't read from file, IO error")
- exit(1)
- def write_file(filename, data):
- try:
- with codecs.open(filename, 'w', encoding='utf-8', errors='ignore') as file:
- file.write(data)
- return True
- except IOError:
- print("Can't write to file, IO error")
- exit(1)
- def handle_files(list_of_files):
- files_counter = 0
- for file in list_of_files:
- file_name = os.path.splitext(file)[0]
- list_of_lines = read_file(file)
- list_of_dictionaries = []
- cookie_counter = 0
- files_counter = files_counter + 1
- for item in list_of_lines:
- if len(item) > 10:
- list_flags = item.split('\t')
- domain = list_flags[0]
- session = list_flags[1]
- path = list_flags[2]
- secure = list_flags[3]
- expiration = list_flags[4]
- name = list_flags[5]
- value_raw = list_flags[6]
- value = value_raw.rstrip("\r\n")
- dic = {'domain': domain,
- 'expirationDate': expiration,
- 'hostOnly': bool('false'),
- 'httpOnly': bool('false'),
- 'name': name,
- 'path': path,
- "sameSite": "no_restriction",
- 'secure': bool(secure),
- 'session': bool(session),
- 'value': value,
- 'id': cookie_counter
- }
- list_of_dictionaries.append(dic)
- cookie_counter += 1
- list_dump = json.dumps(list_of_dic)
- string_of_dump = str(list_dump)
- json_file_name = file_name + '.json'
- write_file(json_file_name, string_of_dump)
- print('processed', files_counter, 'Chrome logs')
- def main():
- work_dir = sys.argv[1]
- files = find_files(work_dir)
- handle_files(files)
- if __name__ == "__main__":
- main()
Add Comment
Please, Sign In to add comment