【发布时间】:2016-05-05 06:20:11
【问题描述】:
我正在托管一个带有用于登录的 Web 界面的电子邮件服务器,但是我以前没有有效的方法在服务器上注册用户以创建用户登录。出于这个原因,我创建了一个 PHP 系统来创建用户并设置密码,但是在创建了所述系统之后,我知道存在一个重大的安全问题,因为服务器将执行创建用户的脚本,然后更改所述用户的密码。因此人们可以更改不同用户的密码。我现在创建了一个根安全防护,但我需要一个永久解决方案来解决这个问题,以保护我的用户电子邮件。这是我用来创建和设置用户密码的 php 脚本和 shell 脚本。
index.php
<?php
$user=$_POST['user'];
$pass=$_POST['pass'];
$check=$_POST['check'];
if(isset($_POST['submit'])) {
if($user!="root"){
if($pass == $check) {
echo exec ("sudo /root/bin/newuser.sh ".$user." ".$pass."");
echo ("<html> <title>User Created!</title> <p><h1>Congratulation on the successful creation of your user! </h1></p><p><h1>Your login credentials are as follows:</h1></p><p><h1>Username: ".$user."</h1></p><p><h1>Password: " .$pass."</h1></p></html>");
} else {
echo "<html><title>Error creating account!</title><p><h1>Passwords did not match! Please <a href='index.php' reload/> this page!</h1></p></html>";
}
} else {
echo "Stahp plox!";
}
}
?>
<html>
<p align="center">Magnum Dongs Email Registration</p>
<p align="center">Username will be created as Username@magnumdongs.com, there is no need to add the @magnumdongs.com to the enter of the username you create.</p>
<p align="center">Upon creation, you will be able to access your email through our Magnum Dongs Email Web Interface, however you will be unable to recieve email via Outlook or an open source alternative at this time.</p>
<form method="POST" action="index.php" align="center">
<p>Username :
<input name="user" type="text"/>
</p>
<p>Password :
<input name="pass" type="password"/>
</p>
<p>Verify :
<input name="check" type="password"/>
</p>
<input type="submit" name="submit" value="Create User" />
</form>
</html>
newuser.sh
#!/usr/bin/env bash
#echo "Enter username..."
#read user
#echo -e "Username :: $user \n Is this correct? [y,n]"
#read y
#if [[ $y == "y" ]]; then
# useradd -m $user
#else
# echo "Wrong username"
# exit
#fi
usr=$1
pass=$2
useradd -m -s /usr/bin/nologin $usr
echo "$usr:$pass" | chpasswd
提前感谢您的帮助
【问题讨论】: