Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Purpose is premium.crashinyou.me output sorting
- import re
- import sys
- import json
- from urllib.request import urlopen
- from os.path import basename, dirname, join, isfile, normpath
- ipv4_cache = {}
- console_print = False
- hashtypes_regex = (
- ("Authme SHA", "(?i)^\$sha\$[a-zA-Z0-9]{0,16}\$[a-fA-F0-9]{64}"),
- ("BCrypt", "^[$]2[abxy]?[$](?:0[4-9]|[12][0-9]|3[01])[$][.0-9a-zA-Z]{53}"),
- ("Other", ".*"),
- )
- def check_location(ipv4_address):
- if ipv4_address in ipv4_cache:
- data = ipv4_cache[ipv4_address]
- else:
- url = "https://ipinfo.io/" + ipv4_address + "/json"
- response = urlopen(url)
- if response is None:
- print("Ошибка проверки местоположения. Нет интернет соединения?")
- exit(1)
- data = json.load(response)
- ipv4_cache[ipv4_address] = data
- return data["city"] + ", " + data["region"] + ", " + data["country"]
- def date_sort(d):
- d = d[0].split(".")
- return int(d[0]) + int(d[1]) * 12 if len(d) == 2 else int(d[0]) * 12
- def printall(f, *args):
- if console_print:
- print(*args)
- print(*args, file=f)
- def main(fp="input.txt"):
- ciy_response = open(fp, "r", encoding="utf-8", errors="ignore")
- ciy_response_sorted = open(
- join(dirname(fp), "sorted_" + basename(fp)),
- "w",
- encoding="utf-8",
- errors="ignore",
- )
- username = ""
- linked_entries = {}
- passw_unique = {}
- for line in ciy_response.readlines():
- if username == "" and "Username" in line:
- username = line[len("Username :") + 1 :].strip()
- if "Password" in line:
- passw = line[len("Password :") + 1 :].strip()
- continue
- if "IP" in line:
- location = check_location(line[len("IP :") + 1 :].strip())
- if not location in passw_unique:
- passw_unique[location] = dict(
- (hashtype, set()) for hashtype, _ in hashtypes_regex
- )
- for hashtype, pattern in hashtypes_regex:
- if re.findall(pattern, passw):
- passw_unique[location][hashtype].add(passw)
- break
- continue
- if "Database" in line:
- date = re.findall("\[[\d\.]*\]", line)
- date = "0000" if date == [] else date[0][1:-1]
- server = re.findall(": \S*", line)[0][2:]
- if location in linked_entries:
- linked_entries[location] += [(date, server, passw)]
- else:
- linked_entries[location] = [(date, server, passw)]
- printall(ciy_response_sorted, "Ник:", username)
- for location, servers in linked_entries.items():
- servers.sort(key=date_sort, reverse=True)
- printall(ciy_response_sorted, "\nВсе IP адреса из", location)
- printall(
- ciy_response_sorted,
- "{:<15s} {:<20s} {:<150s}".format("Дата", "Сервер", "Хеш"),
- )
- for server in servers:
- printall(ciy_response_sorted, "{:<15s} {:<20s} {:<150s}".format(*server))
- printall(ciy_response_sorted, "Хеши отдельным списком, без повторов:")
- for hashtype, _ in hashtypes_regex:
- hashset = passw_unique[location][hashtype]
- if hashset:
- printall(ciy_response_sorted, "----", hashtype, "----")
- for hash in hashset:
- printall(ciy_response_sorted, hash)
- if __name__ == "__main__":
- if len(sys.argv) > 2:
- print("Неправильное число аргументов. Укажите ТОЛЬКО путь к файлу.")
- exit(1)
- elif len(sys.argv) == 2:
- filepath = normpath(sys.argv[1])
- if isfile(filepath):
- main(filepath)
- else:
- print("Файл не найден.")
- exit(1)
- else:
- print("Не указан файл. По умолчанию считывается input.txt")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement