From 78c046e09a6d864410b1dc9c608cf19d7f7a63d9 Mon Sep 17 00:00:00 2001 From: J <91372088+jarelllama@users.noreply.github.com> Date: Sun, 2 Feb 2025 16:23:54 +0800 Subject: [PATCH] use while loops instead of for loops when globbing is not needed --- scripts/retrieve_domains.sh | 20 ++++++++++++-------- scripts/test_functions.sh | 1 - scripts/tools.sh | 2 +- scripts/validate_domains.sh | 1 - 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/retrieve_domains.sh b/scripts/retrieve_domains.sh index 07d2849cc..f8d1bacf4 100644 --- a/scripts/retrieve_domains.sh +++ b/scripts/retrieve_domains.sh @@ -507,8 +507,8 @@ source_google_search() { command -v csvgrep > /dev/null || pip install -q csvkit # Loop through search terms - for search_term in $(csvgrep -c 2 -m 'y' -i "$SEARCH_TERMS" \ - | csvcut -c 1 | tail -n +2); do + csvgrep -c 2 -m 'y' -i "$SEARCH_TERMS" | csvcut -c 1 | tail -n +2 \ + | while read -r search_term; do # Stop if rate limited if [[ "$rate_limited" == true ]]; then @@ -580,7 +580,7 @@ source_cybersquatting() { [[ "$USE_EXISTING_RESULTS" == true ]] && return - local domain tlds tld row count runs results + local tlds row count runs results # Install dnstwist command -v dnstwist > /dev/null || pip install -q dnstwist @@ -601,7 +601,9 @@ source_cybersquatting() { | sort -nr | mawk '{print $2}')" # Loop through phishing targets - for domain in $(mawk -F ',' '$4 == "y" {print $1}' "$PHISHING_TARGETS"); do + mawk -F ',' '$4 == "y" {print $1}' "$PHISHING_TARGETS" \ + | while read -r domain; do + # Get info of the target domain row="$(mawk -F ',' -v domain="$domain" \ '$1 == domain {printf $1","$2","$3}' "$PHISHING_TARGETS")" @@ -614,9 +616,9 @@ source_cybersquatting() { # Append TLDs to dnstwist results # Note the dnstwist --tld argument only replaces the TLDs of the # original domain. - for tld in $tlds; do + while read -r tld; do printf "%s\n" "$results" | sed "s/\.com/.${tld}/" >> results.tmp - done + done <<< "$tlds" # Run URLCrazy (bash does not work) ./urlcrazy-master/urlcrazy -r "${domain}.com" -f CSV \ @@ -689,10 +691,12 @@ source_regex() { [[ "$USE_EXISTING_RESULTS" == true ]] && return - local domain row count runs pattern results + local row count runs pattern results # Loop through phishing targets - for domain in $(mawk -F ',' '$8 == "y" {print $1}' "$PHISHING_TARGETS"); do + mawk -F ',' '$8 == "y" {print $1}' "$PHISHING_TARGETS" \ + | while read -r domain; do + # Get info of the target domain row="$(mawk -F ',' -v domain="$domain" \ '$1 == domain {printf $5","$6","$7}' "$PHISHING_TARGETS")" diff --git a/scripts/test_functions.sh b/scripts/test_functions.sh index 0b423f890..f292c0bfc 100644 --- a/scripts/test_functions.sh +++ b/scripts/test_functions.sh @@ -320,7 +320,6 @@ test_known_parked_removal() { # Test removal of common subdomains test_subdomain_removal() { - local subdomain while read -r subdomain; do subdomain="${subdomain}.subdomain-test.com" input "$subdomain" diff --git a/scripts/tools.sh b/scripts/tools.sh index 391616ded..0d58ebf01 100644 --- a/scripts/tools.sh +++ b/scripts/tools.sh @@ -54,7 +54,7 @@ convert_unicode() { # Install idn2 (requires sudo. -qq doesn not work here) command -v idn2 > /dev/null || sudo apt-get install idn2 > /dev/null - # Process the file, handling entries that may cause idn2 to error + # Process the file, handling entries that may cause idn2 to error: # https://www.rfc-editor.org/rfc/rfc5891#section-4.2.3.1. If idn2 does # error, exit 1. { diff --git a/scripts/validate_domains.sh b/scripts/validate_domains.sh index 8390dc209..26daa5249 100644 --- a/scripts/validate_domains.sh +++ b/scripts/validate_domains.sh @@ -84,7 +84,6 @@ validate() { done # Strip away subdomains - local subdomains while read -r subdomain; do # Loop through common subdomains subdomains="$(mawk "/^${subdomain}\./" "$RAW")"