mirror of
https://github.com/drwetter/testssl.sh.git
synced 2025-11-14 14:20:59 +01:00
Fix pattern for matching /etc/hosts entries (3.2)
`grep -w` matches also `string1-whatsoever` so that entries like ``` 192.168.0.10 anystring anystring-apache 192.168.0.11 anystring-tomcat ``` matched 3 entries over 2 lines. This PR fixes #2937 for 3.2 by improving the pattern, so that `string1` needs a trailing whitespace or an EOL -- besides a leading whitespace..
This commit is contained in:
parent
6bb51ab9ba
commit
a5c13a57cf
@ -21886,24 +21886,27 @@ filter_ip4_address() {
|
|||||||
|
|
||||||
# For security testing sometimes we have local entries. Getent is BS under Linux for localhost: No network, no resolution
|
# For security testing sometimes we have local entries. Getent is BS under Linux for localhost: No network, no resolution
|
||||||
# arg1 is the entry we want to look up in the host file
|
# arg1 is the entry we want to look up in the host file
|
||||||
|
#
|
||||||
get_local_aaaa() {
|
get_local_aaaa() {
|
||||||
local ip6=""
|
local ip6=""
|
||||||
local etchosts="/etc/hosts /c/Windows/System32/drivers/etc/hosts"
|
local etchosts="/etc/hosts /c/Windows/System32/drivers/etc/hosts"
|
||||||
|
|
||||||
[[ -z "$1" ]] && echo "" && return 1
|
[[ -z "$1" ]] && echo "" && return 1
|
||||||
# Also multiple records should work fine
|
# grep: find hostname with trailing lf or space. -w doesn't work here
|
||||||
ip6=$(grep -wih "$1" $etchosts 2>/dev/null | grep ':' | grep -Ev '^#|\.local' | grep -Ei "[[:space:]]$1" | awk '{ print $1 }')
|
ip6=$(grep -Eih "[[:space:]]$1([[:space:]]|$)" $etchosts 2>/dev/null | grep ':' | grep -Ev '^#|\.local' | awk '{ print $1 }')
|
||||||
if is_ipv6addr "$ip6"; then
|
if is_ipv6addr "$ip6"; then
|
||||||
echo "$ip6"
|
echo "$ip6"
|
||||||
else
|
else
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_local_a() {
|
get_local_a() {
|
||||||
local ip4=""
|
local ip4=""
|
||||||
local etchosts="/etc/hosts /c/Windows/System32/drivers/etc/hosts"
|
local etchosts="/etc/hosts /c/Windows/System32/drivers/etc/hosts"
|
||||||
|
|
||||||
ip4=$(grep -wih "$1" $etchosts 2>/dev/null | grep -Ev ':|^#|\.local' | grep -Ei "[[:space:]]$1" | awk '{ print $1 }')
|
# grep: find hostname with trailing lf or space. -w doesn't work here
|
||||||
|
ip4=$(grep -Eih "[[:space:]]$1([[:space:]]|$)" $etchosts 2>/dev/null | grep -Ev ':|^#|\.local' | awk '{ print $1 }')
|
||||||
if is_ipv4addr "$ip4"; then
|
if is_ipv4addr "$ip4"; then
|
||||||
echo "$ip4"
|
echo "$ip4"
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user