search
HomeBackend DevelopmentPHP Tutorial网站出问题了,有漏洞,今天来这里请csdn的兄弟帮忙解决

我做了个保健品站 http://www.bjp51.net 这两天有点问题,用360一扫,高危,只有49分,报告如下:



第一个是很严重的问题,今天想把第一个问题解决了。
看下360给出的意见


我不知道怎么改,希望大家帮忙解决下。



回复讨论(解决方案)

这是contrast.php的文件源码

<body><?php$id='';if(!empty($_POST['id'])){    for($i=0; $i<count($_POST['id']);$i++){    $id=$id.($_POST['id'][$i].',');    }	$id=substr($id,0,strlen($id)-1);//去除最后面的","}if ($id==''){echo "<script lanage='javascript'>alert('操作失败!至少要选中一条信息。');window.opener=null;window.open('','_self');window.close()</script>";exit;} $tdwidth=floor(90/$i);//取整,左边占10%$sql="select * from zzcms_main where id in ($id)" ;$rs=mysql_query($sql);?><table width="100%" height="218" border="0" align="center" cellpadding="5" cellspacing="1" class="bgcolor3">  <tr>     <td width="10%" align="center" bgcolor="#FFFFFF">【产品图片】 </td>	 <?php while ($row=mysql_fetch_array($rs)){?>    <td bgcolor="#FFFFFF" style="font-weight:bold" width="<?php echo $tdwidth ?>%"><a href="<?php echo $row["img"]?>" target="_blank"><img  <?php echo getsmallimg($row["img"],"")? alt="网站出问题了,有漏洞,今天来这里请csdn的兄弟帮忙解决" > alt="<?php echo $row["proname"]?>"  border="0" ></a></td>    <?php	}	?>  </tr>  <tr class="bgcolor1">     <td width="100" align="center">【产品名称】 </td>    <?php 	 mysql_data_seek($rs,0);	while ($row=mysql_fetch_array($rs)){?>    <td   style="max-width:90%"><?php echo $row["proname"]?></td>    <?php	}	?>     </tr>  <tr>     <td width="100" align="center" bgcolor="#FFFFFF">【主要功能】</td>       <?php 	 mysql_data_seek($rs,0);	while ($row=mysql_fetch_array($rs)){?>    <td valign="top" bgcolor="#FFFFFF" ><?php echo $row["prouse"]?></td>   <?php   }   ?>  </tr>  <tr class="bgcolor1">     <td width="100" align="center">【规格包装】</td>       <?php 	 mysql_data_seek($rs,0);	while ($row=mysql_fetch_array($rs)){?>    <td><?php echo $row["gg"]?></td>   <?php   }   ?>  </tr>  <tr  class="bgcolor1">     <td width="100" align="center"><strong>招商区域</strong></td>        <?php 	 mysql_data_seek($rs,0);	while ($row=mysql_fetch_array($rs)){?>    <td><?php echo $row["city"]?></td>    <?php	}	?>  </tr>  <tr>     <td width="100" align="center" bgcolor="#FFFFFF"><strong>产品说明</strong></td>        <?php 	 mysql_data_seek($rs,0);	while ($row=mysql_fetch_array($rs)){?>    <td valign="top" bgcolor="#FFFFFF"><?php echo nl2br($row["sm"])?></td>   <?php   }   ?>  </tr>  <tr class="bgcolor1">     <td width="100" align="center"><strong>可提供的支持</strong></td>        <?php 	 mysql_data_seek($rs,0);	while ($row=mysql_fetch_array($rs)){?>    <td valign="top"><?php echo nl2br($row["zc"])?></td>    <?php	}	?>  </tr>  <tr>     <td width="100" align="center" bgcolor="#FFFFFF"><strong>对代理商的要求</strong></td>       <?php 	 mysql_data_seek($rs,0);	while ($row=mysql_fetch_array($rs)){?>    <td valign="top" bgcolor="#FFFFFF"><?php echo nl2br($row["yq"])?></td>   <?php   }   ?>  </tr>  <tr class="bgcolor1">     <td width="100" align="center"><strong>备注</strong></td>        <?php 	 mysql_data_seek($rs,0);	while ($row=mysql_fetch_array($rs)){?>    <td><?php echo nl2br($row["other"])?></td>   <?php   }   ?>  </tr></table><table width="100%"  style="max-width:90%" border="0" cellpadding="0" cellspacing="0">  <tr>    <td align="center"><input type="button" name="Submit" value="关闭本窗口" onClick="javascript:window.close()"></td>  </tr></table><?phpmysql_close($conn);?></body>

$id='';
if(!empty($_POST['id'])){
    for($i=0; $i      $id=$id.($_POST[' id'][$i].',');
    }
    $id=substr($id,0,strlen($id)-1);//去除最后面的","
}
$sql="select * from zzcms_main where id in ( $id)" 

他认为你未经检查就在 sql 指令中使用了传入的数据

$id='';
if(!empty($_POST['id'])){
    for($i=0; $i      $id=$id.($_POST[' id'][$i].',');
    }
    $id=substr($id,0,strlen($id)-1);//去除最后面的","
}
$sql="select * from zzcms_main where id in ( $id)" 

他认为你未经检查就在 sql 指令中使用了传入的数据



我是php小白,请问我应该怎么验证,怎么检查好呢?

还有我不检查,是不是很容易被注入呢?

 $id = $id . (intval($_POST['id'][$i]) . ',');

SQL注入的原理是,从地址栏或者表单中注入


如果你从地址栏得到一个$_GET["a"],不经过过滤就直接使用到程序中,就会造成威胁。比如:

如果$_GET["a"]=1;那么:
$sql = "SELECT * FROM AA  WHERE id =$_GET["a"]";就是$sql = "SELECT * FROM AA  WHERE id =1";
但如果别人通过地址栏自行修改,把$_GET["a"]的值改为1  or (and) XXX各类代码,那这个查询语句就变成

$sql = "SELECT * FROM AA  WHERE id =1 or(and)  xxx";


于是就中招了。

所以地址栏和表单得到的参数,一定要格式化,过滤好,指定是什么类型,多长,限制哪些字符……

$sql="select * from zzcms_main where id in ($id)" ;
$id?有?行??,用??入什?都可以,?然被注入了。

因?id只能是?字,所以可以用intval?成?字,如果非?字???0,??就注入不到了。

安全级别:高危
安全等级打败了全国46%的网站!

 $id=$id.(intval($_POST['id'][$i]).',');

传入的数据把单引号替换为两个连续的单引号 , sql语句用传入的参数时加上单引号。
$id = str_replace("'","''",$_POST['id']);
$sql = " select * from tb_user wher id='$id' ";
这样就不怕注入了。



谢谢 您们的回答  我目前是把$id=$id.($_POST['id'][$i].','); 替换成 $id = $id . (intval($_POST['id'][$i]) . ','

就对了

上面的不对,我改成这样了
if(!empty($_POST['id'])){
    for($i=0; $i     //$id=$id.($_POST['id'][$i].',');
     $id = $id.(intval($_POST['id'][$i]).',');
    }
$id=substr($id,0,strlen($id)-1);//去除最后面的","
}

这样是不是对了

if(!empty($_POST['id'])) {  $id = join(',', array_map('intval', $_POST['id']));}
最好把 $id 换个名字

if(!empty($_POST['id'])) {  $id = join(',', array_map('intval', $_POST['id']));}
最好把 $id 换个名字


我对php不熟,我就用这段代码,不用找变量了
感谢版主无私的精神。
我才发现,另一个问题也是您在为我解决,再次感谢!
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment