Skip to content

Commit dd166c8

Browse files
committed
Add certipy-find module
1 parent adc83b7 commit dd166c8

1 file changed

Lines changed: 115 additions & 0 deletions

File tree

nxc/modules/certipy-find.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env python3
2+
import json
3+
from os import makedirs
4+
from certipy.commands.find import Find
5+
from certipy.lib.target import Target, DnsResolver
6+
from certipy.lib.formatting import pretty_print
7+
8+
from nxc.paths import NXC_PATH
9+
10+
11+
class NXCModule:
12+
"""Module made by: @NeffIsBack, @gatariee"""
13+
name = "certipy-find"
14+
description = ""
15+
supported_protocols = ["ldap"]
16+
17+
def __init__(self, context=None, module_options=None):
18+
self.context = context
19+
self.module_options = module_options
20+
21+
def options(self, context, module_options):
22+
"""
23+
VULN Show only vulnerable configurations (Default: True)
24+
ENABLED Show only enabled templates
25+
26+
Export options:
27+
TEXT Export results to a plain text file
28+
CSV Export results to a CSV file
29+
JSON Export results to a JSON file
30+
"""
31+
self.vuln = True
32+
self.enabled = False
33+
self.output_path = f"{NXC_PATH}/modules/certipy-find"
34+
self.json = False
35+
self.csv = False
36+
self.text = False
37+
38+
if "VULN" in module_options:
39+
self.vuln = module_options["VULN"].lower() in ["true", "1", "yes"]
40+
if "ENABLED" in module_options:
41+
self.enabled = module_options["ENABLED"].lower() in ["true", "1", "yes"]
42+
43+
# Export options
44+
if "JSON" in module_options:
45+
self.json = module_options["JSON"].lower() in ["true", "1", "yes"]
46+
if "CSV" in module_options:
47+
self.csv = module_options["CSV"].lower() in ["true", "1", "yes"]
48+
if "TEXT" in module_options:
49+
self.text = module_options["TEXT"].lower() in ["true", "1", "yes"]
50+
51+
def on_login(self, context, connection):
52+
resolv = DnsResolver.create(connection.args.dns_server if connection.args.dns_server else connection.host)
53+
target = Target(
54+
resolver=resolv,
55+
domain=connection.domain,
56+
username=connection.username,
57+
password=connection.password,
58+
lmhash=connection.lmhash,
59+
nthash=connection.nthash,
60+
target_ip=connection.host,
61+
ldap_port=connection.port,
62+
ldap_scheme="ldaps" if connection.port == 636 else "ldap",
63+
ldap_signing=connection.signing_required,
64+
ldap_channel_binding=connection.cbt_status in ["Always", "When Supported"],
65+
)
66+
67+
finder = Find(
68+
target=target,
69+
json=self.json,
70+
csv=self.csv,
71+
text=self.text,
72+
output_path=self.output_path,
73+
stdout=True,
74+
vulnerable=self.vuln,
75+
enabled=self.enabled,
76+
)
77+
78+
# Get templates and CAs
79+
templates = finder.get_certificate_templates()
80+
cas = finder.get_certificate_authorities()
81+
finder._link_cas_and_templates(cas, templates)
82+
83+
# Get OIDs
84+
oids = finder.get_issuance_policies()
85+
86+
# Process information
87+
finder._link_templates_and_policies(templates, oids)
88+
finder._process_ca_properties(cas)
89+
finder._process_template_properties(templates)
90+
91+
output = finder.get_output_for_text_and_json(templates, cas, oids)
92+
pretty_print(output, print_func=context.log.highlight)
93+
94+
# Save to disk if any export option specified
95+
if self.json or self.csv or self.text:
96+
makedirs(self.output_path, exist_ok=True)
97+
98+
if self.json:
99+
with open(f"{self.output_path}/certipy-find.json", "w") as f:
100+
json.dump(
101+
output,
102+
f,
103+
indent=2,
104+
default=str,
105+
)
106+
if self.csv:
107+
template_output = finder.get_template_output_for_csv(output)
108+
ca_output = finder.get_ca_output_for_csv(output)
109+
with open(f"{self.output_path}/certipy-find-templates.csv", "w") as f:
110+
f.write(template_output)
111+
with open(f"{self.output_path}/certipy-find-cas.csv", "w") as f:
112+
f.write(ca_output)
113+
if self.text:
114+
with open(f"{self.output_path}/certipy-find.txt", "w") as f:
115+
pretty_print(output, print_func=lambda x: f.write(x + "\n"))

0 commit comments

Comments
 (0)