Skip to content

Instantly share code, notes, and snippets.

@insi2304
Created July 13, 2023 05:02
Show Gist options
  • Save insi2304/27e6a19b3daca239a69aca44d36a76a5 to your computer and use it in GitHub Desktop.
Save insi2304/27e6a19b3daca239a69aca44d36a76a5 to your computer and use it in GitHub Desktop.
Enumerate Kubernetes Services
import socket
# Resolve DNS
resolver = socket.getaddrinfo("any.any.svc.cluster.local", None)
ports = []
hosts = []
print("Services and ports running in this cluster")
print("------------------------------------------")
for result in resolver:
_, _, _, _, address = result
host = address[0]
port = address[1]
ports.append(port)
hosts.append(host)
name = host.split(".")[0]
namespace = host.split(".")[1]
print(f"Service: {name} in namespace: {namespace} on port: {port}")
ports = list(set(ports))
hosts = list(set(hosts))
print("\n\n\nnmap command to scan the cluster network")
print("----------------------------------------------")
print(f"nmap -sTVC -v -n -p {','.join(map(str, ports))} {' '.join(hosts)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment