Guest User

https://xss.is from pablo

a guest
Apr 16th, 2019
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Python:
  2. import codecs
  3. import glob
  4. import sys
  5. import os
  6. import json
  7.  
  8. def find_files(work_dir):
  9.     dir_pattern = 'Cookies'
  10.     files_pattern = '/**/*'
  11.     extension_pattern = '.log'
  12.     chrome_pattern = 'Chrome'
  13.     list_of_files = []
  14.     list_of_fs_objects = glob.glob(work_dir + files_pattern, recursive=True)
  15.     for object in list_of_fs_objects:
  16.         if dir_pattern in object \
  17.                 and (not os.path.isdir(object)) \
  18.                 and extension_pattern in object \
  19.                 and chrome_pattern in object:
  20.             list_of_files.append(object)
  21.     print('find', len(list_of_files), 'Chrome logs')
  22.     return list_of_files
  23.  
  24. def read_file(filename):
  25.     try:
  26.         with codecs.open(filename, 'r', encoding='utf-8', errors='ignore') as file:
  27.             file_data = file.readlines()
  28.             return file_data
  29.     except IOError:
  30.         print("Can't read from file, IO error")
  31.         exit(1)
  32.  
  33.  
  34. def write_file(filename, data):
  35.     try:
  36.         with codecs.open(filename, 'w', encoding='utf-8', errors='ignore') as file:
  37.             file.write(data)
  38.             return True
  39.     except IOError:
  40.         print("Can't write to file, IO error")
  41.         exit(1)
  42.  
  43. def handle_files(list_of_files):
  44.     files_counter = 0
  45.     for file in list_of_files:
  46.         file_name = os.path.splitext(file)[0]
  47.         list_of_lines = read_file(file)
  48.         list_of_dictionaries = []
  49.         cookie_counter = 0
  50.         files_counter = files_counter + 1
  51.         for item in list_of_lines:
  52.             if len(item) > 10:
  53.                 list_flags = item.split('\t')
  54.                 domain = list_flags[0]
  55.                 session = list_flags[1]
  56.                 path = list_flags[2]
  57.                 secure = list_flags[3]
  58.                 expiration = list_flags[4]
  59.                 name = list_flags[5]
  60.                 value_raw = list_flags[6]
  61.                 value = value_raw.rstrip("\r\n")
  62.                 dic = {'domain': domain,
  63.                        'expirationDate': expiration,
  64.                        'hostOnly': bool('false'),
  65.                        'httpOnly': bool('false'),
  66.                        'name': name,
  67.                        'path': path,
  68.                        "sameSite": "no_restriction",
  69.                        'secure': bool(secure),
  70.                        'session': bool(session),
  71.                        'value': value,
  72.                        'id': cookie_counter
  73.                        }
  74.  
  75.                 list_of_dictionaries.append(dic)
  76.                 cookie_counter += 1
  77.         list_dump = json.dumps(list_of_dic)
  78.         string_of_dump = str(list_dump)
  79.         json_file_name = file_name + '.json'
  80.         write_file(json_file_name, string_of_dump)
  81.     print('processed', files_counter, 'Chrome logs')
  82.  
  83. def main():
  84.     work_dir = sys.argv[1]
  85.     files = find_files(work_dir)
  86.     handle_files(files)
  87.  
  88. if __name__ == "__main__":
  89.     main()
Add Comment
Please, Sign In to add comment