Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/allanlw/svg-cheatsheet

A cheatsheet for exploiting server-side SVG processors.
https://github.com/allanlw/svg-cheatsheet

Last synced: about 1 month ago
JSON representation

A cheatsheet for exploiting server-side SVG processors.

Awesome Lists containing this project

README

        

# SVG SSRF Cheatsheet

Hosts that process SVG can potentially be vulnerable to SSRF, LFI, XSS, RCE because of the rich feature set of SVG.

All of these methods specify a URI, which can be absolute or relative. File and HTTP protocol are important to test, but it could also support other protocols depending on the implementation (e.g. PHP stream schemes), including javascript: and data:.

This document contains a list of all the ways I know about to abuse this functionality in SVG.

Note that some services that claim to not accept SVG as an input format actually do with a little coaxing.

* For uploads, send a JPEG/PNG mime type and filename.
* For downloads, have a JPEG/PNG filename and mime type. If refused, check for TOCTOU on the URL (double fetch) and if it follows redirects.
* I haven't seen it but Mime sniffing confusion is probably also possibleMime sniffing confusion as SVG is difficult to sniff because it can start with extra XML garbage. In fact, AFAICT the standard `file` command doesn't include any SVG magic, so it's likely up to the individual implementations.

# Images
SVG can include external images directly via the `` tag.

``` xml

```

Note that you can use this to include *other SVG* images too.

# The `` tag

SVG can include external SVG content via the `` tag.

file1.svg:
``` xml

```

file2.svg:
```

```

# CSS

## CSS Stylesheet ``

SVG can include external stylesheets via the `` tag, just like html.

``` xml


```

## CSS stylesheet via `@include`

``` xml


@import url(http://example.com/style.css);

```

## CSS Stylesheet via ``

``` xml

```

# XSLT

SVGs can include XSLT stylesheets via ``. Surprisingly, this does seem to work in chrome.

``` xml

```

``` xml





```

Note: due to the nature of XSLT, the input doesn't actually *have* to be a valid SVG file if the xml-stylesheet is ignored, but it's useful to bypass filters.

Also, Because I have no interest in learning XSLT, this template just wholesale replaces the entire "old" image with the new one.

# Javascript

## Inline

SVG can natively include inline javascript, just like HTML.

``` xml



// <![CDATA[
document.getElementById("foo").setAttribute("fill", "blue");
// ]]>

```

## External

SVG can also include external scripts.

``` xml


```

## Inline in event

SVG can also have inline event handlers that get executed onload.

``` xml


```

You can also bind handlers to animations and some other events. Read the SVG spec.

# XXE

Because SVG is XML, it can also have XXEs:

``` xml


]>

My &xxe;

```

# ``

The `` tag is insane. It can be used to include arbitrary (X)HTML in an SVG.

For example, to include an iframe:

``` xml



```

If you don't have network access (e.g. sandbox) you can put a data URI or a javascript uri as the target of the iframe:

``` xml



k

```

If you haven't had enough SVGs, you can also include more SVGs via the `` or `` tags. I think probably it's theoretically possible to put Flash in there too.

Note that also because you're in a different XML namespace, anything that stripped only `svg:script` might not have stripped `html:script` (or similar for attributes).

# Other

It's possible to include external fonts if you ever wanted to do that, I think both via CSS and via native attributes. This isn't really useful though because webfonts require CORS for some reason I don't really understand related to DRM for font resources to prevent hotlinking. I guess sometimes there are font engine vulnerabilities though.

## Text

This example from the SVG spec shows using a tref node to reference text by URI, however it doesn't seem to work in any viewer I've tried. If there is an implementation that supports it, it might also support external URIs for the href in the tref.

``` xml



Referenced character data


Example tref01 - inline vs reference text content

Inline character data





```

# Improvements

If you know of any other methods or relevant information/examples, feel free to open an issue/PR.

If you found this useful, I'd appreciate it if you'd let me know! It makes my day.

``` quote
Copyright 2019 Allan Wirth .

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.
```