HTB 용 초기 정보 수집 스크립트

  1. ip랑 filename을 받아서 port scan 후 오픈된 포트만 모아서 -sCV로 기본 스크립트, 버전 스캔 수행
  2. domain name 발견 시 hosts file에 추가
  3. ffuf 로 directory brute forcing 수행

개선 필요사항

1. brute forcing 조건 분기 추가 필요
file size 같은 것이 연속으로 나올 시 해당 프로세스 종료 후 file size 필터 옵션까지 추가한 새로운 프로세스 생성

#!/bin/bash
read -p "Enter target ip: " ip 
read -p "Enter file name to save: " filename
ports=$(sudo -sS nmap -p- -Pn -n --min-rate=10000 $ip | grep '^[0-9]' | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//)
result=$(sudo nmap -p$ports -sCV $ip -oA $filename)
echo "$result"

host=$(echo "$result" | grep -oP '(?<=http://)[^/ ]+')

if [[ -n "$host" ]]; then
    echo "$ip $host" | sudo tee -a /etc/hosts
    echo "The domain name has been added to hosts file"
else
    echo "No valid URL found. Skippng"
fi

read -p "Do you wanna web directory brute forcing? (yes/y) " answer

answer=$(echo "$answer" | tr '[:upper:]' '[:lower:]')

if [[ "$answer" == "yes" || "$answer" == "y" ]]; then
    echo -e "\nWordlists list:"
    echo "1. /usr/share/wordlists/dirb/common.txt"
    echo "2. /usr/share/dirbuster/wordlists/directory-list-2.3-small.txt"
    echo "3. /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt"
    read -p "Select a wordlist option (1, 2, or 3): " option
    case $option in
        1)
            wordlist="/usr/share/wordlists/dirb/common.txt"
            ;;
        2)
            wordlist="/usr/share/dirbuster/wordlists/directory-list-2.3-small.txt"
            ;;
        3)
            wordlist="/usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt"
            ;;
        *)
            echo "invvalid option selected. Exiting"
            exit 1
            ;;
    esac

    if [[ -n "$host" ]]; then
        ffuf -u "http://$host/FUZZ" -w "$wordlist" -fc 404
    else
        ffuf -u "http://$ip/FUZZ" -w "$wordlist" -fc 404
    fi
else
    echo "Brute forcing skipped."
fi

ip=""
host=""
filename=""
ports=""
result=""

+ Recent posts