javascript - 如何在这个登录页面模拟 XSS
问题描述
登录.php
<html>
<head>
<title> Login </title>
</head>
<style>
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px;
}
</style>
<body>
<div class="container">
<form method="post" action="logged.php">
<div id="div_login">
<h1>Login</h1>
<div>
<input type="text" class="textbox" id="txt_uname" name="txt_uname" placeholder="Username" />
</div>
<div>
<input type="password" class="textbox" id="txt_pwd" name="txt_pwd" placeholder="Password"/>
</div>
<div>
<input type="submit" value="Submit" name="but_submit" id="but_submit" />
</div>
</div>
<div class='container' id='footer'>
<h3>Leave us some feedback ! </h3>
<div>
<input type="text" class="textbox" id="txt_feedback" name="txt_feedback" placeholder="Feedback" />
</div>
</div>
</form>
</div>
</body>
</html>
记录的.php
<?php
include "configs.php";
if(isset($_POST['but_submit'])){
$uname = mysqli_real_escape_string($con,$_POST['txt_uname']);
$password = $_POST['txt_pwd'];
$fback=$_POST['txt_feedback'];
if ($uname != "" && $password != ""){
$sql_query = "select count(*) as cntUser from users where username='".$uname."' and password='".$password."'";
$result = mysqli_query($con,$sql_query);
$row = mysqli_fetch_array($result);
$sql = "UPDATE users SET feedback='$fback' WHERE username='".$uname."' and password='".$password."'";
if ($con->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $con->error;
}
$count = $row['cntUser'];
if($count > 0){
$_SESSION['uname'] = $uname;
header('Location: home.php');
}else{
echo "Invalid username and password";
}
}
}
我希望反馈输入字段具有 xss 漏洞,以便我可以通过提供脚本作为字段的输入来触发 JavaScript 警报框。我该如何做到这一点?截至目前,它只是进入主页而不会触发任何警报框。我已经在这个页面上实现了 SQL 注入,效果很好。
解决方案
我认为您将其用作有关如何防止 XSS 的学习练习
更改以下内容:
echo "Invalid username and password";
为了实现XSS:
echo "Invalid username:".$_POST['txt_uname']." and password";
然后在用户名字段中输入以下文本
<image src="x" onerror="alert('XSS')">
为了防止像我上面所做的那样回显变量时出现 XSS,您可以使用 htmlentities() 包装变量,如下面的代码:
echo "Invalid username:".htmlentities($_POST['txt_uname'])." and password";
这是实现 XSS 的几种方法之一,因此您最好从特定站点学习,这些站点更详细地了解防止 XSS 的不同方法和解决方案。
推荐阅读
- reactjs - arr[Symbol.iterator] 在使用 useState 和上下文时不是函数
- javascript - 通过环境变量设置代理以在 AWS EC2 上部署 React 应用程序
- apache-kafka - 将 Pcap 从 Suricata 发送到 Kafka
- wpf - 我可以在“x”命名空间中创建 XAML 属性吗
- python - 重命名 JSON 键名
- time - 用 php Carbon 转换 javascript 时间会返回奇怪的时间?
- java - 找不到来自另一个 maven 项目的 Bean/Component
- sql - 我试图在同时获得 MAX 结果的同时删除重复项。我无法删除重复项
- r - 有没有一种方法或内置的 R 函数可以对列表中重复名称的值求和?
- liquibase - 前提
不适用于架构