Personal using a vulnerability search tool, vul File Inclusion has been found, which is in the following codes:
$url = (isset($_GET['url'])) ? htmlentities(strip_tags($_GET['url'])) : '';
$parametros = explode('/', $url);
$paginas_permitidas = array('pedidos','novo_ticket','tickets_abertos','tickets_fechados','ticket','perfil','detalhes','categorias');
if($url == ''){
include_once "../../pages/home.php";
}elseif(in_array($parametros[0], $paginas_permitidas)){
include_once "../../pages/".$parametros[0].'.php';
}elseif($parametros[0] == 'categoria'){
if(isset($parametros[1]) && !isset($parametros[2])){
include_once "../../pages/categoria.php";
}elseif(isset($parametros[2])){
include_once "../../pages/subcategoria.php";
}
}else{
include_once "../../pages/erro404.php";
}
// Também da alerta de File Inclusion neste codigo
if(!isset($_GET['pagina']) || $_GET['pagina'] == ''){
include_once "../../../pages/home.php";
}else{
$pagina = strip_tags($_GET['pagina']);
if(file_exists('../../../pages/'.$pagina.'.php')){
include_once "../../../pages/$pagina".'.php';
}else{
echo '<div class="alert alert-danger">
<strong>Desculpe mas a pagina que você procura, não existe!</strong>
</div>';
}
}
A friend suggested using the following code as a basis:
$path_parts = pathinfo(dirname(__FILE__) . "/{$file}.php");
$str = "{$path_parts['filename']}.php";
(file_exists($str)) ? require_once($str) : exit(Functions::__error("ERROR OPEN FILE: {$str}"));
However, I tried booting in my system because I did not have a lot of programming, can anyone help me or hint how to implement the above code so that the vul is eliminated?