This article briefly describes how to defend against xss attacks and SQL injection in php. For more information, see the introduction. the XSS attack instance code is as follows: arbitrary execution code n... this article briefly describes how to defend against xss attacks and SQL
are due to the way multiple queries exist. The MySQL monitor completely allows such a query. The common MySQL gui-phpmyadmin will copy all of the previous content before the final query and do just that.
However, most of the multiple queries in an injection context are managed by PHP's MySQL extensions. Fortunately, by default, it is not allowed to execute multiple instructions in a single query; Attempting to execute two directives (such as the one
Don't talk about it. Come on!
1. http://www.bkjia.com/Article/200806/27934.html
2. http://www.bkjia.com/Article/201203/125690.html
1. What is SQL Injection? view it with the keyword wikipedia.
2. Local test code:
If the form is submitted correctly, print hello, "username"
Otherwise, print "404 not found !"
Require 'config. php ';
$ DBConnection = mysql_conn
disaster recovery.
As mentioned above, SQL injection mainly submits insecure data to the database for attack purposes. To prevent SQL injection attacks, PHP comes with a function that can process input strings and perform initial security processing on the input at a lower
recovery.
As mentioned above, SQL Injection mainly submits insecure data to the database for attack purposes. To prevent SQL injection attacks, PHP comes with a function that can process input strings and perform initial security processing on the input at a lower level, th
Because the user's input might be this:?
1
value‘); DROP TABLE table;--
Then the SQL query will become as follows:?
1
INSERTINTO `table` (`column`) VALUES(‘value‘); DROP TABLEtable;--‘)
What effective methods should be taken to prevent SQL injection?Best Answer (from Theo):Use preprocessing statement
In php, the addslashes function and SQL anti-injection, addslashessql. In php, the addslashes function and the SQL anti-injection function are provided. This document describes the addslashes function and the
program completely allows such a query. A common MySQL gui-phpmyadmin that copies all of the previous content before the final query, and only does so. However, most of the multiple queries in an injection context are managed by PHP's MySQL extension. Fortunately, by default, it is not allowed to execute multiple instructions in a single query; Attempting to execute two instructions (such as the one shown above) will simply lead to failure-no errors
The mysql_real_escape_string () function escapes special characters in the string used in the SQL statement. The following characters are affected:
The code is as follows
Copy Code
X00NR'"X1a
If successful, the function returns the escaped string. If it fails, it returns false.
Easy to use the following function, you can effectively filter.
The code is as follows
Copy Code
function S
pdoexceptions in order to properly handle the error. However, the first setattribute () call is mandatory, and it prohibits PDO from simulating pre-processing statements, while using a true preprocessing statement that has MySQL to execute a preprocessing statement. This ensures that statements and parameters are not processed by PHP before they are sent to MySQL, which will make it impossible for an attacker to inject malicious
::attr_emulate_prepares, false);$dbConnection->setattribute (Pdo::attr_errmode, pdo::errmode_exception); In the above example, the error mode (Attr_errmode) is not required, but it is recommended. In this way, when a fatal error (Fatal error) occurs, the script does not stop running, but it gives the programmer an opportunity to capture the pdoexceptions in order to properly handle the error. However, the first setattribute () call is required, which prohibits PDO analog preprocessing statements
implementation. We will explain how to protect your scripts from SQL injection, prevent cross-site scripting and remote execution, and prevent "hijacking" of temporary files and sessions.
In the last installment, we will implement a secure Web application. You will learn how to authenticate users, authorize and track application use, avoid data loss, securely execute highly risky system commands, and be a
In order to prevent SQL injection attacks, PHP has a function to handle the input string, you can at the lower level of the input on the security of the initial treatment, that is, magic quotes. (PHP.ini MAGIC_QUOTES_GPC). If the MAGIC_QUOTES_GPC option is enabled, single quotes, double quotes, and other characters in the string you enter will be automatically pr
($ _ POST ['sub']) {
Echo $ _ POST ['test'];
}
A very simple piece of code. here we just simulate the use scenario ..
Join the attacker to submit
Script alert (document. cookie); script
The returned page displays the cookie information on the current page.
We can use some message boards (which are not filtered in advance). Then, when the administrator reviews and modifies the information, the COOKIE information is stolen and sent to the attacker's space or mailbox .. Attackers can use the coo
attacks and prevention ..
Submit Form:
The Code is as follows:
Received file:
The Code is as follows:
If (empty ($ _ POST ['sub']) {
Echo $ _ POST ['test'];
}
A very simple piece of code. Here we just simulate the use scenario ..
Join the attacker to submit
Script alert (document. cookie); script
The returned page displays the cookie information on the current page.
We can use some message boards (which are not filtered in advance). Then, when the Administrator reviews and modifies the in
For a long time, the security of web has great controversy and challenge. Among them, SQL injection is a common attack method, the common practice of developers is to constantly filter, escape parameters, but our PHP Dafa inherently weak type of mechanism, always let hackers have the advantage, bypassing defense and defense is always in the infighting.Brother Lia
Php cloud two SQL secondary injection
Php cloud two-site secondary injection
The latest version. Two injection points. Along with a little trick to bypass waf.First:/member/model/index. class. php39 rows
function index_action(){$t
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.