0
Personnel using a vulnerability search tool, vul File Inclusion was 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 the 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 floated while trying to implement in my system by not knowing much of programming, someone can help me or give hint on how to implement the above code so vul is eliminated?
Have you considered disabling the
error_reporting
php place at the top of the pageerror_reporting(0)
so that the file path is not found– user28266
@rray and if the attacker scans advanced and sees the vulnerability, screwed
– Jonathan Silva
recommend you use url amigavel is much safer see here
– user28266
@Marcosbrinner but I’m using friendly url
– Jonathan Silva