Created
July 13, 2023 05:02
-
-
Save insi2304/27e6a19b3daca239a69aca44d36a76a5 to your computer and use it in GitHub Desktop.
Enumerate Kubernetes Services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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