View difference between Paste ID: PZVCENqY and MXcu7BsR
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/env python3
2
# Purpose is premium.crashinyou.me output sorting
3
4
import re
5
import sys
6
import json
7
from urllib.request import urlopen
8
from os.path import basename, dirname, join, isfile, normpath
9
10
ipv4_cache = {}
11
console_print = False
12
hashtypes_regex = (
13
    ("Authme SHA", "(?i)^\$sha\$[a-zA-Z0-9]{0,16}\$[a-fA-F0-9]{64}"),
14
    ("BCrypt", "^[$]2[abxy]?[$](?:0[4-9]|[12][0-9]|3[01])[$][.0-9a-zA-Z]{53}"),
15
    ("Other", ".*"),
16
)
17
18
19
def check_location(ipv4_address):
20
    if ipv4_address in ipv4_cache:
21
        data = ipv4_cache[ipv4_address]
22
    else:
23
        url = "https://ipinfo.io/" + ipv4_address + "/json"
24
        response = urlopen(url)
25
        if response is None:
26
            print("Ошибка проверки местоположения. Нет интернет соединения?")
27
            exit(1)
28
        data = json.load(response)
29
        ipv4_cache[ipv4_address] = data
30
    return data["city"] + ", " + data["region"] + ", " + data["country"]
31
32
33
def date_sort(d):
34
    d = d[0].split(".")
35
    return int(d[0]) + int(d[1]) * 12 if len(d) == 2 else int(d[0]) * 12
36
37
38
def printall(f, *args):
39
    if console_print:
40
        print(*args)
41
    print(*args, file=f)
42
43
44
def main(fp="input.txt"):
45
    ciy_response = open(fp, "r", encoding="utf-8", errors="ignore")
46
    ciy_response_sorted = open(
47
        join(dirname(fp), "sorted_" + basename(fp)),
48
        "w",
49
        encoding="utf-8",
50
        errors="ignore",
51
    )
52
    username = ""
53
    linked_entries = {}
54
    passw_unique = {}
55
    for line in ciy_response.readlines():
56
        if username == "" and "Username" in line:
57
            username = line[len("Username :") + 1 :].strip()
58
        if "Password" in line:
59
            passw = line[len("Password :") + 1 :].strip()
60
            continue
61
        if "IP" in line:
62
            location = check_location(line[len("IP :") + 1 :].strip())
63
            if not location in passw_unique:
64
                passw_unique[location] = dict(
65
                    (hashtype, set()) for hashtype, _ in hashtypes_regex
66
                )
67
            for hashtype, pattern in hashtypes_regex:
68
                if re.findall(pattern, passw):
69
                    passw_unique[location][hashtype].add(passw)
70
                    break
71
            continue
72
        if "Database" in line:
73
            date = re.findall("\[[\d\.]*\]", line)
74
            date = "0000" if date == [] else date[0][1:-1]
75
            server = re.findall(": \S*", line)[0][2:]
76
            if location in linked_entries:
77
                linked_entries[location] += [(date, server, passw)]
78
            else:
79
                linked_entries[location] = [(date, server, passw)]
80
    printall(ciy_response_sorted, "Ник:", username)
81
    for location, servers in linked_entries.items():
82
        servers.sort(key=date_sort, reverse=True)
83
        printall(ciy_response_sorted, "\nВсе IP адреса из", location)
84
        printall(
85
            ciy_response_sorted,
86
            "{:<15s} {:<20s} {:<150s}".format("Дата", "Сервер", "Хеш"),
87
        )
88
        for server in servers:
89
            printall(ciy_response_sorted, "{:<15s} {:<20s} {:<150s}".format(*server))
90
        printall(ciy_response_sorted, "Хеши отдельным списком, без повторов:")
91
        for hashtype, _ in hashtypes_regex:
92
            hashset = passw_unique[location][hashtype]
93
            if hashset:
94
                printall(ciy_response_sorted, "----", hashtype, "----")
95
                for hash in hashset:
96
                    printall(ciy_response_sorted, hash)
97
98
99
if __name__ == "__main__":
100
    if len(sys.argv) > 2:
101
        print("Неправильное число аргументов. Укажите ТОЛЬКО путь к файлу.")
102
        exit(1)
103
    elif len(sys.argv) == 2:
104
        filepath = normpath(sys.argv[1])
105
        if isfile(filepath):
106
            main(filepath)
107
        else:
108
            print("Файл не найден.")
109
            exit(1)
110
    else:
111
        print("Не указан файл. По умолчанию считывается input.txt")
112
        main()
113