mirror of
https://github.com/aquasecurity/kube-hunter.git
synced 2026-05-14 05:07:02 +00:00
Initial Commit
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
.idea/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
6
__init__.py
Normal file
6
__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from .kube_open_dashboard import KubeOpenDashboard
|
||||
from .port_discovery import PortDiscovery
|
||||
from .host_discovery import HostDiscovery
|
||||
|
||||
__all__ = [HostDiscovery, KubeOpenDashboard, PortDiscovery]
|
||||
|
||||
18
events.py
Normal file
18
events.py
Normal file
@@ -0,0 +1,18 @@
|
||||
hooks = {}
|
||||
|
||||
|
||||
def trigger_event(name, item):
|
||||
print('Event Lookup: ', name, item)
|
||||
if name in hooks:
|
||||
for single_hook in hooks[name]:
|
||||
print("Event triggerd!", single_hook, item)
|
||||
single_hook(item).execute()
|
||||
|
||||
|
||||
def register_event(name, callback):
|
||||
print('NEW Event: ', name, callback)
|
||||
if name not in hooks:
|
||||
# default dict
|
||||
hooks[name] = []
|
||||
if callback not in hooks[name]:
|
||||
hooks[name].append(callback)
|
||||
16
host_discovery.py
Normal file
16
host_discovery.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from netifaces import interfaces, ifaddresses, AF_INET
|
||||
from netaddr import IPNetwork
|
||||
import events
|
||||
|
||||
|
||||
class HostDiscovery(object):
|
||||
def __init__(self, task):
|
||||
pass
|
||||
|
||||
def execute(self):
|
||||
for ifaceName in interfaces():
|
||||
addresses = [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [])]
|
||||
if addresses:
|
||||
subnet = IPNetwork('{0}/24'.format(addresses[0]))
|
||||
for single_ip in IPNetwork(subnet):
|
||||
events.trigger_event('NEW_HOST', {'host': single_ip})
|
||||
31
kube_open_dashboard.py
Normal file
31
kube_open_dashboard.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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:
|
||||
print("KubeOpenDashboard :: Open Dashboard!", self.host)
|
||||
|
||||
|
||||
events.register_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()
|
||||
6
modules/__init__.py
Normal file
6
modules/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from .kube_open_dashboard import KubeOpenDashboard
|
||||
from .port_discovery import PortDiscovery
|
||||
from .host_discovery import HostDiscovery
|
||||
|
||||
__all__ = [HostDiscovery, KubeOpenDashboard, PortDiscovery]
|
||||
|
||||
BIN
modules/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
modules/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/host_discovery.cpython-36.pyc
Normal file
BIN
modules/__pycache__/host_discovery.cpython-36.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/kube_open_dashboard.cpython-36.pyc
Normal file
BIN
modules/__pycache__/kube_open_dashboard.cpython-36.pyc
Normal file
Binary file not shown.
BIN
modules/__pycache__/port_discovery.cpython-36.pyc
Normal file
BIN
modules/__pycache__/port_discovery.cpython-36.pyc
Normal file
Binary file not shown.
16
modules/host_discovery.py
Normal file
16
modules/host_discovery.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from netifaces import interfaces, ifaddresses, AF_INET
|
||||
from netaddr import IPNetwork
|
||||
import events
|
||||
|
||||
|
||||
class HostDiscovery(object):
|
||||
def __init__(self, task):
|
||||
pass
|
||||
|
||||
def execute(self):
|
||||
for ifaceName in interfaces():
|
||||
addresses = [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [])]
|
||||
if addresses:
|
||||
subnet = IPNetwork('{0}/24'.format(addresses[0]))
|
||||
for single_ip in IPNetwork(subnet):
|
||||
events.trigger_event('NEW_HOST', {'host': single_ip})
|
||||
31
modules/kube_open_dashboard.py
Normal file
31
modules/kube_open_dashboard.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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:
|
||||
print("KubeOpenDashboard :: Open Dashboard!", self.host)
|
||||
|
||||
|
||||
events.register_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()
|
||||
36
modules/port_discovery.py
Normal file
36
modules/port_discovery.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from socket import socket
|
||||
import events
|
||||
|
||||
default_ports = [8001, 10250, 10255, 30000]
|
||||
|
||||
|
||||
class PortDiscovery(object):
|
||||
def __init__(self, task):
|
||||
self.host = task['host']
|
||||
|
||||
def execute(self):
|
||||
for single_port in default_ports:
|
||||
if self.test_connection(self.host, single_port):
|
||||
events.trigger_event('OPEN_PORT', {'host': self.host, 'port': single_port})
|
||||
events.trigger_event('OPEN_PORT_{port}'.format(port=single_port),
|
||||
{'host': self.host, 'port': single_port})
|
||||
|
||||
@staticmethod
|
||||
def test_connection(host, port):
|
||||
s = socket()
|
||||
s.settimeout(1)
|
||||
success = s.connect_ex((str(host), port))
|
||||
s.close()
|
||||
if success == 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
events.register_event('NEW_HOST', PortDiscovery)
|
||||
|
||||
if __name__ == "__main__":
|
||||
queue = list()
|
||||
queue.append(PortDiscovery({'host': '192.168.1.117'}))
|
||||
queue.append(PortDiscovery({'host': '192.168.1.101'}))
|
||||
for i in queue:
|
||||
i.execute()
|
||||
36
port_discovery.py
Normal file
36
port_discovery.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from socket import socket
|
||||
import events
|
||||
|
||||
default_ports = [8001, 10250, 10255, 30000]
|
||||
|
||||
|
||||
class PortDiscovery(object):
|
||||
def __init__(self, task):
|
||||
self.host = task['host']
|
||||
|
||||
def execute(self):
|
||||
for single_port in default_ports:
|
||||
if self.test_connection(self.host, single_port):
|
||||
events.trigger_event('OPEN_PORT', {'host': self.host, 'port': single_port})
|
||||
events.trigger_event('OPEN_PORT_{port}'.format(port=single_port),
|
||||
{'host': self.host, 'port': single_port})
|
||||
|
||||
@staticmethod
|
||||
def test_connection(host, port):
|
||||
s = socket()
|
||||
s.settimeout(1)
|
||||
success = s.connect_ex((str(host), port))
|
||||
s.close()
|
||||
if success == 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
events.register_event('NEW_HOST', PortDiscovery)
|
||||
|
||||
if __name__ == "__main__":
|
||||
queue = list()
|
||||
queue.append(PortDiscovery({'host': '192.168.1.117'}))
|
||||
queue.append(PortDiscovery({'host': '192.168.1.101'}))
|
||||
for i in queue:
|
||||
i.execute()
|
||||
Reference in New Issue
Block a user