Last active
September 23, 2019 01:49
-
-
Save mikeabreu/b2bcbfbb84443a831d9d204d57fb737d to your computer and use it in GitHub Desktop.
Certificate Transparency Bash Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Add these functions to your .bashrc or .zshrc and use from your terminal. | |
get_certs_domains() { | |
# Credit goes to Ronnie Flathers, taken from https://twitter.com/ropnop/status/972151279463124994 | |
curl -s https://crt.sh\?q\=%25.$1 | awk -v pattern="<TD>.*$1" '$0 ~ pattern {gsub("<[^>]*>","");gsub(//,""); print}' | sort -u | |
} | |
get_certs() { | |
curl -s https://crt.sh\?q\=%25.$1 | awk '/\?id=[0-9]*/{nr[NR]; nr[NR+1]; nr[NR+3]; nr[NR+4]}; NR in nr' | sed 's/<TD style="text-align:center"><A href="?id=//g' | sed 's#">[0-9]*</A></TD>##g' | sed 's#<TD style="text-align:center">##g' | sed 's#</TD>##g' | sed 's#<TD>##g' | sed 's#<A style=["a-z: ?=0-9-]*>##g' | sed 's#</A>##g' | sed 'N;N;N;s/\n/\t\t/g' | |
} | |
get_certs_to_csv() { | |
echo 'ID,Logged At,Identity,Issuer Name' > $1.csv | |
curl -s https://crt.sh\?q\=%25.$1 | awk '/\?id=[0-9]*/{nr[NR]; nr[NR+1]; nr[NR+3]; nr[NR+4]}; NR in nr' | sed 's/<TD style="text-align:center"><A href="?id=//g' | sed 's#">[0-9]*</A></TD>##g' | sed 's#<TD style="text-align:center">##g' | sed 's#</TD>##g' | sed 's#<TD>##g' | sed 's#<A style=["a-z: ?=0-9-]*>##g' | sed 's#</A>##g' | sed 's/,/;/g' | sed 'N;N;N;s/\n/,/g' | sed 's/,[ ]*/,/g' | sed 's/^[ ]*//g' >> $1.csv | |
} | |
# Example | |
$ get_certs_domains mikeabreu.com | |
www.mikeabreu.com | |
api.mikeabreu.com | |
# Example | |
$ get_certs mikeabreu.com | |
328469607 2018-02-12 www.mikeabreu.com C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3 | |
276563784 2017-12-12 www.mikeabreu.com C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3 | |
221039748 2017-09-30 api.mikeabreu.com C=US, O=Let's Encrypt, CN=Let's Encrypt Authority X3 | |
# Example | |
$ get_certs_to_csv mikeabreu.com | |
$ cat mikeabreu.com.csv | |
ID,Logged At,Identity,Issuer Name | |
328469607,2018-02-12,www.mikeabreu.com,C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3 | |
276563784,2017-12-12,www.mikeabreu.com,C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3 | |
221039748,2017-09-30,www.mikeabreu.com,C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment