about summary refs log tree commit diff
path: root/analyze.py
blob: 9d151c040c5449b5e9461779e1d3d78a19fed864 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import re
import operator
import sys

username_metrics = {}
ip_metrics = {}
port_metrics = {}
password_metrics = {}

counter = 0

with open("password_list.txt", "a") as passwordfile:
    with open(sys.argv[1]) as data:
        content = data.readlines()
        
        for line in content[3:]:
            username_ip_port_password = line[43:]

            # Get the username, print it and add it into the username_metrics dict

            username = username_ip_port_password.split("@")[0]

            if username in username_metrics: 
                username_metrics[username] += 1 
            else:
                username_metrics[username] = 1

            # Get the ip, print it and add it into the ip_metrics dict

            ip_port_password = username_ip_port_password.strip(username + "@")
            ip = ip_port_password.split(":")[0]

            if ip in ip_metrics: 
                ip_metrics[ip] += 1 
            else:
                ip_metrics[ip] = 1

            # Get the port, print it and add it into the port_metrics dict

            port = ip_port_password.split(":")[1]

            if port in port_metrics: 
                port_metrics[port] += 1 
            else:
                port_metrics[port] = 1

            # Get the password, print it and add it into the password_metrics dict

            password = ip_port_password.strip(ip + ":" + port + ": ").split("\'")[1]
            
            if password in password_metrics: 
                password_metrics[password] += 1 
            else:
                password_metrics[password] = 1

            # append the password to the passwordfile
            passwordfile.write(password + "\n")

            counter += 1

print("Amount of hits processed: " + str(counter))

plt.tight_layout()

# plot the most used usernames
print("-----------------")
print("Most tried usernames:")
sorted_username_metrics = sorted(username_metrics.items(), key=operator.itemgetter(1))

username = []
username_count = []

for item in sorted_username_metrics[-20:]:
    print("{:<20}{:<10}".format(item[0], item[1]))
    username.append(item[0])
    username_count.append(item[1])

plt.bar(username, username_count)
plt.title("usernames")
plt.xlabel('username used to login')
plt.xticks(rotation=90)
plt.ylabel('amount of attempts')
plt.savefig("usernames.png", dpi=400, orientation="landscape")
plt.clf()
        
# plot the most used passwords 
print("-----------------")
print("Most tried passwords:")
sorted_password_metrics = sorted(password_metrics.items(), key=operator.itemgetter(1))
password = []
password_count = []

for item in sorted_password_metrics[-15:]:
    print("{:<20}{:<10}".format(item[0], item[1]))
    password.append(item[0])
    password_count.append(item[1])

plt.bar(password, password_count)
plt.title("passwords")
plt.xlabel('passwords used to login')
plt.xticks(rotation=90)
plt.ylabel('amount of attempts')
plt.savefig("passwords.png", dpi=400, orientation='landscape')
plt.clf()

# plot the most frequent ips 
print("-----------------")
print("Most frequent ips:")
sorted_ip_metrics = sorted(ip_metrics.items(), key=operator.itemgetter(1))
ip = []
ip_count = []

for item in sorted_ip_metrics[-15:]:
    print("{:<20}{:<10}".format(item[0], item[1]))
    ip.append(item[0])
    ip_count.append(item[1])


plt.bar(ip, ip_count)
plt.title("ips")
plt.xlabel('ip used to login')
plt.xticks(rotation=90)
plt.ylabel('amount of attempts')
plt.savefig("ip.png", dpi=400, orientation='landscape')
plt.clf()

# plot the most frequent ports 
print("-----------------")
print("Most frequent ports:")
sorted_port_metrics = sorted(port_metrics.items(), key=operator.itemgetter(1))
port = []
port_count = []

for item in sorted_port_metrics[-15:]:
    print("{:<20}{:<10}".format(item[0], item[1]))
    port.append(item[0])
    port_count.append(item[1])

plt.bar(port, port_count)
plt.title("ports")
plt.xlabel('port used to login')
plt.xticks(rotation=90)
plt.ylabel('amount of attempts')
plt.savefig("port.png", dpi=400, orientation='landscape')
plt.clf()