首页 > 解决方案 > 这个php登录系统安全吗?

问题描述

这个登录页面是否安全,正在研究 sql-injection,如果是,它们是一个漏洞,我该如何管理它?

我之前将用户详细信息加密到一个文件中并存储在本地。我也使用 localhost,考虑迁移到域。将用户详细信息存储在文件中是否有任何问题?
请忽略html

<?php
session_start();
?>
<html>
     <body>


          <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
          <input type="text" name="Username"value="">
          <?php if ($_SERVER["REQUEST_METHOD"] == "POST"){
          $user = $_REQUEST['Username'];
          }  ?>

          <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
          <input type="password" name="Password"value="">
          <?php if ($_SERVER["REQUEST_METHOD"] == "POST"){
          $password = $_REQUEST['Password'];
          }    
          if (isset($_POST['submit'])) {
               $file = $user.".txt";
               if (file_exists($file)){
                  $contents = file_get_contents($file);
                  $ciphering = "AES-128-CTR"; 
                  $iv_length = openssl_cipher_iv_length($ciphering); 
                  $options = 0; 
                  $decryption_iv = '#secret#'; 
                  $decryption_key = "#key#";   
                  $decryption= openssl_decrypt ($contents, $ciphering,  
                  $decryption_key, $options, $decryption_iv);  
                  if($decryption==$password){
                        echo("details match");
                        setcookie("username", $user,time()+2000);
                        $_SESSION["logged_in"] = true;
                        $_SESSION["username"] = $user;
                        header("Location:/login/new folder/findchat.php?username");
                        exit();

                     }
                     else{
                          echo('Complete im not a robot');
                     }              
          }
          else{echo("pasword or username is not valid");}
          }
          ?>
          <input type="submit"value="submit"name="submit">


     </body>

</html>

抱歉我的拼写错误,谢谢

标签: javascriptphpsqlsecuritysession

解决方案


Wow, this is awful. There's tons of vulnerabilities. Here's the ones that jump out at me at first glance:

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">

This is vulnerable to XSS, like this: http://example.com/badlogin.php/"><script>alert("xss")</script>

$file = $user.".txt";
if (file_exists($file)){
   $contents = file_get_contents($file);

Trivial directory traversal.

$decryption= openssl_decrypt ($contents, $ciphering,  
$decryption_key, $options, $decryption_iv);  
if($decryption==$password){

You're supposed to hash passwords, not encrypt them.

About the only vulnerability you don't have is SQL injection, and that's because you don't use any SQL.


推荐阅读