首页 > 解决方案 > 我不确定为什么我的代码没有存储 XSS

问题描述

更新:我将我的有效负载更改"<img src="fake.jpg" onerror="alert()">为 XSS 工作,所以我仍然不知道为什么它不起作用,但至少我存储的 XSS 现在正在工作。感谢大家的帮助。

我从 GitHub 下载了一个聊天代码,该代码是用 PHP 和 MYSQL 编写的 当然,所有内容都存储在数据库中,但是每当我尝试注入 XSS 时,标签或标签的内容都不会显示,但是在数据库中,我看到了 alert() 它只是不让我在网站上看到它本身...有谁知道可能导致问题的原因?这是 index.php:

<?php
include 'db.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>::Message::</title>
    <link rel="stylesheet" href="style.css">
    <script>
        function ajax() {
            var req =  new XMLHttpRequest();
            req.onreadystatechange = function() {
                if (req.readyState == 4 && req.status == 200) {
                    document.getElementById('chat').innerHTML = req.responseText;
                } 
            }
            req.open('GET','chat.php', true);
            req.send();
        }
        setInterval(function(){ajax()},1000);
    </script>
</head>
<body onload="ajax();">

<div class="page">
    <div class="display-box">
        <div id="chat"></div>
    </div>
    <div class="form">
        <form action="" method="post">
            <label for="name">Name:</label><br>
            <input type="text" name="name" placeholder="Your name"><br>
            <label for="message">Write some thing:</label><br>
            <textarea name="message" id="message-write" cols="30" rows="3"></textarea><br>
            <input type="submit" name="submit" value="Send">
        </form>
        <?php
        if (isset($_POST['submit'])) {
            $name = $_POST['name'];
            $message = $_POST['message'];

            $query = "INSERT INTO tbl_chat (name, message) VALUES ('$name','$message')";
            $run = $con->query($query);
        }
        ?>
    </div>
</div>
    
</body>
</html>

这是聊天:

<?php
include 'db.php';
            $query = "SELECT * FROM `tbl_chat` ORDER BY id DESC";
            $run = $con->query($query);
            while($row = $run->fetch_array()):
        ?>
        <div class="chating_data">
            <span id="name"><?php echo $row['name'];?></span><br>
            <span id="message"><?php echo $row['message'];?></span>
        </div>
<?php endwhile; ?>

标签: phphtmlmysqlxss

解决方案


我认为您可能正在使用现代浏览器来阻止您的漏洞利用。这并不意味着应用程序没有漏洞,它只是意味着它非常容易受到攻击,甚至浏览器也可以自动检测到漏洞利用。

尝试发送以下响应标头:

X-XSS-Protection: 0

你可以这样做header('X-XSS-Protection: 0');,看看是否允许你尝试 XSS。您还可以在此聊天中显示 XSS 消息,而不是响应您的“恶意”请求,而是在之后显示 - 它应该可以工作,因为浏览器无法将您的请求与响应相关联。


推荐阅读