В 2196 году ты не попадешь в кибервойска если не решишь вот эту задачу.
You won't get into cyberforce in 2196 if you don't solve this task.
Need whale deployment.
Image: cr.yandex/crp56e8fvolm1rqugnkf/web-waf:latest
Port: 80
Compose(local) deploy:
cd deploy
docker compose -p web-scanner up --build -d
Provide zip file: public/web-waf.zip.
WAF bypass by providing two "Content-Type" headers.
В задаче есть WAF на основе OpenResty, который пытается заблокировать запрос, если находит в нем недопустымые символы.
WAF умеет проверять Content-Type, чтобы проверять тело запроса в зависимости от типа данных.
Под WAF находится приложение, уязвимое к SQL-injection. Приложение также поддерживает 2 вида
Content-Type: application/json
и application/x-www-form-urlencoded
.
Уязвимость заключается в том, что код WAF не ожидает что заголовок Content-Type может встретиться дважды. В таком случае, функция get_headers возвращает список строк, а не строку и WAF не может проверить тело запроса.
Однако, PHP все еще сможет понять такой запрос и мы сможем сделать SQL-injection.
Далее мы можем получить RCE, т.к. после получения сессии админа с помощью SQL-injection нам будет доступна функция
exec()
, с помощью которой мы можем записать PHP-shell в файл используя "ATTACH DATABASE".
В публичном архиве задания дана БД, в которой в истории команд можно найти пароль от пользователя admin
.
Зная данный пароль, мы можем сразу перейти к шагу "RCE" из авторского решения.
The challenge uses a WAF based on OpenResty that tries to block a query if it finds restricted characters in it.
The WAF uses the Content-Type
header to check the request body depending on the provided value.
Downstream WAF there is a PHP application that is vulnerable to SQL-injection. The application also supports two types of content:
Content-Type: application/json
and application/x-www-form-urlencoded
.
The vulnerability is that the WAF code does not expect the Content-Type header to be encountered twice. In such a case, the get_headers function returns a list of strings, not a string, and WAF will not be able to check the request body.
However, PHP will still be able to understand such a query, so we can do a SQL-injection.
Next we can get the RCE, because after we get the admin session using SQL-injection we will have access to the exec()
function.
Using this, we would be able to write PHP-shell to a file using "ATTACH DATABASE".
In the public archive we have a database where we can find the password of the user admin
in the command history.
Knowing this password, we can go directly to the "RCE" step from the author's solution.
Should be auto-generated by Whale.
No
Should be auto-generated by Whale.