1. Resources
  2. Identity Threats
  3. Active Directory

MSSQL Linked Server Abuse

Also known as: SQL Server linked server abuse, Linked server crawling, OPENQUERY abuse, Database link hopping, SQL Server trusted links

A login on one SQL Server instance can run queries through linked servers with the rights of the account each link maps to, often sysadmin on the remote instance.

Platform
Active Directory
Impact
High
Last updated
Attack difficulty
Medium
Detection difficulty
High
Privileges required: Any authenticated identity
Any login on a SQL Server instance that has a linked server whose login mapping applies to the caller. Often any domain user.
What the attacker gains
Queries, and with RPC enabled commands, on remote SQL Server instances as the mapped account, across network segments, domains and forests.
Threat groups
AkiraAPT18APT28APT29APT33APT39APT41AxiomBlackByteCarbanakChimeraCinnamon TempestDragonflyFIN10and 39 more in MITRE ATT&CKGroups that MITRE ATT&CK records using T1078, T1210.

How it works

A linked server is a route from one SQL Server instance to another data source. An administrator defines it once on the source instance, and from then on local queries can read and write remote tables or run statements on the remote side. Each linked server has login mappings that decide which identity the source instance presents to the destination on behalf of a local login. Microsoft documents two kinds:

  • Self mapping (@useself = true, the default created with the linked server). The source instance connects with the caller's own credentials. For a Windows-authenticated caller this means SQL Server impersonates the client and carries its identity to the second server, which Microsoft calls delegation. Across machines that second hop works only if Kerberos delegation is configured for it.
  • Fixed mapping (@useself = false). The source instance connects as the remote login named in @rmtuser, with the password stored in the mapping. With @locallogin = NULL the mapping applies to every local login.

The fixed mapping is where the abuse lies. It lets many callers share one destination account without presenting their own credentials. When that account is sa or a sysadmin on the destination, any login on the source instance, including one that every domain user gets, runs remote statements as sysadmin. The mapping was created to make an application work, and nobody checked who else could use it.

Statements reach the remote side in three ways: four-part names ([SRV02].[db].[schema].[table]), OPENQUERY, which passes a query text through to the linked server, and EXECUTE (...) AT, which runs arbitrary statements there and needs the link's RPC Out option.

Links form chains. The destination may have its own linked servers, and a pass-through query can itself contain a pass-through query. One low-privileged login can therefore reach instances several hops away, in other network segments, domains or forests, as long as each hop's mapping lets the previous hop's identity through. Network controls that stop a workstation from reaching a database server do not stop the first database server from reaching it.

Two limits keep the picture accurate:

  • Rights do not transfer across a link. Being sysadmin on the source gives nothing on the destination. Only the mapped remote login's rights count there.
  • A definition is not access. A linked server entry shows that an administrator configured a route. Whether it is reachable, and what the remote login may do, has to be checked on the destination.

Self mapping and Kerberos delegation

With self mapping and Windows authentication, the first hop authenticates the user to the source instance, and the source instance must then act as the user toward the destination. That is a Kerberos double hop, and it works only when the source's service account is allowed to delegate to the destination's MSSQLSvc service: constrained delegation on the service account, or resource-based constrained delegation on the destination's account. A failed second hop is the normal result when delegation is not configured.

Where it is configured, the SQL Server service account is a delegation-enabled account, and an attacker who controls it can obtain tickets to the back-end services in its delegation list for other users. A delegation list that includes a back-end service outside the application's own boundary widens that reach.

ATT&CK mapping

Using a link with the rights its mapping grants is Valid Accounts (T1078), applied to lateral movement and privilege escalation. Exploitation of Remote Services (T1210) applies only when a vulnerability in the remote service is exploited. A permitted linked server operation alone is not enough for that technique.

Prerequisites

  • A login on an instance that has at least one linked server.
  • A login mapping on that link that applies to the caller: a fixed mapping for all logins, a mapping for the caller's login, or self mapping with working delegation or matching SQL credentials.
  • For the attack to pay off: a mapped remote login with more rights than the caller needs, ideally sysadmin on the destination.
  • For EXECUTE ... AT: RPC Out enabled on the link.

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

1. List linked servers and their mappings

-- Linked servers defined on this instance
SELECT name, product, provider, data_source, is_linked,
       is_rpc_out_enabled, is_data_access_enabled
FROM sys.servers;

-- Login mappings: which local principal maps to which remote login
SELECT s.name AS linked_server,
       p.name AS local_login,          -- NULL means all local logins
       l.uses_self_credential,
       l.remote_name
FROM sys.linked_logins AS l
JOIN sys.servers AS s ON l.server_id = s.server_id
LEFT JOIN sys.server_principals AS p ON l.local_principal_id = p.principal_id;

In the Impacket client the same listing is one command:

mssqlclient.py -windows-auth corp.example.com/alice@SRV01.corp.example.com
SQL> enum_links

2. Find out who you are on the other side

SELECT *
FROM OPENQUERY([SRV02],
    'SELECT @@SERVERNAME AS server,
            SYSTEM_USER AS remote_login,
            IS_SRVROLEMEMBER(''sysadmin'') AS is_sysadmin');

If RPC Out is enabled, EXECUTE AT gives the same answer and is not limited to queries:

EXECUTE ('SELECT SYSTEM_USER, IS_SRVROLEMEMBER(''sysadmin'')') AT [SRV02];

In the Impacket shell, use_link moves the session to the linked server so that the following statements run there. use_link .. goes back one level and use_link localhost returns to the starting instance:

SQL> use_link SRV02
SQL> enum_links
SQL> use_link ..

3. Follow the chain

A pass-through query can carry another one, with the quotes doubled at each level:

SELECT *
FROM OPENQUERY([SRV02],
    'SELECT * FROM OPENQUERY([SRV03],
        ''SELECT @@SERVERNAME AS server, SYSTEM_USER AS remote_login'')');

PowerUpSQL automates the crawl. It follows every link from a starting instance, reports the login and sysadmin status at each hop, and can run a query on all of them:

Get-SqlServerLinkCrawl -Verbose -Instance SRV01.corp.example.com

Get-SqlServerLinkCrawl -Verbose -Instance SRV01.corp.example.com `
    -Query "select name from master..sysdatabases"

4. Act on the destination

What follows depends on the remote login. As sysadmin on the destination, the attacker reads any database there and can go on to operating system commands. If RPC Out is off, a caller with the ALTER ANY LINKED SERVER permission on the source can turn it on (the Impacket shell's enable_rpc command does the same):

EXECUTE sp_serveroption 'SRV02', 'rpc out', true;

Then statements that are not plain queries can run remotely, for example the configuration change that xp_cmdshell needs.

Impact

Linked servers give lateral movement inside the database tier that ignores the usual boundaries. One weak login on a development or reporting instance can become sysadmin on a production instance, and from there reach the data, the operating system and the service account of that server. Chains cross domain and forest boundaries wherever a database link does, which is often where no Active Directory trust path was meant to exist.

A fixed mapping also hides the caller. The destination records a login by the shared remote account, from the source server's address. Which person or application on the source started it has to be reconstructed from the source instance, if anything was recorded there.

OPSEC and artifacts

  • Everything travels server to server. The attacker's host talks only to the first instance. Each further hop is a connection made by a SQL Server instance to another, exactly like the application traffic the link exists for. Firewalls and network sensors see expected flows.
  • Queries instead of configuration changes. OPENQUERY reads without altering anything. Enabling RPC Out is a change to the link's options that stays visible in sys.servers and is recorded by SQL Server Audit where server-level changes are audited.
  • Destination login records. With login auditing on the destination, each use of a fixed mapping is a successful login by the mapped remote account from the source instance's host. The account and the source are both expected, so only volume, timing or the statements that follow stand out.
  • Windows events. With Windows authentication between instances, the destination host records a network logon (event 4624 type 3), and with self mapping the domain controller records service ticket requests made through delegation (event 4769). A fixed mapping to a SQL login creates no Windows event at all.
  • Attribution gap. A shared remote name conceals the originating caller. Tying a destination action to a person needs a matching session on the source instance for the same time. A remote login event alone does not prove that data was changed.
  • Crawling. An automated crawl touches every link once in quick succession and asks the same identity questions at each hop, which is unlike an application's fixed set of queries.

Detection

  • Inventory first. Run the mapping query from step 1 on every instance. Every fixed mapping that applies to all logins, and every remote login with sysadmin, is a finding without any attack having happened.
  • Destination logins by link accounts outside their pattern. A mapped account that normally runs a nightly job and suddenly logs in during the day, or runs statements it never ran before.
  • Identity probes through a link. Pass-through statements that ask for SYSTEM_USER, IS_SRVROLEMEMBER or @@SERVERNAME, visible in SQL Server Audit on the destination when statement-level auditing covers them.
  • Link option and mapping changes. RPC Out enabled, a new linked server, a new or changed login mapping.
  • Delegation changes on SQL Server service accounts. The constrained delegation modified rules cover changes to an account's delegation list.

SQL Server Audit needs its own collection path; Windows event collection does not include it. A delegation setting on an account shows what is permitted, not that a ticket was issued or used, and a direct connection by the same user can look like delegated access. Compare the destination service in the ticket request with the services in the approved delegation list.

Mitigation

  • Replace catch-all mappings. Remove the default and "all logins" mappings and map only the specific local logins that need the link. Microsoft's own guidance is to use sp_droplinkedsrvlogin and sp_addlinkedsrvlogin to control which logins can use a linked server.
  • Give the remote login the minimum rights. A link used for reporting needs read access to a few tables, not sysadmin. Apply least privilege on the destination side, where the rights are evaluated.
  • Every remote principal maps to a documented workload. Remove linked servers nobody owns.
  • Leave RPC Out off unless a workload needs remote procedure execution.
  • Keep delegation narrow. If self mapping with Windows authentication is required, use constrained delegation limited to the one back-end service, never unconstrained delegation, and audit who can change it. Mark privileged accounts as sensitive or put them in Protected Users so they cannot be delegated; the Protected Users and delegation guide covers both.
  • Harden the service accounts. Run each instance under its own group managed service account without rights on other servers. See how to secure Active Directory service accounts.
  • Do not link across trust levels. A link from a low-trust instance to a high-trust one moves the boundary to the weaker server.
  • Audit logins and server changes on instances that are link destinations, and test application compatibility before removing a mapping.

Detection rules for this attack

Log events to collect

FAQ

What is a linked server?

A definition on one SQL Server instance that lets it run queries against another data source, usually another SQL Server instance. Each linked server has login mappings that decide which account is used on the remote side when a local login runs a query through the link.

Why does a low-privileged login become sysadmin through a link?

Because of the login mapping. An administrator can map all local logins to one fixed remote login and store its password. If that remote login is sa or another sysadmin, every login on the source instance, however weak, runs its remote queries as sysadmin on the destination.

Do sysadmin rights on one instance carry over a link?

No. Rights do not transfer. On the remote instance the session has the rights of the remote login that the mapping selects, which can be higher or lower than the caller's rights on the source instance.

Is using a linked server an exploit?

No. A query through a link that the mapping permits is the feature working as configured, with valid accounts. That is why Exploitation of Remote Services (T1210) applies only when a vulnerability in the remote service is actually exploited; a permitted linked server operation alone does not qualify.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.