mirror of
https://github.com/aquasecurity/kube-hunter.git
synced 2026-05-17 06:37:11 +00:00
2. Changed method of hidden stacking of event, to send self as an argument, by inheriting from "Hunter" class. where the publish acts as a proxy to the handler. 3. Added new way of categorizing events, while added an option to subscribe to a father event. if en event gets publish, if its father event is hooked, the hook will be triggered 4. Added a reporter in log/ which listens to parent events, meanwhile Vulnerability and OpenService were added. all logging will be made from reporter from now on
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import logging
|
|
import sys
|
|
import time
|
|
from enum import Enum
|
|
from ..types import Hunter
|
|
|
|
from netaddr import IPNetwork
|
|
|
|
from ..events import handler
|
|
from ..events.types import HostScanEvent, NewHostEvent
|
|
from netifaces import AF_INET, ifaddresses, interfaces
|
|
|
|
|
|
# for comparing prefixes
|
|
class InterfaceTypes(Enum):
|
|
LOCALHOST = "127.0.0"
|
|
|
|
@handler.subscribe(HostScanEvent)
|
|
class HostDiscovery(Hunter):
|
|
def __init__(self, event):
|
|
self.event = event
|
|
# self.external = event.external
|
|
|
|
def execute(self):
|
|
logging.info("Discovering Open Kubernetes Services...")
|
|
|
|
self.publish_event(NewHostEvent(host="acs954agent1.westus2.cloudapp.azure.com")) # test cluster
|
|
# for ifaceName in interfaces():
|
|
# for ip in self.generate_addresses(ifaceName):
|
|
# handler.publish_event(NewHostEvent(host=ip))
|
|
|
|
def generate_addresses(self, ifaceName):
|
|
for address in [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [])]:
|
|
subnet = IPNetwork('{0}/24'.format(address))
|
|
for ip in IPNetwork(subnet):
|
|
if not self.event.localhost and InterfaceTypes.LOCALHOST.value in ip.__str__():
|
|
continue
|
|
yield ip |