首页 > 解决方案 > 有什么方法可以在提到的脚本中只列出带有“YES”的密码

问题描述

有什么方法可以使用下面提到的脚本仅列出带有“YES”的密码。脚本看起来有效,但它提供了巨大的列表,包括密码 YES 和 NO。如果我们可以通过在脚本中使用 grep 过滤 o/p (echo $result) 但不确定如何通过,那就太好了。感谢这方面的帮助,因为我必须运行脚本并查找在 Prod 服务器中启用的密码

#!/usr/bin/env bash

# OpenSSL requires the port number.
SERVER=$1
DELAY=1
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')

echo Obtaining cipher list from $(openssl version).

for cipher in ${ciphers[@]}
do
echo -n Testing $cipher...
result=$(echo -n | openssl s_client -cipher "$cipher" -connect $SERVER 2>&1)
if [[ "$result" =~ ":error:" ]] ; then
  error=$(echo -n $result | cut -d':' -f6)
  echo NO \($error\)
else
  if [[ "$result" =~ "Cipher is ${cipher}" || "$result" =~ "Cipher    :" ]] ; then
    echo YES
  else
    echo UNKNOWN RESPONSE
    echo $result
  fi
fi
sleep $DELAY
done

标签: bashshellopenssl

解决方案


推荐阅读