Created
August 21, 2022 20:01
-
-
Save ahrex/8d2c15086a116bb9388424c40687f20f to your computer and use it in GitHub Desktop.
Bash script for enumerating ciphersuites
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
#!/usr/bin/env bash | |
# | |
# https://superuser.com/questions/109213/how-do-i-list-the-ssl-tls-cipher-suites-a-particular-website-offers#comment2253795_224263 | |
# https://gist.github.com/jahir/23c4202eee12e377ef3acf1dcdc7c776 | |
CIPHERS='ALL:eNULL' | |
DELAY=${2:-0.1} | |
SERVER=${1:?usage: $0 <host:port> [delay, default is ${DELAY}s] [ciphers, default is ${CIPHERS}]} | |
MAXLEN=$(openssl ciphers "$CIPHERS" | sed -e 's/:/\n/g' | awk '{ if ( length > L ) { L=length} }END{ print L}') | |
STARTTLS="" | |
if [[ "$SERVER" = *:25 ]]; then | |
STARTTLS="-starttls smtp" | |
fi | |
echo Using $(openssl version). | |
declare -A TLSMAP=( [tls1]=cipher [tls1_1]=cipher [tls1_2]=cipher [tls1_3]=ciphersuites ) | |
for tlsver in "${!TLSMAP[@]}" | |
do | |
echo "Using $tlsver" | |
ciphers=$(openssl ciphers -$tlsver -s "$CIPHERS" | sed -e 's/:/ /g') | |
for cipher in ${ciphers[@]} | |
do | |
in=$(openssl s_client -$tlsver -${TLSMAP[$tlsver]} "$cipher" $STARTTLS -connect $SERVER </dev/null 2>&1) | |
if [[ "$in" =~ ":error:" ]] ; then | |
result="NO ($(echo -n $in | cut -d':' -f6))" | |
else | |
if [[ "$in" =~ "Cipher is ${cipher}" || "$in" =~ "Cipher :" ]] ; then | |
result='YES' | |
else | |
result="UNKNOWN RESPONSE\n$in" | |
fi | |
fi | |
printf 'Testing %-*s ... %s\n' "$MAXLEN" "$cipher" "$result" | |
sleep $DELAY | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment