Repository navigation
Expand file tree
/
Copy pathwordpress_analysis.py
More file actions
131 lines (111 loc) · 4.63 KB
/
Copy pathwordpress_analysis.py
File metadata and controls
131 lines (111 loc) · 4.63 KB
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
#!/usr/bin/env python3
# wp-pentest by Joseph Godwin Kimani
# This script is designed to analyze a batch of WordPress websites by retrieving essential information such as IP addresses, usernames, site details, and plugin lists.
# https://github.com/josephgodwinkimani/wp-pentest
import socket
import time
import requests
import json
# your log file here
LOG_FILE = 'wordpress_analysis_log.txt'
HEADERS = {
'Accept': '*/*',
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
}
def log_message(message):
"""Logs messages to a file with timestamps."""
with open(LOG_FILE, 'a') as log_file:
timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
log_file.write(f"{timestamp} - {message}\n")
def format_url(url):
"""Formats the URL by removing protocol prefixes."""
return url.lower().replace('http://', '').replace('https://', '')
def fetch_ip(url):
"""Fetches the IP address of the given URL."""
try:
return socket.gethostbyname(url)
except socket.gaierror:
return "Unable to resolve IP"
def get_admin_page_status(url):
"""Checks if the WordPress admin page is accessible."""
response = requests.get(f"{url}/wp-admin", allow_redirects=False)
return response.status_code == 200
def fetch_usernames(url):
"""Fetches usernames from the WordPress REST API."""
try:
response = requests.get(f"{url}/wp-json/wp/v2/users/", headers=HEADERS)
if response.status_code == 200:
users = response.json()
return [user['slug'] for user in users]
else:
return ["Unable to fetch usernames"]
except Exception as e:
return [f"Error: {str(e)}"]
def fetch_site_info(url):
"""Fetches general site information from the WordPress REST API."""
try:
response = requests.get(f"{url}/wp-json", headers=HEADERS)
if response.status_code == 200:
info = response.json()
return {
"name": info.get('name', 'N/A'),
"description": info.get('description', 'N/A'),
"url": info.get('url', 'N/A'),
"version": info.get('version', 'N/A')
}
else:
return {"name": "N/A", "description": "N/A", "url": "N/A", "version": "N/A"}
except Exception as e:
return {"name": "Error", "description": str(e), "url": "Error", "version": "Error"}
def fetch_plugins(url):
"""Fetches a list of installed plugins from the WordPress REST API."""
try:
response = requests.get(f"{url}/wp-json/wp/v2/plugins/", headers=HEADERS)
if response.status_code == 200:
plugins = response.json()
return [plugin['name'] for plugin in plugins]
else:
return ["Unable to fetch plugins"]
except Exception as e:
return [f"Error: {str(e)}"]
def analyze_target(target_url):
"""Analyzes the target WordPress site and logs results."""
formatted_url = format_url(target_url)
log_message(f"Starting analysis for: {formatted_url}")
# Fetch IP Address
print("Resolving IP address...")
ip_address = fetch_ip(formatted_url)
log_message(f"IP Address: {ip_address}")
# Fetch Site Information
print("Fetching site information...")
site_info = fetch_site_info(f"http://{formatted_url}")
log_message(f"Site Name: {site_info['name']}")
log_message(f"Description: {site_info['description']}")
log_message(f"Site URL: {site_info['url']}")
log_message(f"WordPress Version: {site_info['version']}")
# Fetch Usernames
print("Fetching usernames...")
usernames = fetch_usernames(f"http://{formatted_url}")
log_message("Usernames: " + ", ".join(usernames))
# Check Admin Page Accessibility
print("Checking admin page accessibility...")
admin_accessible = get_admin_page_status(f"http://{formatted_url}")
admin_status = "Accessible" if admin_accessible else "Not Accessible"
log_message(f"Admin Page Status: {admin_status}")
# Fetch Plugins (if possible)
print("Fetching plugins...")
plugins = fetch_plugins(f"http://{formatted_url}")
log_message("Plugins: " + ", ".join(plugins))
def main():
"""Main function to execute the script."""
# Read URLs from file
with open('websites.txt', 'r') as file:
urls = file.readlines()
for url in urls:
target_url = url.strip()
if target_url:
print(f"\nStarting analysis for: {target_url}\n")
analyze_target(target_url)
if __name__ == "__main__":
main()