feat: añadidos los retos y el script para ir mostrando quien va más
avanzado
This commit is contained in:
43
retos/1-logs/gen-access-log.sh
Executable file
43
retos/1-logs/gen-access-log.sh
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
# Se ejecuta en: dentro del CT plantilla, lanzado por template.sh.
|
||||
# Uso: bash gen-access-log.sh > access.log
|
||||
# Genera una hora de log de nginx (formato combinado, unas 5000 líneas). Una IP
|
||||
# que ataca el login hace unas 600 peticiones; la siguiente, unas 300. La
|
||||
# semilla es fija: el mismo awk da siempre el mismo log.
|
||||
set -euo pipefail
|
||||
|
||||
awk -v seed=2026 -v lines=5000 'BEGIN {
|
||||
srand(seed)
|
||||
attacker = "203.0.113.66"
|
||||
office = "198.51.100.10"
|
||||
n_ips = split("192.0.2.14 192.0.2.27 192.0.2.33 192.0.2.48 192.0.2.51 " \
|
||||
"192.0.2.69 192.0.2.77 192.0.2.85 192.0.2.102 192.0.2.118 " \
|
||||
"192.0.2.131 192.0.2.140 192.0.2.156 192.0.2.173 192.0.2.190 " \
|
||||
"198.51.100.7 198.51.100.21 198.51.100.36 198.51.100.44 198.51.100.59 " \
|
||||
"198.51.100.63 198.51.100.88 198.51.100.95 198.51.100.120 " \
|
||||
"203.0.113.5 203.0.113.18 203.0.113.29 203.0.113.42 203.0.113.57 " \
|
||||
"203.0.113.81", ips, " ")
|
||||
n_paths = split("/ /index.html /eventos /eventos/taller-bash /blog " \
|
||||
"/blog/primeros-pasos-con-git /css/main.css /js/app.js /img/logo.png " \
|
||||
"/favicon.ico /api/miembros /contacto", paths, " ")
|
||||
n_agents = split("Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0|" \
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36|" \
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1|" \
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15", agents, "|")
|
||||
|
||||
for (i = 0; i < lines; i++) {
|
||||
t = int(i * 3600 / lines)
|
||||
time = sprintf("29/Oct/2026:03:%02d:%02d +0100", int(t / 60), t % 60)
|
||||
r = rand()
|
||||
if (r < 0.12) {
|
||||
printf "%s - - [%s] \"POST /wp-login.php HTTP/1.1\" 401 172 \"-\" \"python-requests/2.32.3\"\n", attacker, time
|
||||
continue
|
||||
}
|
||||
# La oficina sale a internet con una sola IP: mucho tráfico, pero legítimo
|
||||
ip = r < 0.18 ? office : ips[1 + int(rand() * n_ips)]
|
||||
status = rand() < 0.9 ? 200 : (rand() < 0.5 ? 304 : 404)
|
||||
bytes = status == 304 ? 0 : 200 + int(rand() * 20000)
|
||||
printf "%s - - [%s] \"GET %s HTTP/1.1\" %d %d \"https://club.example.org/\" \"%s\"\n", \
|
||||
ip, time, paths[1 + int(rand() * n_paths)], status, bytes, agents[1 + int(rand() * n_agents)]
|
||||
}
|
||||
}'
|
||||
Reference in New Issue
Block a user