@@ -1923,50 +1923,57 @@ http_head() {
19231923# arg2: extra http header
19241924#
19251925# return codes:
1926- # 0: all fine
1927- # 1: server dind 't respond within HEADER_MAXSLEEP
1928- # 3: server dind 't respond within HEADER_MAXSLEEP and PROXY was defined
1926+ # 0: all fine (response header is returned as string)
1927+ # 1: server didn 't respond within HEADER_MAXSLEEP
1928+ # 3: server didn 't respond within HEADER_MAXSLEEP and PROXY was defined
19291929#
1930- http_header_printf () {
1930+ http_head_printf () {
19311931 local request_header="$2"
19321932 local useragent="$UA_STD"
1933- local tmpfile=$TEMPDIR/$NODE.$NODEIP.http_header_printf .log
1934- local errfile=$TEMPDIR/$NODE.$NODEIP.http_header_printf -err.log
1933+ local tmpfile=$TEMPDIR/$NODE.$NODEIP.http_head_printf .log
1934+ local errfile=$TEMPDIR/$NODE.$NODEIP.http_head_printf -err.log
19351935 local -i ret=0
19361936 local proto="" foo="" node="" query=""
19371937
19381938 [[ $DEBUG -eq 0 ]] && errfile=/dev/null
19391939
19401940 IFS=/ read -r proto foo node query <<< "$1"
1941- exec 33<>/dev/tcp/$node/80
1942- 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 &
1941+ node=${node%:*}
1942+ # $node works here good as it connects via IPv6 first, then IPv4.
1943+ # This is a subshell, so fd 8 is not inherited
1944+ bash -c "exec 8<>/dev/tcp/$node/80" 2>/dev/null &
19431945 wait_kill $! $HEADER_MAXSLEEP
1944- if [[ $? -ne 0 ]]; then
1945- # not killed
1946- if [[ -n "$PROXY" ]]; then
1947- ret=3
1946+ if [[ $? -ne 3 ]]; then
1947+ # process with pid !$ wasn't killed but was that a reject? So we try again
1948+ # to make sure there wasn't a TCP reset
1949+ bash -c "exec 8<>/dev/tcp/$node/80" 2>/dev/null
1950+ if [[ $? -eq 0 ]]; then
1951+ exec 33<>/dev/tcp/$node/80
1952+ # not killed --> socket open. Now we connect to the virtual host "$node"
1953+ 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
1954+ ret=0
1955+ if [[ $DEBUG -eq 0 ]] ; then
1956+ cat <&33
1957+ else
1958+ cat <&33 >$tmpfile
1959+ cat $tmpfile
1960+ fi
1961+ else
1962+ if [[ -n "$PROXY" ]]; then
1963+ ret=3
1964+ else
1965+ ret=1
1966+ fi
19481967 fi
1949- ret=1
1950- else
1951- ret=0
1952- fi
1953- if [[ $DEBUG -eq 0 ]] ; then
1954- cat <&33
1955- else
1956- cat <&33 >$tmpfile
1957- cat $tmpfile
1968+ exec 33<&-
1969+ exec 33>&-
19581970 fi
1959- exec 33<&-
1960- exec 33>&-
19611971 return $ret
19621972}
19631973
19641974
19651975ldap_get() {
19661976 local ldif
1967- local -i success
1968- local crl="$1"
1969- local tmpfile="$2"
19701977 local jsonID="$3"
19711978
19721979 if type -p curl &>/dev/null; then
@@ -17704,18 +17711,24 @@ run_opossum() {
1770417711 case $service in
1770517712 HTTP)
1770617713 uri=${URI/https:\/\//}
17707- response=$(http_header_printf http://${uri} 'Upgrade: TLS/1.0\r\n\r\nClose\r\n')
17714+ response=$(http_head_printf http://${uri} 'Upgrade: TLS/1.0\r\n\r\nClose\r\n')
1770817715 # In any case we use $response but we handle the return codes
17709- case $? in
17710- 0) ret=0 ;;
17711- 1|3) ret=7 ;; # got stuck
17712- esac
17716+ # 0: connection was fine, 1 or 3: no http connection
17717+ ret=$?
1771317718 if [[ $response =~ Upgrade:\ TLS ]]; then
1771417719 prln_svrty_high "VULNERABLE (NOT ok)"
1771517720 fileout "$jsonID" "CRITICAL" "VULNERABLE" "$cve" "$cwe" "$hint"
17716- else
17721+ elif [[ $ret -eq 0 ]]; then
1771717722 prln_svrty_good "not vulnerable (OK)"
17718- fileout "$jsonID" "OK" "not vulnerable $append" "$cve" "$cwe"
17723+ fileout "$jsonID" "OK" "not vulnerable" "$cve" "$cwe"
17724+ else
17725+ if [[ $ret -eq 3 ]]; then
17726+ prln_local_problem "direct connection to port 80 failed, better try without proxy"
17727+ fileout "$jsonID" "WARN" "direct connection to port 80 failed, try w/o no proxy" "$cve" "$cwe"
17728+ else
17729+ outln "connection to port 80 failed"
17730+ fileout "$jsonID" "INFO" "connection to port 80 failed" "$cve" "$cwe"
17731+ fi
1771917732 fi
1772017733 ;;
1772117734 IMAP|FTP|POP3|SMTP|LMTP|NNTP)
0 commit comments