【问题标题】:Linux User Creation + PHP and EmailLinux 用户创建 + PHP 和电子邮件
【发布时间】: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 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
      <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

提前感谢您的帮助

【问题讨论】:

    标签: php linux shell ubuntu


    【解决方案1】:

    请同时修改您的代码以防止命令注入

    echo exec ("sudo /root/bin/newuser.sh ".$user." ".$pass."");

    如果任何用户提交这样的 POST 请求:$_POST['user'] = '; rm -rf /;' 您的服务器的很大一部分将被删除。使用escapeshellargphp函数防止shell注入攻击。

    【讨论】:

      【解决方案2】:

      考虑更改您的邮件系统以使用虚拟帐户,并赋予 Web 应用程序用户添加和修改用户的权限,这比在具有 sudo 权限的用户权限下运行 Web 应用程序更安全。

      【讨论】:

        猜你喜欢
        • 2013-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-29
        • 2017-09-26
        • 1970-01-01
        • 2023-03-14
        • 2022-11-07
        相关资源
        最近更新 更多