脚本
-
[root@localhost lscj]# more checkpass2.sh
-
#! /bin/sh
-
-
# set -x
-
-
# Get the key value of input arguments format like '--args=value'.
-
get_key_value()
-
{
-
echo "$1" | sed 's/^--[a-zA-Z_-]*=//'
-
}
-
-
# Usage will be helpful when you need to input the valid arguments.
-
usage()
-
{
-
cat <<EOF
-
Usage: $0 [configure-options]
-
-?, --help Show this help message.
-
--host=<> Set mysql host ip address
-
--user=<> Set mysql user
-
--password=<> Set mysql password
-
--port=<> Set mysql host port
-
Note: this script is intended for internal use by developers.
-
-
EOF
-
}
-
-
# Print the default value of the arguments of the script.
-
print_default()
-
{
-
cat <<EOF
-
The default value of the variables:
-
host=127.0.0.1
-
user=root
-
port=3306
-
EOF
-
}
-
-
# Parse the input arguments and get the value of the input argument.
-
parse_options()
-
{
-
while test $# -gt 0
-
do
-
case "$1" in
-
--host=*)
-
HOST=`get_key_value "$1"`;;
-
--user=*)
-
USER=`get_key_value "$1"`;;
-
--password=*)
-
PASSWORD=`get_key_value "$1"`;;
-
--port=*)
-
PORT=`get_key_value "$1"`;;
-
-? | --help)
-
usage
-
print_default
-
exit 0;;
-
*)
-
echo "Unknown option '$1'"
-
exit 1;;
-
esac
-
shift
-
done
-
}
-
-
############################################################
-
# Define the variables the script used for executing.
-
HOST=127.0.0.1
-
USER=root
-
PORT=3306
-
currentDIR=`dirname ${0}`
-
-
# Call the parse_options function to parse the input arguments.
-
parse_options "$@"
-
echo ${HOST}
-
echo ${USER}
-
echo ${PASSWORD}
-
echo ${PORT}
-
-
mysql -u${USER} -p${PASSWORD} -h${HOST} -P${PORT} -Ne 'select user,host,password from mysql.user'>./userinfo
-
-
#echo "------------ host:${HOST} port:${PORT} checkTime:`date +'%Y-%m-%d %T'`-------------">>./weakPassword.log
-
cat /root/python/lscj/userinfo|while read line
-
do
-
userName=`echo $line|awk -F' ' '{print $1}'`
-
userHost=`echo $line|awk -F' ' '{print $2}'`
-
userPwd=`echo $line|awk -F' ' '{print $3}'`
-
echo "userName=$userName,userHost=$userHost,userPwd=$userPwd"
-
result=`mysql -uroot -pESBecs00 -Ne "select 1 from test.tb_weak_password where password='$userPwd'"`
-
if [ ! -n "$result" ]
-
then
-
echo "User:${userName}@${userHost} is safe!!">>safe.log
-
else
-
echo "User:${userName}@${userHost} is unsaft!!">>unsafe.log
-
fi
-
echo ""
-
echo ""
-
done
test.tb_weak_password是密码字典!需要自己去生成,通过对比检查用户密码的强弱性
运行结果如下
[root@localhost lscj]# sh checkpass2.sh --password=ESBecs00
[root@localhost lscj]# more unsafe.log
User:root@localhost is unsaft!!
User:liang@% is unsaft!!
[root@localhost lscj]# more safe.log
User:jonn@% is safe!!
User:tom@% is safe!!
User:marry@% is safe!!
User:karry@% is safe!!
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29096438/viewspace-1840999/
,如需转载,请注明出处,否则将追究法律责任。