diff --git a/target.sh b/target.sh new file mode 100755 index 0000000..5746fad --- /dev/null +++ b/target.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail +trap cleanup SIGINT SIGTERM ERR EXIT + +script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) + +usage() { + cat << EOF +Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] + +This script checks each subdirectory in the base directory for an 'inscope.txt' file. +If found, it prints each domain in the file. Otherwise, it reports no domains found. + +Available options: + +-h, --help Print this help and exit +-v, --verbose Print script debug info +EOF + exit +} + +cleanup() { + trap - SIGINT SIGTERM ERR EXIT + # add cleanup tasks here, if needed +} + +setup_colors() { + if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then + NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' + else + NOFORMAT='' RED='' GREEN='' YELLOW='' + fi +} + +msg() { + echo >&2 -e "${1-}" +} + +die() { + local msg=$1 + local code=${2-1} # default exit status 1 + msg "$msg" + exit "$code" +} + +parse_params() { + while :; do + case "${1-}" in + -h | --help) usage ;; + -v | --verbose) set -x ;; + --no-color) NO_COLOR=1 ;; + -?*) die "Unknown option: $1" ;; + *) break ;; + esac + shift + done +} + +parse_params "$@" +setup_colors + +# script logic here +baseDir=~/tgt + +if [[ -d "$baseDir" ]]; then + for dir in "$baseDir"/*/; do + if [[ -f "${dir}/inscope.txt" ]]; then + programName=$(basename "$dir") + msg "${GREEN}Grabbing domains for $programName:${NOFORMAT}" + cat "${dir}/inscope.txt" | xargs -I{} echo "{} is in scope." + else + programName=$(basename "$dir") + msg "${YELLOW}No root domains found in ${baseDir}/$programName!${NOFORMAT}" + fi + done +else + msg "${RED}Directory '$baseDir' does not exist.${NOFORMAT}" +fi +