<dd id="sga4y"><optgroup id="sga4y"></optgroup></dd>
<nav id="sga4y"><code id="sga4y"></code></nav>
  • <optgroup id="sga4y"></optgroup>

    XSLT Injection

    ABSTRACT

    如果處理未驗證的 XSL 樣式表,可能會使攻擊者修改得到的 XML 的結構和內容,從文件系統中加入任意文件,或者執行任意 PHP 代碼。

    EXPLANATION

    XSLT injection 會在以下情況中出現:

    1. 數據從一個不可信賴的數據源進入程序。

    2. 數據寫入到 XSL 樣式表中。


    通常,應用程序利用 XSL 樣式表來轉換 XML 文檔的格式。XSL 樣式表中包括特殊函數,雖然此類函數能改善轉換進程,但如果使用不當也會帶來更多漏洞。

    如果攻擊者能夠在樣式表中寫入 XSL 元素,則可以更改 XSL 樣式表和處理的語義。攻擊者可能會更改樣式表的輸出,使 XSS (cross-site scripting) 攻擊被啟用,暴露本地文件系統資源的內容,或者執行任意 PHP 命令。如果攻擊者完全控制了提交給應用程序的樣式表,則攻擊者可能還會執行 XXE (Xml eXternal Entity) Injection 攻擊。

    例 1:下面是一些易受 XSLT Injection 攻擊的代碼:


    ...
    <?php

    $xml = new DOMDocument;
    $xml->load('local.xml');

    $xsl = new DOMDocument;
    $xsl->load($_GET['key']);

    $processor = new XSLTProcessor;
    $processor->registerPHPFunctions();
    $processor->importStyleSheet($xsl);

    echo $processor->transformToXML($xml);

    ?>
    ...


    當攻擊者能將標識的 XSL 送入 XSTL 處理器時,上述代碼會導致三種不同的攻擊:

    1. XSS:



    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
    <xsl:template match="/">
    <script>alert(123)</script>
    </xsl:template>
    </xsl:stylesheet>



    在處理 XSL 樣式表時,<script> 會進入受害者的瀏覽器,從而能夠實施 cross-site scripting 攻擊。

    2. 讀取服務器文件系統中的任意文件:



    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
    <xsl:template match="/">
    <xsl:copy-of select="document('/etc/passwd')"/>
    </xsl:template>
    </xsl:stylesheet>



    上述 XSL 樣式表將返回 /etc/passwd 文件的內容。

    3. 執行任意 PHP 代碼:

    XSLT 處理器通過啟用"registerPHPFunctions",能將本機 PHP 語言方法暴露為 XSLT 函數。



    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
    <xsl:template match="/">
    <xsl:value-of select="php:function('passthru','ls -la')"/>
    </xsl:template>
    </xsl:stylesheet>



    上述樣式表將輸出服務器上運行的 "ls" 命令的結果。

    REFERENCES

    [1] Standards Mapping - OWASP Top 10 2010 - (OWASP 2010) A1 Injection

    [2] Standards Mapping - OWASP Top 10 2007 - (OWASP 2007) A2 Injection Flaws

    [3] Standards Mapping - OWASP Top 10 2004 - (OWASP 2004) A6 Injection Flaws

    [4] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3510 CAT I

    [5] Standards Mapping - Security Technical Implementation Guide Version 3.4 - (STIG 3.4) APP3510 CAT I

    [6] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 631

    [7] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 - (PCI 1.2) Requirement 6.3.1.1, Requirement 6.5.2

    [8] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 - (PCI 2.0) Requirement 6.5.1

    [9] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 - (PCI 1.1) Requirement 6.5.6

    [10] Standards Mapping - FIPS200 - (FISMA) SI


    Copyright 2013 Fortify Software - All rights reserved.
    (Generated from version 2013.1.1.0008 of the Fortify Secure Coding Rulepacks)
    desc.dataflow.php.xslt_injection

    97av