-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordpress_checks.py
172 lines (140 loc) · 5.96 KB
/
wordpress_checks.py
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python
import os
import re
from datetime import date, timedelta
from os.path import join, isfile
# Define the day of interest in the Apache common log format.
try:
# daysago = int(sys.argv[1])
daysago = 1
except:
daysago = 1
the_day = date.today() - timedelta(daysago)
apache_day = the_day.strftime('[%d/%b/%Y:')
# Define Output file
stats_output = open(os.getcwd() + '/stats.txt', "w")
# Define log path directory
path = "/home/username/Desktop/domlogs"
# Get list of dir contents
logs_path_contents = os.listdir(path)
# Get list of files only from this directory
logs = filter(lambda f: isfile(join(path, f)), logs_path_contents)
# Initialize dictionaries for hit counters
wp_login_dict = {}
wp_cron_dict = {}
wp_xmlrpc_dict = {}
wp_admin_ajax_dict = {}
for log in logs:
file = os.path.join(path, log)
text = open(file, "r")
wp_login_hit_count = 0
wp_cron_hit_count = 0
wp_xmlrpc_hit_count = 0
wp_admin_ajax_hit_count = 0
for line in text:
if apache_day in line:
if re.match("(.*)(wp-login.php)(.*)", line):
wp_login_hit_count = wp_login_hit_count + 1
if re.match("(.*)(wp-cron.php)(.*)", line):
wp_cron_hit_count = wp_cron_hit_count + 1
if re.match("(.*)(xmlrpc.php)(.*)", line):
wp_xmlrpc_hit_count = wp_xmlrpc_hit_count + 1
if re.match("(.*)(admin-ajax.php)(.*)", line):
wp_admin_ajax_hit_count = wp_admin_ajax_hit_count + 1
# print >> stats_output, log + "|" + line,
# print(log + "|" + line, end="", file=stats_output)
log = log.replace('-ssl_log', '', 1)
log = log.replace('.access_log', '', 1)
wp_login_dict[log] = int(wp_login_hit_count)
wp_cron_dict[log] = int(wp_cron_hit_count)
wp_xmlrpc_dict[log] = int(wp_xmlrpc_hit_count)
wp_admin_ajax_dict[log] = int(wp_admin_ajax_hit_count)
# print(log)
# print("Wordpress Logins => " + str(wp_login_hit_count))
# print("Wordpress wp-cron => " + str(wp_cron_hit_count))
# print("Wordpress xmlrpc => " + str(wp_xmlrpc_hit_count))
# print("Wordpress admin-ajax => " + str(wp_admin_ajax_hit_count))
# print("===============================================================")
text.close()
# print(wp_login_dict.mostcommon(10))
# print(wp_cron_dict.mostcommon(10))
# print(wp_xmlrpc_dict.mostcommon(10))
# print(wp_admin_ajax_dict.mostcommon(10))
# d = sorted(a.items(),key=lambda x: (x[1], x[0]), reverse=True) # Value then Key
# wp_logintop = sorted(wp_login_dict.items(), key=lambda x: (x[1], x[0]), reverse=True) # Value then Key
# wp_crontop = sorted(wp_cron_dict.items(), key=lambda x: (x[1], x[0]), reverse=True) # Value then Key
# wp_xmlrpctop = sorted(wp_xmlrpc_dict.items(), key=lambda x: (x[1], x[0]), reverse=True) # Value then Key
# wp_admin_ajaxtop = sorted(wp_admin_ajax_dict.items(), key=lambda x: (x[1], x[0]), reverse=True) # Value then Key
# print('+++++++++++++++++++++++++++++++++++')
# print('The original Wordpress login dictionary')
# print(wp_login_dict)
# print('+++++++++++++++++++++++++++++++++++')
# print('The sorted Wordpress login dictionary')
# print(wp_logintop)
# print('+++++++++++++++++++++++++++++++++++')
# print('+++++++++++++++++++++++++++++++++++')
# print('The original Wordpress wp-cron dictionary')
# print(wp_cron_dict)
# print('+++++++++++++++++++++++++++++++++++')
# print('The sorted Wordpress cron dictionary')
# print(wp_crontop)
# print('+++++++++++++++++++++++++++++++++++')
# print('+++++++++++++++++++++++++++++++++++')
# print('The original Wordpress wp-xmlrpc dictionary')
# print(wp_xmlrpc_dict)
# print('+++++++++++++++++++++++++++++++++++')
# print('The sorted Wordpress xmlrpc dictionary')
# print(wp_xmlrpctop)
# print('+++++++++++++++++++++++++++++++++++')
# print('+++++++++++++++++++++++++++++++++++')
# print('The original Wordpress wp-admin ajax dictionary')
# print(wp_admin_ajax_dict)
# print('+++++++++++++++++++++++++++++++++++')
# print('The sorted Wordpress admin_ajax dictionary')
# print(wp_admin_ajaxtop)
# print('+++++++++++++++++++++++++++++++++++')
# print('+++++++++++++++++++++++++++++++++++')
# print('sorted_d')
# print(sorted_d)
# print('Sorted reverse')
# print(sortedreverse)
# d = Counter(
# d = Counter(wp_login_dict)
# d.most_common()
# for k, v in d.most_common(10):
# print('%s: %i' % (k, v))
# create a function which returns the value of a dictionary
def keyfunction(k):
return d[k]
d = wp_login_dict
print('''
Wordpress Bruteforce Logins for wp-login.php %s''' % the_day.strftime('%b %d, %Y'))
print('============================================')
# sort by dictionary by the values and print top 10 {key, value} pairs
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
print("%s: %i" % (key, d[key]))
print('============================================')
d = wp_cron_dict
print('''
Wordpress Cron wp-cron.php(virtual cron) checks for %s''' % the_day.strftime('%b %d, %Y'))
print('============================================')
# sort by dictionary by the values and print top 10 {key, value} pairs
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
print("%s: %i" % (key, d[key]))
print('============================================')
d = wp_xmlrpc_dict
print('''
Wordpress XMLRPC Attacks checks for xmlrpc.php for %s''' % the_day.strftime('%b %d, %Y'))
print('============================================')
# sort by dictionary by the values and print top 10 {key, value} pairs
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
print("%s: %i" % (key, d[key]))
print('============================================')
d = wp_admin_ajax_dict
print('''
Wordpress Heartbeat API checks for admin-ajax.php for %s''' % the_day.strftime('%b %d, %Y'))
print('============================================')
# sort by dictionary by the values and print top 10 {key, value} pairs
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
print("%s: %i" % (key, d[key]))
print('============================================')