Lab: Stealing OAuth access tokens via a proxy page

Mô tả

Phòng thí nghiệm sử dụng OAuth service để cho phép người dùng đăng nhập bằng social media account. Flawed validation của OAuth service khiến nó cho phép kẻ tấn công leak access tokens tới trang tùy ý trong client application.

Người dùng quản trị sẽ mở bất kỳ thứ gì bạn gửi từ máy chủ khai thác và họ luôn có phiên hoạt động với dịch vụ OAuth.

Bạn có thể đăng nhập thông qua tài khoản mạng xã hội của mình bằng thông tin đăng nhập sau: wiener:peter.

Mục tiêu: Xác định lỗ hổng thứ cấp trong client application và sử dụng lỗ hổng này làm proxy để đánh cắp access token của tài khoản admin. Sủ dụng access token để lấy API key của admin

Giải pháp

Tham số redirect_uri trong GET /auth?cliend_id=... có lỗ hổng duyệt thư mục nhưng với domain hợp lệ

Quan sát comment form rằng nó bao gồm iframe trong mỗi blog post. Chú ý vào trang /post/comment/comment-form rằng nó sử dụngpostMessage() để gửi thuộc tínhwindow.location.href đến windows cha của nó. Quan trọng là nó cho phép đăng tin nhắn đến bất kỳ nguồn gốc nào ( *).

Trên máy chủ khai thác tạo exploit sau:

redirect_uriđể nó đến comment-form. Đoạn <script> hiển thị tin nhắn web trong access log của exploit server.

Kiểm tra bằng View exploit rồi gửi đến nạn nhân

27.72.144.83    2024-08-22 10:51:35 +0000 "GET /https%3A%2F%2F0a9d000103b07fd981683400000900f8.web-security-academy.net%2Fpost%2Fcomment%2Fcomment-form%23access_token%3Dx0h-5fWvDDI0p0xcES7TPNp4540jon4Jo1RqKhXBiEN%26expires_in%3D3600%26token_type%3DBearer%26scope%3Dopenid%2520profile%2520email HTTP/1.1" 404 "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"
10.0.3.127      2024-08-22 10:52:54 +0000 "GET /https%3A%2F%2F0a9d000103b07fd981683400000900f8.web-security-academy.net%2Fpost%2Fcomment%2Fcomment-form%23access_token%3DytAVVyIobqqyZUwib7QgkZ6SUlvLeljy4jdPiuyH1AK%26expires_in%3D3600%26token_type%3DBearer%26scope%3Dopenid%2520profile%2520email HTTP/1.1" 404 "user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
Decode đường dẫn nhận được để lấy token

Gửi lại GET /me request trong Burp Repeater, thay thế token trong Authorization: Bearer header bằng token vừa lấy được. Kết quả trả về sẽ có API key của admin

Last updated