Mình tham gia giải lần này chủ yếu là để lấy lại cảm giác tay khi chơi ctf (gọi là tìm lại cái phong độ tí ti đã mất cũng được 🤣), mặc dù bản thân không giỏi các dạng đề về client side nhưng ở post này cũng xin gửi đến mọi người 2 bài, mà thật ra là mình cũng chỉ giải được có mỗi 2 câu này.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
peanut-xss
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Tổng quan
Trang web cho phép người dùng soạn thảo nội dung bằng html
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
đồng thời hỗ trợ tính năng "expandable, embeddable explanations" với thư viện nutshell.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Source của trang chủ yếu nằm ở front end và bên cạnh nutshell, thư viện DOMPurify được sử dụng cho mục đích sanitize html.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Về yêu cầu của bài, có thể đoán được flag cần lấy nằm trong cookie của bot.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Phân tích
Để tìm hướng giải cho bài này, cần phân tích mã nguồn của thư viện nutshell. Sau khi được sanitize bởi DOMpurify mặc định sẽ khởi chạy hàm Nutshell.start()
Xét với trường hợp window == window.top
(không nằm trong iframe), thực hiện thêm vào các định dạng + ẩn đi các heading + chuyển links thành các "expandable" elements + …
Hàm Nutshell.convertLinksToExpandables()
có một sink DOM-based XSS, với ex
là các anchor element lấy từ dom
(document.body
)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Chẳng hạn một tag a
có dạng
ta có đoạn code dòng 615 sẽ tương đương
Vậy chỉ cần chèn payload XSS vào vị trí chuỗi CTF
là có thể hoàn thành challenge.
Về sự khác nhau giữa innerText và innerHTML
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Với một trang html như sau
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Ta có được kết quả khi truy xuất innerText và innerHTML tương ứng là:
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Từ đó suy ra payload "sống sót" được khỏi DOMPurify mà vẫn khai thác được DOM-based XSS:
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Khai thác
Set up exploit server
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Gửi link cho bot
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Kết quả
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
adminplz
Source tải tại link
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Tổng quan
Truy cập vào đường dẫn, ta thấy có hai chức năng
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Trang web được xây dựng dựa trên spring boot framework và mục tiêu của bài này vẫn là khai thác lỗi client-side để lấy flag.
Phân tích
- Về vị trí của flag -> nằm trong file
/flag.html

- Về chức năng login, chỉ đơn giản là set thuộc tính
user
của session object với giá trị là user
object từ request.

Trong đó user
object là một model với hai thuộc tính username
và password

- Về chức năng report, sẽ khởi chạy instance của headless chrome đến đường dẫn url lấy từ người dùng (mỗi lần report cách nhau 5p)

bot trước tiên sẽ thực hiện đăng nhập vào trang web, sau đó mới truy cập đến đường dẫn được cung cấp

- Trong mã nguồn tồn tại một controller
/admin
, chủ yếu dành cho admin để xem bất kì resource nào dựa vào view
param.
Hai method isAdmin()
và isLoggedIn()
như sau

Server sử dụng thư viện log4j để log lại username và session cookie trong trường hợp "user hiện tại đã đăng nhập và muốn xem các view có chứa chuỗi flag".
Vị trí của file log:

Bên cạnh đó, CSP
filter được dùng để triển khai csp cho trang web

Và thuộc tính Same Site của cookie là Strict

Sau khi thử login vào account admin và view các resource thì mình nhận thấy mặc định giá trị content type trong response thông qua ApplicationContext.getResource()
là text/html

-> Vậy có thể tận dụng file này cho việc khai thác.
Ý tưởng để giải bài này là
- Khiến server log lại session cookie của admin (bot)
- Tìm cách lấy session cookie
- Sử dụng session cookie và truy cập đến
/admin?view=/flag.html
để lấy flag
Để giải quyết vấn đề (1) chỉ cần report với đường dẫn url là http://127.0.0.1:8080/admin?view=/flag.html
.
Về vấn đề (2), do directive default-src
bị set thành none
nên khó có thể XSS với các cách thường hay làm, nhưng vì mục tiêu chỉ là session cookie của bot nên mình áp dụng kĩ thuật dangling markup - cụ thể là sử dụng metag
tag và redirect con bot đến exploit server.
Khai thác
- Gửi các request theo thứ tự hợp lý để ghi được payload hoàn chỉnh vào log file và trigger redirect.
Burp Project
- Lấy được session cookie của bot


