Skip to content

Commit 267bd93

Browse files
committed
change colors and add values into db
1 parent 5bbdb70 commit 267bd93

3 files changed

Lines changed: 42 additions & 15 deletions

File tree

nxc/protocols/ldap.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ def __init__(self, args, db, host):
149149
self.output_filename = None
150150
self.smbv1 = None
151151
self.signing = False
152-
self.signing_required = False
153-
self.cbt_status = 0
152+
self.signing_required = None
153+
self.cbt_status = None
154154
self.admin_privs = False
155155
self.no_ntlm = False
156156
self.sid_domain = ""
@@ -235,6 +235,7 @@ def get_ldap_username(self):
235235
return ""
236236

237237
def check_ldap_signing(self):
238+
self.signing_required = False
238239
ldap_url = f"ldap://{self.target}"
239240
ldap_connection = ldap_impacket.LDAPConnection(url=ldap_url, baseDN=self.baseDN, dstIp=self.host, signing=False)
240241
try:
@@ -244,14 +245,15 @@ def check_ldap_signing(self):
244245
self.signing_required = True
245246

246247
def check_ldaps_cbt(self):
248+
self.cbt_status = "Never"
247249
ldap_url = f"ldaps://{self.target}"
248250
ldap_connection = ldap_impacket.LDAPConnection(url=ldap_url, baseDN=self.baseDN, dstIp=self.host)
249251
ldap_connection._LDAPConnection__channel_binding_value = None
250252
try:
251253
ldap_connection.login(user=" ",domain=self.domain)
252254
except ldap_impacket.LDAPSessionError as e:
253255
if str(e).find("data 80090346") >= 0:
254-
self.cbt_status = 2 # CBT is Required
256+
self.cbt_status = "Always" # CBT is Required
255257
elif str(e).find("data 52e") >= 0:
256258
ldap_connection = ldap_impacket.LDAPConnection(url=ldap_url, baseDN=self.baseDN, dstIp=self.host)
257259
tmp = bytearray(ldap_connection._LDAPConnection__channel_binding_value)
@@ -261,7 +263,7 @@ def check_ldaps_cbt(self):
261263
ldap_connection.login(user=" ",domain=self.domain)
262264
except ldap_impacket.LDAPSessionError as e:
263265
if str(e).find("data 80090346") >= 0:
264-
self.cbt_status = 1 # CBT is When Supported
266+
self.cbt_status = "When Supported" # CBT is When Supported
265267

266268
def enum_host_info(self):
267269
self.hostname = self.target.split(".")[0].upper() if "." in self.target else self.target
@@ -309,15 +311,17 @@ def enum_host_info(self):
309311
self.host,
310312
self.hostname,
311313
self.domain,
312-
self.server_os
314+
self.server_os,
315+
self.signing_required,
316+
self.cbt_status
313317
)
314318
except Exception as e:
315319
self.logger.debug(f"Error adding host {self.host} into db: {e!s}")
316320

317321
def print_host_info(self):
318322
self.logger.debug("Printing host info for LDAP")
319323
signing = colored(f"signing:Enforced", host_info_colors[0], attrs=["bold"]) if self.signing_required else colored(f"signing:None", host_info_colors[1], attrs=["bold"])
320-
cbt_status = colored(f"channel binding:Always", host_info_colors[0], attrs=["bold"]) if self.cbt_status == 2 else colored(f"channel binding:{'Never' if self.cbt_status == 0 else 'When Supported'}", host_info_colors[1], attrs=["bold"])
324+
cbt_status = colored(f"channel binding:{self.cbt_status}", host_info_colors[3], attrs=["bold"]) if self.cbt_status == "Always" else colored(f"channel binding:{self.cbt_status}", host_info_colors[2], attrs=["bold"])
321325
ntlm = colored(f"(NTLM:{not self.no_ntlm})", host_info_colors[2], attrs=["bold"]) if self.no_ntlm else ""
322326
self.logger.extra["protocol"] = "LDAP" if str(self.port) == "389" else "LDAPS"
323327
self.logger.extra["port"] = self.port

nxc/protocols/ldap/database.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def db_schema(db_conn):
3838
"ip" text,
3939
"hostname" text,
4040
"domain" text,
41-
"os" text
41+
"os" text,
42+
"signing" boolean,
43+
"cbt_status" text
4244
)"""
4345
)
4446

@@ -57,7 +59,7 @@ def reflect_tables(self):
5759
)
5860
sys.exit()
5961

60-
def add_host(self, ip, hostname, domain, os):
62+
def add_host(self, ip, hostname, domain, os, signing = None, cbt_status = None):
6163
"""Check if this host has already been added to the database, if not, add it in."""
6264
hosts = []
6365
updated_ids = []
@@ -71,7 +73,9 @@ def add_host(self, ip, hostname, domain, os):
7173
"ip": ip,
7274
"hostname": hostname,
7375
"domain": domain,
74-
"os": os
76+
"os": os,
77+
"signing" : signing,
78+
"cbt_status" : cbt_status
7579
}
7680
hosts = [new_host]
7781
# update existing hosts data
@@ -85,6 +89,12 @@ def add_host(self, ip, hostname, domain, os):
8589
host_data["hostname"] = hostname
8690
if domain is not None:
8791
host_data["domain"] = domain
92+
if os is not None:
93+
host_data["os"] = os
94+
if signing is not None:
95+
host_data["signing"] = signing
96+
if cbt_status is not None:
97+
host_data["cbt_status"] = cbt_status
8898
# only add host to be updated if it has changed
8999
if host_data not in hosts:
90100
hosts.append(host_data)

nxc/protocols/ldap/db_navigator.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ def display_hosts(self, hosts):
1010
"IP",
1111
"Hostname",
1212
"Domain",
13-
"OS"
13+
"OS",
14+
"Signing",
15+
"Channel Binding"
1416
]
1517
]
1618

@@ -25,14 +27,18 @@ def display_hosts(self, hosts):
2527
except Exception:
2628
os = host[4]
2729

30+
signing = "Enforced" if bool(host[5]) else "None"
31+
cbt_status = host[6]
32+
2833
data.append(
2934
[
3035
host_id,
3136
ip,
3237
hostname,
3338
domain,
34-
os
35-
]
39+
os,
40+
signing,
41+
cbt_status ]
3642
)
3743
print_table(data, title="Hosts")
3844

@@ -54,7 +60,9 @@ def do_hosts(self, line):
5460
"IP",
5561
"Hostname",
5662
"Domain",
57-
"OS"
63+
"OS",
64+
"Signing",
65+
"Channel Binding"
5866
]
5967
]
6068
host_id_list = []
@@ -71,13 +79,18 @@ def do_hosts(self, line):
7179
except Exception:
7280
os = host[4]
7381

82+
signing = "Enforced" if bool(host[5]) else "None"
83+
cbt_status = host[6]
84+
7485
data.append(
7586
[
7687
host_id,
7788
ip,
7889
hostname,
7990
domain,
80-
os
91+
os,
92+
signing,
93+
cbt_status
8194
]
8295
)
8396
print_table(data, title="Host")
@@ -87,7 +100,7 @@ def help_hosts(self):
87100
hosts [filter_term]
88101
By default prints all hosts
89102
Table format:
90-
| 'HostID', 'IP', 'Hostname', 'Domain', 'OS' |
103+
| 'HostID', 'IP', 'Hostname', 'Domain', 'OS', 'Signing, 'Channel Binding' |
91104
Subcommands:
92105
filter_term - filters hosts with filter_term
93106
If a single host is returned (e.g. `hosts 15`, it prints the following tables:

0 commit comments

Comments
 (0)