guardicore / labs_campaigns

355 stars 106 forks source link

newer systems don't have netstat by default #7

Open bornhorstj opened 4 years ago

bornhorstj commented 4 years ago

netstat missing

you might want to update to us SS -ano if netstat is missing

if [[ -x "$(command -v netstat)" ]]; then

    if [[ $(netstat -ano | grep LISTEN | grep 1234) ]]; then
    listening_port=true
    echo "[*] Listening on port 1234"
    fi
fi

if [[ -x "$(command -v ss)" ]]; then

    if [[ $(ss -ano | grep LISTEN | grep 1234) ]]; then
    listening_port=true
    echo "[*] Listening on port 1234"
    fi
fi
PenelopeFudd commented 4 years ago

Skip ss and netstat entirely:

if grep -q '00000000:04D2 [0:]* 0A ' /proc/net/tcp*; then
  listening_port=true
  echo "[*] Listening on port 1234 (ipv4 or ipv6)"
fi

if grep ':04D2 ' /proc/net/tcp* | grep -v ' 00000000*:0000 0A'; then
  echo "[*] Active connection on port 1234 (ipv4 or ipv6)"
fi

Explanation: