Skip to content

Commit

Permalink
Add a query for the linked server config if we are local admin
Browse files Browse the repository at this point in the history
  • Loading branch information
NeffIsBack committed Dec 21, 2024
1 parent 1e583a0 commit 2a98a92
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions nxc/modules/enum_links.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class NXCModule:
"""
Enumerate SQL Server linked servers
Module by deathflamingo
Module by deathflamingo, NeffIsBack
"""

name = "enum_links"
description = "Enumerate linked SQL Servers"
description = "Enumerate linked SQL Servers and their login configurations."
supported_protocols = ["mssql"]
opsec_safe = True
multiple_hosts = True
Expand All @@ -14,6 +14,9 @@ def __init__(self):
self.mssql_conn = None
self.context = None

def options(self, context, module_options):
pass

def on_login(self, context, connection):
self.context = context
self.mssql_conn = connection.conn
Expand All @@ -25,6 +28,18 @@ def on_login(self, context, connection):
else:
self.context.log.fail("No linked servers found.")

def on_admin_login(self, context, connection):
res = self.mssql_conn.sql_query("EXEC sp_helplinkedsrvlogin")
srvs = [srv for srv in res if srv["Local Login"] != "NULL"]
if not srvs:
self.context.log.fail("No linked servers found.")
return
self.context.log.success("Linked servers found:")
for srv in srvs:
self.context.log.display(f"Linked server: {srv['Linked Server']}")
self.context.log.display(f" - Local login: {srv['Local Login']}")
self.context.log.display(f" - Remote login: {srv['Remote Login']}")

def get_linked_servers(self) -> list:
"""
Fetches a list of linked servers.
Expand All @@ -36,5 +51,3 @@ def get_linked_servers(self) -> list:
query = "EXEC sp_linkedservers;"
res = self.mssql_conn.sql_query(query)
return [server["SRV_NAME"] for server in res] if res else []
def options(self, context, module_options):
pass

0 comments on commit 2a98a92

Please sign in to comment.