Skip to content

Instantly share code, notes, and snippets.

@alonsoir
Last active June 10, 2025 10:06
Show Gist options
  • Save alonsoir/b4fc54acf47ac2512944a6822a30b047 to your computer and use it in GitHub Desktop.
Save alonsoir/b4fc54acf47ac2512944a6822a30b047 to your computer and use it in GitHub Desktop.
El script automatiza un pipeline de reconocimiento y análisis de vulnerabilidades web en Kali Linux. Acepta como entrada un dominio objetivo y ejecuta una serie de herramientas especializadas, organizadas en fases, para extraer subdominios, escanear puertos, realizar fingerprinting y buscar posibles vulnerabilidades.
#!/bin/bash
set -e
# ==================== COLORES ====================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
NC='\033[0m' # Sin color
# ==================== PARÁMETROS ====================
TARGET=$1
OUTPUT_DIR=${2:-"./output"}
MAX_PARALLEL=${3:-4}
if [[ -z "$TARGET" ]]; then
echo -e "${RED}Uso: $0 <dominio> [output_dir] [max_parallel]${NC}"
exit 1
fi
DATE=$(date +"%d-%m-%Y")
mkdir -p "$OUTPUT_DIR"
# ==================== CONFIGURACIÓN DE GO ====================
setup_go_env() {
echo -e "${BLUE}[*] Configurando entorno Go...${NC}"
# Configurar variables de Go para mejor conectividad
export GOPROXY=direct
export GOSUMDB=off
export GO111MODULE=on
# Asegurar que Go está en PATH
if [ -d "/usr/lib/go-1.*/bin" ]; then
export PATH=$PATH:/usr/lib/go-1.*/bin
fi
# Configurar GOPATH si no existe
if [ -z "$GOPATH" ]; then
export GOPATH=$HOME/go
mkdir -p $GOPATH/bin
fi
export PATH=$PATH:$GOPATH/bin
# Guardar en bashrc para futuras sesiones
if ! grep -q "GOPATH" ~/.bashrc; then
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
echo 'export GOPROXY=direct' >> ~/.bashrc
echo 'export GOSUMDB=off' >> ~/.bashrc
fi
}
# ==================== VERIFICACIÓN DE HERRAMIENTAS ====================
check_tool() {
local tool=$1
if command -v $tool &> /dev/null; then
echo -e "${GREEN}[✓] $tool ya está instalado${NC}"
return 0
else
echo -e "${YELLOW}[!] $tool no encontrado${NC}"
return 1
fi
}
# ==================== INSTALACIÓN DE DEPENDENCIAS ====================
echo -e "${BLUE}[*] Verificando e instalando dependencias...${NC}"
# Actualizar repositorios solo si es necesario
echo -e "${BLUE}[*] Actualizando repositorios...${NC}"
sudo apt update
# Configurar entorno Go
setup_go_env
# Herramientas disponibles en repositorios de Kali (prioritarias)
KALI_TOOLS=("nmap" "amass" "findomain" "ffuf" "nuclei" "wpscan" "subfinder")
echo -e "${BLUE}[*] Instalando herramientas desde repositorios de Kali...${NC}"
for tool in "${KALI_TOOLS[@]}"; do
if ! check_tool $tool; then
echo -e "${YELLOW}[!] Instalando $tool desde repositorios...${NC}"
sudo apt install -y $tool || echo -e "${RED}[ERROR] No se pudo instalar $tool desde repositorios${NC}"
fi
done
# Instalar Python/pip si no existe (para arjun)
if ! command -v pip3 &> /dev/null; then
echo -e "${YELLOW}[!] Instalando Python3 y pip...${NC}"
sudo apt install -y python3-pip
fi
# Herramientas que requieren Go install (solo las necesarias)
GO_TOOLS=(
"assetfinder:github.com/tomnomnom/assetfinder@latest"
"naabu:github.com/projectdiscovery/naabu/v2/cmd/naabu@latest"
"httpx:github.com/projectdiscovery/httpx/cmd/httpx@latest"
"gau:github.com/lc/gau@latest"
)
echo -e "${BLUE}[*] Instalando herramientas con Go (con reintentos)...${NC}"
for tool_info in "${GO_TOOLS[@]}"; do
tool_name=$(echo $tool_info | cut -d: -f1)
tool_url=$(echo $tool_info | cut -d: -f2)
if ! check_tool $tool_name; then
echo -e "${YELLOW}[!] Instalando $tool_name...${NC}"
# Intentar instalar con reintentos
for attempt in {1..3}; do
echo -e "${BLUE}[*] Intento $attempt/3 para $tool_name${NC}"
if timeout 60 go install -v $tool_url; then
echo -e "${GREEN}[✓] $tool_name instalado exitosamente${NC}"
break
else
echo -e "${RED}[ERROR] Fallo en intento $attempt para $tool_name${NC}"
if [ $attempt -eq 3 ]; then
echo -e "${RED}[WARNING] No se pudo instalar $tool_name. Continuando sin esta herramienta...${NC}"
fi
sleep 2
fi
done
fi
done
# Instalar arjun con pip
if ! check_tool arjun; then
echo -e "${YELLOW}[!] Instalando arjun con pip...${NC}"
pip3 install arjun --break-system-packages 2>/dev/null || pip3 install arjun
fi
# Verificar que las herramientas críticas están disponibles
echo -e "\n${BLUE}[*] Verificación final de herramientas...${NC}"
CRITICAL_TOOLS=("subfinder" "nmap" "httpx")
for tool in "${CRITICAL_TOOLS[@]}"; do
if ! check_tool $tool; then
echo -e "${RED}[ERROR] Herramienta crítica $tool no disponible. El script puede fallar.${NC}"
fi
done
# ==================== FUNCIONES MEJORADAS ====================
run_batch() {
local batch_name=$1
shift
local cmds=("$@")
echo -e "\n${GREEN}[FASE $batch_name]${NC}"
local running=0
local pids=()
for cmd in "${cmds[@]}"; do
# Verificar que la herramienta existe antes de ejecutar
tool_name=$(echo $cmd | awk '{print $1}')
if ! command -v $tool_name &> /dev/null; then
echo -e "${RED}[SKIP] $tool_name no disponible, saltando: $cmd${NC}"
continue
fi
echo -e "${BLUE}[RUNNING] $cmd${NC}"
bash -c "$cmd" &
pids+=($!)
((running++))
if [[ $running -ge $MAX_PARALLEL ]]; then
# Esperar a que terminen los procesos actuales
for pid in "${pids[@]}"; do
wait $pid 2>/dev/null || echo -e "${YELLOW}[WARNING] Proceso $pid terminó con error${NC}"
done
pids=()
running=0
fi
done
# Esperar procesos restantes
for pid in "${pids[@]}"; do
wait $pid 2>/dev/null || echo -e "${YELLOW}[WARNING] Proceso $pid terminó con error${NC}"
done
}
# ==================== VERIFICACIÓN DE CONECTIVIDAD ====================
echo -e "\n${BLUE}[*] Verificando conectividad con el objetivo...${NC}"
if ping -c 2 $TARGET &>/dev/null; then
echo -e "${GREEN}[✓] Conectividad con $TARGET confirmada${NC}"
else
echo -e "${YELLOW}[WARNING] No se puede hacer ping a $TARGET, continuando de todos modos...${NC}"
fi
# ==================== CREACIÓN DE ARCHIVOS TEMPORALES ====================
TEMP_SUBDOMAINS="$OUTPUT_DIR/temp_all_subdomains_${TARGET}_${DATE}.txt"
touch "$TEMP_SUBDOMAINS"
# ==================== BATCHES MEJORADOS ====================
FASE1_CMDS=(
"subfinder -d $TARGET -silent -o $OUTPUT_DIR/subfinder_${TARGET}_${DATE}.txt 2>/dev/null || echo 'Subfinder falló'"
"assetfinder --subs-only $TARGET > $OUTPUT_DIR/assetfinder_${TARGET}_${DATE}.txt 2>/dev/null || echo 'Assetfinder falló'"
"amass enum -passive -d $TARGET -o $OUTPUT_DIR/amass_${TARGET}_${DATE}.txt 2>/dev/null || echo 'Amass falló'"
"findomain -t $TARGET -q -o $OUTPUT_DIR/findomain_${TARGET}_${DATE}.txt 2>/dev/null || echo 'Findomain falló'"
)
# Combinar resultados de subdominios después de la fase 1
combine_subdomains() {
echo -e "${BLUE}[*] Combinando resultados de subdominios...${NC}"
cat $OUTPUT_DIR/*finder*_${TARGET}_${DATE}.txt $OUTPUT_DIR/amass_${TARGET}_${DATE}.txt 2>/dev/null | \
sort -u > "$TEMP_SUBDOMAINS"
echo -e "${GREEN}[✓] $(wc -l < "$TEMP_SUBDOMAINS") subdominios únicos encontrados${NC}"
}
FASE2_CMDS=(
"naabu -l $TEMP_SUBDOMAINS -silent -o $OUTPUT_DIR/naabu_${TARGET}_${DATE}.txt 2>/dev/null || echo 'Naabu falló'"
"httpx -l $TEMP_SUBDOMAINS -silent -o $OUTPUT_DIR/httpx_${TARGET}_${DATE}.txt 2>/dev/null || echo 'HTTPx falló'"
"ffuf -u https://$TARGET/FUZZ -w /usr/share/seclists/Discovery/Web-Content/common.txt -mc 200,301,302,403 -s -o $OUTPUT_DIR/ffuf_${TARGET}_${DATE}.json 2>/dev/null || echo 'FFUF falló'"
"nmap -iL $TEMP_SUBDOMAINS -T4 -F --open -oA $OUTPUT_DIR/nmap_${TARGET}_${DATE} 2>/dev/null || echo 'Nmap falló'"
)
FASE3_CMDS=(
"gau $TARGET > $OUTPUT_DIR/gau_${TARGET}_${DATE}.txt 2>/dev/null || echo 'GAU falló'"
"arjun -i $OUTPUT_DIR/httpx_${TARGET}_${DATE}.txt -o $OUTPUT_DIR/arjun_${TARGET}_${DATE}.txt 2>/dev/null || echo 'Arjun falló'"
"nuclei -l $OUTPUT_DIR/httpx_${TARGET}_${DATE}.txt -silent -o $OUTPUT_DIR/nuclei_${TARGET}_${DATE}.txt 2>/dev/null || echo 'Nuclei falló'"
"wpscan --url https://$TARGET --enumerate u --no-banner -o $OUTPUT_DIR/wpscan_${TARGET}_${DATE}.txt 2>/dev/null || echo 'WPScan falló'"
)
# ==================== EJECUCIÓN MEJORADA ====================
echo -e "\n${GREEN}[*] Iniciando pipeline de reconocimiento para $TARGET${NC}"
echo -e "${BLUE}[*] Resultados se guardarán en: $OUTPUT_DIR${NC}"
run_batch "1: Reconocimiento de subdominios" "${FASE1_CMDS[@]}"
combine_subdomains
run_batch "2: Escaneo de puertos y servicios" "${FASE2_CMDS[@]}"
run_batch "3: Detección de vulnerabilidades y parámetros" "${FASE3_CMDS[@]}"
# ==================== RESUMEN FINAL ====================
echo -e "\n${GREEN}===============================================${NC}"
echo -e "${GREEN} RESUMEN DE RESULTADOS${NC}"
echo -e "${GREEN}===============================================${NC}"
for file in $OUTPUT_DIR/*_${TARGET}_${DATE}.*; do
if [ -f "$file" ]; then
lines=$(wc -l < "$file" 2>/dev/null || echo "0")
basename_file=$(basename "$file")
echo -e "${BLUE}$basename_file:${NC} $lines líneas"
fi
done
echo -e "\n${GREEN}✅ Pipeline completo. Resultados guardados en $OUTPUT_DIR${NC}"
echo -e "${BLUE}[INFO] Archivos temporales conservados para análisis adicional${NC}"
# Limpiar archivo temporal
rm -f "$TEMP_SUBDOMAINS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment