SlideShare uma empresa Scribd logo
1 de 28
Securing Apache and PHP

    Justin Mayhue and Christopher Pau
Motivation
●   Via LAMP (Linux, Apache, MySQL, and
    PHP) web hosts have a popular, free
    OS/software solution
●   According to Netcraft, over 47% of
    webservers use the Apache as of October
    2007
●   Popularity makes for an easy target, as
    oftentimes configurations are not well
    thought-out
Who should be concerned?
●   Webmasters – installation of scripts
    (permissions errors: chmod 777? 755?)
●   Web Developers – creating software for
    various configurations (what is enabled?
    Disabled?)
●   Web Hosts – security of their server and
    possible abuse
●   Average Users – where is their data saved?
    Who can access it? How is it secured?
Background: Apache
●   Free, open-source, Unix-based webserver
    software available for Linux, Mac OSX,
    Windows, and other platforms
●   Design features revolve around modules
    used to control, interpret, and deliver web
    content to clients
●   Supports virtual hosting – multiple users can
    host independent sites on the same server
    platform
Background: PHP
●   PHP (PHP: Hypertext Processor) is a
    scripting language aimed at creating dynamic
    content
●   Like Apache, it is free, open-source software
    available for a variety of operating systems
●   Works with Apache to filter user input and
    provide content for Apache to serve back to
    the users
Theory: CGI Binaries
●   CGI (Common Gateway Interface) is a
    protocol for exchanging information between
    a server and an external application
●   Under this protocol, the external application
    is run upon each request (i.e., a new process
    is created), and this application closes after
    delivering output to the server
●   PHP was originally designed to run as a set
    of CGI binaries
●   #!/usr/local/bin/php
Theory: Apache Modules
●   Rather than creating an instance of a
    process for every request, Apache provides
    functionality for persistent modules to run
●   These modules can handle certain types of
    requests indefinitely without terminating
●   PHP has been adapted to run as an Apache
    module, as well, and was used this way in
    the Web Security lab
Apache Module vs. CGI Binaries
●   Which is optimal for running PHP?
●   PHP as an Apache module yields speed
      Only one instance of PHP, the module itself,
      needs to be running at one time
      Resources such as dedicated connections to a
      MySQL database can be preserved across
      sessions
●   Also, this allows PHP to be configured via
    .htaccess directives – an Apache-specific
    function
Apache Module vs. CGI Binaries

 Apache                    Apache

            Worker - PHP              Worker - CGI   PHP


            Worker - PHP              Worker - CGI   PHP


            Worker - PHP              Worker - CGI   PHP


            Worker - PHP              Worker - CGI   PHP




 Database and              Database and
 other resources           other resources
Apache Module vs. CGI Binaries
●   However, Apache runs as a separate user,
    inheriting permissions of “nobody” -- thus all
    resources PHP uses must be accessible to
    “nobody” as well
●   PHP as a CGI binary favors security
      CGI binaries can interface with an Apache
      module (such as suEXEC or suPHP) to run as a
      separate user
      This allows separate permissions for multiple
      users and multiple resource needs in a shared
      hosting environment
Apache Module vs. CGI Binaries
User: apache (nobody)                  With suEXEC or suPHP
     Apache                   Apache
                                                        User: file owner
               Worker - PHP              Worker - CGI       PHP


               Worker - PHP              Worker - CGI       PHP


               Worker - PHP              Worker - CGI       PHP


               Worker - PHP              Worker - CGI       PHP




    Database and              Database and
    other resources           other resources
Apache Module vs. CGI Binaries
                                  With suEXEC or suPHP
  Apache                            Apache
                                     User secureddata.com chroot

       /path/to/SecuredData.com         /path/to/SecuredData.com
                                     User hackworld.com chroot

       /path/to/HackWorld.com           /path/to/HackWorld.com



  /etc/passwd                      /etc/passwd
       World Readable r - x

Edit anything writeable r w x     Locked per user directory
PHP Safe Mode
●   As an alternative to running PHP as a CGI
    binary for increased permissions security,
    PHP provides the Safe Mode configuration
●   Provides user permissions security
●   Places limitations on the file structure PHP
    can access (PHP fopen)
●   Can disable the use of certain potentially
    vulnerable functions
PHP Safe Mode
●   However, such restrictions are considered
    “architecturally incorrect” -- PHP itself is
    blocking and manipulating its own normal
    operation
●   Can easily be bypassed if functions are
    allowed to execute on command line
      exec(“cat stuff >> /etc/passwd”)
●   Will not be included in future versions PHP 6
    and beyond
●   Still, frequently used by many hosts
Alternative Solutions:
              ModSecurity
●   ModSecurity is an Apache module designed
    as a web application firewall
●   Operates at application layer
      Protocol-level firewalls used in routers and
      gateway-level machines usually filter traffic
      based on source and destination
      ModSecurity is generally used to filter traffic
      based upon the contents – including both the
      headers and payload data
●   Rules-based, applied before sending traffic to
    handling application or module
Alternative Solutions:
            ModSecurity
Default rules block
   ● Protocol violations
   ● Protocol anomalies

   ● Request Limits

   ● Http Policy

   ● Bad Robots

   ● Generic Attacks

   ● Trojans

   ● Outbound Connections
Alternative Solution: Suhosin
     and PHP-Hardening Patch
●   Provides a third-party alternative to manual
    configuration solutions previously discussed
●   Protects against known vulnerabilities such
    as buffer overflows, as well as PHP core
    vulnerabilities that could potentially be
    exploited
●   Similar in concept to libsafe and other patch-
    based protection schemes
In the Lab
●   Part I: Analyze PHP as an Apache module
    and Safe Mode as a security option

●   Part II: Analyze PHP as a CGI binary and
    suPHP as a flexibility extension

●   Part III: Explore mod_security as an
    application-layer firewall solution to security
    exploits
Part I: Apache Module
●   PHP is already installed in lab as an Apache
    module from Web Security lab
●   grabfile.php and newfile.php: test PHP's
    permissions for reading, writing, and
    modifying files
Part I: Apache Module
●   Permission issue example: separate user,
    ftpuser, attempting to modify an example file
    written by PHP/Apache
Part I: Safe Mode
●   Safe Mode is then enabled via php.ini, and
    the tests repeated, as well as including
    remote scripts in PHP files
Part II: PHP as a CGI Binary
●   Apache is then installed as a CGI binary, and
    http.conf is modified accordingly
●   The tests are then repeated – still runs as
    “nobody” user
Part II: suPHP
●   suPHP is then installed, and tests run again
●   In this case, scripts are set to run as their
    owner, thus ftpuser can modify file created by
    its own scripts
Part III: ModSecurity
  ●   mod_security is then installed, and a few
      example rules are given
  ●   A number of previous exploits are then
      attempted, and the results examined
SecRule REQUEST_FILENAME|ARGS “SELECT COUNT”
“deny,log,auditlog,status:400,msg:’SELECT COUNT query denied’
Conclusions


●   PHP run as an Apache module and as a CGI
    binary both have benefits and drawbacks

●   Specific implementation depends upon the
    needs of the host, and of the webmasters
    using the host
Conclusions

●   Companies and individuals should be familiar
    with the global platform and configuration of
    their chosen hosts

●   Especially in shared hosting environments,
    users may not have the option of changing
    their configuration at will
Conclusions
●   Hosts should be aware of the pros and cons
    of the hosting configuration(s) they offer, and
    be prepared to deal with updates

●   For instance, PHP as an Apache module
    running in safe mode is very prevalent, but
    will soon be phased out – hosts must deal
    with this change
Questions?

Mais conteúdo relacionado

Mais procurados

FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101Rami Sayar
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshopAdam Culp
 
A Look at Command Line Swift
A Look at Command Line SwiftA Look at Command Line Swift
A Look at Command Line SwiftJoshuaKaplan22
 
Ninja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for BeginnersNinja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for BeginnersChang W. Doh
 
Development and deployment with composer and kite
Development and deployment with composer and kiteDevelopment and deployment with composer and kite
Development and deployment with composer and kiteChristian Opitz
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architectureElizabeth Smith
 
Introduction to webprogramming using PHP and MySQL
Introduction to webprogramming using PHP and MySQLIntroduction to webprogramming using PHP and MySQL
Introduction to webprogramming using PHP and MySQLanand raj
 
Cache in Chromium: Disk Cache
Cache in Chromium: Disk CacheCache in Chromium: Disk Cache
Cache in Chromium: Disk CacheChang W. Doh
 
OpenCms Days 2016: Next generation content repository
OpenCms Days 2016: Next generation content repository OpenCms Days 2016: Next generation content repository
OpenCms Days 2016: Next generation content repository Alkacon Software GmbH & Co. KG
 

Mais procurados (14)

FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Composer
ComposerComposer
Composer
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshop
 
A Look at Command Line Swift
A Look at Command Line SwiftA Look at Command Line Swift
A Look at Command Line Swift
 
Php
PhpPhp
Php
 
Ninja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for BeginnersNinja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for Beginners
 
Development and deployment with composer and kite
Development and deployment with composer and kiteDevelopment and deployment with composer and kite
Development and deployment with composer and kite
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architecture
 
Introduction to webprogramming using PHP and MySQL
Introduction to webprogramming using PHP and MySQLIntroduction to webprogramming using PHP and MySQL
Introduction to webprogramming using PHP and MySQL
 
Cache in Chromium: Disk Cache
Cache in Chromium: Disk CacheCache in Chromium: Disk Cache
Cache in Chromium: Disk Cache
 
OpenCms Days 2016: Next generation content repository
OpenCms Days 2016: Next generation content repository OpenCms Days 2016: Next generation content repository
OpenCms Days 2016: Next generation content repository
 
Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?
 
Node.js Course 2 of 2 - Advanced techniques
Node.js Course 2 of 2 - Advanced techniquesNode.js Course 2 of 2 - Advanced techniques
Node.js Course 2 of 2 - Advanced techniques
 

Semelhante a Download It

Information on PHP Handlers
Information on PHP HandlersInformation on PHP Handlers
Information on PHP HandlersHTS Hosting
 
Learn PHP Lacture1
Learn PHP Lacture1Learn PHP Lacture1
Learn PHP Lacture1ADARSH BHATT
 
Apache2 BootCamp : Understanding Apache Internals
Apache2 BootCamp : Understanding Apache InternalsApache2 BootCamp : Understanding Apache Internals
Apache2 BootCamp : Understanding Apache InternalsWildan Maulana
 
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...Ontico
 
Php through the eyes of a hoster confoo
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confooCombell NV
 
Linux advanced concepts - Part 2
Linux advanced concepts - Part 2Linux advanced concepts - Part 2
Linux advanced concepts - Part 2NAILBITER
 
Escalando php e drupal- performance ao infinito e além! - DrupalCamp SP 2015
Escalando php e drupal- performance ao infinito e além! - DrupalCamp SP 2015Escalando php e drupal- performance ao infinito e além! - DrupalCamp SP 2015
Escalando php e drupal- performance ao infinito e além! - DrupalCamp SP 2015Handrus Nogueira
 
DrupalCamp SP 2015 - Escalando PHP e Drupal- Performance ao infinito e além!
DrupalCamp SP 2015 -  Escalando PHP e Drupal- Performance ao infinito e além!DrupalCamp SP 2015 -  Escalando PHP e Drupal- Performance ao infinito e além!
DrupalCamp SP 2015 - Escalando PHP e Drupal- Performance ao infinito e além!Taller Negócio Digitais
 
Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015
Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015
Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015Handrus Nogueira
 
Tribal Nova Docker feedback
Tribal Nova Docker feedbackTribal Nova Docker feedback
Tribal Nova Docker feedbackNicolas Degardin
 
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012Blend Interactive
 

Semelhante a Download It (20)

How PHP works
How PHP works How PHP works
How PHP works
 
Secure PHP environment
Secure PHP environmentSecure PHP environment
Secure PHP environment
 
PHP Handlers
PHP HandlersPHP Handlers
PHP Handlers
 
Information on PHP Handlers
Information on PHP HandlersInformation on PHP Handlers
Information on PHP Handlers
 
Wc13
Wc13Wc13
Wc13
 
Learn PHP Lacture1
Learn PHP Lacture1Learn PHP Lacture1
Learn PHP Lacture1
 
Apache2 BootCamp : Understanding Apache Internals
Apache2 BootCamp : Understanding Apache InternalsApache2 BootCamp : Understanding Apache Internals
Apache2 BootCamp : Understanding Apache Internals
 
Php intro
Php introPhp intro
Php intro
 
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
Подталкиваем PHP к пределу возможностей, Michael Armstrong (lite speed techno...
 
Php through the eyes of a hoster confoo
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confoo
 
PHP {in}security
PHP {in}securityPHP {in}security
PHP {in}security
 
You Can Be an Open Source Library
You Can Be an Open Source LibraryYou Can Be an Open Source Library
You Can Be an Open Source Library
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
slides (PPT)
slides (PPT)slides (PPT)
slides (PPT)
 
Linux advanced concepts - Part 2
Linux advanced concepts - Part 2Linux advanced concepts - Part 2
Linux advanced concepts - Part 2
 
Escalando php e drupal- performance ao infinito e além! - DrupalCamp SP 2015
Escalando php e drupal- performance ao infinito e além! - DrupalCamp SP 2015Escalando php e drupal- performance ao infinito e além! - DrupalCamp SP 2015
Escalando php e drupal- performance ao infinito e além! - DrupalCamp SP 2015
 
DrupalCamp SP 2015 - Escalando PHP e Drupal- Performance ao infinito e além!
DrupalCamp SP 2015 -  Escalando PHP e Drupal- Performance ao infinito e além!DrupalCamp SP 2015 -  Escalando PHP e Drupal- Performance ao infinito e além!
DrupalCamp SP 2015 - Escalando PHP e Drupal- Performance ao infinito e além!
 
Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015
Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015
Escalando php e drupal- performance ao infinito e além! - Drupal camp sp 2015
 
Tribal Nova Docker feedback
Tribal Nova Docker feedbackTribal Nova Docker feedback
Tribal Nova Docker feedback
 
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012
"Building Modern PHP Applications" - Jackson Murtha, South Dakota Code Camp 2012
 

Mais de webhostingguy

Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Frameworkwebhostingguy
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guidewebhostingguy
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3webhostingguy
 
Load-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serversLoad-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serverswebhostingguy
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidationwebhostingguy
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreementwebhostingguy
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...webhostingguy
 
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...webhostingguy
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructurewebhostingguy
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.pptwebhostingguy
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy webhostingguy
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandiserswebhostingguy
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Productswebhostingguy
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mbwebhostingguy
 

Mais de webhostingguy (20)

File Upload
File UploadFile Upload
File Upload
 
Running and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test FrameworkRunning and Developing Tests with the Apache::Test Framework
Running and Developing Tests with the Apache::Test Framework
 
MySQL and memcached Guide
MySQL and memcached GuideMySQL and memcached Guide
MySQL and memcached Guide
 
Novell® iChain® 2.3
Novell® iChain® 2.3Novell® iChain® 2.3
Novell® iChain® 2.3
 
Load-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web serversLoad-balancing web servers Load-balancing web servers
Load-balancing web servers Load-balancing web servers
 
SQL Server 2008 Consolidation
SQL Server 2008 ConsolidationSQL Server 2008 Consolidation
SQL Server 2008 Consolidation
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
 
What is mod_perl?
What is mod_perl?What is mod_perl?
What is mod_perl?
 
Master Service Agreement
Master Service AgreementMaster Service Agreement
Master Service Agreement
 
Notes8
Notes8Notes8
Notes8
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...Dell Reference Architecture Guide Deploying Microsoft® SQL ...
Dell Reference Architecture Guide Deploying Microsoft® SQL ...
 
Managing Diverse IT Infrastructure
Managing Diverse IT InfrastructureManaging Diverse IT Infrastructure
Managing Diverse IT Infrastructure
 
Web design for business.ppt
Web design for business.pptWeb design for business.ppt
Web design for business.ppt
 
IT Power Management Strategy
IT Power Management Strategy IT Power Management Strategy
IT Power Management Strategy
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandisers
 
OLUG_xen.ppt
OLUG_xen.pptOLUG_xen.ppt
OLUG_xen.ppt
 
Parallels Hosting Products
Parallels Hosting ProductsParallels Hosting Products
Parallels Hosting Products
 
Microsoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 MbMicrosoft PowerPoint presentation 2.175 Mb
Microsoft PowerPoint presentation 2.175 Mb
 
Reseller's Guide
Reseller's GuideReseller's Guide
Reseller's Guide
 

Download It

  • 1. Securing Apache and PHP Justin Mayhue and Christopher Pau
  • 2. Motivation ● Via LAMP (Linux, Apache, MySQL, and PHP) web hosts have a popular, free OS/software solution ● According to Netcraft, over 47% of webservers use the Apache as of October 2007 ● Popularity makes for an easy target, as oftentimes configurations are not well thought-out
  • 3. Who should be concerned? ● Webmasters – installation of scripts (permissions errors: chmod 777? 755?) ● Web Developers – creating software for various configurations (what is enabled? Disabled?) ● Web Hosts – security of their server and possible abuse ● Average Users – where is their data saved? Who can access it? How is it secured?
  • 4. Background: Apache ● Free, open-source, Unix-based webserver software available for Linux, Mac OSX, Windows, and other platforms ● Design features revolve around modules used to control, interpret, and deliver web content to clients ● Supports virtual hosting – multiple users can host independent sites on the same server platform
  • 5. Background: PHP ● PHP (PHP: Hypertext Processor) is a scripting language aimed at creating dynamic content ● Like Apache, it is free, open-source software available for a variety of operating systems ● Works with Apache to filter user input and provide content for Apache to serve back to the users
  • 6. Theory: CGI Binaries ● CGI (Common Gateway Interface) is a protocol for exchanging information between a server and an external application ● Under this protocol, the external application is run upon each request (i.e., a new process is created), and this application closes after delivering output to the server ● PHP was originally designed to run as a set of CGI binaries ● #!/usr/local/bin/php
  • 7. Theory: Apache Modules ● Rather than creating an instance of a process for every request, Apache provides functionality for persistent modules to run ● These modules can handle certain types of requests indefinitely without terminating ● PHP has been adapted to run as an Apache module, as well, and was used this way in the Web Security lab
  • 8. Apache Module vs. CGI Binaries ● Which is optimal for running PHP? ● PHP as an Apache module yields speed Only one instance of PHP, the module itself, needs to be running at one time Resources such as dedicated connections to a MySQL database can be preserved across sessions ● Also, this allows PHP to be configured via .htaccess directives – an Apache-specific function
  • 9. Apache Module vs. CGI Binaries Apache Apache Worker - PHP Worker - CGI PHP Worker - PHP Worker - CGI PHP Worker - PHP Worker - CGI PHP Worker - PHP Worker - CGI PHP Database and Database and other resources other resources
  • 10. Apache Module vs. CGI Binaries ● However, Apache runs as a separate user, inheriting permissions of “nobody” -- thus all resources PHP uses must be accessible to “nobody” as well ● PHP as a CGI binary favors security CGI binaries can interface with an Apache module (such as suEXEC or suPHP) to run as a separate user This allows separate permissions for multiple users and multiple resource needs in a shared hosting environment
  • 11. Apache Module vs. CGI Binaries User: apache (nobody) With suEXEC or suPHP Apache Apache User: file owner Worker - PHP Worker - CGI PHP Worker - PHP Worker - CGI PHP Worker - PHP Worker - CGI PHP Worker - PHP Worker - CGI PHP Database and Database and other resources other resources
  • 12. Apache Module vs. CGI Binaries With suEXEC or suPHP Apache Apache User secureddata.com chroot /path/to/SecuredData.com /path/to/SecuredData.com User hackworld.com chroot /path/to/HackWorld.com /path/to/HackWorld.com /etc/passwd /etc/passwd World Readable r - x Edit anything writeable r w x Locked per user directory
  • 13. PHP Safe Mode ● As an alternative to running PHP as a CGI binary for increased permissions security, PHP provides the Safe Mode configuration ● Provides user permissions security ● Places limitations on the file structure PHP can access (PHP fopen) ● Can disable the use of certain potentially vulnerable functions
  • 14. PHP Safe Mode ● However, such restrictions are considered “architecturally incorrect” -- PHP itself is blocking and manipulating its own normal operation ● Can easily be bypassed if functions are allowed to execute on command line exec(“cat stuff >> /etc/passwd”) ● Will not be included in future versions PHP 6 and beyond ● Still, frequently used by many hosts
  • 15. Alternative Solutions: ModSecurity ● ModSecurity is an Apache module designed as a web application firewall ● Operates at application layer Protocol-level firewalls used in routers and gateway-level machines usually filter traffic based on source and destination ModSecurity is generally used to filter traffic based upon the contents – including both the headers and payload data ● Rules-based, applied before sending traffic to handling application or module
  • 16. Alternative Solutions: ModSecurity Default rules block ● Protocol violations ● Protocol anomalies ● Request Limits ● Http Policy ● Bad Robots ● Generic Attacks ● Trojans ● Outbound Connections
  • 17. Alternative Solution: Suhosin and PHP-Hardening Patch ● Provides a third-party alternative to manual configuration solutions previously discussed ● Protects against known vulnerabilities such as buffer overflows, as well as PHP core vulnerabilities that could potentially be exploited ● Similar in concept to libsafe and other patch- based protection schemes
  • 18. In the Lab ● Part I: Analyze PHP as an Apache module and Safe Mode as a security option ● Part II: Analyze PHP as a CGI binary and suPHP as a flexibility extension ● Part III: Explore mod_security as an application-layer firewall solution to security exploits
  • 19. Part I: Apache Module ● PHP is already installed in lab as an Apache module from Web Security lab ● grabfile.php and newfile.php: test PHP's permissions for reading, writing, and modifying files
  • 20. Part I: Apache Module ● Permission issue example: separate user, ftpuser, attempting to modify an example file written by PHP/Apache
  • 21. Part I: Safe Mode ● Safe Mode is then enabled via php.ini, and the tests repeated, as well as including remote scripts in PHP files
  • 22. Part II: PHP as a CGI Binary ● Apache is then installed as a CGI binary, and http.conf is modified accordingly ● The tests are then repeated – still runs as “nobody” user
  • 23. Part II: suPHP ● suPHP is then installed, and tests run again ● In this case, scripts are set to run as their owner, thus ftpuser can modify file created by its own scripts
  • 24. Part III: ModSecurity ● mod_security is then installed, and a few example rules are given ● A number of previous exploits are then attempted, and the results examined SecRule REQUEST_FILENAME|ARGS “SELECT COUNT” “deny,log,auditlog,status:400,msg:’SELECT COUNT query denied’
  • 25. Conclusions ● PHP run as an Apache module and as a CGI binary both have benefits and drawbacks ● Specific implementation depends upon the needs of the host, and of the webmasters using the host
  • 26. Conclusions ● Companies and individuals should be familiar with the global platform and configuration of their chosen hosts ● Especially in shared hosting environments, users may not have the option of changing their configuration at will
  • 27. Conclusions ● Hosts should be aware of the pros and cons of the hosting configuration(s) they offer, and be prepared to deal with updates ● For instance, PHP as an Apache module running in safe mode is very prevalent, but will soon be phased out – hosts must deal with this change