XSS - 使用 PHP 执行 Javascript

XSS - Execute Javascript with PHP

我正在 Android 中测试 XSS 漏洞攻击。为此,我开发了一个 Web 视图,我在其中加载了一个 html 文件,其中包含一个用于输入姓名和电子邮件的简单表单。 html 文件的内容是:

<html>
<body>

<form action="search.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>

我通过 get 将数据发送到 php 文件,该文件与名称字段中写入的内容相呼应。 php 文件的内容是:

<html>
<head>
<title> You searched for: </title>
</head>
<body>
<?php
    echo $_GET['name'];
?>
</body>
</html>

现在,我打算在 name 字段中写入 Javascript,这样当我回显它时,脚本被执行。在 name 字段中传递的普通字符串被成功回显,所以我知道 php 代码实际上在工作。

这适用于:Mozilla Firefox。

不适用于:Chrome、Android 模拟器、Android 真实设备。

编辑:我错过了输入。我在 name 字段中添加了一个 Javascript。所以输入可以是一个简单的脚本如:

<script language="Javascript">alert("Hello");</script>

由于我没有清理输入,我希望脚本能够执行。您可以参考此 link 了解更多信息。

但是输出的是一个没有输出的空白页,这意味着脚本没有被执行。

有什么想法吗?

注意:我担心这不适用于 emulator/Android 设备,所以请不要回答 Chrome.

尝试使用脚本标签以外的其他内容,例如 html,例如 <b>hello</b>,看看它是否呈现为粗体。 Chrome 有一个 XSS 审核员可以阻止反射 XSS 攻击。检查控制台以查看是否是这种情况。

Chrome 将在控制台中显示一条注释:

The XSS Auditor refused to execute a script in '<your page>' because its source code was found within the request. The auditor was enabled as the server sent neither an 'X-XSS-Protection' nor 'Content-Security-Policy' header.

这里有一篇关于security.se的相关文章:https://security.stackexchange.com/questions/53474/is-chrome-completely-secure-against-reflected-xss

我刚看到你的编辑。我的答案是针对 chrome,但我怀疑您的 android 设备正在采用类似的技术(我没有可用于测试的技术)。如果你想绕过审核员,你可以这样做:

<html>
   <head>
      <title> You searched for: </title>
   </head>
   <body>
      <script>
         <?php
            echo $_GET['name'];
         ?>
      <script>
   </body>
</html>

然后你可以提出像?name=alert(1) 这样的请求,审核员可能不会阻止它。