javascript - 这个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>
抱歉我的拼写错误,谢谢
解决方案
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.
推荐阅读
- python - 用零填充 3D 列表中的缺失值以创建 3D numpy 数组
- python-3.x - 缩短用于按顺序点亮 LED 的 python 代码
- javascript - Angular:按钮文本插值不起作用
- spring-boot - 扩展反应性 crud 存储库
- bash - 使用 bash perl 更改部分重复的后缀
- python - TF Hub 微调错误:ValueError:无法找到可以处理输入的数据适配器
- mysql - MYSQL:复制列但更改类型
- javascript - 通过拆分属性为数组的对象来创建对象
- python - 是否有错误订单编码的名称
- php - PHP上的FFMPEG无法打开文件