diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/discovery/__init__.py b/discovery/__init__.py new file mode 100644 index 0000000..7d881ec --- /dev/null +++ b/discovery/__init__.py @@ -0,0 +1,6 @@ +from .dashboard import KubeDashboard +from .ports import PortDiscovery +from .hosts import HostDiscovery + +__all__ = [HostDiscovery, KubeDashboard, PortDiscovery] + diff --git a/discovery/dashboard.py b/discovery/dashboard.py new file mode 100644 index 0000000..6dcd8ec --- /dev/null +++ b/discovery/dashboard.py @@ -0,0 +1,16 @@ +import events +import requests + +class KubeDashboard(object): + def __init__(self, task): + self.task = task + self.host = task['host'] + self.port = task['port'] or 80 + pass + + def execute(self): + # TODO: insert logic for detremining dashboard/insecure dashboard is there + events.handler.publish_event('KUBE_DASHBOARD', {'host': self.host, 'port': self.port}) + + +events.handler.subscribe_event('OPEN_PORT_30000', KubeDashboard) diff --git a/modules/host_discovery.py b/discovery/hosts.py similarity index 100% rename from modules/host_discovery.py rename to discovery/hosts.py diff --git a/modules/port_discovery.py b/discovery/ports.py similarity index 81% rename from modules/port_discovery.py rename to discovery/ports.py index 714e0ee..7f66eab 100644 --- a/modules/port_discovery.py +++ b/discovery/ports.py @@ -1,8 +1,8 @@ from socket import socket import events -default_ports = [8001, 10250, 10255, 30000] +default_ports = [8001, 10250, 10255, 30000] class PortDiscovery(object): def __init__(self, task): @@ -11,9 +11,7 @@ class PortDiscovery(object): def execute(self): for single_port in default_ports: if self.test_connection(self.host, single_port): - events.handler.publish_event('OPEN_PORT', {'host': self.host, 'port': single_port}) - events.handler.publish_event('OPEN_PORT_{port}'.format(port=single_port), - {'host': self.host, 'port': single_port}) + events.handler.publish_event('OPEN_PORT_{port}'.format(port=single_port), {'host': self.host, 'port': single_port}) @staticmethod def test_connection(host, port): diff --git a/events.py b/events.py index 938dc09..79c9f8a 100644 --- a/events.py +++ b/events.py @@ -16,8 +16,8 @@ class EventQueue(Queue, object): t.start() def publish_event(self, name, item): + safe_print('Event {} got published with {}'.format(name, item)) if name in self.hooks: - safe_print('Event {} got published with {}'.format(name, item)) for single_hook in self.hooks[name]: self.put(single_hook(item)) diff --git a/events.pyc b/events.pyc deleted file mode 100644 index 6e98d5a..0000000 Binary files a/events.pyc and /dev/null differ diff --git a/hunting/__init__.py b/hunting/__init__.py new file mode 100644 index 0000000..d73b2a6 --- /dev/null +++ b/hunting/__init__.py @@ -0,0 +1,4 @@ +from .dashboard import KubeDashboard + +__all__ = [KubeDashboard] + diff --git a/hunting/dashboard.py b/hunting/dashboard.py new file mode 100644 index 0000000..3cff369 --- /dev/null +++ b/hunting/dashboard.py @@ -0,0 +1,29 @@ +import events +import requests +from events import safe_print + +class KubeDashboard(object): + def __init__(self, task): + self.host = task['host'] + self.port = task['port'] or 30000 + + def execute(self): + print("KUBEDASHBOARD At: {} {}".format(self.host, self.port)) + if self.secured: + safe_print("SECURED DASHBOARD") + else: + safe_print("INSECURE DASHBOARD") + + @property + def secured(self): + try: + r = requests.get("http://{host}:{port}/api/v1/node?itemsPerPage=100".format(host=self.host, port=self.port)) + except requests.exceptions.ConnectionError: + return True + + ret = r.json() + if 'listMeta' in ret: + return False + return True + +events.handler.subscribe_event('KUBE_DASHBOARD', KubeDashboard) \ No newline at end of file diff --git a/kube-hunter.py b/kube-hunter.py index eae7ca4..4fbcd42 100644 --- a/kube-hunter.py +++ b/kube-hunter.py @@ -1,11 +1,12 @@ -import modules +import discovery +import hunting import threading import time import sys def main(): try: - modules.HostDiscovery({}).execute() + discovery.HostDiscovery({}).execute() # Blocking to see discovery output while(True): time.sleep(1) diff --git a/modules/__init__.py b/modules/__init__.py deleted file mode 100644 index 440ff65..0000000 --- a/modules/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -from .kube_open_dashboard import KubeOpenDashboard -from .port_discovery import PortDiscovery -from .host_discovery import HostDiscovery - -__all__ = [HostDiscovery, KubeOpenDashboard, PortDiscovery] - diff --git a/modules/__init__.pyc b/modules/__init__.pyc deleted file mode 100644 index 928d88d..0000000 Binary files a/modules/__init__.pyc and /dev/null differ diff --git a/modules/__pycache__/__init__.cpython-36.pyc b/modules/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 94eb4c7..0000000 Binary files a/modules/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/modules/__pycache__/host_discovery.cpython-36.pyc b/modules/__pycache__/host_discovery.cpython-36.pyc deleted file mode 100644 index 4881d0b..0000000 Binary files a/modules/__pycache__/host_discovery.cpython-36.pyc and /dev/null differ diff --git a/modules/__pycache__/kube_open_dashboard.cpython-36.pyc b/modules/__pycache__/kube_open_dashboard.cpython-36.pyc deleted file mode 100644 index 651003b..0000000 Binary files a/modules/__pycache__/kube_open_dashboard.cpython-36.pyc and /dev/null differ diff --git a/modules/__pycache__/port_discovery.cpython-36.pyc b/modules/__pycache__/port_discovery.cpython-36.pyc deleted file mode 100644 index cf0d4d1..0000000 Binary files a/modules/__pycache__/port_discovery.cpython-36.pyc and /dev/null differ diff --git a/modules/host_discovery.pyc b/modules/host_discovery.pyc deleted file mode 100644 index b366fd0..0000000 Binary files a/modules/host_discovery.pyc and /dev/null differ diff --git a/modules/kube_open_dashboard.py b/modules/kube_open_dashboard.py deleted file mode 100644 index 99f8273..0000000 --- a/modules/kube_open_dashboard.py +++ /dev/null @@ -1,29 +0,0 @@ -import events -import requests - -class KubeOpenDashboard(object): - def __init__(self, task): - self.task = task - self.host = task['host'] - self.port = task['port'] or 80 - pass - - def execute(self): - try: - r = requests.get("http://{host}:{port}/api/v1/node?itemsPerPage=100".format(host=self.host, port=self.port)) - except requests.exceptions.ConnectionError: - return None - - ret = r.json() - if 'listMeta' in ret: - events.safe_print("KubeOpenDashboard :: Open Dashboard!", self.host) - - -events.handler.subscribe_event('OPEN_PORT_30000', KubeOpenDashboard) - -if __name__ == "__main__": - queue = list() - queue.append(KubeOpenDashboard({'host': '192.168.1.117', 'port': 30000})) - queue.append(KubeOpenDashboard({'host': '192.168.1.117', 'port': None})) - for i in queue: - i.execute() diff --git a/modules/kube_open_dashboard.pyc b/modules/kube_open_dashboard.pyc deleted file mode 100644 index be5cf26..0000000 Binary files a/modules/kube_open_dashboard.pyc and /dev/null differ diff --git a/modules/port_discovery.pyc b/modules/port_discovery.pyc deleted file mode 100644 index 34704db..0000000 Binary files a/modules/port_discovery.pyc and /dev/null differ