Skip to content

Instantly share code, notes, and snippets.

@AlLongley
Created January 6, 2023 23:24
Show Gist options
  • Save AlLongley/8be503d9794c9750b5447aa73427e2c3 to your computer and use it in GitHub Desktop.
Save AlLongley/8be503d9794c9750b5447aa73427e2c3 to your computer and use it in GitHub Desktop.
Fast DNS subdomain SSL certificate lookup directly from CRT.SH database crt_sh_psql.sh
#!/bin/bash
if [ "x$1" = "x" ];
then echo "You need to specify an input file containing domain names to iterate over!";echo "Usage: $0 list_of_domain_names.txt"
exit;
fi
if ! [ -x "$(command -v psql)" ]; then
echo 'Error: psql is not installed.' >&2
echo 'Try installing it: sudo apt install postgresql-client' >&2
exit 1
fi
filename=$1
while read dns; do
echo $dns
echo ""
Q="select distinct(lower(name_value)) FROM certificate_and_identities cai WHERE plainto_tsquery('$dns') @@ identities(cai.CERTIFICATE) AND lower(cai.NAME_VALUE) LIKE ('%.$dns')"
psql -P pager=off -P footer=off -U guest -d certwatch --host crt.sh -c "$Q" | sed -e '$d' -e 's/^ //' -e '1,2d'
done < "$filename"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment