Fixed SQL injection vulnerabilities by using PDO statements.

Not tested as I do not have a database schema and am too lazy to reverse engineer it.
pull/11/head
dbursem 2015-02-06 01:01:05 +01:00
rodzic db210f3829
commit 6c7374c870
3 zmienionych plików z 59 dodań i 68 usunięć

2
.gitignore vendored 100644
Wyświetl plik

@ -0,0 +1,2 @@
.idea
config.php

Wyświetl plik

@ -1,44 +1,47 @@
<?php <?php
$link="";
require('sql.php'); require('sql.php');
ouvrebase();
if (isset($_GET['rec'])) { $recc="'&r=".$_GET['rec']."'"; $reqc=" AND rec='".$_GET['rec']."'"; } else { $recc = "\"\""; $reqc=""; } $q="select * from live where tim > 0";
if (isset($_GET['pw'])) { $parc="'&p=".$_GET['pw']."'"; } else { $parc = "\"\""; }
if (isset($_GET['rec']))
{
$recc="'&r=".$_GET['rec']."'";
$q .=" AND rec=?";
$params[] = $_GET['rec'];
}
else
{
$recc = "\"\"";
}
if (isset($_GET['pw']))
$req="select * from live where tim > 0"; {
$req.=$reqc; $parc="'&p=".$_GET['pw']."'";
}
else
{
$parc = "\"\"";
}
$latmax=$latmin=$lonmax=$lonmin=0; $latmax=$latmin=$lonmax=$lonmin=0;
if (!$result=@mysql_query ($req)) $stmt = $dbh->prepare($q);
{ $stmt->execute($params);
echo "<BR><BR><CENTER>Request error $req</CENTER><BR><BR>";
@mysql_close($link);
exit();
}
if ($stmt->columnCount() == 0)
if (@mysql_num_rows($result)==0) {
{
$latmax=60; $latmax=60;
$latmin=35; $latmin=35;
$lonmax=30; $lonmax=30;
$lonmin=-10; $lonmin=-10;
$lon=2; $lon=2;
$lat=45; $lat=45;
}
}
else else
{ {
$aa=0; $aa=0;
while($ligne = $stmt->fetch(PDO::FETCH_ASSOC))
while($ligne = @mysql_fetch_array($result))
{ {
extract($ligne); extract($ligne);
if ($aa==0) if ($aa==0)
@ -55,7 +58,7 @@ else
if ($lon<$lonmin) $lonmin=$lon; if ($lon<$lonmin) $lonmin=$lon;
} }
} }
} }
echo "<!DOCTYPE html> echo "<!DOCTYPE html>
@ -123,5 +126,3 @@ catch(e) {
</body> </body>
</html>"; </html>";
@mysql_close($link);
?>

30
sql.php
Wyświetl plik

@ -1,23 +1,11 @@
<?php <?php
function ouvrebase() include 'config.php';
{
// **************** Connexion et ouverture de la base ************************
global $link;
//if (!($link = @mysql_connect( ))) // en local
if (!($link = @mysql_connect("****hostname****", "****username****", "****password****" ))) //
{
echo "<BR><BR><CENTER>Connection not possible</CENTER><BR><BR>";
@mysql_close($link);
exit();
}
if (!(@mysql_select_db ("****databasename****",$link))) try
{ {
echo "<BR><BR><CENTER>Database access not possible</CENTER><BR><BR>"; $dbh = new PDO($cfg['db_type'].':host='.$cfg['db_host'].';dbname='.$cfg['db_name'], $cfg['db_user'], $cfg['db_pass']);
@mysql_close($link); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
exit(); }
} catch (PDOException $e) {
// *************************************************************************** echo 'Connection failed: ' . $e->getMessage();
}
}
?>