You cannot have one โexitโ function and expect it to work all the time. There are various attacks that require specific sanitation procedures. The only way to understand this concept is to write vulnerable code and then use it. Writing an exploit code is vital to understanding any security system.
For example, this query is vulnerable to Sql injection:
$host=htmlspecialchars($_GET[host],ENT_QUOTES); $name=htmlspecialchars($_GET[name],ENT_QUOTES); mysql_query("select * from user where Host='$host' and Name='$name' ");
Exploit: http: //localhost/sqli_test.php? Host = \ & name =% 20sleep (20) -% 201
The best escape function for mysql is mysqli_real_escape_string (), but this may fail:
mysql_query("select * from user where id=".mysqli_real_escape_string($_GET[id]));
use: http: //localhost/sqli_test.php? id = 1% 20or% 20sleep (20)
In fact, the best way to take care of SQL injection is not to call the escape function, its using parameterized ADODB queries for SQL injection. For XSS, use htmlspecialcahrs ($ var, ENT_QUTOES). Read the OWASP top 10 because there is so much more that can go wrong with web application security.
rook
source share