Merge pull request #1387 from Diogo-Damasceno/fix/nxcdb-host-csv-header

Fix #1385: derive nxcdb hosts CSV header from the protocol's HostsTable
This commit is contained in:
Alex authored and GitHub committed 2026-09-23 20:27:47 +02:00
commit 4134e689e0
1 file changed
+14 -29
+14 -29
View File
@@ -40,6 +40,17 @@ def write_csv(filename, headers, entries):
csv_file.writerow(entry)
def host_csv_headers(hosts_table, mode="simple"):
"""Return the CSV header for a hosts export, taken from the protocol's own HostsTable.
"simple" keeps the first 8 columns, the historical width of the SMB export, "detailed" returns them all.
"""
columns = tuple(col.name for col in hosts_table.columns)
if mode == "detailed":
return columns
return columns[:8]
def write_list(filename, entries):
"""Writes a file with a simple list"""
with open(os.path.expanduser(filename), "w") as export_file:
@@ -169,39 +180,13 @@ class DatabaseNavigator(cmd.Cmd):
print("[-] invalid arguments, export hosts <simple|detailed|signing> <filename>")
return
csv_header_simple = (
"id",
"ip",
"hostname",
"domain",
"os",
"dc",
"smbv1",
"signing",
)
csv_header_detailed = (
"id",
"ip",
"hostname",
"domain",
"os",
"dc",
"smbv1",
"signing",
"spooler",
"zerologon",
"petitpotam",
)
filename = line[2]
if line[1].lower() == "simple":
hosts = self.db.get_hosts()
simple_hosts = [host[:8] for host in hosts]
write_csv(filename, csv_header_simple, simple_hosts)
# TODO: maybe add more detail like who is an admin on it, shares discovered, etc
csv_header = host_csv_headers(self.db.HostsTable, "simple")
write_csv(filename, csv_header, [host[: len(csv_header)] for host in self.db.get_hosts()])
elif line[1].lower() == "detailed":
hosts = self.db.get_hosts()
write_csv(filename, csv_header_detailed, hosts)
write_csv(filename, host_csv_headers(self.db.HostsTable, "detailed"), self.db.get_hosts())
elif line[1].lower() == "signing":
hosts = self.db.get_hosts("signing")
signing_hosts = [host[1] for host in hosts]