From e09d79aad910550d54aaeb7a4e02f06d5563a99b Mon Sep 17 00:00:00 2001 From: Dirk Wetter Date: Sun, 20 Jul 2025 15:40:35 +0200 Subject: [PATCH] Fix error message on UI when testing Opossum As `wait_kill()` returns with 0 when a TCP reset is encountered and the process is not killed, we need to open the socket again in a sub shell. Which is safe in the foreground. If then the subshell returns with 0 we can safely connect to port 80. --- testssl.sh | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/testssl.sh b/testssl.sh index 1468996..89efaa2 100755 --- a/testssl.sh +++ b/testssl.sh @@ -1942,26 +1942,31 @@ http_head_printf() { # This is a subshell, so fd 8 is not inherited bash -c "exec 8<>/dev/tcp/$node/80" 2>/dev/null & wait_kill $! $HEADER_MAXSLEEP - if [[ $? -eq 0 ]]; then - exec 33<>/dev/tcp/$node/80 - # not killed --> socket open. Now we connect to the virtual host "$node" - printf -- "%b" "HEAD ${proto}//${node}/${query} HTTP/1.1\r\nUser-Agent: ${useragent}\r\nHost: ${node}\r\n${request_header}\r\nAccept: */*\r\n\r\n\r\n" >&33 2>$errfile - ret=0 - if [[ $DEBUG -eq 0 ]] ; then - cat <&33 + if [[ $? -ne 3 ]]; then + # process with pid !$ wasn't killed but was that a reject? So we try again + # to make sure there wasn't a TCP reset + bash -c "exec 8<>/dev/tcp/$node/80" 2>/dev/null + if [[ $? -eq 0 ]]; then + exec 33<>/dev/tcp/$node/80 + # not killed --> socket open. Now we connect to the virtual host "$node" + printf -- "%b" "HEAD ${proto}//${node}/${query} HTTP/1.1\r\nUser-Agent: ${useragent}\r\nHost: ${node}\r\n${request_header}\r\nAccept: */*\r\n\r\n\r\n" >&33 2>$errfile + ret=0 + if [[ $DEBUG -eq 0 ]] ; then + cat <&33 + else + cat <&33 >$tmpfile + cat $tmpfile + fi else - cat <&33 >$tmpfile - cat $tmpfile - fi - else - if [[ -n "$PROXY" ]]; then - ret=3 - else - ret=1 + if [[ -n "$PROXY" ]]; then + ret=3 + else + ret=1 + fi fi + exec 33<&- + exec 33>&- fi - exec 33<&- - exec 33>&- return $ret }