Skip to content

Commit 50a5b6b

Browse files
committed
Merge branch 'main' into fix-dbs
2 parents a4ad689 + 43da2af commit 50a5b6b

12 files changed

Lines changed: 607 additions & 29 deletions

File tree

nxc/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,16 @@ def print_host_info(self):
206206
def create_conn_obj(self):
207207
return
208208

209+
def disconnect(self):
210+
return
211+
209212
def check_if_admin(self):
210213
return
211214

212215
def kerberos_login(self, domain, username, password="", ntlm_hash="", aesKey="", kdcHost="", useCache=False):
213216
return
214217

215-
def plaintext_login(self, domain, username, password):
218+
def plaintext_login(self, username, password):
216219
return
217220

218221
def hash_login(self, domain, username, ntlm_hash):
@@ -234,6 +237,7 @@ def proto_flow(self):
234237
else:
235238
self.logger.debug("Calling command arguments")
236239
self.call_cmd_args()
240+
self.disconnect()
237241

238242
def call_cmd_args(self):
239243
"""Calls all the methods specified by the command line arguments

nxc/database.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,8 @@ def write_configfile(config, config_path):
5151
config.write(configfile)
5252

5353

54-
def create_workspace(workspace_name, p_loader=None):
55-
"""
56-
Create a new workspace with the given name.
57-
58-
Args:
59-
----
60-
workspace_name (str): The name of the workspace.
61-
62-
Returns:
63-
-------
64-
None
65-
"""
66-
if exists(path_join(WORKSPACE_DIR, workspace_name)):
67-
print(f"[-] Workspace {workspace_name} already exists")
68-
else:
69-
print(f"[*] Creating {workspace_name} workspace")
70-
mkdir(path_join(WORKSPACE_DIR, workspace_name))
71-
54+
def init_protocol_dbs(workspace_name, p_loader=None):
55+
"""Check for each protocol if the database exists, if not create it."""
7256
if p_loader is None:
7357
p_loader = ProtocolLoader()
7458
protocols = p_loader.get_protocols()
@@ -93,6 +77,27 @@ def create_workspace(workspace_name, p_loader=None):
9377
conn.close()
9478

9579

80+
def create_workspace(workspace_name, p_loader=None):
81+
"""
82+
Create a new workspace with the given name.
83+
84+
Args:
85+
----
86+
workspace_name (str): The name of the workspace.
87+
88+
Returns:
89+
-------
90+
None
91+
"""
92+
if exists(path_join(WORKSPACE_DIR, workspace_name)):
93+
print(f"[-] Workspace {workspace_name} already exists")
94+
else:
95+
print(f"[*] Creating {workspace_name} workspace")
96+
mkdir(path_join(WORKSPACE_DIR, workspace_name))
97+
98+
init_protocol_dbs(workspace_name, p_loader)
99+
100+
96101
def delete_workspace(workspace_name):
97102
shutil.rmtree(path_join(WORKSPACE_DIR, workspace_name))
98103
print(f"[*] Workspace {workspace_name} deleted")
@@ -137,3 +142,7 @@ def db_execute(self, *args):
137142
res = self.sess.execute(*args)
138143
self.lock.release()
139144
return res
145+
146+
147+
# Even if the default workspace exists, we still need to check if every protocol has a database (in case of a new protocol)
148+
init_protocol_dbs("default")

0 commit comments

Comments
 (0)