通过LINKS进行SQL注入?

问题描述:

它对我的数据库表编辑两个字段(note_name和note_description),我需要从一个形式类似这样的链接,并在新的领域的一些信息:通过LINKS进行SQL注入?

LINK:

/main_edit.php?edit=note_name2&type=PHP 

AND:

elseif(isset($_GET['edit'])){ 
     $note_type=$_GET['type']; 
     $old_note_name=$_GET['edit']; 
     $new_note_name=mysql_real_escape_string($_POST['new_note_name']); 
     $new_note_description=mysql_real_escape_string($_POST['new_note_description']); 
     $query="UPDATE functions 
       SET note_name='{$new_note_name}', 
       note_description='{$new_note_description}' 
       WHERE note_name='{$old_note_name}' 
       "; 
     $result = mysql_query($query, $connection);} 

是SQL注入通过链接可能在这里,如果是的话如何保护它呢?

谢谢!

是 - 你是不是出于某种原因逃脱$old_note_name,与它是在查询到底是最脆弱的变量。你似乎知道该怎么做......就像对其他人使用mysql_real_escape_string那样。

否则,这一切将采取: /main_edit.php?type=PHP&edit=note_name2';drop table functions;#

+0

供参考:通常情况下,一个离开的时候反对投票,以便回答者可以改善他们的答案评论。没有评论的反对票没有意义。 – 2011-12-13 22:28:56

是因为你不是在逃避$_GET['edit'] ..什么要试试这个:

$old_note_name=mysql_real_escape_string($_GET['edit']); 

更改此设置: -

$old_note_name=$_GET['edit']; 

$old_note_name= mysql_real_escape_string($_GET['edit'], $connection); 

并申请$连接到所有通话的功能mysql_real_escape_string

最后,看看mysqliPDO

你可以使用预处理语句,是这样的:

$query = "UPDATE functions SET note_name=?, note_description=? WHERE note_name=?"; 
$statement = $connection->prepare($query); 
$statement->bind_param('sss', $new_note_name, $new_note_description, $old_note_name); 
$statement->execute(); 
+2

如果可以的话,我会+1000。停止连接字符串以进行SQL查询,使用预先准备好的语句。 – Arkh 2011-12-13 17:37:52