PHP Secure Configuration Checker

Overview

Build Status

PHP Secure Configuration Checker

Check current PHP configuration for potential security flaws.

Simply access this file from your webserver or run on CLI.

Author

This software was written by Ben Fuhrmannek, SektionEins GmbH, in an effort to automate php.ini checks and spend more time on cheerful tasks.

Idea

  • one single file for easy distribution
  • simple tests for each security related ini entry
  • a few other tests - not too complicated though
  • compatible with PHP >= 5.4, or if possible >= 5.0
  • NO complicated/overengineered code, e.g. no classes/interfaces, test-frameworks, libraries, ... -> It is supposed to be obvious on first glance - even for novices - how this tool works and what it does!
  • NO (or very few) dependencies

Usage / Installation

  • CLI: Simply call php phpconfigcheck.php. That's it. Add -a to see hidden results as well, -h for HTML output and -j for JSON output.

  • WEB: Copy this script to any directory accessible by your webserver, e.g. your document root. See also 'Safeguards' below.

    The output in non-CLI mode is HTML by default. This behaviour can be changed by setting the environment variable PCC_OUTPUT_TYPE=text or PCC_OUTPUT_TYPE=json.

    Some test cases are hidden by default, specifically skipped, ok and unknown/untested. To show all results, use phpconfigcheck.php?showall=1. This does not apply to JSON output, which returns all results by default.

    To control the output format in WEB mode use phpconfigcheck.php?format=..., where the value of format maybe one of text, html or json. For example: phpconfigcheck.php?format=text. The format parameter takes precedence over PCC_OUTPUT_TYPE.

Safeguards

Most of the time it is a good idea to keep security related issues such as your PHP configuration to yourself. The following safeguards have been implemented:

  • mtime check: This script stops working in non-CLI mode after two days. Re-arming the check can be done by touch phpconfigcheck.php or by copying the script to your server again (e.g. via SCP). This check can be disabled by setting the environment variable: PCC_DISABLE_MTIME=1, e.g. SetEnv PCC_DISABLE_MTIME 1 in apache's .htaccess.

  • source IP check: By default only localhost (127.0.0.1 and ::1) can access this script. Other hosts may be added by setting PCC_ALLOW_IP to a your IP address or a wildcard pattern, e.g. SetEnv PCC_ALLOW_IP 10.0.0.* in .htaccess. You may also choose to access your webserver via SSH Port forwarding, e.g. ssh -D or ssh -L.

Troubleshooting

  • disabled functions: This scripts needs a few functions to work properly, such as ini_get() and stat(). If one of these functions is blacklisted (or not whitelisted) then execution will fail or produce invalid output. In these cases it is possible to temporarily put Suhosin in simulation mode and omit disable_functions. To be on the safe side, relaxed security configuration can be done with .htaccess in a separate directory. Also, this script may be called from command line with your webserver's configuration, e.g. php -n -c /etc/.../php.ini phpconfigcheck.php.

  • CLI: Older PHP versions don't known about SAPI name 'cli' and use CGI style output even on cli. Workaround: PCC_OUTPUT_TYPE=text /opt/php/php-5.1.6/bin/php phpconfigcheck.php

WARNING

This tool will only support you setting up a secure PHP environment. Nothing else. Your setup, software or any related configuration may still be vulnerable, even if this tool's output suggests otherwise.

Notes

Comments
  • Check for commonly used modules like xdebug

    Check for commonly used modules like xdebug

    The PHP.ini could be checked against loaded modules like zend_extension=xdebug.so. Xdebug for example is commonly used but should not be available in production environment. Is such a check wished?

    enhancement 
    opened by DeepDreamer89 3
  • False positive: suhosin.log.file.name in document root (when none present)

    False positive: suhosin.log.file.name in document root (when none present)

    Bravo! Nicely done, and very handy auditing tool.

    pcc tells me:

    suhosin.log.file.name in document root
    Checks if suhosin.log.file.name path is in the current document root
    

    I have not installed the module or the patch.

    OS: OS/2 Apache: 2.2.29 PHP: 5.4.36 (as module)

    opened by LewisR 3
  • False warning due to values using

    False warning due to values using "Off"

    Hi, First of all, thank you for this initiative. I just install a default Linux Debian 7.7 with Apache and PHP 5.4 and in the php.ini file it is written : enable_dl = Off which seems fine to me but when using your script, it still give me a high risk on enable_dl.

    Looking at phpinfo() function I've got enable_dl Off witch seems also correct.

    Looking at your script, and trying to debug it, it seems that the problem comes from the usage of ini_get_all function.

    print_r(ini_get_all()); give me this kind of thing [enable_dl] => Array ( [global_value] => [local_value] => [access] => 4 )

    As you see, there seems to be no value at all.

    If I put 0 in the php.ini the ini_get_all function return 0 If I put 1 in the php.ini the ini_get_all function return 1 If I put Off or off in the php.ini the ini_get_all function return nothing If I put On or on in the php.ini the ini_get_all function return 1

    This problem is not only for enable_dl, it's a global problem.

    opened by jledrogo 2
  • Latest version reports

    Latest version reports "script is rather old"

    I'm experimenting with Version 0.1-dev11 and it's reporting:

    [*] This script is rather old. Please check for updates: https://github.com/sektioneins/pcc

    Is there a later version that I'm somehow missing? I see there have been minor updates as recently as six months ago - is there further development being done on this script?

    We'd like to feature it on linuxsecurity.com.

    opened by dwreski 1
  • Failure in suhosin check if snuffleupagus is active

    Failure in suhosin check if snuffleupagus is active

    If running PHP 7.x and hence using snuffleupagus instead of suhosin the following check in line 1249 causes the whole script to abort if the default snuffleupagus ruleset is active: test_log_in_document_root('suhosin.log.file.name') The reason is that test_log_in_document_root calls ini_get('suhosin.log.file.name') and the default snuffleupagus ruleset forbids to call ini_get() for any suhosin parameters. This could possibly be improved by replacing line 1249 with the following code: extension_loaded('suhosin') && test_log_in_document_root('suhosin.log.file.name')

    opened by jeriedel24 0
  • Dubious use of constant STDOUT

    Dubious use of constant STDOUT

    The constant STDOUT is only defined if PHP is called in CLI mode. In line 1367 the constant STDOUT is used unconditionally which leads to warning or even error messages if PHP is not called in CLI mode. Dubious use is: if (function_exists('posix_isatty') && posix_isatty(STDOUT)) { Safe use could be: if (function_exists('posix_isatty') && defined('STDOUT') && posix_isatty(STDOUT)) {

    opened by jeriedel24 0
  • Test for intl.error_level is logically wrong

    Test for intl.error_level is logically wrong

    In line 792 the test for intl.error_level is logically wrong. It is: intval($v) | E_ERROR which always yields true regardless of the value of $v. It should be: intval($v) & E_ERROR

    opened by jeriedel24 0
  • Typos: memory_limit text

    Typos: memory_limit text

    I'm no whiz at Github, so I'll just paste my diff:

    diff -u2 original/phpconfigcheck.php updated/phpconfigcheck.php
    --- original/phpconfigcheck.php 2015-01-07 21:47:04.000000000 -0500
    +++ updated/phpconfigcheck.php  2015-01-07 21:50:56.000000000 -0500
    @@ -239,5 +239,5 @@
            'max_input_time' => "It may be useful to limit the time a script is allowed to parse input. This should be decided on a per application basis.",
            'max_input_nesting_level' => "Deep input nesting is only required in rare cases and may trigger unexpected ressource limits.",
    -       'memory_limit' => "A high memory limit may easy lead lead to ressource exhaustion and thus make your application vulnerable to denial-of-service attacks. This value should be set approximately 20% above empirically gathered maximum memory requirement.",
    +       'memory_limit' => "A high memory limit may easily lead to resource exhaustion and thus make your application vulnerable to denial-of-service attacks. This value should be set approximately 20% above an empirically gathered maximum memory requirement.",
            'post_max_size' => "Setting the maximum allowed POST size to a high value may lead to denial-of-service from memory exhaustion. If your application does not need huge file uploads, consider setting this option to a lower value. Note: File uploads have to be covered by this setting as well.",
            'post_max_size>memory_limit' => "post_max_size must be lower than memory_limit. Otherwise, a simple POST request will let PHP reach the configured memory limit and stop execution. Apart from denial-of-service an attacker may try to split a transaction, e.g. let PHP execute only a part of a program.",
    

    Thanks again for this handy tool!

    opened by LewisR 0
  • Inverse test for log_errors parameter (missing !)

    Inverse test for log_errors parameter (missing !)

    Hi,

    The warning message about not logging error is "You are not logging errors." and I aggree it should be activated. So I suppose line 346 should be : if(!is_on($v)) {

    instead of if(is_on($v)) {

    opened by jledrogo 0
  • Values are not shown corectly

    Values are not shown corectly

    I had tried the script but some values are not shown corectly.

    from command line

    php -i | grep suhosin.request.disallow_nul suhosin.request.disallow_nul => 1 => 1

    and your script recommends

    [high ] php.ini / suhosin.request.disallow_nul nul-protection off. Unless binary data is handled unencoded - which would be very obscure - this feature wants to remain enabled.

    The problem seem to be with all of the following:

    php.ini / suhosin.cookie.disallow_nul php.ini / suhosin.get.disallow_nul php.ini / suhosin.post.disallow_nul php.ini / suhosin.request.disallow_nul

    php version: PHP 5.4.30 (cli) (built: Jun 27 2014 11:59:31) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies with the ionCube PHP Loader v4.4.1, Copyright (c) 2002-2013, by ionCube Ltd. with Suhosin v0.9.36, Copyright (c) 2007-2014, by SektionEins GmbH

    opened by TempleNode 0
  • changes to avoid depreaction warnings in php 8.2

    changes to avoid depreaction warnings in php 8.2

    Running this now on php 8.2 I got a couple of deprecation warnings

    This change should fix them.

    warning on

    Deprecated ${} string interpolation.

    strtoupper(null)

    opened by seanburlington 0
  • Composer support

    Composer support

    Hi. I know that one point of the basic idea of this library is:

    NO complicated/overengineered code, e.g. no classes/interfaces, test-frameworks, libraries, ... -> It is supposed to be obvious on first glance - even for novices - how this tool works and what it does!

    But I think it should be great if the library had some basic support for composer, for easy distribution and use. So, for "advanced users", they can install the library with composer and then execute it with some code like:

    require 'vendor/autoload.php';
    
    Pcc::check();
    

    And for novices, just execute the php file phpconfigcheck.php that launch the class and print the result.

    enhancement 
    opened by oscarotero 0
Owner
SektionEins GmbH
SektionEins GmbH
PHP Secure Communications Library

phpseclib - PHP Secure Communications Library Supporting phpseclib Become a backer or sponsor on Patreon One-time donation via PayPal or crypto-curren

null 4.9k Jan 7, 2023
PHP Secure Headers

Secure Headers Add security related headers to HTTP response. The package includes Service Providers for easy Laravel integration. Version Installatio

null 431 Dec 26, 2022
A multitool library offering access to recommended security related libraries, standardised implementations of security defences, and secure implementations of commonly performed tasks.

SecurityMultiTool A multitool library offering access to recommended security related libraries, standardised implementations of security defences, an

Pádraic Brady 131 Oct 30, 2022
Quickly and easily secure HTML text.

Larasane Quickly sanitize text into safe-HTML using fluid methods. Requirements PHP 7.4, 8.0 or later. Laravel 7.x, 8.x or later. Installation Just fi

Italo 40 Jul 20, 2021
Secure API Toolkit

Sapient: Secure API toolkit Sapient secures your PHP applications' server-to-server HTTP(S) traffic even in the wake of a TLS security breakdown (comp

Paragon Initiative Enterprises 315 Jan 3, 2023
Create cryptographically secure pseudo-random numbers, and manage big integers

laminas-math This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steering

Laminas Project 23 Nov 24, 2022
PHPIDS (PHP-Intrusion Detection System) is a simple to use, well structured, fast and state-of-the-art security layer for your PHP based web application

PHPIDS PHPIDS (PHP-Intrusion Detection System) is a simple to use, well structured, fast and state-of-the-art security layer for your PHP based web ap

null 752 Jan 3, 2023
php-chmod is a PHP library for easily changing permissions recursively.

PHP chmod php-chmod is a PHP library for easily changing the permissions recursively. Versions & Dependencies Version PHP Documentation ^1.1 ^7.4 curr

Mathias Reker ⚡️ 5 Oct 7, 2022
PHP 5.x support for random_bytes() and random_int()

random_compat PHP 5.x polyfill for random_bytes() and random_int() created and maintained by Paragon Initiative Enterprises. Although this library sho

Paragon Initiative Enterprises 8k Jan 5, 2023
Simple Encryption in PHP.

php-encryption composer require defuse/php-encryption This is a library for encrypting data with a key or password in PHP. It requires PHP 5.6 or new

Taylor Hornby 3.6k Jan 3, 2023
Standards compliant HTML filter written in PHP

HTML Purifier HTML Purifier is an HTML filtering solution that uses a unique combination of robust whitelists and aggressive parsing to ensure that no

Edward Z. Yang 2.7k Jan 5, 2023
A database of PHP security advisories

PHP Security Advisories Database The PHP Security Advisories Database references known security vulnerabilities in various PHP projects and libraries.

null 1.9k Dec 18, 2022
A php.ini scanner for best security practices

Scanner for PHP.ini The Iniscan is a tool designed to scan the given php.ini file for common security practices and report back results. Currently it

psec.io 1.5k Dec 5, 2022
🤖 Id obfuscation based on Knuth's multiplicative hashing method for PHP.

Optimus id transformation With this library, you can transform your internal id's to obfuscated integers based on Knuth's integer hash. It is similar

Jens Segers 1.2k Jan 2, 2023
㊙️ AntiXSS | Protection against Cross-site scripting (XSS) via PHP

㊙️ AntiXSS "Cross-site scripting (XSS) is a type of computer security vulnerability typically found in Web applications. XSS enables attackers to inje

Lars Moelleken 570 Dec 16, 2022
An experimental object oriented SSH api in PHP

PHP SSH (master) Provides an object-oriented wrapper for the php ssh2 extension. Requirements You need PHP version 5.3+ with the SSH2 extension. Insta

Antoine Hérault 355 Dec 6, 2022
TCrypto is a simple and flexible PHP 5.3+ in-memory key-value storage library

About TCrypto is a simple and flexible PHP 5.3+ in-memory key-value storage library. By default, a cookie will be used as a storage backend. TCrypto h

timoh 57 Dec 2, 2022
Fetches random integers from random.org instead of using PHP's PRNG implementation

TrulyRandom Composer-compatible library to interact with random.org's API in order to generate truly random lists of integers, sequences of integers,

Erik Wurzer 46 Nov 25, 2022
PHPGGC is a library of PHP unserialize() payloads along with a tool to generate them, from command line or programmatically.

PHPGGC: PHP Generic Gadget Chains PHPGGC is a library of unserialize() payloads along with a tool to generate them, from command line or programmatica

Ambionics Security 2.5k Jan 4, 2023