reconFTW is a tool designed to perform automated recon on a target domain by running the best set of tools to perform scanning and finding out vulnerabilities
Shell bug-bountybugbountybugbounty-tooldnshackingnucleiosintpenetration-testingpentestpentest-toolpentestingreconreconnaissancescannersecuritysecurity-toolssubdomainsubdomain-enumerationvulnerabilities
feat(osint): optional Lunar domain-exposure enrichment (#1042)
six2dezcece45fd9207
diff --git a/modules/modes.sh b/modules/modes.shindex 710914f..d5a11ba 100644--- a/modules/modes.sh+++ b/modules/modes.sh@@ -682,7 +682,7 @@ function osint() {metadata apileaks third_party_misconfigs zonetransfer# Group 4: Mail/DNS/Cloudparallel_funcs "${PAR_OSINT_GROUP4_SIZE:-3}" \- mail_hygiene spoof cloud_enum_scan+ mail_hygiene spoof cloud_enum_scan lunar_exposureelsedomain_infoip_info@@ -699,6 +699,7 @@ function osint() {mail_hygienespoofcloud_enum_scan+ lunar_exposurefi}diff --git a/modules/osint.sh b/modules/osint.shindex 9188c6e..f8a9065 100644--- a/modules/osint.sh+++ b/modules/osint.sh@@ -655,6 +655,57 @@ function third_party_misconfigs() {fi}+function lunar_exposure() {+ ensure_dirs osint++ if { [[ ! -f "$called_fn_dir/.${FUNCNAME[0]}" ]] || [[ $DIFF == true ]]; } \+ && [[ $LUNAR_EXPOSURE == true ]] && [[ $OSINT == true ]] \+ && ! [[ $domain =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then++ start_func "${FUNCNAME[0]}" "Domain exposure in infostealer logs and breaches (Lunar)"++ local _out="${dir}/osint/lunar_exposure.json"+ local _tmp _code+ if ! _tmp=$(mktemp -t reconftw_lunar.XXXXXX); then+ end_func "Could not create a temporary file for the Lunar query" "${FUNCNAME[0]}"+ return+ fi++ # Staged, then published by rename: a truncated or error body must not+ # replace a good result from a previous run.+ _code=$(run_command curl -s --max-time "${LUNAR_TIMEOUT:-30}" \+ -H 'Accept: application/json' \+ -w '%{http_code}' -o "$_tmp" \+ "https://api.lunarcyber.com/domain-exposure?domain=${domain}" 2>>"$LOGFILE") || _code="000"++ if [[ "$_code" != "200" ]]; then+ rm -f "$_tmp" 2>/dev/null+ end_func "Lunar API returned HTTP ${_code:-000}; no exposure data recorded" "${FUNCNAME[0]}"+ return+ fi++ # A 200 carrying a non-JSON body is an outage or interstitial page, not+ # data. Record nothing rather than a file downstream has to guess about.+ if ! jq -e . "$_tmp" >/dev/null 2>&1; then+ rm -f "$_tmp" 2>/dev/null+ end_func "Lunar API returned 200 with a non-JSON body; nothing recorded" "${FUNCNAME[0]}"+ return+ fi++ mv "$_tmp" "$_out"+ end_func "Results are saved in $domain/osint/lunar_exposure.json" "${FUNCNAME[0]}"++ else+ if [[ $LUNAR_EXPOSURE == false ]] || [[ $OSINT == false ]]; then+ skip_notification "disabled"+ elif [[ $domain =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then+ return+ else+ skip_notification "processed"+ fi+ fi+}+function spoof() {ensure_dirs osintdiff --git a/tests/unit/test_lunar_exposure.bats b/tests/unit/test_lunar_exposure.batsnew file mode 100644index 0000000..ae67baf--- /dev/null+++ b/tests/unit/test_lunar_exposure.bats@@ -0,0 +1,92 @@+#!/usr/bin/env bats+#+# Coverage for the Lunar domain-exposure enrichment (#1042).+#+# The API is free and unauthenticated, so the failure worth guarding is not+# credentials — it is publishing a file that is not exposure data. A 200 from an+# outage page, a captive portal, or a rate-limit interstitial is still a 200, and+# writing its body to osint/lunar_exposure.json makes every downstream consumer+# guess. These tests pin the staging contract: the artefact appears only when the+# response is both 200 AND parseable JSON, and a failed query never replaces a+# good result from a previous run.++setup() {+ source "$(cd "$(dirname "$BATS_TEST_FILENAME")" && pwd)/../helpers/common.bash"+ setup_recon_env++ export TEST_DIR="$(mktemp -d)"+ export domain="example.com"+ export dir="$TEST_DIR/$domain"+ export called_fn_dir="$dir/.called_fn"+ mkdir -p "$dir/osint" "$called_fn_dir"+ cd "$dir"++ export OSINT=true LUNAR_EXPOSURE=true DIFF=false LUNAR_TIMEOUT=5++ # Stub curl: honours -o and -w '%{http_code}' the way the function relies on.+ mkdir -p "$TEST_DIR/bin"+ cat > "$TEST_DIR/bin/curl" <<'STUB'+#!/usr/bin/env bash+out=""+while [[ $# -gt 0 ]]; do+ case "$1" in+ -o) out="$2"; shift 2 ;;+ *) shift ;;+ esac+done+[[ -n "$out" ]] && printf '%s' "${FAKE_BODY:-}" > "$out"+printf '%s' "${FAKE_CODE:-200}"+STUB+ chmod +x "$TEST_DIR/bin/curl"+ export PATH="$TEST_DIR/bin:$PATH"+ export DRY_RUN=false ADAPTIVE_RATE_LIMIT=false DEBUG_LOG=""+}++teardown() {+ cd /+ rm -rf "$TEST_DIR"+}++@test "a 200 with JSON is published as the exposure artefact" {+ export FAKE_CODE=200+ export FAKE_BODY='{"domain":"example.com","exposures":3}'+ lunar_exposure+ [ -f "$dir/osint/lunar_exposure.json" ] \+ && jq -e '.exposures == 3' "$dir/osint/lunar_exposure.json" >/dev/null+}++@test "a non-200 writes no artefact" {+ export FAKE_CODE=503+ export FAKE_BODY='upstream unavailable'+ lunar_exposure+ [ ! -f "$dir/osint/lunar_exposure.json" ]+}++@test "a 200 carrying a non-JSON body writes no artefact" {+ export FAKE_CODE=200+ export FAKE_BODY='<html><body>rate limited</body></html>'+ lunar_exposure+ [ ! -f "$dir/osint/lunar_exposure.json" ]+}++@test "a failed query does not replace a previous good result" {+ printf '%s' '{"domain":"example.com","exposures":7}' > "$dir/osint/lunar_exposure.json"+ export FAKE_CODE=500+ export FAKE_BODY='boom'+ lunar_exposure+ jq -e '.exposures == 7' "$dir/osint/lunar_exposure.json" >/dev/null+}++@test "disabled by default: LUNAR_EXPOSURE=false performs no query" {+ export LUNAR_EXPOSURE=false+ lunar_exposure+ [ ! -f "$dir/osint/lunar_exposure.json" ]+}++@test "an IP target is skipped: the API takes domains" {+ export domain="203.0.113.10"+ export FAKE_CODE=200+ export FAKE_BODY='{"domain":"203.0.113.10"}'+ lunar_exposure+ [ ! -f "$dir/osint/lunar_exposure.json" ]+}