Skip to content

Commit 09719a3

Browse files
committed
Remove the last 1s euristic
In the wait loop, I was relying on a 1s sleep to eliminate a possible late zero return value server close on the last attempt. - do globaly one more harmless "for" iteration and remove the sleep 1 for faster and more robust result - correct the non HTTP case iteration value - adjust the timeout to the conservative 6s in the non HTTP case, for HTTP case it become 33s - improve comments
1 parent dab177f commit 09719a3

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

testssl.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17179,10 +17179,7 @@ run_renego() {
1717917179
restore_errfile=0
1718017180
fi
1718117181
if [[ $SERVICE != HTTP ]]; then
17182-
# Connection could be closed by the server after one try so we will try two iteration
17183-
# to not close the openssl s_client STDIN too early like on the HTTP case.
17184-
# See https://github.com/drwetter/testssl.sh/issues/2590
17185-
ssl_reneg_attempts=2
17182+
ssl_reneg_attempts=1
1718617183
fi
1718717184
# We try again if server is HTTP. This could be either a node.js server or something else.
1718817185
# Mitigations (default values) for:
@@ -17200,28 +17197,34 @@ run_renego() {
1720017197
# too early losing all the attempts before the session establishment as OpenSSL will not buffer them
1720117198
# (only the first will be till the establishement of the session).
1720217199
(j=0; while [[ $(grep -ac '^SSL-Session:' $TMPFILE) -ne 1 ]] && [[ $j -lt 30 ]]; do sleep $ssl_reneg_wait; ((j++)); done; \
17203-
for ((i=0; i < ssl_reneg_attempts; i++ )); do sleep $ssl_reneg_wait; echo R; k=0; \
17200+
# Connection could be closed by the server with 0 return value. We do one more iteration to not close
17201+
# s_client STDIN too early as the close could come at any time and race with the tear down of s_client.
17202+
# See https://github.com/drwetter/testssl.sh/issues/2590
17203+
# In this case the added iteration is harmfull as it will just spin in backgroup
17204+
for ((i=0; i <= ssl_reneg_attempts; i++ )); do sleep $ssl_reneg_wait; echo R; k=0; \
1720417205
# 0 means client is renegotiating & doesn't return an error --> vuln!
1720517206
# 1 means client tried to renegotiating but the server side errored then. You still see RENEGOTIATING in the output
1720617207
# Exemption from above: server closed the connection but return value was zero
1720717208
# See https://github.com/drwetter/testssl.sh/issues/1725 and referenced issue @haproxy
1720817209
while [[ $(grep -ac '^RENEGOTIATING' $ERRFILE) -ne $((i+1)) ]] && [[ -f $TEMPDIR/allowed_to_loop ]] \
1720917210
&& [[ $(tail -n1 $ERRFILE |grep -acE '^(RENEGOTIATING|depth|verify|notAfter)') -eq 1 ]] \
1721017211
&& [[ $k -lt 120 ]]; \
17211-
do sleep $ssl_reneg_wait; ((k++)); if (tail -5 $TMPFILE| grep -qa '^closed'); then sleep 1; break; fi; done; \
17212+
do sleep $ssl_reneg_wait; ((k++)); if (tail -5 $TMPFILE| grep -qa '^closed'); then break; fi; done; \
1721217213
done) | \
1721317214
$OPENSSL_NOTIMEOUT s_client $(s_client_options "$proto $legacycmd $STARTTLS $BUGS -connect $NODEIP:$PORT $PROXY $SNI") >$TMPFILE 2>>$ERRFILE &
1721417215
pid=$!
17215-
( sleep $((ssl_reneg_attempts*3)) && kill $pid && touch $TEMPDIR/was_killed ) >&2 2>/dev/null &
17216+
( sleep $((ssl_reneg_attempts*3+3)) && kill $pid && touch $TEMPDIR/was_killed ) >&2 2>/dev/null &
1721617217
watcher=$!
1721717218
# Trick to get the return value of the openssl command, output redirection and a timeout.
1721817219
# Yes, some target hang/block after some tries (some LiteSpeed servers don't answer at all on "R" and block).
1721917220
wait $pid
1722017221
tmp_result=$?
1722117222
pkill -HUP -P $watcher
1722217223
wait $watcher
17224+
# Stop any backgroud wait loop
1722317225
rm -f $TEMPDIR/allowed_to_loop
17224-
# If we are here, we have done the loop
17226+
# If we are here, we have done the loop. Count the effective renego attempts.
17227+
# It could be less than the numbers of "for" itterations (minus one) in case of late server close.
1722517228
loop_reneg=$(grep -ac '^RENEGOTIATING' $ERRFILE)
1722617229
# As above, some servers close the connection and return value is zero
1722717230
if (tail -5 $TMPFILE| grep -qa '^closed'); then
@@ -17239,7 +17242,7 @@ run_renego() {
1723917242
1) prln_svrty_good "not vulnerable (OK)"
1724017243
fileout "$jsonID" "OK" "not vulnerable" "$cve" "$cwe"
1724117244
;;
17242-
2) pr_svrty_good "likely not vulnerable (OK)"; outln ", timed out ($((${ssl_reneg_attempts}*3))s)" # it hung
17245+
2) pr_svrty_good "likely not vulnerable (OK)"; outln ", timed out ($((${ssl_reneg_attempts}*3+3))s)" # it hung
1724317246
fileout "$jsonID" "OK" "likely not vulnerable (timed out)" "$cve" "$cwe"
1724417247
;;
1724517248
*) prln_warning "FIXME (bug): $sec_client_renego"
@@ -17256,7 +17259,7 @@ run_renego() {
1725617259
fileout "$jsonID" "OK" "not vulnerable, mitigated" "$cve" "$cwe"
1725717260
;;
1725817261
2) pr_svrty_good "not vulnerable (OK)"; \
17259-
outln " -- mitigated ($loop_reneg successful reneg within ${ssl_reneg_attempts} in $((${ssl_reneg_attempts}*3))s(timeout))"
17262+
outln " -- mitigated ($loop_reneg successful reneg within ${ssl_reneg_attempts} in $((${ssl_reneg_attempts}*3+3))s(timeout))"
1726017263
fileout "$jsonID" "OK" "not vulnerable, mitigated" "$cve" "$cwe"
1726117264
;;
1726217265
*) prln_warning "FIXME (bug): $sec_client_renego ($ssl_reneg_attempts tries)"

0 commit comments

Comments
 (0)