Skip to content

Instantly share code, notes, and snippets.

@brandonlou
Last active August 11, 2020 04:20
Show Gist options
  • Save brandonlou/aca4620775a402ebed5c7383169aaa44 to your computer and use it in GitHub Desktop.
Save brandonlou/aca4620775a402ebed5c7383169aaa44 to your computer and use it in GitHub Desktop.
Check for available usernames
#!/bin/bash
# Check at least one argument is passed.
if [ $# -eq 0 ]
then
echo "Usage: ./open-users.sh [website URL]"
exit 1
fi
URL=$1
NAME=$(basename "$0" .sh)
TMP_FILE=$(mktemp /tmp/"$NAME".XXXXXX)
LOG_FILE=$(date +"%m-%d-%Y-%H:%M:%S-openusers.log")
export LOG_FILE # Allows check_name function to access.
echo "Username combinations stored at $TMP_FILE"
echo "Logging to $LOG_FILE"
# Generate all 3 alphanumeric combinations.
for first in {a..z} {0..9}; do
for second in {a..z} {0..9}; do
for third in {a..z} {0..9}; do
echo "https://$URL/$first$second$third" >> "$TMP_FILE"
done
done
done
# Shuffle the username combinations.
gshuf "$TMP_FILE" -o "$TMP_FILE"
# Takes a URL, then writes to stdout and a log file if response is not 200.
check_name() {
FULL_URL=$0
RES_CODE=$(curl -o /dev/null -L -s -w "%{http_code}" -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko)" "$FULL_URL")
if [ "$RES_CODE" -ne "200" ]; then
echo "$FULL_URL $RES_CODE" | tee -a "$LOG_FILE"
fi
}
export -f check_name
# You can speed this up but servers may respond back with HTTP status code 429
xargs -n1 -P1 bash -c 'check_name "$@"' < "$TMP_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment