Skip to content

Commit 832969c

Browse files
committed
better output
1 parent cf99d9c commit 832969c

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

nxc/modules/link_xpcmd.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,21 @@ def on_login(self, context, connection):
3131
return
3232

3333
self.context.log.display(f"Running command on {self.linked_server}: {self.command}")
34-
result = self.mssql_conn.sql_query(f"EXEC ('xp_cmdshell ''{self.command}''') AT [{self.linked_server}]")
35-
self.context.log.success(f"Command output: {result}")
34+
query = f"EXEC ('xp_cmdshell ''{self.command}''') AT [{self.linked_server}]"
35+
result = self.mssql_conn.sql_query(query)
36+
37+
if result:
38+
output_lines = []
39+
for row in result:
40+
output_value = row.get("output")
41+
if output_value and output_value != "NULL":
42+
output_lines.append(str(output_value))
43+
44+
if output_lines:
45+
self.context.log.success("Executed command via linked server")
46+
for line in output_lines:
47+
self.context.log.highlight(line.strip())
48+
else:
49+
self.context.log.display("Command executed but returned no output")
50+
else:
51+
self.context.log.fail("No result returned from query")

0 commit comments

Comments
 (0)