-
Notifications
You must be signed in to change notification settings - Fork 1
/
WPScanner.py
83 lines (68 loc) · 3.07 KB
/
WPScanner.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
import requests
from bs4 import BeautifulSoup
class WPDoesntUse(Exception):
"""Target site doesn't use wp error"""
class WPScanner:
def __init__(self, site_url: str):
self.vulnerability_path = ["wp-includes/uploads", "wp-includes/rest-api", "wp-includes", "wp-admin", "wp-upload", "wordpress/wp-content/uploads/"]
self.session = requests.Session()
self.site_url = site_url
source = self.get_page_source()
if not "wp-content" in source and not "wp-includes" in source and not "wp-includes" in source:
raise WPDoesntUse("Maybe this site doesn't use WordPress.")
def get_page_source(self):
response = self.session.get(self.site_url).text
self.soup = BeautifulSoup(response, 'html.parser')
return response
def get_wordpress_version(self):
source = self.get_page_source()
generator_tags = self.soup.find_all("meta", attrs={"name": "generator"})
for generator in generator_tags:
content = str(generator).split('"')[1]
if "WordPress" in content:
return content
def get_all_plugins(self):
plugin_list = []
source = self.get_page_source()
css_tags = self.soup.find_all("link")
for tag in css_tags:
tag = str(tag)
if "wp-content/plugins/" in tag:
name, version = tag.split("href=")[1].split('"')[1].split("/css/")[-1].split('.css?ver=')
plugin_list.append({"name": name, "version": version})
return plugin_list
def get_all_themes(self):
theme_list = []
source = self.get_page_source()
css_tags = self.soup.find_all("link")
for tag in css_tags:
tag = str(tag)
if "theme" in tag:
name = tag.split("href=")[1].split('"')[1].split("/css/")[-1]
name, version = name.split('?ver=') if "?ver=" in name else [name, None]
theme_list.append({"name": name, "version": version})
return theme_list
def get_vulnerability_page(self):
vulnerability_page_list = []
http = "https://" if "https://" in self.site_url else "http://"
site_origin = http + self.site_url.replace(http, "").split("/")[0] + "/"
for path in self.vulnerability_path:
url = site_origin + path
status = self.session.get(url).status_code
if status == 302 or "20" in str(status):
vulnerability_page_list.append(url)
return vulnerability_page_list
def get_all_users(self):
user_list = []
http = "https://" if "https://" in self.site_url else "http://"
site_origin = http + self.site_url.replace(http, "").split("/")[0] + "/"
url = site_origin + "wp-json/wp/v2/users"
response = self.session.get(url)
try:
response_json = response.json()
response.raise_for_status()
for response in response_json:
user_list.append(response["name"])
except requests.HTTPError:
return None
return user_list