I can not insert into mysql. Injection problem but which one?

Discussion in 'PHP' started by baris22, Nov 23, 2007.

  1. #1
    I am inserting long text files into the database. There is 1 character (i do not know which one) i can not insert into the database.

    Which character do you think will cause the problem?

    i use this code to escape from injection.


    
    
    if (!get_magic_quotes_gpc()) {
    					$title=addslashes($title);
    					$links=addslashes($links);
    					$description=addslashes($description);
    				}
    				$to_replace = array("\r\n","|","\n","\\r\\n","\\n");
    
    
    PHP:
     
    baris22, Nov 23, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Nov 23, 2007 IP
  3. kreoton

    kreoton Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    kreoton, Nov 23, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    nico_swd, Nov 23, 2007 IP
  5. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    I changed it into

    $links.=$_POST['links'][$i];
    				$description=$_POST['description'][$i];
    				$type=$_POST['type'];
    				if (!get_magic_quotes_gpc()) {
    					$title=mysql_real_escape_string($title);
    					$links=mysql_real_escape_string($links);
    					$description=mysql_real_escape_string($description);
    				}
    				$to_replace = array("\r\n","|","\n","\\r\\n","\\n");
    			  $title = str_replace($to_replace, " ", $title);
    			  $description = str_replace($to_replace, " ", $description);
    				//echo $title . '<br/>';
    				$query="INSERT INTO `filedetails` VALUES ('', '".$type."', '".$title."', '".$description."', '".$links."','0000000000')";
    				mysql_query($query);
    				echo mysql_error();
    PHP:

    But same problem. Is it right the way i use the code?

    thanks
     
    baris22, Nov 23, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    No.

    mysql_real_escape_string() should always be applied (on anything non-numeric), regardless of get_magic_quotes_gpc().

    In fact, if magic quotes are enabled, you should apply stipslashes() first, and then mysql_real_escape_string().

    www.php.net/mysql_real_escape_string

    EDIT:

    And can you explain your "problem"? What happens?
     
    nico_swd, Nov 23, 2007 IP
  7. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #7
    It does not insert into database. I get this error:

    Service Temporarily Unavailable
    The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
     
    baris22, Nov 23, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    That looks more like a problem with your server, and not the script.

    However, you might want to try replacing this:
    
    mysql_query($query);
    
    PHP:
    With:
    
    mysql_query($query) OR die(mysql_error());
    
    PHP:
    And see if you get a specific error.
     
    nico_swd, Nov 23, 2007 IP
  9. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #9
    no, it is not the server. if that character is not on the text it works fine. if that character is on the text I get that error.

    I am just going to try your code.
     
    baris22, Nov 23, 2007 IP
  10. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #10
    I get same error

    Service Temporarily Unavailable
    The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
     
    baris22, Nov 23, 2007 IP
  11. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #11
    I used this. it did not work either. I do not know if the code is right.

    $links.=$_POST['links'][$i];
    				$description=$_POST['description'][$i];
    				$type=$_POST['type'];
    				
    				$title=stripslashes($title);
    				$links=stripslashes($links);
    				$description=stripslashes($description);
    				
    				$title=mysql_real_escape_string($title);
    				$links=mysql_real_escape_string($links);
    				$description=mysql_real_escape_string($description);
    				
    				$to_replace = array("\r\n","|","\n","\\r\\n","\\n");
    			  $title = str_replace($to_replace, " ", $title);
    			  $description = str_replace($to_replace, " ", $description);
    				//echo $title . '<br/>';
    				$query="INSERT INTO `filedetails` VALUES ('', '".$type."', '".$title."', '".$description."', '".$links."','0000000000')";
    				mysql_query($query);
    				echo mysql_error();
    PHP:
     
    baris22, Nov 23, 2007 IP
  12. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #12
    
    $to_replace = array("\r\n","|","\n","\\r\\n","\\n");
    
    
    $links .= $_POST['links'][$i];
    $description = str_replace($to_replace, " ",$_POST['description'][$i]);
    $title = str_replace($to_replace, " ", $title);
    $type = $_POST['type'];
    
    $query = "INSERT INTO `filedetails` VALUES ('', '".mysql_escape_string($type)."', '".mysql_escape_string($title)."',
    	'".mysql_escape_string($description)."', '".mysql_escape_string($links)."','0000000000')";
    mysql_query($query);
    echo 'MYSQL ERROR IS: '.mysql_error();
    
    PHP:
    What is the output?

    Peace,
     
    Barti1987, Nov 23, 2007 IP
  13. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #13
    Edited

    Oh my god. I found the answer after 2 long days.

    When i try to add the word "wget " to database it does not work.

    I am so serious. When i try to add "wget " (there is a space after) it does not work.






    Thanks for your time.

    Output is still same. I do not get an error message.



    it says

    Service Temporarily Unavailable
    The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.


    I am going to try adding one by one and see where the problem is
     
    baris22, Nov 24, 2007 IP
  14. lazukars

    lazukars Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I read mysql_real_escape_string() has a vulnerability when it comes to * and _ characters. Does anyone have any mysql injection examples when it comes to the * and _ problem. What can be done to fix this hole in mysql_real_escape_string()

    Sincerely,
    Ryan
     
    lazukars, Dec 5, 2007 IP