# rm-rf.es | Administración de sistemas

Bitácora personal de un SysAdmin Gnu/Linux, Windows, BSD...

Ocultar la versión de PHP


Algo importante en la seguridad de servidores web es ofrecer siempre la menor cantidad de información acerca de las versiones del software instalado en el servidor. Hace ya bastante tiempo vimos cómo ocultar o enmascarar la versión de Apachela versión de Bind.

En este caso vamos a ocultar la versión de PHP, es extremadamente sencillo. Únicamente hay que editar el fichero de configuración general php.ini y modificar el siguiente parámetro a Off:

expose_php Off

Ya podemos verificar que al hacer la petición contra el sitio web la información PHP ya no se muestra:

# telnet servidor 80

Connected to xxx.com (xx.xx.xx.xx).
Escape character is '^]'.
HEAD / HTTP/1.0

HTTP/1.1 200 OK
Date: Fri, 13 Aug 2010 14:18:09 GMT
Server: Apache
Last-Modified: Fri, 12 Feb 2010 12:22:56 GMT
ETag: "44967c-6f-53ca4800"
Accept-Ranges: bytes
Content-Length: 111
Connection: close
Content-Type: text/html

Connection closed by foreign host.

Información sobre PHP desde línea de comandos


A través de la línea de comandos podemos averiguar información relativa a PHP muy interesante, como por ejemplo:

Versión de PHP instalada:

$ php -v

PHP 5.X.X (cli) (built: Jun 18 2009 18:16:19)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with Zend Extension Manager vX.X.X, Copyright (c) 2003-2007, by Zend Technologies
    with Zend Optimizer vX.X.X, Copyright (c) 1998-2007, by Zend Technologies

Módulos de PHP instalados/compilados:

$ php -m
[PHP Modules]
bcmath
calendar
ctype
curl
date
dom
filter
ftp
gd
...
...
...
[Zend Modules]
Zend Extension Manager
Zend Optimizer

Información general PHP:

La salida de este comando es la misma que <? phpinfo() ?> en un script php.

$ php -i
phpinfo()
PHP Version => 5.X.X

System => Linux  #1 SMP Thu May 7 10:39:21 EDT 2009 iX86
Build Date => Jun 18 2009 18:14:47
Configure Command =>  './configure'  '--disable-pdo' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable
-mbstring' '--enable-sockets' '--enable-zip' '--prefix=/usr/local' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-curl=/opt/curlssl/' '--with-freetype-dir=/usr' '--with-gd' '--wit
Server API => Command Line Interface
Virtual Directory Support => disabled
....
....
....
This program makes use of the Zend Scripting Language Engine:
Zend Engine vX.X.X, Copyright (c) 1998-2009 Zend Technologies
    with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
    with Zend Optimizer vX.X.X, Copyright (c) 1998-2007, by Zend Technologies
....
....
....

Mostrar ficheros de configuración cargados y sus rutas:

$ php --ini

Configuration File (php.ini) Path: /xxx/xxx/xx
Loaded Configuration File:         /xxx/xxx/xxx/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

Mostrar configuración de un módulo/extensión instalado:

La sintaxis es php –ri módulo

$ php --ri openssl
openssl

OpenSSL support => enabled
OpenSSL Version => OpenSSL X.X.Xe-fips-xxx 01 Jul 2008

Mostrar información de un módulo/extensión instalado:

La sintaxis es php –re módulo

$ php --re openssl
Extension [
 extension #35 openssl version  ] {

  - Constants [36] {
    Constant [ string OPENSSL_VERSION_TEXT ] { OpenSSL X.X.Xe-fips-xxx 01 Jul 2008 }
    Constant [ integer OPENSSL_VERSION_NUMBER ] { 9469999 }
    Constant [ integer X509_PURPOSE_SSL_CLIENT ] { 1 }
    Constant [ integer X509_PURPOSE_SSL_SERVER ] { 2 }
    Constant [ integer X509_PURPOSE_NS_SSL_SERVER ] { 3 }
    Constant [ integer X509_PURPOSE_SMIME_SIGN ] { 4 }
    Constant [ integer X509_PURPOSE_SMIME_ENCRYPT ] { 5 }
    Constant [ integer X509_PURPOSE_CRL_SIGN ] { 6 }
    Constant [ integer X509_PURPOSE_ANY ] { 7 }
    Constant [ integer OPENSSL_ALGO_SHA1 ] { 1 }
    Constant [ integer OPENSSL_ALGO_MD5 ] { 2 }
    Constant [ integer OPENSSL_ALGO_MD4 ] { 3 }
    Constant [ integer OPENSSL_ALGO_MD2 ] { 4 }
    Constant [ integer OPENSSL_ALGO_DSS1 ] { 5 }
...
...
...

Respecto a estos dos últimos puntos, también podemos buscar información acerca de una clase (php –rf clase) y de una función (php –rc función).