sql注入

老是看到怎么防sql注入。今天我就想了想怎么去sql注入。以前一直不明白,今天突然想到了。把代码列出来。

include “config/config.testdb.php”;
include “config/config.smarty.php”;
include “class/class.db.php”;
$x=$_GET[‘x’];
$db=db::getInstance();
$sql= “update money set x=x-$x where id=1”;
echo $sql;
$db->query($sql);

$sql= “update money set y=y+$x where id=1”;
$db->query($sql);

$sql=”select * from money where id=1″;
$rs=$db->getAll($sql);
print_r($rs);

?>

怎么注入呢?

看我传的参数!

http://www.news.com/index.php?x=189,y=2000

发生了什么事?

update money set x=x-189,y=2000 where id=1

看我加粗的地方!sql语句并不是我期待的,但是个正确的语句!

小心!一不小心,也许你也会乱!

9 Comments