2
0
mirror of https://github.com/mozilla/cipherscan.git synced 2024-11-22 14:23:41 +01:00

Merge pull request #18 from tomato42/wip

Hodgepodge of fixes
This commit is contained in:
Julien Vehent 2014-08-28 16:02:19 -04:00
commit ecd77f94fc
4 changed files with 1000165 additions and 1000003 deletions

View File

@ -9,10 +9,13 @@ DOBENCHMARK=0
BENCHMARKITER=30 BENCHMARKITER=30
OPENSSLBIN="$(dirname $0)/openssl" OPENSSLBIN="$(dirname $0)/openssl"
CACERTS=${CACERTS:-/etc/pki/tls/certs/ca-bundle.crt} CACERTS=${CACERTS:-/etc/pki/tls/certs/ca-bundle.crt}
if [ ! -e "$CACERTS" ]; then
CACERTS="/etc/ssl/certs/ca-certificates.crt"
fi
if [ ! -e "$CACERTS" ]; then if [ ! -e "$CACERTS" ]; then
echo "Warning: CA Certificates not found at $CACERTS, export CACERTS variable with location of your trust anchors" 1>&2 echo "Warning: CA Certificates not found at $CACERTS, export CACERTS variable with location of your trust anchors" 1>&2
fi fi
CIPHERSUITE="ALL:COMPLEMENTOFALL" CIPHERSUITE="ALL:COMPLEMENTOFALL:+aRSA"
DEBUG=0 DEBUG=0
VERBOSE=0 VERBOSE=0
DELAY=0 DELAY=0
@ -75,6 +78,13 @@ test_cipher_on_target() {
do do
debug echo \"Q\" \| $sslcommand $tls_version debug echo \"Q\" \| $sslcommand $tls_version
local tmp=$(echo "Q" | $sslcommand $tls_version 1>/dev/stdout 2>/dev/null) local tmp=$(echo "Q" | $sslcommand $tls_version 1>/dev/stdout 2>/dev/null)
if grep 'OCSP Response Data' <<<"$tmp" >/dev/null; then
current_ocspstaple="True"
else
current_ocspstaple="False"
fi
# filter out the OCSP server certificate
tmp=$(awk 'BEGIN { pr="yes" } /^======================================/ { if ( pr=="yes" ) pr="no"; else pr="yes" } { if ( pr == "yes" ) print }' <<<"$tmp")
current_cipher=$(grep "New, " <<<"$tmp"|awk '{print $5}') current_cipher=$(grep "New, " <<<"$tmp"|awk '{print $5}')
current_pfs=$(grep 'Server Temp Key' <<<"$tmp"|awk '{print $4$5$6$7}') current_pfs=$(grep 'Server Temp Key' <<<"$tmp"|awk '{print $4$5$6$7}')
current_protocol=$(egrep "^\s+Protocol\s+:" <<<"$tmp"|awk '{print $3}') current_protocol=$(egrep "^\s+Protocol\s+:" <<<"$tmp"|awk '{print $3}')
@ -82,7 +92,11 @@ test_cipher_on_target() {
if [ -z $current_pubkey ]; then if [ -z $current_pubkey ]; then
current_pubkey=0 current_pubkey=0
fi fi
current_sigalg=$(openssl x509 -noout -text 2>/dev/null <<<"$tmp"|grep Signature\ Algorithm | head -n 1 | awk '{print $3}') || current_sigalg="None" current_tickethint=$(grep 'ticket lifetime hint' <<<"$tmp"|awk '{print $6 }')
if [ -z $current_tickethint ]; then
current_tickethint=None
fi
current_sigalg=$(${OPENSSLBIN} x509 -noout -text 2>/dev/null <<<"$tmp"|grep Signature\ Algorithm | head -n 1 | awk '{print $3}') || current_sigalg="None"
grep 'Verify return code: 0 ' <<<"$tmp" >/dev/null grep 'Verify return code: 0 ' <<<"$tmp" >/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
current_trusted="True" current_trusted="True"
@ -115,6 +129,8 @@ test_cipher_on_target() {
pubkey=$current_pubkey pubkey=$current_pubkey
sigalg=$current_sigalg sigalg=$current_sigalg
trusted=$current_trusted trusted=$current_trusted
tickethint=$current_tickethint
ocspstaple=$current_ocspstaple
# grab the cipher and PFS key size # grab the cipher and PFS key size
done done
# if cipher is empty, that means none of the TLS version worked with # if cipher is empty, that means none of the TLS version worked with
@ -126,13 +142,13 @@ test_cipher_on_target() {
# if cipher contains NONE, the cipher wasn't accepted # if cipher contains NONE, the cipher wasn't accepted
elif [ "$cipher" == '(NONE) ' ]; then elif [ "$cipher" == '(NONE) ' ]; then
result="$cipher $protocols $pubkey $sigalg $trusted $pfs" result="$cipher $protocols $pubkey $sigalg $trusted $tickethint $ocspstaple $pfs"
verbose "handshake failed, server returned ciphersuite '$result'" verbose "handshake failed, server returned ciphersuite '$result'"
return 1 return 1
# the connection succeeded # the connection succeeded
else else
result="$cipher $protocols $pubkey $sigalg $trusted $pfs" result="$cipher $protocols $pubkey $sigalg $trusted $tickethint $ocspstaple $pfs"
verbose "handshake succeeded, server returned ciphersuite '$result'" verbose "handshake succeeded, server returned ciphersuite '$result'"
return 0 return 0
fi fi
@ -166,9 +182,9 @@ get_cipher_pref() {
[ "$OUTPUTFORMAT" == "terminal" ] && [ $DEBUG -lt 1 ] && echo -n '.' [ "$OUTPUTFORMAT" == "terminal" ] && [ $DEBUG -lt 1 ] && echo -n '.'
local ciphersuite="$1" local ciphersuite="$1"
if [ -e $CACERTS ]; then if [ -e $CACERTS ]; then
local sslcommand="timeout $TIMEOUT $OPENSSLBIN s_client -CAfile $CACERTS $SCLIENTARGS -connect $TARGET -cipher $ciphersuite" local sslcommand="timeout $TIMEOUT $OPENSSLBIN s_client -CAfile $CACERTS -status $SCLIENTARGS -connect $TARGET -cipher $ciphersuite"
else else
local sslcommand="timeout $TIMEOUT $OPENSSLBIN s_client $SCLIENTARGS -connect $TARGET -cipher $ciphersuite" local sslcommand="timeout $TIMEOUT $OPENSSLBIN s_client -status $SCLIENTARGS -connect $TARGET -cipher $ciphersuite"
fi fi
verbose "Connecting to '$TARGET' with ciphersuite '$ciphersuite'" verbose "Connecting to '$TARGET' with ciphersuite '$ciphersuite'"
test_cipher_on_target "$sslcommand" test_cipher_on_target "$sslcommand"
@ -190,6 +206,8 @@ display_results_in_terminal() {
local pubkey local pubkey
local sigalg local sigalg
local trusted local trusted
local tickethint
local ocspstaple
local different=False local different=False
for cipher in "${cipherspref[@]}"; do for cipher in "${cipherspref[@]}"; do
pciph=$(echo $cipher|awk '{print $1}') pciph=$(echo $cipher|awk '{print $1}')
@ -203,6 +221,8 @@ display_results_in_terminal() {
pubkey=$(awk '{print $3}' <<<$cipher) pubkey=$(awk '{print $3}' <<<$cipher)
sigalg=$(awk '{print $4}' <<<$cipher) sigalg=$(awk '{print $4}' <<<$cipher)
trusted=$(awk '{print $5}' <<<$cipher) trusted=$(awk '{print $5}' <<<$cipher)
tickethint=$(awk '{print $6}' <<<$cipher)
ocspstaple=$(awk '{print $7}' <<<$cipher)
else else
if [ "$pubkey" != "$(awk '{print $3}' <<<$cipher)" ]; then if [ "$pubkey" != "$(awk '{print $3}' <<<$cipher)" ]; then
different=True different=True
@ -213,6 +233,9 @@ display_results_in_terminal() {
if [ "$trusted" != "$(awk '{print $5}' <<<$cipher)" ]; then if [ "$trusted" != "$(awk '{print $5}' <<<$cipher)" ]; then
different=True different=True
fi fi
if [ "$tickethint" != "$(awk '{print $6}' <<<$cipher)" ]; then
different=True
fi
fi fi
results=("${results[@]}" "$r") results=("${results[@]}" "$r")
ctr=$((ctr+1)) ctr=$((ctr+1))
@ -220,13 +243,13 @@ display_results_in_terminal() {
if [ $DOBENCHMARK -eq 1 ]; then if [ $DOBENCHMARK -eq 1 ]; then
if [ $different == "True" ]; then if [ $different == "True" ]; then
header="prio ciphersuite protocols pubkey_size signature_algoritm trusted pfs_keysize avg_handshake_microsec" header="prio ciphersuite protocols pubkey_size signature_algoritm trusted ticket_hint pfs_keysize avg_handshake_microsec"
else else
header="prio ciphersuite protocols pfs_keysize avg_handshake_microsec" header="prio ciphersuite protocols pfs_keysize avg_handshake_microsec"
fi fi
else else
if [ $different == "True" ]; then if [ $different == "True" ]; then
header="prio ciphersuite protocols pubkey_size signature_algorithm trusted pfs_keysize" header="prio ciphersuite protocols pubkey_size signature_algorithm trusted ticket_hint pfs_keysize"
else else
header="prio ciphersuite protocols pfs_keysize" header="prio ciphersuite protocols pfs_keysize"
fi fi
@ -240,7 +263,8 @@ display_results_in_terminal() {
if [ $different == "True" ]; then if [ $different == "True" ]; then
echo $result|grep -v '(NONE)' echo $result|grep -v '(NONE)'
else else
echo $result|grep -v '(NONE)'|awk '{print $1 " " $2 " " $3 " " $7}' # prints priority, ciphersuite, protocols and pfs_keysize
echo $result|grep -v '(NONE)'|awk '{print $1 " " $2 " " $3 " " $9}'
fi fi
done|column -t done|column -t
echo echo
@ -250,6 +274,12 @@ display_results_in_terminal() {
else else
echo "Certificate: UNTRUSTED, $pubkey bit, $sigalg signature" echo "Certificate: UNTRUSTED, $pubkey bit, $sigalg signature"
fi fi
echo "TLS ticket lifetime hint: $tickethint"
fi
if [[ $ocspstaple == "True" ]]; then
echo "OCSP stapling: supported"
else
echo "OCSP stapling: not supported"
fi fi
} }
@ -265,7 +295,9 @@ display_results_in_json() {
echo -n "\"pubkey\":[\"$(echo $cipher|awk '{print $3}'|sed 's/,/","/g')\"]," echo -n "\"pubkey\":[\"$(echo $cipher|awk '{print $3}'|sed 's/,/","/g')\"],"
echo -n "\"sigalg\":[\"$(echo $cipher|awk '{print $4}'|sed 's/,/","/g')\"]," echo -n "\"sigalg\":[\"$(echo $cipher|awk '{print $4}'|sed 's/,/","/g')\"],"
echo -n "\"trusted\":\"$(echo $cipher|awk '{print $5}'|sed 's/,/","/g')\"," echo -n "\"trusted\":\"$(echo $cipher|awk '{print $5}'|sed 's/,/","/g')\","
pfs=$(echo $cipher|awk '{print $6}') echo -n "\"ticket_hint\":\"$(echo $cipher|awk '{print $6}')\","
echo -n "\"ocsp_stapling\":\"$(echo $cipher|awk '{print $7}')\","
pfs=$(echo $cipher|awk '{print $8}')
[ "$pfs" == "" ] && pfs="None" [ "$pfs" == "" ] && pfs="None"
echo -n "\"pfs\":\"$pfs\"}" echo -n "\"pfs\":\"$pfs\"}"
ctr=$((ctr+1)) ctr=$((ctr+1))

View File

@ -23,6 +23,8 @@ protocolstats = defaultdict(int)
handshakestats = defaultdict(int) handshakestats = defaultdict(int)
keysize = defaultdict(int) keysize = defaultdict(int)
sigalg = defaultdict(int) sigalg = defaultdict(int)
tickethint = defaultdict(int)
ocspstaple = defaultdict(int)
dsarsastack = 0 dsarsastack = 0
total = 0 total = 0
for r,d,flist in os.walk(path): for r,d,flist in os.walk(path):
@ -35,6 +37,8 @@ for r,d,flist in os.walk(path):
tempecckeystats = {} tempecckeystats = {}
tempdsakeystats = {} tempdsakeystats = {}
tempsigstats = {} tempsigstats = {}
tempticketstats = {}
tempcipherstats = {}
ciphertypes = 0 ciphertypes = 0
AESGCM = False AESGCM = False
AES = False AES = False
@ -42,9 +46,13 @@ for r,d,flist in os.walk(path):
DES3 = False DES3 = False
CAMELLIA = False CAMELLIA = False
RC4 = False RC4 = False
ADH = False
DHE = False DHE = False
AECDH = False
ECDHE = False ECDHE = False
RSA = False RSA = False
ECDH = False
DH = False
SSL2 = False SSL2 = False
SSL3 = False SSL3 = False
TLS1 = False TLS1 = False
@ -53,6 +61,7 @@ for r,d,flist in os.walk(path):
dualstack = False dualstack = False
ECDSA = False ECDSA = False
trusted = False trusted = False
ocsp_stapling = None
""" process the file """ """ process the file """
f_abs = os.path.join(r,f) f_abs = os.path.join(r,f)
@ -77,7 +86,11 @@ for r,d,flist in os.walk(path):
continue continue
""" store the ciphers supported """ """ store the ciphers supported """
if 'AES128-GCM' in entry['cipher'] or 'AES256-GCM' in entry['cipher']: if 'ADH' in entry['cipher'] or 'AECDH' in entry['cipher']:
ciphertypes += 1
name = "z:" + entry['cipher']
tempcipherstats[name] = 1
elif 'AES128-GCM' in entry['cipher'] or 'AES256-GCM' in entry['cipher']:
if not AESGCM: if not AESGCM:
AESGCM = True AESGCM = True
ciphertypes += 1 ciphertypes += 1
@ -104,15 +117,25 @@ for r,d,flist in os.walk(path):
else: else:
ciphertypes += 1 ciphertypes += 1
name = "z:" + entry['cipher'] name = "z:" + entry['cipher']
cipherstats[name] += 1 tempcipherstats[name] = 1
""" store key handshake methods """ """ store key handshake methods """
if 'ECDHE' in entry['cipher']: if 'ECDHE' in entry['cipher']:
ECDHE = True ECDHE = True
temppfsstats[entry['pfs']] = 1 temppfsstats[entry['pfs']] = 1
elif 'DHE' in entry['cipher']: elif 'DHE' in entry['cipher'] or 'EDH' in entry['cipher']:
DHE = True DHE = True
temppfsstats[entry['pfs']] = 1 temppfsstats[entry['pfs']] = 1
elif 'AECDH' in entry['cipher']:
AECDH = True
elif 'ADH' in entry['cipher']:
ADH = True
elif 'ECDH' in entry['cipher']:
ECDH = True
elif 'DH' in entry['cipher']:
DH = True
else:
RSA = True
""" save the key size """ """ save the key size """
if 'ECDSA' in entry['cipher']: if 'ECDSA' in entry['cipher']:
@ -133,6 +156,17 @@ for r,d,flist in os.walk(path):
""" save key signatures size """ """ save key signatures size """
tempsigstats[entry['sigalg'][0]] = 1 tempsigstats[entry['sigalg'][0]] = 1
""" save tls ticket hint """
if 'ticket_hint' in entry:
tempticketstats[entry['ticket_hint']] = 1
""" check if OCSP stapling is supported """
if 'ocsp_stapling' in entry:
if entry['ocsp_stapling'] == 'True':
ocsp_stapling=True
else:
ocsp_stapling=False
""" store the versions of TLS supported """ """ store the versions of TLS supported """
for protocol in entry['protocols']: for protocol in entry['protocols']:
if protocol == 'SSLv2': if protocol == 'SSLv2':
@ -175,6 +209,19 @@ for r,d,flist in os.walk(path):
for s in tempsigstats: for s in tempsigstats:
sigalg[s] += 1 sigalg[s] += 1
if len(tempticketstats) == 1:
for s in tempticketstats:
tickethint[s + " only"] += 1
for s in tempticketstats:
tickethint[s] += 1
if ocsp_stapling is None:
ocspstaple['Unknown'] += 1
elif ocsp_stapling:
ocspstaple['Supported'] += 1
else:
ocspstaple['Unsupported'] += 1
""" store cipher stats """ """ store cipher stats """
if AESGCM: if AESGCM:
cipherstats['AES-GCM'] += 1 cipherstats['AES-GCM'] += 1
@ -209,12 +256,24 @@ for r,d,flist in os.walk(path):
cipherstats['RC4 forced in TLS1.1+'] += 1 cipherstats['RC4 forced in TLS1.1+'] += 1
cipherstats['RC4 Preferred'] += 1 cipherstats['RC4 Preferred'] += 1
for cipher in tempcipherstats:
cipherstats[cipher] += 1
""" store handshake stats """ """ store handshake stats """
if AECDH:
handshakestats['AECDH'] += 1
if ADH:
handshakestats['ADH'] += 1
if ECDHE: if ECDHE:
handshakestats['ECDHE'] += 1 handshakestats['ECDHE'] += 1
if DHE: if DHE:
handshakestats['DHE'] += 1 handshakestats['DHE'] += 1
if DHE and ECDHE:
handshakestats['ECDHE and DHE'] += 1
if ECDH:
handshakestats['ECDH'] += 1
if DH:
handshakestats['DH'] += 1
if RSA: if RSA:
handshakestats['RSA'] += 1 handshakestats['RSA'] += 1
@ -279,6 +338,12 @@ for stat in sorted(pfsstats):
pfspercent = round(pfsstats[stat] / handshakestats['DHE'] * 100, 4) pfspercent = round(pfsstats[stat] / handshakestats['DHE'] * 100, 4)
sys.stdout.write(stat.ljust(25) + " " + str(pfsstats[stat]).ljust(10) + str(percent).ljust(9) + str(pfspercent) + "\n") sys.stdout.write(stat.ljust(25) + " " + str(pfsstats[stat]).ljust(10) + str(percent).ljust(9) + str(pfspercent) + "\n")
print("\nTLS session ticket hint Count Percent ")
print("-------------------------+---------+--------")
for stat in sorted(tickethint):
percent = round(tickethint[stat] / total * 100, 4)
sys.stdout.write(stat.ljust(25) + " " + str(tickethint[stat]).ljust(10) + str(percent).ljust(9) + "\n")
print("\nCertificate sig alg Count Percent ") print("\nCertificate sig alg Count Percent ")
print("-------------------------+---------+--------") print("-------------------------+---------+--------")
for stat in sorted(sigalg): for stat in sorted(sigalg):
@ -293,6 +358,12 @@ for stat in sorted(keysize):
sys.stdout.write("RSA/ECDSA Dual Stack".ljust(25) + " " + str(dsarsastack).ljust(10) + str(round(dsarsastack/total * 100, 4)) + "\n") sys.stdout.write("RSA/ECDSA Dual Stack".ljust(25) + " " + str(dsarsastack).ljust(10) + str(round(dsarsastack/total * 100, 4)) + "\n")
print("\nOCSP stapling Count Percent ")
print("-------------------------+---------+--------")
for stat in sorted(ocspstaple):
percent = round(ocspstaple[stat] / total * 100, 4)
sys.stdout.write(stat.ljust(25) + " " + str(ocspstaple[stat]).ljust(10) + str(percent).ljust(9) + "\n")
print("\nSupported Protocols Count Percent") print("\nSupported Protocols Count Percent")
print("-------------------------+---------+-------") print("-------------------------+---------+-------")
for stat in sorted(protocolstats): for stat in sorted(protocolstats):

View File

@ -1,35 +1,94 @@
#!/usr/bin/env bash #!/usr/bin/env bash
parallel=50 parallel=10
max_bg=400 max_bg=50
absolute_max_bg=100
max_load=50
if [ $(ulimit -u) -lt $((10*absolute_max_bg)) ]; then
echo "max user processes too low, use ulimit -u to increase"
exit 1
fi
[ ! -e "results" ] && mkdir results [ ! -e "results" ] && mkdir results
function wait_for_jobs() { function wait_for_jobs() {
local no_jobs local no_jobs
no_jobs=$(jobs | wc -l) no_jobs=$(jobs | wc -l)
while [ $no_jobs -gt $1 ]; do while [ $no_jobs -gt $1 ] || awk -v maxload=$max_load '{ if ($1 < maxload) exit 1 }' /proc/loadavg; do
if awk -v maxload=$max_load '{ if ($1 > maxload) exit 1 }' /proc/loadavg && [ $no_jobs -lt $absolute_max_bg ]; then
return
fi
sleep 1 sleep 1
no_jobs=$(jobs | wc -l) no_jobs=$(jobs | wc -l)
done done
} }
function scan_host() {
# do not scan the same host multiple times
if [ -e results/$1@$2 ]; then
return
fi
tcping -u 10000000 $2 443;
if [ $? -gt 0 ]; then
return
fi
../cipherscan -json -servername $1 $2:443 > results/$1@$2
}
function scan_host_no_sni() {
# do not scan the same host multiple times
if [ -e results/$1 ]; then
return
fi
tcping -u 10000000 $1 443;
if [ $? -gt 0 ]; then
return
fi
../cipherscan -json $1:443 > results/$1
}
function scan_hostname() {
if [[ ! -z $(awk -F. '$1>=0 && $1<=255 && $2>=0 && $2<=255 &&
$3>=0 && $3<=255 && $4>=0 && $4<=255 && NF==4' <<<"$1") ]]; then
scan_host_no_sni $1
return
fi
local host_ips=$(host $1 | awk '/has address/ {print $4}')
local www_ips=$(host www.$1 | awk '/has address/ {print $4}')
if [ ! -z "$host_ips" ] && [ ! -z "$www_ips" ]; then
# list of IPs that are in www but not in host
local diff=$(grep -Fv "$host_ips" <<< "$www_ips")
head -n 1 <<< "$host_ips" | while read ip; do
scan_host $1 $ip
done
if [ ! -z "$diff" ]; then
head -n 1 <<<"$diff" | while read ip; do
scan_host www.$1 $ip
done
fi
else
if [ ! -z "$host_ips" ]; then
head -n 1 <<<"$host_ips" | while read ip; do
scan_host $1 $ip
done
fi
if [ ! -z "$www_ips" ]; then
head -n 1 <<<"$www_ips" | while read ip; do
scan_host www.$1 $ip
done
fi
fi
}
i=0 i=0
count=$(wc -l top-1m.csv | awk '{print $1}') count=$(wc -l top-1m.csv | awk '{print $1}')
while [ $i -lt $count ] while [ $i -lt $count ]
do do
echo processings sites $i to $((i + parallel)) echo processings sites $i to $((i + parallel))
for t in $(tail -$(($count - $i)) top-1m.csv | head -$parallel |cut -d ',' -f 2) for t in $(tail -$(($count - $i)) top-1m.csv | head -$parallel |cut -d ',' -f 2|cut -d "/" -f 1)
do do
(tcping -u 10000000 $t 443; (scan_hostname $t)&
if [ $? -gt 0 ];then
tcping -u 10000000 www.$t 443;
if [ $? -gt 0 ]; then
continue;
else
../cipherscan -json www.$t:443 > results/www.$t
continue;
fi;
fi;../cipherscan -json $t:443 > results/$t )&
done done
i=$(( i + parallel)) i=$(( i + parallel))
wait_for_jobs $max_bg wait_for_jobs $max_bg

File diff suppressed because it is too large Load Diff