Skip to content

Commit 7d8cf71

Browse files
committed
Further robustness check to winshock (#1719)
This commit adds * a check for the elliptical curves * and a check for TLS extensions which will again reduces false positives. Background: * https://en.wikipedia.org/wiki/Comparison_of_TLS_implementations#Supported_elliptic_curves * https://en.wikipedia.org/wiki/Comparison_of_TLS_implementations#Extensions Also: * Docu phrased more precise (we're not checking ciphers and HTTP Server banner only * As a last resort we also take 'Microsoft-HTTPAPI/2.0' as a server header on the HTTPS branch and query the HTTP branch for Microsoft-IIS/8.x. * $EXPERIMENTAL overrides some banner and service related checks. So that e.g. SMTP servers can also be checked. Last but bot least ist's a vulnerability of the TLS stack. For better debugging we'll keep the TLS extensions and offered curves in a file. Also it adds a debug1() function which may be needed on other occasions. Also the output is better coded as we put "check patches locally to confirm" into a variable. There's still room for improvement: * More extensions (see https://raw.githubusercontent.com/cisco/joy/master/doc/using-joy-fingerprinting-00.pdf) * We could need a separate determine_curves() function, see #1730 as otherwise we can't use the curves in a non-default run.
1 parent 53bef58 commit 7d8cf71

4 files changed

Lines changed: 119 additions & 42 deletions

File tree

doc/testssl.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ Security headers (X\-Frame\-Options, X\-XSS\-Protection, Expect\-CT,\.\.\. , CSP
385385
\fB\-L, \-\-lucky13\fR Checks for LUCKY13 vulnerability\. It checks for the presence of CBC ciphers in TLS versions 1\.0 \- 1\.2\.
386386
.
387387
.P
388-
\fB\-WS, \-\-winshock\fR Checks for Winshock vulnerability\. It tests for absence of GCM ciphers which were introduced in the fix and correlates that with the server banner\.
388+
\fB\-WS, \-\-winshock\fR Checks for Winshock vulnerability\. It tests for the absence of a lot of ciphers, some TLS extensions and ec curves which were introduced later in Windows\. In the end the server banner is being looked at\.
389389
.
390390
.P
391391
\fB\-4, \-\-rc4, \-\-appelbaum\fR Checks which RC4 stream ciphers are being offered\.

doc/testssl.1.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/testssl.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ Also for multiple server certificates are being checked for as well as for the c
254254

255255
`-L, --lucky13` Checks for LUCKY13 vulnerability. It checks for the presence of CBC ciphers in TLS versions 1.0 - 1.2.
256256

257-
`-WS, --winshock` Checks for Winshock vulnerability. It tests for absence of GCM ciphers which were introduced in the fix and correlates that with the server banner.
257+
`-WS, --winshock` Checks for Winshock vulnerability. It tests for the absence of a lot of ciphers, some TLS extensions and ec curves which were introduced later in Windows. In the end the server banner is being looked at.
258258

259259
`-4, --rc4, --appelbaum` Checks which RC4 stream ciphers are being offered.
260260

testssl.sh

Lines changed: 116 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,10 @@ debugme() {
759759
[[ "$DEBUG" -ge 2 ]] && "$@"
760760
return 0
761761
}
762+
debugme1() {
763+
[[ "$DEBUG" -ge 1 ]] && "$@"
764+
return 0
765+
}
762766

763767
hex2dec() {
764768
echo $((16#$1))
@@ -7436,9 +7440,14 @@ determine_tls_extensions() {
74367440
[[ $success -eq 0 ]] && extract_new_tls_extensions $TMPFILE
74377441
tmpfile_handle ${FUNCNAME[0]}.txt
74387442
fi
7443+
7444+
# Keep it "on file" for debugging purposes
7445+
debugme1 safe_echo "$TLS_EXTENSIONS" >"$TEMPDIR/$NODE.$NODEIP.tls_extensions.txt"
7446+
74397447
return $success
74407448
}
74417449

7450+
74427451
extract_certificates() {
74437452
local version="$1"
74447453
local savedir
@@ -10150,6 +10159,8 @@ run_fs() {
1015010159
fi
1015110160
CURVES_OFFERED="$curves_offered"
1015210161
CURVES_OFFERED=$(strip_trailing_space "$CURVES_OFFERED")
10162+
# Keep it "on file" for debugging purposes
10163+
debugme1 safe_echo "$CURVES_OFFERED" >"$TEMPDIR/$NODE.$NODEIP.curves_offered.txt"
1015310164

1015410165
# find out what groups are supported.
1015510166
if "$using_sockets" && ( "$fs_tls13_offered" || "$ffdhe_offered" ); then
@@ -13333,6 +13344,7 @@ parse_tls_serverhello() {
1333313344
[[ $DEBUG -ge 1 ]] && tmpfile_handle ${FUNCNAME[0]}.txt
1333413345
return 1
1333513346
fi
13347+
# https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml
1333613348
case $extension_type in
1333713349
0000) tls_extensions+="TLS server extension \"server name\" (id=0), len=$extension_len\n" ;;
1333813350
0001) tls_extensions+="TLS server extension \"max fragment length\" (id=1), len=$extension_len\n" ;;
@@ -17441,26 +17453,33 @@ run_beast(){
1744117453
# This vulnerability affected all SChannel services -- most notably RDP (port 3398 normally). See
1744217454
# https://support.microsoft.com/en-us/help/2992611/ms14-066-vulnerability-in-schannel-could-allow-remote-code-execution-n
1744317455
# and http://www.securitysift.com/exploiting-ms14-066-cve-2014-6321-aka-winshock for "exploiting"/crashing lsass.exe.
17456+
# What we do here is giving a strong hint.
1744417457
#
17445-
# What we do here is giving a hint, as with the Rollup patch MS introduced later is to supply the additional ciphers
17458+
# First we check whether TLS 1.3 is available. Then with the fix MS introduced came additional ciphers
1744617459
# TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 TLS_RSA_WITH_AES_256_GCM_SHA384 TLS_RSA_WITH_AES_128_GCM_SHA256
1744717460
# = DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES128-GCM-SHA256 AES256-GCM-SHA384 AES128-GCM-SHA256.
17448-
# We check for those (in sockets only to avoid overhead) and for port 443 we also grab the server banner to be more sure.
17449-
# Also we check whether TLS 1.3 is available and some ciphers (ARIA, CCM, CAMELLIA and CHACHAPOLY). Those ciphers could
17450-
# also be retrieved from our array TLS_CIPHER_RFC_NAME[i] and using TLS_CIPHER_HEXCODE[i]. The latter will be done later.
17461+
# We also check for the absence of ciphers which came in way later (ECDHE-RSA-AES128-GCM-SHA256 / ECDHE-RSA-AES256-GCM-SHA384), or
17462+
# more ciphers like ARIA, CCM, CAMELLIA and CHACHAPOLY. (Those ciphers could also be retrieved from our array TLS_CIPHER_RFC_NAME[i]
17463+
# and using TLS_CIPHER_HEXCODE[i]. We may want to # do that later. We check for all this in sockets only to avoid overhead.)
17464+
# Then we check for absence of elliptical curves and TLS extensions.
17465+
# That all should minimize false # positives because of middle boxes, proxies and later Windows versions.
17466+
# The last straw then is to check for webserver banners (http.sys, IIS/8.0 and IIS/8.5).
1745117467
#
1745217468
run_winshock() {
17453-
local ws_ciphers_hex='00,9F, 00,9D, 00,9E, 00,9C'
17469+
local wsfixed_ciphers='00,9F, 00,9D, 00,9E, 00,9C'
1745417470
local aria_ciphers='C0,3D,C0,3F,C0,41,C0,43,C0,45,C0,47,C0,49,C0,4B,C0,4D,C0,4F,C0,51,C0,53,C0,55,C0,57,C0,59,C0,5B,C0,5D,C0,5F,C0,61,C0,63,C0,65,C0,67,C0,69,C0,6B,C0,6D,C0,6F,C0,71,C0,3C,C0,3E,C0,40,C0,42,C0,44,C0,46,C0,48,C0,4A,C0,4C,C0,4E,C0,50,C0,52,C0,54,C0,56,C0,58,C0,5A,C0,5C,C0,5E,C0,60,C0,62,C0,64,C0,66,C0,68,C0,6A,C0,6C,C0,6E,C0,70'
1745517471
local camellia_ciphers='C0,9B,C0,99,C0,97,C0,95,C0,77,C0,73,00,C4,00,C3,00,C2,00,C1,00,88,00,87,00,86,00,85,00,C5,00,89,C0,79,C0,75,00,C0,00,84,C0,7B,C0,7D,C0,7F,C0,81,C0,83,C0,85,C0,87,C0,89,C0,8B,C0,8D,C0,8F,C0,91,C0,93,C0,76,C0,72,00,BE,00,BD,00,BC,00,BB,00,45,00,44,00,43,00,42,00,BF,00,46,C0,78,C0,74,00,BA,00,41,C0,9A,C0,98,C0,96,C0,94,C0,7A,C0,7C,C0,7E,C0,80,C0,82,C0,84,C0,86,C0,88,C0,8A,C0,8C,C0,8E,C0,90,C0,92'
1745617472
local chacha_ccm_ciphers='CC,14,CC,13,CC,15,CC,A9,CC,A8,CC,AA,C0,AF,C0,AD,C0,A3,C0,9F,CC,AE,CC,AD,CC,AC,C0,AB,C0,A7,C0,A1,C0,9D,CC,AB,C0,A9,C0,A5,16,B7,16,B8,13,04,13,05,C0,AE,C0,AC,C0,A2,C0,9E,C0,AA,C0,A6,C0,A0,C0,9C,C0,A8,C0,A4'
1745717473
# TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 / TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = ECDHE-RSA-AES128-GCM-SHA256 / ECDHE-RSA-AES256-GCM-SHA384
1745817474
# came in Server 2016, see https://notsomany.com/2016/08/26/achieve-a-on-sslabs-iis-8-5-windows-2012-r2/
1745917475
# https://docs.microsoft.com/en-us/windows/win32/secauthn/cipher-suites-in-schannel
17460-
local more_excluded_ciphers='C0,2f, C0,30'
17476+
local more_excluded_ciphers='C0,2F, C0,30'
17477+
# These are the three NIST curves allowed only. Keep in mind prime256v1=secp256r1 and MS labels them as P256, P384 and P521
17478+
local allowed_curves="prime256v1 secp384r1 secp521r1"
17479+
local curve="" tls_ext=""
1746117480
local -i sclient_success=0
17462-
local is_iis8=true
1746317481
local server_banner=""
17482+
local check_patches=" - check patches locally to confirm"
1746417483
local cve="CVE-2014-6321"
1746517484
local cwe="CWE-94"
1746617485
local jsonID="winshock"
@@ -17475,62 +17494,108 @@ run_winshock() {
1747517494
if [[ "$(has_server_protocol "tls1_3")" -eq 0 ]] ; then
1747617495
# There's no MS server supporting TLS 1.3. Winshock was way back in time
1747717496
pr_svrty_best "not vulnerable (OK)"
17478-
debugme echo " - TLS 1.3 found"
17497+
debugme1 echo " - TLS 1.3 found"
1747917498
fileout "$jsonID" "OK" "not vulnerable " "$cve" "$cwe"
1748017499
outln
1748117500
return 0
1748217501
fi
1748317502

17484-
# Next we weed out is whether we run HTTP or RDP (on standard port)
17485-
if [[ $SERVICE != HTTP ]] && [[ $PORT != 3389 ]]; then
17486-
prln_svrty_best "not vulnerable (OK) - no HTTP or RDP"
17487-
fileout "$jsonID" "OK" "not vulnerable - no HTTP or RDP" "$cve" "$cwe"
17488-
return 0
17489-
fi
17490-
1749117503
# Now we check whether any CAMELLIA, ARIA, CCM or CHACHA cipher is available.
1749217504
# We do this in two shots in order to stay below the 128 cipher limit
1749317505
tls_sockets "03" "${aria_ciphers},${chacha_ccm_ciphers}, 00,ff"
1749417506
sclient_success=$?
1749517507
if [[ $sclient_success -eq 0 ]] || [[ "$sclient_success" -eq 2 ]]; then
17496-
pr_svrty_best "not vulnerable (OK)"
17497-
debugme echo " - ARIA, CHACHA or CCM ciphers found"
17508+
pr_svrty_best "not vulnerable (OK)" ; outln " - ARIA, CHACHA or CCM ciphers found"
1749817509
fileout "$jsonID" "OK" "not vulnerable " "$cve" "$cwe"
17499-
outln
1750017510
return 0
1750117511
fi
1750217512
tls_sockets "03" "${camellia_ciphers},${more_excluded_ciphers}, 00,ff"
1750317513
sclient_success=$?
1750417514
if [[ $sclient_success -eq 0 ]] || [[ "$sclient_success" -eq 2 ]]; then
17505-
pr_svrty_best "not vulnerable (OK)"
17506-
debugme echo " - CAMELLIA or ECDHE_RSA GCM ciphers found"
17515+
pr_svrty_best "not vulnerable (OK)"; outln " - CAMELLIA or ECDHE_RSA GCM ciphers found"
1750717516
fileout "$jsonID" "OK" "not vulnerable " "$cve" "$cwe"
17508-
outln
1750917517
return 0
1751017518
fi
1751117519

17512-
# Now we have RDP and HTTP left and need to check the fixed ciphers
17513-
tls_sockets "03" "${ws_ciphers_hex}, 00,ff"
17520+
# Now we need to check the fixed ciphers
17521+
tls_sockets "03" "${wsfixed_ciphers}, 00,ff"
1751417522
sclient_success=$?
1751517523
if [[ $sclient_success -eq 0 ]] || [[ "$sclient_success" -eq 2 ]]; then
1751617524
# has rollup ciphers
17517-
pr_svrty_best "not vulnerable (OK)"
17518-
debugme echo " - GCM rollup ciphers found"
17525+
pr_svrty_best "not vulnerable (OK)"; outln " - GCM rollup ciphers found"
1751917526
fileout "$jsonID" "OK" "not vulnerable" "$cve" "$cwe"
17520-
outln
1752117527
return 0
1752217528
elif [[ $sclient_success -ne 1 ]]; then
1752317529
prln_warning "check failed, connect problem"
1752417530
fileout "$jsonID" "WARN" "check failed, connect problem" "$cve" "$cwe"
1752517531
return 1
1752617532
fi
1752717533

17534+
# Basic idea: https://en.wikipedia.org/wiki/Comparison_of_TLS_implementations#Supported_elliptic_curves
17535+
# [[ -z "$CURVES_OFFERED" ]] && sub_check_curves
17536+
if [[ -n "$CURVES_OFFERED" ]]; then
17537+
# Check whether there are any additional curves besides $allowed_curves
17538+
for curve in $CURVES_OFFERED; do
17539+
if ! [[ $allowed_curves =~ $curve ]]; then
17540+
pr_svrty_best "not vulnerable (OK)"; outln " - curve $curve detected"
17541+
fileout "$jsonID" "OK" "not vulnerable - curve $curve detected" "$cve" "$cwe"
17542+
return 0
17543+
fi
17544+
done
17545+
fi
17546+
#FIXME: The catch is that when a user didn't invoke run_fs() before, this wasn't processed + CURVES_OFFERED
17547+
# is empty. So we could call it like above but need to move curves detection into a seperate function
17548+
# (~ sub_check_curves) which is some work. But also for the sake of clean code this needs to be done.
17549+
17550+
17551+
[[ -z "$TLS_EXTENSIONS" ]] && determine_tls_extensions
17552+
# Basis of the following https://en.wikipedia.org/wiki/Comparison_of_TLS_implementations#Extensions
17553+
# Our standard: https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml
17554+
17555+
# According to Wikipedia above these are the ones which can be detected unders version of Windows
17556+
# Secure Renegotiation, Server Name Indication, Certificate Status Request, Supplemental Data, Extended Master Secret, ALPN
17557+
# supplemental_data(23) (RFC 4680) seems to have been overwritten by extended master secret(23) RFC 7627
17558+
# local -a allowed_tls_ext=("server name" "status_request" "extended master secret" "application layer protocol negotiation")
17559+
# Instead we rather focus on the ones which according to that source weren't available
17560+
# Encrypt-then-MAC, Maximum Fragment Length, Keying Material Exporter, TLS Fallback SCSV, ClientHello Padding
17561+
# Padding is client side. Don't know what they mean by the fallback SCSV. That is not an extension
17562+
local -a forbidden_tls_ext=("encrypt-then-mac" "max fragment length")
17563+
# Open whether ec_point_formats, supported_groups(=elliptic_curves), heartbeat are supported under windows <=2012
17564+
# key_share and supported_versions are extensions which came with TLS 1.3. We checked the protocol before.
17565+
if [[ -n "$TLS_EXTENSIONS" ]]; then
17566+
# Check whether there are any TLS extension which should not be available under <= Windows 2012 R2
17567+
for tls_ext in $TLS_EXTENSIONS; do
17568+
# We use the whole array, got to be careful when the array becomes bigger (unintented match)
17569+
if [[ ${forbidden_tls_ext[@]} =~ $tls_ext ]]; then
17570+
pr_svrty_best "not vulnerable (OK)"; outln " - TLS extension $tls_ext detected"
17571+
fileout "$jsonID" "OK" "not vulnerable - TLS extension $tls_ext detected" "$cve" "$cwe"
17572+
return 0
17573+
fi
17574+
done
17575+
fi
17576+
17577+
# More would be possible if we look @ the following:
17578+
# See also https://github.com/cisco/joy/blob/master/fingerprinting/resources/fingerprint_db.json.gz
17579+
# https://resources.sei.cmu.edu/asset_files/Presentation/2019_017_001_539902.pdf
17580+
# https://raw.githubusercontent.com/cisco/joy/master/doc/using-joy-fingerprinting-00.pdf
17581+
17582+
17583+
17584+
# Now the solid determination more or less done. What's left now is to detect the service
17585+
# and perform an educated guess.
17586+
17587+
# Next we weed out is whether we run HTTP or RDP (on standard port).
17588+
# Using the experimental flag we can test it also on other ports / services
17589+
if [[ $SERVICE != HTTP ]] && [[ $PORT != 3389 ]] && ! "$EXPERIMENTAL"; then
17590+
pr_svrty_best "not vulnerable (OK)"; outln " - no HTTP or RDP"
17591+
fileout "$jsonID" "OK" "not vulnerable - no HTTP or RDP" "$cve" "$cwe"
17592+
return 0
17593+
fi
17594+
1752817595
if [[ $SERVICE != HTTP ]] && [[ $PORT == 3389 ]]; then
17529-
# We take a guess here for RDP as we don't have a banner
17530-
out "probably "
17531-
pr_svrty_critical "vulnerable (NOT ok)"
17532-
outln " - check patches locally to confirm"
17533-
fileout "${jsonID}" "CRITICAL" "probably vulnerable (NOT OK). Check patches locally to confirm"
17596+
# We take a security guess here (better safe than sorry) for RDP as we don't have a banner
17597+
out "probably "; pr_svrty_critical "vulnerable (NOT ok)"; outln "$check_patches"
17598+
fileout "${jsonID}" "CRITICAL" "probably vulnerable (NOT OK) $check_patches"
1753417599
return 0
1753517600
fi
1753617601

@@ -17550,15 +17615,27 @@ run_winshock() {
1755017615
fi
1755117616
if [[ $server_banner =~ Microsoft-IIS\/8.5 ]]; then
1755217617
# Windows 2012 R2 is less likely than Windows 2012
17553-
out "probably "
17554-
pr_svrty_critical "vulnerable (NOT ok)"
17555-
outln " - check patches locally to confirm"
17556-
fileout "${jsonID}" "CRITICAL" "probably vulnerable (NOT OK). Check patches locally to confirm"
17618+
out "probably "; pr_svrty_critical "vulnerable (NOT ok)"; outln "$check_patches"
17619+
fileout "${jsonID}" "CRITICAL" "probably vulnerable (NOT OK) $check_patches"
1755717620
elif [[ $server_banner =~ Microsoft-IIS\/8.0 ]]; then
17558-
out "likely "
17559-
pr_svrty_critical "VULNERABLE (NOT ok)"
17560-
outln " - check patches locally to confirm"
17561-
fileout "${jsonID}" "CRITICAL" "likely vulnerable (NOT OK). Check patches locally to confirm"
17621+
out "likely "; pr_svrty_critical "VULNERABLE (NOT ok)"; outln "$check_patches"
17622+
fileout "${jsonID}" "CRITICAL" "likely vulnerable (NOT OK) $check_patches"
17623+
elif [[ $server_banner =~ Microsoft-HTTPAPI\/2.0 ]]; then
17624+
# This is http.sys. It may or may not indicate a 2012 server. IIS is not yet configured though.
17625+
# So we have a peek on port 80
17626+
http_get $NODE "$TEMPDIR/$NODE.$NODEIP.http-header.txt"
17627+
server_banner="$(grep -Eai '^Server:' $TEMPDIR/$NODE.$NODEIP.http-header.txt)"
17628+
if [[ $server_banner =~ Microsoft-IIS\/8.5 ]]; then
17629+
out "probably "; pr_svrty_critical "vulnerable (NOT ok)"; outln "$check_patches"
17630+
fileout "${jsonID}" "CRITICAL" "probably vulnerable (NOT OK) $check_patches"
17631+
elif [[ $server_banner =~ Microsoft-IIS\/8.0 ]]; then
17632+
out "likely "; pr_svrty_critical "VULNERABLE (NOT ok)"; outln "$check_patches"
17633+
fileout "${jsonID}" "CRITICAL" "likely vulnerable (NOT OK) $check_patches"
17634+
else
17635+
out "likely "; prln_svrty_best "not vulnerable (OK)"
17636+
fileout "$jsonID" "OK" "not vulnerable" "$cve" "$cwe"
17637+
outln
17638+
fi
1756217639
else
1756317640
pr_svrty_best "not vulnerable (OK)"
1756417641
outln " - doesn't seem to be IIS 8.x"

0 commit comments

Comments
 (0)