$password=testword
$
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
$echo $pass
這樣我們可以得到更確實的利用,接下來我們可以考慮寫成shell script來執行,如下:
#vi adduser.sh#!/bin/bash
# Script to add a user to Linux system
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
/usr/sbin/useradd -m -p $pass $username
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
fi
以上adduser.sh需要root執行,我們就可看到互動且詢問式的輸入新增使用者和password了。
