@@ -1923,50 +1923,57 @@ http_head() {
1923
1923
# arg2: extra http header
1924
1924
#
1925
1925
# 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
1929
1929
#
1930
- http_header_printf () {
1930
+ http_head_printf () {
1931
1931
local request_header="$2"
1932
1932
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
1935
1935
local -i ret=0
1936
1936
local proto="" foo="" node="" query=""
1937
1937
1938
1938
[[ $DEBUG -eq 0 ]] && errfile=/dev/null
1939
1939
1940
1940
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 &
1943
1945
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
1948
1967
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>&-
1958
1970
fi
1959
- exec 33<&-
1960
- exec 33>&-
1961
1971
return $ret
1962
1972
}
1963
1973
1964
1974
1965
1975
ldap_get() {
1966
1976
local ldif
1967
- local -i success
1968
- local crl="$1"
1969
- local tmpfile="$2"
1970
1977
local jsonID="$3"
1971
1978
1972
1979
if type -p curl &>/dev/null; then
@@ -17704,18 +17711,24 @@ run_opossum() {
17704
17711
case $service in
17705
17712
HTTP)
17706
17713
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')
17708
17715
# 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=$?
17713
17718
if [[ $response =~ Upgrade:\ TLS ]]; then
17714
17719
prln_svrty_high "VULNERABLE (NOT ok)"
17715
17720
fileout "$jsonID" "CRITICAL" "VULNERABLE" "$cve" "$cwe" "$hint"
17716
- else
17721
+ elif [[ $ret -eq 0 ]]; then
17717
17722
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
17719
17732
fi
17720
17733
;;
17721
17734
IMAP|FTP|POP3|SMTP|LMTP|NNTP)
0 commit comments