Skip to content

Commit

Permalink
use while loops instead of for loops when globbing is not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jarelllama authored Feb 2, 2025
1 parent c58aef5 commit 78c046e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
20 changes: 12 additions & 8 deletions scripts/retrieve_domains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")"
Expand All @@ -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 \
Expand Down Expand Up @@ -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")"
Expand Down
1 change: 0 additions & 1 deletion scripts/test_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion scripts/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
{
Expand Down
1 change: 0 additions & 1 deletion scripts/validate_domains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ validate() {
done

# Strip away subdomains
local subdomains
while read -r subdomain; do # Loop through common subdomains
subdomains="$(mawk "/^${subdomain}\./" "$RAW")"

Expand Down

0 comments on commit 78c046e

Please sign in to comment.