Website out of the question, there is a loophole, today came here to ask Csdn's brother to help solve

Source: Internet
Author: User
Website problem, there is a loophole, today came here to ask Csdn's brother to help solve
I made a health supplement station http://www.bjp51.net these two days a bit of a problem, with 3,601 sweep, high-risk, only 49 points, the report is as follows:



The first one is a very serious problem, and today I want to solve the first problem.
Look at the comments given in 360


I do not know how to change, I hope you help solve the next.



------Solution--------------------
$id = ";
if (!empty ($_post[' id ')) {
for ($i =0; $i <>
$id= $id. ($_post[' ID' [$i]. ', ');
}
$id =substr ($id, 0,strlen ($id)-1);//Remove the back of the ","
}
$sql = "SELECT * from Zzcms_main where ID in ( $id)"

He thinks you're using incoming data in SQL instructions without checking.
------Solution--------------------
The principle of SQL injection is to inject from the Address bar or form


If you get a $_get["a" from the address bar, it is a threat to use the program directly without filtering it. Like what:

If $_get["a"]=1; then:
$sql = "SELECT * from AA where ID =$_get[" a "]"; is $sql = "SELECT * from AA where id = 1";
But if other people through the address bar self-modification, the value of $_get["a"] to 1 or (and) xxx All kinds of code, then this query statement becomes

$sql = "SELECT * from AA WHERE ID =1 or (and) xxx";


So the middle of the recruit.

So the address bar and the form gets the parameters, must be formatted, filtered well, specify what type, how long, which characters are limited ...
------Solution--------------------
$sql = "SELECT * from Zzcms_main where ID in ($id)";
$id did not go through the discard, the user can enter anything, and of course is injected.

Because the ID can only be a number, it is possible to use intval to convert to numbers, if the non-number will be converted to 0, this is not injected.
------Solution--------------------
The incoming data replaces the single quotation mark with two consecutive single quotes, and the SQL statement adds single quotation marks to the arguments that are passed in.
$id = Str_replace ("'", "'", $_post[' id '));
$sql = "SELECT * from Tb_user wher id= ' $id '";
This is not afraid of injecting.
------Solution--------------------
if (!empty ($_post[' id ')) {
$id = Join (', ', Array_map (' intval ', $_post[' id ')));
}
Better put $id in a different name.
  • Related Article

    Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.