Pamtester 自动进行密码测试

Pamtester 自动进行密码测试

我们有一个系统映像,它使用 root 的默认密码。这应该被改变,尽管我有一种感觉并不是所有用户都会这样做。

我知道我可以使用 pamtester 测试登录:

# pamtester system-auth root authenticate
Password:

它要求在命令行上输入密码。我想自动化这个。这可以做到吗?

答案1

vi ./authenticate_test.sh
#!/bin/bash

echo "Checking your password. If it doesn't work, script will wait for a few seconds, don't worry..."

pamtester login $1 authenticate << eof
`echo $2`
eof

if [[ $? -eq 0 ]]
then
  echo "script> Successful"
else
  echo "script> Fail"
fi

然后使用:

$ ./authenticate_test.sh customuser rightpassword
Checking your password. If it doesn't work, script will wait for a few seconds, don't worry...
Password: pamtester: successfully authenticated
script> Successful
$ ./authenticate_test.sh customuser wrongpassword
Checking your password. If it doesn't work, script will wait for a few seconds, don't worry...
Password: pamtester: Authentication failure
script> Fail

答案2

是的,通过使用预计脚本语言。

答案3

检查 /etc/shadow 文件中的哈希值。您已经拥有哈希值,因为它是您图像的一部分。只需确保 root 密码哈希值不同即可。

答案4

Ahere-document也做到了这一点:

testparm ... << eof
`echo $password`
eof

相关内容