#!/usr/bin/env bash # # amass_wizard.sh — Interactive install & configuration wizard for OWASP Amass (v5+). # # Usage: # ./amass_wizard.sh # interactive wizard # ./amass_wizard.sh --free # walk only the 14 high-value FREE data sources # ./amass_wizard.sh --check # report current status only # ./amass_wizard.sh --list # show the 48-source catalog, tiers, and state # ./amass_wizard.sh --verify # live-validate all configured keys in parallel # ./amass_wizard.sh --import # import keys from subfinder/uncover/bbot/theHarvester/env # ./amass_wizard.sh --yes # auto-confirm non-destructive prompts (e.g. with --import) # set -euo pipefail AMASS_CONFIG_DIR="${AMASS_CONFIG_DIR:-$HOME/.config/amass}" MAIN_CFG="$AMASS_CONFIG_DIR/config.yaml" DS_CFG="$AMASS_CONFIG_DIR/datasources.yaml" NONINTERACTIVE=false LIST_ONLY=false VERIFY_ONLY=false FREE_ONLY=false IMPORT_ONLY=false ASSUME_YES=false if [[ "${BASH_SOURCE[0]:-$0}" == "$0" ]]; then for arg in "$@"; do case "$arg" in --check) NONINTERACTIVE=true ;; --list) LIST_ONLY=true ;; --verify) VERIFY_ONLY=true ;; --free) FREE_ONLY=true ;; --import) IMPORT_ONLY=true ;; -y|--yes) ASSUME_YES=true ;; -h|--help) sed -n '2,13p' "$0"; exit 0 ;; *) echo "Unknown option: $arg" >&2; exit 1 ;; esac done fi # ---------- UI helpers ------------------------------------------------------- BOLD=$'\033[1m'; DIM=$'\033[2m'; GREEN=$'\033[32m'; YELLOW=$'\033[33m' RED=$'\033[31m'; CYAN=$'\033[36m'; RESET=$'\033[0m' step() { printf "\n%s== %s ==%s\n" "$BOLD" "$1" "$RESET"; } ok() { printf " %s✔%s %s\n" "$GREEN" "$RESET" "$1"; } warn() { printf " %s!%s %s\n" "$YELLOW" "$RESET" "$1"; } fail() { printf " %s✘%s %s\n" "$RED" "$RESET" "$1" >&2; } link() { printf " %s➜%s %s\n" "$CYAN" "$RESET" "$1"; } confirm() { if $ASSUME_YES; then return 0; fi local reply; read -r -p "$1 [y/N] " reply /dev/null 2>&1; } have_yq_v4() { have yq && yq --version 2>&1 | grep -Eq 'mikefarah|version v?4\.' } require_yq_v4() { if ! have yq; then fail "yq not found. Install mikefarah/yq v4 (e.g. 'brew install yq')." return 1 fi if ! have_yq_v4; then fail "Incompatible yq detected ($(yq --version 2>&1 | head -1)). Install mikefarah/yq v4." return 1 fi return 0 } lower() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]'; } mask_key() { local k="$1" len=${#1} if [[ $len -le 4 ]]; then printf '****' elif [[ $len -le 7 ]]; then printf '%s****%s' "${k:0:1}" "${k:$((len - 1)):1}" else printf '%s****%s' "${k:0:2}" "${k:$((len - 2)):2}" fi } # Hidden read: read_secret "prompt" -> echoes value, prints newline to tty. read_secret() { local __val="" read -r -s -p "$1" __val /dev/tty 2>/dev/null || printf '\n' >&2 printf '%s' "$__val" } read_visible() { local __val="" read -r -p "$1" __val /dev/null || true } ensure_datasources_cfg() { require_yq_v4 || return 1 ensure_config_dir if [[ ! -s "$DS_CFG" ]]; then ( umask 077 cat >"$DS_CFG" <<'EOF' datasources: [] global_options: minimum_ttl: 1440 EOF ) else (umask 077 && yq -i '.datasources = (.datasources // []) | .global_options.minimum_ttl = (.global_options.minimum_ttl // 1440)' "$DS_CFG") fi chmod 600 "$DS_CFG" 2>/dev/null || true } ensure_main_cfg() { require_yq_v4 || return 1 ensure_config_dir if [[ ! -s "$MAIN_CFG" ]]; then ( umask 077 cat >"$MAIN_CFG" <<'EOF' options: datasources: "./datasources.yaml" EOF ) else (umask 077 && yq -i '.options.datasources = (.options.datasources // "./datasources.yaml")' "$MAIN_CFG") fi chmod 600 "$MAIN_CFG" 2>/dev/null || true } # ---------- Data source catalog (all 48 from examples/datasources.yaml) ------ # Format: NAME|TTL(minutes)|signup URL|credential type|tier # credtype: key | keysecret | userpass | userkey | dualkey | dualapp # tier: free | freemium | paid | retired SOURCES=( "Shodan|10080|https://account.shodan.io/register|key|free" "Censys|10080|https://platform.censys.io/account/api|keysecret|free" "GitHub|4320|https://github.com/settings/tokens/new?scopes=repo&description=Amass|key|free" "GitLab|4320|https://gitlab.com/-/user_settings/personal_access_tokens|key|free" "Chaos|4320|https://chaos.projectdiscovery.io|key|free" "URLScan|1440|https://urlscan.io/user/signup|key|free" "VirusTotal|10080|https://www.virustotal.com/gui/join-us|key|free" "AlienVault|1440|https://otx.alienvault.com/|key|free" "SecurityTrails|1440|https://securitytrails.com/app/account|key|free" "Hunter|1440|https://hunter.io/users/sign_up|key|free" "IPinfo|1440|https://ipinfo.io/|key|free" "HackerTarget|1440|https://hackertarget.com/member/|key|free" "LeakIX|1440|https://leakix.net/user|key|free" "FullHunt|1440|https://fullhunt.io/user/register|key|free" "Netlas|1440|https://netlas.io/account/profile|key|freemium" "IPdata|1440|https://ipdata.co/|key|freemium" "WhoisXMLAPI|1440|https://www.whoisxmlapi.com/user/register|key|freemium" "BeVigil|1440|https://bevigil.com/|key|freemium" "ONYPHE|4320|https://www.onyphe.io/login|key|freemium" "FOFA|10080|https://fofa.info/|userkey|freemium" "ZoomEye|1440|https://www.zoomeye.org/|userpass|freemium" "Quake|4320|https://quake.360.net/|key|freemium" "IntelX|1440|https://intelx.io/|key|freemium" "CIRCL|1440|https://www.circl.lu/services/passive-dns/|userpass|freemium" "Spamhaus|1440|https://www.spamhaus.org/|userpass|freemium" "CertCentral|1440|https://www.entrust.com/certificate-transparency-log-dashboard|userkey|freemium" "FacebookCT|4320|https://developers.facebook.com/|dualapp|freemium" "Yandex|1440|https://yandex.com/dev/console/|userkey|freemium" "SOCRadar|1440|https://socradar.io/labs/|key|freemium" "DNSRepo|1440|https://dnsrepo.noc.org/|key|freemium" "PublicWWW|10080|https://publicwww.com/|key|freemium" "BigDataCloud|1440|https://www.bigdatacloud.com/|key|freemium" "ASNLookup|1440|https://www.asnlookup.com/|key|freemium" "BinaryEdge|10080|https://app.binaryedge.io/account/api|key|paid" "PassiveTotal|10080|https://passivetotal.riskiq.com/|userkey|paid" "DNSDB|4320|https://www.farsightsecurity.com/solutions/dnsdb/|key|paid" "BuiltWith|10080|https://builtwith.com/|key|paid" "Ahrefs|4320|https://ahrefs.com/|key|paid" "C99|4320|https://c99.io/API%20keys.html|dualkey|paid" "Pastebin|10080|https://pastebin.com/api_scrape_tos|key|paid" "PentestTools|10080|https://pentest-tools.com/|key|paid" "ZETAlytics|1440|https://zetalytics.com/|key|paid" "ThreatBook|1440|https://x.threatbook.com/|key|paid" "DNSlytics|1440|https://dnslytics.com/api|key|paid" "Deepinfo|1440|https://www.deepinfo.com/|key|paid" "Detectify|1440|https://detectify.com/|key|paid" "360PassiveDNS|3600|https://360.passivedns.cn/|key|paid" "BufferOver|1440|https://bufferover.io|key|retired" ) lookup_catalog_entry() { local target; target="$(lower "$1")" local e sname for e in "${SOURCES[@]}"; do sname="${e%%|*}" if [[ "$(lower "$sname")" == "$target" ]]; then printf '%s' "$e" return 0 fi done return 1 } # ---------- Live key validation (22 verified sources) ------------------------ # Secrets are passed via `curl -K -` stdin so they never appear in `ps` argv. # Return codes: # 0 = valid (populates VALIDATION_NOTE with plan/quota when available) # 1 = rejected (401/403/invalid key) # 2 = no online probe available (or curl missing) # 3 = inconclusive (network error, timeout, 429 rate-limit, 5xx) VALIDATION_NOTE="" # Allows test suites to route probes to a local mock server via AMASS_WIZARD_MOCK_URL. api_url() { local src="$1" real_url="$2" if [[ -n "${AMASS_WIZARD_MOCK_URL:-}" ]]; then local q="" [[ "$real_url" == *\?* ]] && q="?${real_url#*\?}" printf '%s/%s%s' "${AMASS_WIZARD_MOCK_URL%/}" "$src" "$q" else printf '%s' "$real_url" fi } HTTP_CODE="" HTTP_BODY="" # Reads curl `-K -` lines from stdin, populates HTTP_CODE and HTTP_BODY. http_fetch_from_cfg() { local tmpbody tmpbody="$(mktemp)" HTTP_CODE="$(curl -sS -m 10 -o "$tmpbody" -w '%{http_code}' -K - 2>/dev/null || printf '000')" HTTP_BODY="$(cat "$tmpbody" 2>/dev/null || true)" rm -f "$tmpbody" } classify_http_status() { local code="$1" case "$code" in 200|204) return 0 ;; 401|403) return 1 ;; 429) VALIDATION_NOTE="rate-limited (HTTP 429)"; return 3 ;; 000) VALIDATION_NOTE="network/timeout error"; return 3 ;; *) VALIDATION_NOTE="unexpected HTTP $code"; return 3 ;; esac } jq_extract() { have jq || return 0 printf '%s' "$HTTP_BODY" | jq -r "$1" 2>/dev/null || true } validate_key() { local name="$1" key="$2" extra="${3:-}" VALIDATION_NOTE="" have curl || { VALIDATION_NOTE="curl not installed"; return 2; } local ek uk ue target ek="$(curl_escape "$key")" uk="$(urlencode "$key")" ue="$(urlencode "$extra")" case "$name" in Shodan) target="$(api_url "Shodan" "https://api.shodan.io/api-info?key=${uk}")" http_fetch_from_cfg </dev/null || echo "" } # Prints all non-empty secret scalars for a source (one per line). existing_secrets_list() { local name="$1" [[ -f "$DS_CFG" ]] && have_yq_v4 || return 0 DS_NAME="$name" yq -r '[.datasources[]? | select(.name == strenv(DS_NAME)) | .creds[]? | (.password // .secret // .apikey // "")] | map(select(. != "" and . != "null")) | .[]' "$DS_CFG" 2>/dev/null || true } # Prints masked summary of all configured accounts on a source, e.g. "ab****cd, ef****gh (2 keys)". existing_masked_summary() { local name="$1" s count=0 joined="" while IFS= read -r s; do [[ -z "$s" ]] && continue count=$((count + 1)) if [[ -z "$joined" ]]; then joined="$(mask_key "$s")" else joined="$joined, $(mask_key "$s")" fi done < <(existing_secrets_list "$name") if [[ $count -gt 1 ]]; then printf '%s (%d keys)' "$joined" "$count" else printf '%s' "$joined" fi } # Checks if a concrete secret scalar is already saved under a source (for deduping imports). source_has_secret() { local name="$1" candidate="$2" s while IFS= read -r s; do [[ "$s" == "$candidate" ]] && return 0 done < <(existing_secrets_list "$name") return 1 } # Extracts `\t\t` lines for all populated accounts of a source. existing_pairs_all() { local name="$1" type="$2" [[ -f "$DS_CFG" ]] && have_yq_v4 || return 0 case "$type" in keysecret|dualapp) DS_NAME="$name" yq -r '.datasources[]? | select(.name == strenv(DS_NAME)) | .creds | to_entries[]? | select((.value.apikey // .value.secret // "") != "") | (.key + "\t" + (.value.apikey // "") + "\t" + (.value.secret // ""))' "$DS_CFG" 2>/dev/null || true ;; userpass) DS_NAME="$name" yq -r '.datasources[]? | select(.name == strenv(DS_NAME)) | .creds | to_entries[]? | select((.value.password // "") != "") | (.key + "\t" + (.value.username // "") + "\t" + (.value.password // ""))' "$DS_CFG" 2>/dev/null || true ;; userkey) DS_NAME="$name" yq -r '.datasources[]? | select(.name == strenv(DS_NAME)) | .creds | to_entries[]? | select((.value.apikey // "") != "") | (.key + "\t" + (.value.username // "") + "\t" + (.value.apikey // ""))' "$DS_CFG" 2>/dev/null || true ;; *) DS_NAME="$name" yq -r '.datasources[]? | select(.name == strenv(DS_NAME)) | .creds | to_entries[]? | select((.value.apikey // "") != "") | (.key + "\t" + (.value.apikey // "") + "\t")' "$DS_CFG" 2>/dev/null || true ;; esac } # Backwards-compatible helper returning `\t` for the first populated slot. existing_pair() { local line line="$(existing_pairs_all "$1" "$2" | head -1)" [[ -n "$line" ]] || return 1 printf '%s\n' "${line#*$'\t'}" } configured_count() { [[ -f "$DS_CFG" ]] && have_yq_v4 || { echo 0; return; } yq -r '[.datasources[]? | select(([.creds[]? | (.apikey // .password // .secret // "")] | map(select(. != "" and . != "null")) | length) > 0) | .name] | unique | length' "$DS_CFG" 2>/dev/null || echo 0 } delete_source() { local name="$1" [[ -f "$DS_CFG" ]] && require_yq_v4 || return 0 (umask 077 && DS_NAME="$name" yq -i '.datasources |= map(select(.name != strenv(DS_NAME)))' "$DS_CFG") chmod 600 "$DS_CFG" 2>/dev/null || true } # ---------- Upsert & multi-key append into datasources.yaml ------------------ # Uses environment variables + `strenv()` so secrets never hit `ps` argv and # special characters (quotes, backslashes, numeric IDs) never break YAML. cred_value_expr() { local type="$1" extra="${2:-}" case "$type" in key|dualkey) printf '{"apikey": strenv(DS_KEY)}' ;; keysecret) if [[ -n "$extra" ]]; then printf '{"apikey": strenv(DS_KEY), "secret": strenv(DS_EXTRA)}' else printf '{"apikey": strenv(DS_KEY)}' fi ;; userpass) printf '{"username": strenv(DS_KEY), "password": strenv(DS_EXTRA)}' ;; userkey) printf '{"username": strenv(DS_KEY), "apikey": strenv(DS_EXTRA)}' ;; dualapp) printf '{"apikey": strenv(DS_KEY), "secret": strenv(DS_EXTRA)}' ;; *) return 1 ;; esac } upsert_source() { local name="$1" ttl="$2" type="$3" key="$4" extra="${5:-}" app2_key="${6:-}" app2_sec="${7:-}" ensure_datasources_cfg || return 1 ensure_main_cfg || return 1 local expr case "$type" in key) expr='{"name": strenv(DS_NAME), "ttl": (env(DS_TTL) | tonumber), "creds": {"account": {"apikey": strenv(DS_KEY)}}}' ;; keysecret) if [[ -n "$extra" ]]; then expr='{"name": strenv(DS_NAME), "ttl": (env(DS_TTL) | tonumber), "creds": {"account": {"apikey": strenv(DS_KEY), "secret": strenv(DS_EXTRA)}}}' else expr='{"name": strenv(DS_NAME), "ttl": (env(DS_TTL) | tonumber), "creds": {"account": {"apikey": strenv(DS_KEY)}}}' fi ;; userpass) expr='{"name": strenv(DS_NAME), "ttl": (env(DS_TTL) | tonumber), "creds": {"account": {"username": strenv(DS_KEY), "password": strenv(DS_EXTRA)}}}' ;; userkey) expr='{"name": strenv(DS_NAME), "ttl": (env(DS_TTL) | tonumber), "creds": {"account": {"username": strenv(DS_KEY), "apikey": strenv(DS_EXTRA)}}}' ;; dualkey) if [[ -n "$extra" ]]; then expr='{"name": strenv(DS_NAME), "ttl": (env(DS_TTL) | tonumber), "creds": {"account1": {"apikey": strenv(DS_KEY)}, "account2": {"apikey": strenv(DS_EXTRA)}}}' else expr='{"name": strenv(DS_NAME), "ttl": (env(DS_TTL) | tonumber), "creds": {"account1": {"apikey": strenv(DS_KEY)}}}' fi ;; dualapp) if [[ -n "$app2_key" && -n "$app2_sec" ]]; then expr='{"name": strenv(DS_NAME), "ttl": (env(DS_TTL) | tonumber), "creds": {"app1": {"apikey": strenv(DS_KEY), "secret": strenv(DS_EXTRA)}, "app2": {"apikey": strenv(DS_APP2_KEY), "secret": strenv(DS_APP2_SEC)}}}' else expr='{"name": strenv(DS_NAME), "ttl": (env(DS_TTL) | tonumber), "creds": {"app1": {"apikey": strenv(DS_KEY), "secret": strenv(DS_EXTRA)}}}' fi ;; *) fail "Unknown credential type: $type"; return 1 ;; esac ( umask 077 DS_NAME="$name" DS_TTL="$ttl" DS_KEY="$key" DS_EXTRA="$extra" \ DS_APP2_KEY="$app2_key" DS_APP2_SEC="$app2_sec" \ yq -i "(.datasources |= (map(select(.name != strenv(DS_NAME))) + [$expr]))" "$DS_CFG" ) chmod 600 "$DS_CFG" 2>/dev/null || true } # Appends an additional named credential slot (`account2`, `account3`, ... or `app2`, ...) # under an existing datasource entry for Amass multi-key rate-limit rotation. append_source_cred() { local name="$1" ttl="$2" type="$3" key="$4" extra="${5:-}" ensure_datasources_cfg || return 1 ensure_main_cfg || return 1 if [[ -z "$(existing_entry "$name")" ]]; then upsert_source "$name" "$ttl" "$type" "$key" "$extra" return $? fi local prefix="account" [[ "$type" == "dualapp" ]] && prefix="app" local used n=1 slot="" used="$(DS_NAME="$name" yq -r '.datasources[]? | select(.name == strenv(DS_NAME)) | .creds | keys | .[]' "$DS_CFG" 2>/dev/null || true)" while true; do n=$((n + 1)) slot="${prefix}${n}" if ! printf '%s\n' "$used" | grep -qx "$slot"; then break fi done local vexpr vexpr="$(cred_value_expr "$type" "$extra")" || return 1 ( umask 077 DS_NAME="$name" DS_SLOT="$slot" DS_KEY="$key" DS_EXTRA="$extra" \ yq -i "(.datasources[] | select(.name == strenv(DS_NAME)) | .creds[strenv(DS_SLOT)]) = $vexpr" "$DS_CFG" ) chmod 600 "$DS_CFG" 2>/dev/null || true } # ---------- Credential collection per shape ---------------------------------- prompt_credentials() { local name="$1" type="$2" single_slot="${3:-false}" PROMPT_KEY="" PROMPT_EXTRA="" PROMPT_APP2_KEY="" PROMPT_APP2_SEC="" case "$type" in key) PROMPT_KEY="$(trim_ws "$(read_secret " Paste your $name API key (hidden): ")")" [[ -n "$PROMPT_KEY" ]] || { warn "Empty key — skipped."; return 1; } ;; keysecret) if [[ "$name" == "Censys" ]]; then PROMPT_KEY="$(trim_ws "$(read_secret " Paste your Censys Platform PAT (or legacy API ID) (hidden): ")")" [[ -n "$PROMPT_KEY" ]] || { warn "Empty key — skipped."; return 1; } PROMPT_EXTRA="$(trim_ws "$(read_secret " Paste legacy Censys Secret (hidden, or Enter if using PAT): ")")" else PROMPT_KEY="$(trim_ws "$(read_secret " Paste your $name API key / ID (hidden): ")")" [[ -n "$PROMPT_KEY" ]] || { warn "Empty key — skipped."; return 1; } PROMPT_EXTRA="$(trim_ws "$(read_secret " Paste your $name SECRET (hidden): ")")" [[ -n "$PROMPT_EXTRA" ]] || { warn "Empty secret — skipped."; return 1; } fi ;; userpass) PROMPT_KEY="$(trim_ws "$(read_visible " Enter your $name username / email: ")")" [[ -n "$PROMPT_KEY" ]] || { warn "Empty username — skipped."; return 1; } PROMPT_EXTRA="$(read_secret " Paste your $name password (hidden): ")" PROMPT_EXTRA="${PROMPT_EXTRA//$'\r'/}" [[ -n "$PROMPT_EXTRA" ]] || { warn "Empty password — skipped."; return 1; } ;; userkey) PROMPT_KEY="$(trim_ws "$(read_visible " Enter your $name username / email: ")")" [[ -n "$PROMPT_KEY" ]] || { warn "Empty username — skipped."; return 1; } PROMPT_EXTRA="$(trim_ws "$(read_secret " Paste your $name API key (hidden): ")")" [[ -n "$PROMPT_EXTRA" ]] || { warn "Empty API key — skipped."; return 1; } ;; dualkey) PROMPT_KEY="$(trim_ws "$(read_secret " Paste your $name API key (hidden): ")")" [[ -n "$PROMPT_KEY" ]] || { warn "Empty key — skipped."; return 1; } if [[ "$single_slot" != "true" ]]; then PROMPT_EXTRA="$(trim_ws "$(read_secret " Paste second $name API key (hidden, Enter if none): ")")" fi ;; dualapp) PROMPT_KEY="$(trim_ws "$(read_visible " Enter your $name App ID: ")")" [[ -n "$PROMPT_KEY" ]] || { warn "Empty App ID — skipped."; return 1; } PROMPT_EXTRA="$(trim_ws "$(read_secret " Paste your $name App Secret (hidden): ")")" [[ -n "$PROMPT_EXTRA" ]] || { warn "Empty App Secret — skipped."; return 1; } if [[ "$single_slot" != "true" ]]; then PROMPT_APP2_KEY="$(trim_ws "$(read_visible " Enter second $name App ID (Enter if none): ")")" if [[ -n "$PROMPT_APP2_KEY" ]]; then PROMPT_APP2_SEC="$(trim_ws "$(read_secret " Paste second $name App Secret (hidden): ")")" [[ -n "$PROMPT_APP2_SEC" ]] || { warn "Empty second App Secret — dropping app2."; PROMPT_APP2_KEY=""; } fi fi ;; *) fail "Unknown credential type: $type"; return 1 ;; esac return 0 } # ---------- One source walkthrough ------------------------------------------- setup_one_source() { require_yq_v4 || return 1 local entry="$1" name ttl url type tier existing reply mode="replace" IFS='|' read -r name ttl url type tier <<<"$entry" existing="$(existing_entry "$name")" echo printf "%s%s[%s]%s %s %s(ttl: %sm, shape: %s)%s\n" \ "$BOLD" "$CYAN" "$name" "$RESET" "$(tier_badge "$tier")" "$DIM" "$ttl" "$type" "$RESET" link "Signup / key page: $url" if [[ "$tier" == "retired" ]]; then warn "$name's free public API has been retired upstream — skip unless you have legacy access." fi if [[ -n "$existing" ]]; then ok "Already configured: $(existing_masked_summary "$name")" read -r -p " [a]dd another key (rotate), [r]eplace all, [d]elete, [k]eep: " reply /dev/null || true local e name type row slot k extra rest label idx=0 running=0 for e in "${SOURCES[@]}"; do IFS='|' read -r name _ _ type _ <<<"$e" [[ -n "$(existing_entry "$name")" ]] || continue local slot_count slot_count="$(existing_pairs_all "$name" "$type" | wc -l | tr -d ' ')" while IFS= read -r row; do [[ -n "$row" ]] || continue slot="${row%%$'\t'*}" rest="${row#*$'\t'}" k="${rest%%$'\t'*}" extra="${rest#*$'\t'}" [[ "$rest" != *$'\t'* ]] && extra="" label="$name" [[ "$slot_count" -gt 1 ]] && label="$name ($slot)" idx=$((idx + 1)) ( set +e validate_key "$name" "$k" "$extra" rc=$? printf '%d|%s|%s\n' "$rc" "$label" "${VALIDATION_NOTE:-}" >"$tmpdir/$idx.res" ) & running=$((running + 1)) if [[ $running -ge 10 ]]; then wait running=0 fi done < <(existing_pairs_all "$name" "$type") done wait local i rc note valid_n=0 bad_n=0 skip_n=0 for ((i = 1; i <= idx; i++)); do [[ -f "$tmpdir/$i.res" ]] || continue IFS='|' read -r rc label note <"$tmpdir/$i.res" local suffix="" [[ -n "$note" ]] && suffix=" ($note)" printf " %-24s " "$label" case "$rc" in 0) printf "%s✔ valid%s%s\n" "$GREEN" "$RESET" "$suffix"; valid_n=$((valid_n + 1)) ;; 1) printf "%s✘ rejected%s%s\n" "$RED" "$RESET" "$suffix"; bad_n=$((bad_n + 1)) ;; 3) printf "%s! inconclusive%s%s\n" "$YELLOW" "$RESET" "$suffix"; skip_n=$((skip_n + 1)) ;; *) printf "%s- unchecked%s%s\n" "$DIM" "$RESET" "$suffix"; skip_n=$((skip_n + 1)) ;; esac done rm -rf "$tmpdir" echo ok "Checked $idx credential(s): $valid_n valid, $bad_n rejected, $skip_n unchecked/inconclusive." [[ $bad_n -eq 0 ]] } # ---------- Import from subfinder / uncover / bbot / theHarvester / env ------ # Discovered items are collected into IMPORT_ITEMS as: # NAME|ORIGIN|KEY|EXTRA IMPORT_ITEMS=() queue_import_candidate() { local name="$1" origin="$2" key="$3" extra="${4:-}" key="$(trim_ws "$key")" extra="$(trim_ws "$extra")" [[ -n "$key" ]] || return 0 [[ "$key" == "null" || "$key" == "YOUR_"* || "$key" == "REPLACE_"* ]] && return 0 local entry type entry="$(lookup_catalog_entry "$name")" || return 0 IFS='|' read -r name _ _ type _ <<<"$entry" local secret_scalar="$key" [[ "$type" == "userpass" || "$type" == "userkey" || "$type" == "dualapp" ]] && secret_scalar="$extra" [[ -n "$extra" && "$type" == "keysecret" ]] && secret_scalar="$extra" [[ -n "$secret_scalar" && "$secret_scalar" != "null" ]] || return 0 # Skip if already stored in datasources.yaml or already queued in this import batch. source_has_secret "$name" "$secret_scalar" && return 0 local item existing_name existing_key existing_extra existing_rest for item in "${IMPORT_ITEMS[@]+"${IMPORT_ITEMS[@]}"}"; do existing_name="${item%%|*}" existing_rest="${item#*|}" existing_rest="${existing_rest#*|}" existing_key="${existing_rest%%|*}" existing_extra="${existing_rest#*|}" if [[ "$existing_name" == "$name" && "$existing_key" == "$key" && "$existing_extra" == "$extra" ]]; then return 0 fi done IMPORT_ITEMS+=("$name|$origin|$key|$extra") } scan_env_imports() { local pair var src local simple_vars=( "SHODAN_API_KEY:Shodan" "GITHUB_TOKEN:GitHub" "GH_TOKEN:GitHub" "GITLAB_TOKEN:GitLab" "PDCP_API_KEY:Chaos" "CHAOS_KEY:Chaos" "VIRUSTOTAL_API_KEY:VirusTotal" "VT_API_KEY:VirusTotal" "URLSCAN_API_KEY:URLScan" "OTX_API_KEY:AlienVault" "ALIENVAULT_API_KEY:AlienVault" "SECURITYTRAILS_API_KEY:SecurityTrails" "HUNTER_API_KEY:Hunter" "IPINFO_TOKEN:IPinfo" "IPDATA_API_KEY:IPdata" "FULLHUNT_API_KEY:FullHunt" "NETLAS_API_KEY:Netlas" "LEAKIX_API_KEY:LeakIX" "BINARYEDGE_API_KEY:BinaryEdge" "WHOISXML_API_KEY:WhoisXMLAPI" "BUILTWITH_API_KEY:BuiltWith" "BEVIGIL_API_KEY:BeVigil" "ONYPHE_API_KEY:ONYPHE" "QUAKE_TOKEN:Quake" "HACKERTARGET_API_KEY:HackerTarget" "CENSYS_PAT:Censys" "CENSYS_API_TOKEN:Censys" ) for pair in "${simple_vars[@]}"; do var="${pair%%:*}" src="${pair#*:}" if [[ -n "${!var:-}" ]]; then queue_import_candidate "$src" "env:$var" "${!var}" "" fi done if [[ -n "${CENSYS_API_ID:-}" && -n "${CENSYS_API_SECRET:-}" ]]; then queue_import_candidate "Censys" "env:CENSYS_API_ID" "$CENSYS_API_ID" "$CENSYS_API_SECRET" fi if [[ -n "${FOFA_EMAIL:-}" && -n "${FOFA_KEY:-}" ]]; then queue_import_candidate "FOFA" "env:FOFA_KEY" "$FOFA_EMAIL" "$FOFA_KEY" fi } scan_pd_provider_yaml() { local file="$1" label="$2" [[ -f "$file" ]] && have_yq_v4 || return 0 local mapping=( "shodan:Shodan:single" "github:GitHub:single" "gitlab:GitLab:single" "chaos:Chaos:single" "virustotal:VirusTotal:single" "urlscan:URLScan:single" "alienvault:AlienVault:single" "securitytrails:SecurityTrails:single" "hunter:Hunter:single" "ipinfo:IPinfo:single" "fullhunt:FullHunt:single" "netlas:Netlas:single" "leakix:LeakIX:single" "binaryedge:BinaryEdge:single" "whoisxmlapi:WhoisXMLAPI:single" "builtwith:BuiltWith:single" "bevigil:BeVigil:single" "onyphe:ONYPHE:single" "quake:Quake:single" "hackertarget:HackerTarget:single" "dnsdb:DNSDB:single" "dnsrepo:DNSRepo:single" "threatbook:ThreatBook:single" "intelx:IntelX:strip_host" "censys:Censys:optional_colon" "fofa:FOFA:colon" "passivetotal:PassiveTotal:colon" "zoomeye:ZoomEye:colon" ) local m keyname amass_name mode val p1 p2 for m in "${mapping[@]}"; do keyname="${m%%:*}" m="${m#*:}" amass_name="${m%%:*}" mode="${m#*:}" while IFS= read -r val; do val="$(trim_ws "$val")" [[ -z "$val" || "$val" == "null" ]] && continue case "$mode" in single) queue_import_candidate "$amass_name" "$label" "$val" "" ;; strip_host) [[ "$val" == *:* ]] && val="${val#*:}" queue_import_candidate "$amass_name" "$label" "$val" "" ;; optional_colon) if [[ "$val" == *:* ]]; then p1="${val%%:*}"; p2="${val#*:}" queue_import_candidate "$amass_name" "$label" "$p1" "$p2" else queue_import_candidate "$amass_name" "$label" "$val" "" fi ;; colon) if [[ "$val" == *:* ]]; then p1="${val%%:*}"; p2="${val#*:}" queue_import_candidate "$amass_name" "$label" "$p1" "$p2" fi ;; esac done < <(PD_KEY="$keyname" yq -r '.[strenv(PD_KEY)][]? // ""' "$file" 2>/dev/null || true) done } scan_theharvester_yaml() { local file="$1" [[ -f "$file" ]] && have_yq_v4 || return 0 local pairs=( "shodan:Shodan" "github:GitHub" "virustotal:VirusTotal" "securityTrails:SecurityTrails" "hunter:Hunter" "bevigil:BeVigil" "binaryedge:BinaryEdge" "builtwith:BuiltWith" "fullhunt:FullHunt" "intelx:IntelX" "netlas:Netlas" "onyphe:ONYPHE" "pentestTools:PentestTools" "projectDiscovery:Chaos" "urlscan:URLScan" "whoisxml:WhoisXMLAPI" ) local p hk src v cid csec for p in "${pairs[@]}"; do hk="${p%%:*}"; src="${p#*:}" v="$(TH_KEY="$hk" yq -r '.apikeys[strenv(TH_KEY)].key // ""' "$file" 2>/dev/null || true)" [[ -n "$v" && "$v" != "null" ]] && queue_import_candidate "$src" "theHarvester" "$v" "" done cid="$(yq -r '.apikeys.censys.id // ""' "$file" 2>/dev/null || true)" csec="$(yq -r '.apikeys.censys.secret // ""' "$file" 2>/dev/null || true)" if [[ -n "$cid" && "$cid" != "null" ]]; then [[ "$csec" == "null" ]] && csec="" queue_import_candidate "Censys" "theHarvester" "$cid" "$csec" fi } scan_bbot_yaml() { local file="$1" [[ -f "$file" ]] && have_yq_v4 || return 0 local pairs=( "shodan_dns:Shodan" "virustotal:VirusTotal" "github:GitHub" "gitlab:GitLab" "chaos:Chaos" "securitytrails:SecurityTrails" "urlscan:URLScan" "hunterio:Hunter" "fullhunt:FullHunt" "bevigil:BeVigil" "builtwith:BuiltWith" "leakix:LeakIX" "otx:AlienVault" "ipdata:IPdata" "c99:C99" "censys:Censys" ) local p mod src v for p in "${pairs[@]}"; do mod="${p%%:*}"; src="${p#*:}" v="$(BB_MOD="$mod" yq -r '.modules[strenv(BB_MOD)].api_key // ""' "$file" 2>/dev/null || true)" if [[ -n "$v" && "$v" != "null" ]]; then if [[ "$src" == "Censys" && "$v" == *:* ]]; then queue_import_candidate "Censys" "bbot" "${v%%:*}" "${v#*:}" else queue_import_candidate "$src" "bbot" "$v" "" fi fi done } import_existing_keys() { step "Import credentials from recon tools & environment" require_yq_v4 || return 1 IMPORT_ITEMS=() local sf_cfg="${AMASS_IMPORT_SUBFINDER:-$HOME/.config/subfinder/provider-config.yaml}" local uc_cfg="${AMASS_IMPORT_UNCOVER:-$HOME/.config/uncover/provider-config.yaml}" local th_cfg="${AMASS_IMPORT_HARVESTER:-$HOME/.theHarvester/api-keys.yaml}" local bb_cfg="${AMASS_IMPORT_BBOT:-$HOME/.config/bbot/secrets.yml}" scan_env_imports scan_pd_provider_yaml "$sf_cfg" "subfinder" scan_pd_provider_yaml "$uc_cfg" "uncover" scan_theharvester_yaml "$th_cfg" scan_bbot_yaml "$bb_cfg" local total=${#IMPORT_ITEMS[@]} if [[ $total -eq 0 ]]; then warn "No new credentials found in env vars, subfinder, uncover, theHarvester, or bbot." return 0 fi echo " Found ${BOLD}${total}${RESET} new credential(s) not yet in datasources.yaml:" echo printf " %-16s %-16s %s\n" "SOURCE" "ORIGIN" "CREDENTIAL" local item name origin key extra rest shown for item in "${IMPORT_ITEMS[@]}"; do name="${item%%|*}" rest="${item#*|}" origin="${rest%%|*}" rest="${rest#*|}" key="${rest%%|*}" extra="${rest#*|}" shown="$key" [[ -n "$extra" ]] && shown="$extra" printf " %-16s %-16s %s\n" "$name" "$origin" "$(mask_key "$shown")" done echo confirm " Import these $total credential(s) into $DS_CFG?" || { warn "Import cancelled."; return 0; } local imported=0 entry ttl type for item in "${IMPORT_ITEMS[@]}"; do name="${item%%|*}" rest="${item#*|}" rest="${rest#*|}" key="${rest%%|*}" extra="${rest#*|}" entry="$(lookup_catalog_entry "$name")" || continue IFS='|' read -r name ttl _ type _ <<<"$entry" if [[ -n "$(existing_entry "$name")" ]]; then append_source_cred "$name" "$ttl" "$type" "$key" "$extra" else upsert_source "$name" "$ttl" "$type" "$key" "$extra" fi imported=$((imported + 1)) done ok "Imported $imported credential(s). Total configured: $(configured_count)/48 sources." echo " Tip: run './amass_wizard.sh --verify' to live-check all imported keys." } # ---------- Free-tier quickstart --------------------------------------------- walk_free_sources() { require_yq_v4 || return 1 step "Free-tier quickstart (14 high-value free sources)" local e tier for e in "${SOURCES[@]}"; do IFS='|' read -r _ _ _ _ tier <<<"$e" [[ "$tier" == "free" ]] || continue setup_one_source "$e" || true done ok "Free-tier pass complete: $(configured_count)/48 sources configured." } # ---------- API keys menu ----------------------------------------------------- setup_api_keys() { require_yq_v4 || return 1 step "Data source API keys — guided setup" echo " Type a ${BOLD}source name${RESET} (case-insensitive), ${BOLD}free${RESET} for the 14 best free sources," echo " ${BOLD}import${RESET} from subfinder/env, ${BOLD}verify${RESET} saved keys, ${BOLD}list${RESET} catalog, ${BOLD}all${RESET}, or ${BOLD}done${RESET}." while true; do read -r -p " > source / free / import / verify / list / all / done: " choice /dev/null || true } remove_scope_domain() { local d; d="$(lower "$(trim_ws "$1")")" [[ -f "$MAIN_CFG" ]] && require_yq_v4 || return 0 (umask 077 && DOMAIN="$d" yq -i 'if .scope.domains then .scope.domains |= map(select(. != strenv(DOMAIN))) else . end' "$MAIN_CFG") chmod 600 "$MAIN_CFG" 2>/dev/null || true } add_scope_blacklist() { local d; d="$(lower "$(trim_ws "$1")")" is_valid_domain "$d" || return 1 ensure_main_cfg || return 1 (umask 077 && DOMAIN="$d" yq -i '.scope.blacklist = ((.scope.blacklist // []) + [strenv(DOMAIN)] | unique | sort)' "$MAIN_CFG") chmod 600 "$MAIN_CFG" 2>/dev/null || true } remove_scope_blacklist() { local d; d="$(lower "$(trim_ws "$1")")" [[ -f "$MAIN_CFG" ]] && require_yq_v4 || return 0 (umask 077 && DOMAIN="$d" yq -i 'if .scope.blacklist then .scope.blacklist |= map(select(. != strenv(DOMAIN))) else . end' "$MAIN_CFG") chmod 600 "$MAIN_CFG" 2>/dev/null || true } setup_scope() { step "Scope: target domains & out-of-scope blacklist" ensure_main_cfg || return 1 while true; do local current bl line current="$(yq -r '.scope.domains[]? // ""' "$MAIN_CFG" 2>/dev/null || true)" bl="$(yq -r '.scope.blacklist[]? // ""' "$MAIN_CFG" 2>/dev/null || true)" if [[ -n "$current" ]]; then echo " In-scope domains:" while IFS= read -r line; do [[ -n "$line" ]] && printf " %s+%s %s\n" "$GREEN" "$RESET" "$line" done <<<"$current" else warn "No domains in scope yet." fi if [[ -n "$bl" ]]; then echo " Blacklisted (out-of-scope) subdomains:" while IFS= read -r line; do [[ -n "$line" ]] && printf " %s-%s %s\n" "$RED" "$RESET" "$line" done <<<"$bl" fi local reply d read -r -p " [a]dd domain, [r]emove domain, [b]lacklist subdomain, [u]nblacklist, [d]one: " reply &1 | head -1)"; return; fi if have brew; then echo " Installing with Homebrew (this can take a while)..." brew install amass have amass && ok "Amass installed." || fail "'amass' not on PATH — restart shell." elif have go; then if confirm " Homebrew not found, but Go is installed. Install Amass v5 via 'go install'?"; then go install -v github.com/owasp-amass/amass/v5/cmd/amass@master local gobin; gobin="$(go env GOPATH 2>/dev/null)/bin" if have amass; then ok "Amass installed." else warn "Installed to $gobin — add it to your PATH: export PATH=\"\$PATH:$gobin\"" fi fi else fail "Neither Homebrew nor Go found. Install Homebrew or Go, then run:" echo " go install -v github.com/owasp-amass/amass/v5/cmd/amass@master" >&2 return 1 fi } # ---------- Status / smoke test ------------------------------------------------- status_report() { step "Status" have amass && ok "amass: $(command -v amass) ($(amass -version 2>&1 | head -1))" || warn "amass: not installed" have_yq_v4 && ok "yq: $(yq --version 2>&1 | head -1)" || warn "yq: mikefarah/yq v4 missing" have curl && ok "curl: $(command -v curl)" || warn "curl: not installed (live checks disabled)" if [[ -f "$MAIN_CFG" ]]; then local linked="" if have_yq_v4; then linked="$(yq -r '.options.datasources // ""' "$MAIN_CFG" 2>/dev/null || true)" fi if [[ -n "$linked" ]]; then ok "config.yaml exists (datasources -> $linked)" else warn "config.yaml exists, but options.datasources is not set" fi else warn "config.yaml missing (will be created automatically)" fi if [[ -f "$DS_CFG" ]] && have_yq_v4; then ok "datasources.yaml: $(configured_count)/48 sources configured" echo printf " %-16s %-12s %s\n" "SOURCE" "TIER" "CREDENTIALS" local e name tier for e in "${SOURCES[@]}"; do IFS='|' read -r name _ _ _ tier <<<"$e" if [[ -n "$(existing_entry "$name")" ]]; then printf " %s✔ %-14s%s %-21s %s\n" "$GREEN" "$name" "$RESET" "$(tier_badge "$tier")" "$(existing_masked_summary "$name")" fi done else warn "datasources.yaml missing (will be created when you add your first key)" fi } smoke_test() { step "Smoke test" if [[ -f "$DS_CFG" ]] && have_yq_v4; then if yq '.datasources | length' "$DS_CFG" >/dev/null 2>&1; then ok "datasources.yaml syntax valid" else fail "datasources.yaml failed YAML parse!" fi fi if [[ -f "$MAIN_CFG" ]] && have_yq_v4; then if yq '.' "$MAIN_CFG" >/dev/null 2>&1; then ok "config.yaml syntax valid" else fail "config.yaml failed YAML parse!" fi fi if ! have amass; then fail "amass not found on PATH." return 0 fi ok "amass on PATH: $(command -v amass)" echo " Example run (Amass v5):" echo " amass enum -config \"$MAIN_CFG\" -d example.com" echo " amass subs -names -d example.com -o \"$HOME/amass_subdomains.txt\"" echo if ! $NONINTERACTIVE && confirm " Run a quick 1-minute passive smoke test against owasp.org?"; then ensure_main_cfg || return 1 local tmpdir count tmpdir="$(mktemp -d)" echo " Running passive enumeration (up to 60s)..." amass enum -config "$MAIN_CFG" -dir "$tmpdir" -log "$tmpdir/amass.log" -d owasp.org -timeout 1 >/dev/null 2>&1 || true count="$(amass subs -dir "$tmpdir" -names -d owasp.org 2>/dev/null | wc -l | tr -d ' ')" ok "Passive smoke test finished: discovered $count subdomain(s) for owasp.org." if [[ -s "$tmpdir/amass.log" ]]; then local errs line errs="$(grep -iE 'error|unauthorized|invalid|forbidden|401|403' "$tmpdir/amass.log" 2>/dev/null | head -5 || true)" if [[ -n "$errs" ]]; then warn "Recent warnings in amass.log:" while IFS= read -r line; do printf " %s\n" "$line" done <<<"$errs" fi fi rm -rf "$tmpdir" fi } # ---------- Main ------------------------------------------------------------------ banner() { printf "%s" "$CYAN" cat <<'EOF' ___ __ __ ____ / _ | / |/ |/ ___| Install & config wizard | | | | /| / | | OWASP Amass v5 — 48 data sources | |_| | | | | | |___ \___/|_| |_| \____| EOF printf "%s\n" "$RESET" } [[ "${BASH_SOURCE[0]:-$0}" != "$0" ]] && return 0 if $NONINTERACTIVE; then banner; status_report; exit 0; fi banner if $LIST_ONLY; then print_catalog; exit 0; fi if $VERIFY_ONLY; then verify_configured_keys; exit $?; fi if $IMPORT_ONLY; then import_existing_keys; exit $?; fi if $FREE_ONLY; then walk_free_sources; exit 0; fi require_yq_v4 || true while true; do step "Main menu" echo " 1) Install Amass" echo " 2) Free-tier quickstart (14 best free sources)" echo " 3) Configure data source API keys (all 48)" echo " 4) Import keys from subfinder / uncover / bbot / theHarvester / env" echo " 5) Verify configured API keys (parallel live check)" echo " 6) Manage scope domains & blacklist" echo " 7) Status & smoke test" echo " q) Quit" read -r -p " Choose: " m