WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit dfeb8c5

Browse files
authored
Merge pull request #2939 from testssl/fix_2938_3.2
Fix pattern for matching /etc/hosts entries (3.2)
2 parents 6bb51ab + a5c13a5 commit dfeb8c5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

testssl.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21886,24 +21886,27 @@ filter_ip4_address() {
2188621886

2188721887
# For security testing sometimes we have local entries. Getent is BS under Linux for localhost: No network, no resolution
2188821888
# arg1 is the entry we want to look up in the host file
21889+
#
2188921890
get_local_aaaa() {
2189021891
local ip6=""
2189121892
local etchosts="/etc/hosts /c/Windows/System32/drivers/etc/hosts"
2189221893

2189321894
[[ -z "$1" ]] && echo "" && return 1
21894-
# Also multiple records should work fine
21895-
ip6=$(grep -wih "$1" $etchosts 2>/dev/null | grep ':' | grep -Ev '^#|\.local' | grep -Ei "[[:space:]]$1" | awk '{ print $1 }')
21895+
# grep: find hostname with trailing lf or space. -w doesn't work here
21896+
ip6=$(grep -Eih "[[:space:]]$1([[:space:]]|$)" $etchosts 2>/dev/null | grep ':' | grep -Ev '^#|\.local' | awk '{ print $1 }')
2189621897
if is_ipv6addr "$ip6"; then
2189721898
echo "$ip6"
2189821899
else
2189921900
echo ""
2190021901
fi
2190121902
}
21903+
2190221904
get_local_a() {
2190321905
local ip4=""
2190421906
local etchosts="/etc/hosts /c/Windows/System32/drivers/etc/hosts"
2190521907

21906-
ip4=$(grep -wih "$1" $etchosts 2>/dev/null | grep -Ev ':|^#|\.local' | grep -Ei "[[:space:]]$1" | awk '{ print $1 }')
21908+
# grep: find hostname with trailing lf or space. -w doesn't work here
21909+
ip4=$(grep -Eih "[[:space:]]$1([[:space:]]|$)" $etchosts 2>/dev/null | grep -Ev ':|^#|\.local' | awk '{ print $1 }')
2190721910
if is_ipv4addr "$ip4"; then
2190821911
echo "$ip4"
2190921912
else

0 commit comments

Comments
 (0)