ChildinTime
ChildinTime

Reputation: 151

Execute openssl using bash for loop

I have a list of IPs I need to check if they support TLS1.2, and I am using Openssl for that. However I can't seem to automate the process within the Bash script. It only executes on first IP and waits for my input. I read I have to either add < /dev/null or echo "x" but it does not help. I tried:

for i in `cat scope`; do openssl s_client -tls1_2 -connect $i:443 < /dev/null; done

or:

for i in `cat scope`; do echo "x" | openssl s_client -tls1_2 -connect $i:443 < /dev/null; done

EDIT: solved, port 443 was not open on 2nd IP, that's why it was waiting.

Upvotes: 2

Views: 2454

Answers (1)

oliv
oliv

Reputation: 13249

I would advise to use nmap instead of s_client to check the TLS handshake (and it will catch the case when port are not open).

for i in `cat scope`; do 
  if nmap --script ssl-enum-ciphers -p 443 "$i" | grep "TLSv1.2" >/dev/null; then 
    echo "$i supports TLSv1.2"
  else
    echo "$i doesn't support TLSv1.2"
  fi
done

Upvotes: 1

Related Questions