MCPcopy Create free account
hub / github.com/bvcyber/RedWizard / get_hosts

Function get_hosts

tools/create-ssh-config.py:52–90  ·  view source on GitHub ↗

Get host information from the ansible configuration

(hosts_yaml)

Source from the content-addressed store, hash-verified

50 host_vars["portforwards"].append(forward_port)
51
52def get_hosts(hosts_yaml):
53 """
54 Get host information from the ansible configuration
55 """
56 hosts = {}
57 for host in hosts_yaml[BACKEND_NAME]["hosts"]:
58 hosts[host] = get_ip_address(hosts_yaml[BACKEND_NAME]["hosts"][host])
59 for host in hosts_yaml[RELAY_NAME]["hosts"]:
60 hosts[host] = get_ip_address(hosts_yaml[RELAY_NAME]["hosts"][host])
61
62 # Gophish hosts have their admin interface ports defined in the hosts file
63 if GOPHISH_NAME in hosts_yaml:
64 for host in hosts_yaml[GOPHISH_NAME]["hosts"]:
65 forward = get_portforward(hosts_yaml[GOPHISH_NAME]["hosts"][host], "gophish_admin_port")
66 # Loop over all existing hosts to find the one with matching IP Address, as names can differ
67 for hostname in hosts:
68 if hosts[hostname]["address"] == forward["address"]:
69 host_vars = hosts[hostname]
70 add_to_forwards(host_vars, forward["forward"])
71
72
73 # OSINT machines currently have no port defined in the hosts file, but expose RDP
74 if OSINT_NAME in hosts_yaml:
75 for host in hosts_yaml[OSINT_NAME]["hosts"]:
76 address = hosts_yaml[OSINT_NAME]["hosts"][host]['ansible_host']
77 for hostname in hosts_yaml['backends']["hosts"]:
78 if hosts_yaml['backends']["hosts"][hostname]['ansible_host'] == address:
79 add_to_forwards(hosts[hostname], 3389)
80
81 # CobaltStrike machines currently have no port defined in the hosts file, but expose 50050
82 if COBALTSTRIKE_NAME in hosts_yaml:
83 for host in hosts_yaml[COBALTSTRIKE_NAME]["hosts"]:
84 address = hosts_yaml[COBALTSTRIKE_NAME]["hosts"][host]["ansible_host"]
85 # Loop over all existing hosts to find the one with matching IP Address, as names can differ
86 for hostname in hosts:
87 if hosts[hostname]["address"] == address:
88 host_vars = hosts[hostname]
89 add_to_forwards(host_vars, 50050)
90 return hosts
91
92def parse_yaml(filename):
93 """

Callers 1

mainFunction · 0.85

Calls 3

get_ip_addressFunction · 0.85
get_portforwardFunction · 0.85
add_to_forwardsFunction · 0.85

Tested by

no test coverage detected