1 / 46

PHP: Security

PHP: Security. Agenda. Introduction to security concepts Authentication, digital certificates, authorization Review key components of the PHP environment Security considerations with PHP applications Security recommendations Security template Security configuration.

dearly
Télécharger la présentation

PHP: Security

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP: Security

  2. Agenda • Introduction to security concepts • Authentication, digital certificates, authorization • Review key components of the PHP environment • Security considerations with PHP applications • Security recommendations • Security template • Security configuration

  3. Introduction to Security Concepts

  4. Security Terminology • Authentication • A method for validating the identity of a client or server. • Client identity is commonly done using a user ID, user name, or client digital certificate. • Validation is usually proven via a password or certificate keys. • Authorization • A method of controlling access to data and objects. • Controlled based on the authenticating user. • Configured in the HTTP server and with native OS/400 objects. • Digital Certificate • An electronic object which identifies a unique client or a server. • Created by a trusted certificate authority (ex. Verisign). • Digital Certificate Manager • A GUI utility to manage digital certificates used by Web applications running on your System i.

  5. CREDIT CARD 1234 5678 9012 1234 5678 9012 VALID FROM GOOD THRU XX/XX/XX XX/XX/XX XX/XX/XX XX/XX/XX John Q Public Using SSL for HTTPS https - Encrypted Communication Capabilities • HTTPSecure - privacy between browser & server • Invoked with https:// protocol in URL • Requires HTTP Server registration with the system's DCM • Can be used with Optional or Required client authentication. • Needs a digital "Server" certificate • Requires Cryptographic Services on the iSeries • Enables use of iSeries's Secure Sockets Layer(SSL) • 5722-AC3 (not needed in V5R4) • Requires OS/400 - Digital Certificate Manager • Provides the ability to work with and manage digital certificate stores and registered applications. • (5722-SS1 option 34)

  6. State of Minnesota 5-8 F D E9 2005 BRN 137 2-14-70 Jane Q Public 123 Hickory ST Anywhere MN 12345 ~~~~ ~~~ 2-14-70 Client Certificate Authentication • Available only when SSL is configured. • When configured, the HTTP server requests a certificate from all clients requesting access over HTTPS. • Can authenticate by: • valid client certificates • certificates with specific DN information • certificates associated with user profiles • certificates within validation lists • A secure connection is established regardless of whether the client has a valid certificate.

  7. HTTP Server for i5/OS User Authentication Process http://company.com/private/page.html 1 Not Authorized (Error 401) 2 URL + User Name & Password 3 or URL + Client Digital Certificate or

  8. HTTP Server Security form: Authentication & Control Access Select the directory to secure in the Server area Under the Server Properties group, click Security

  9. Digital Certificate Manager GUI Now, it's time to use Digital Certificate Manager Select the *SYSTEM Certificate Store NOTE: A link to the DCM GUI can be found under the Related Links.

  10. Review Key Components of PHP Environment

  11. General Security Considerations for Default Environment • The installation of Zend Core creates the several IFS directories: • /www/zendcore/htdocs (to store PHP applications) • /www/zendcore/conf (for IBM HTTP Server config file) • /usr/local/Zend/apache2/conf (for Apache Server config file) • Everyone is able to store and run applications in htdocs directory. • Everyone is able to change the configuration files. • The default environment should not be used for PHP applications that require any level of security. • Use the default environment for prototyping, public applications, and applications using public data. • Once you have a PHP application that you need to secure, you must change the default configurations.

  12. Objects PHP Run-time Environment System i5 i5/OS PHP file URL: http://myproxy:89/core/registration.php i5/OS PASE Zend Core IBM HTTP Server (Reverse Proxy) Apache Server Request Response PHP Module HTML + PHP DB2 UDB Zend Platform Server instance name: ZENDCORE

  13. Generic Reverse Proxy Features • Improves performance • Can cache static documents in memory • Can aid with balancing requests to a set of HTTP servers • Improves security • Can control access at the front door • Can keep server in DMZ separate from internal network • Hides the content server environment • Can log activity • The reverse proxy used in the PHP environment does not realize many of these advantages.

  14. Comparison of the Two HTTP Servers

  15. Default Configuration: IBM HTTP Server (Reverse Proxy) • Server instance name is: ZENDCORE • Configuration file: /www/zendcore/conf/httpd.conf • Listens on port 89 • Only receives URL requests that are sent to that port • Only accepts requests for PHP applications with a URL of /www/zendcore/htdocs • Users are denied access if requesting any other directory/files/applications • Forwards on those requests to the Apache Server • Allows any user to make requests • All data flowing on the network between client and server is public

  16. Default Configuration: Apache Server • Listens on port 8000 • Only receives URL requests that are sent to that port • Configuration file: /usr/local/Zend/apache2/conf/httpd.conf • Only accepts requests coming from the localhost (IP address 127.0.0.1) • Allows any user to make these requests • All data flowing between the IBM HTTP Server (Reverse Proxy) and the Apache server is not encrypted • Starting and stopping this server must be done by a user with *SECOFR authority

  17. Default Configuration: PHP application • PHP applications run under the user profile NOBODY • NOBODY user profile • NOBODY user profile is created by Zend Core product install • NOBODY has *USER level access • NOBODY has no password so you cannot login with it • For objects, programs, and data that the PHP code accesses using the i5/OS PHP toolkit, you should specify the appropriate user and password during the initial connection. • Example: db2_connect(user, pwd, …) • PHP applications are not able to run as a specific user profile which would allow it to access only the data it has access to. • You cannot reconfigure this. All PHP apps run as NOBODY. • PHP application can do different things based on the user making the request.

  18. Conclusions about Security with the Default Environment • After installing Zend Core for i5/OS, placing a PHP application into /www/zendcore/htdocs allows all users to run the PHP application. • You should change/configure this when needed. • Any data sent or retrieved by the user could potentially be “seen” by others on the network. Conclusion: the default environment should not be used for PHP applications requiring any level of security.

  19. Security Recommendations

  20. Security Recommendations for i5/OS • Change the access to the HTTP server configuration files • /www/zendcore/conf/httpd.conf • /usr/local/Zend/apache2/conf/httpd.conf • Webmasters should have all access. • Change the access to the default directory path /www/zendcore/htdocs • For Developers: grant write authority • For Public (*PUBLIC): grant *EXCLUDE authority (they have write by default) • Do not store applications requiring access control in the default directory path • Store applications requiring similar access control in the same directory or subdirectory. Example: /www/zendcore/protected • New PHP application files that need to be secured should be created with the following access: • *PUBLIC *EXCLUDE and write authority for application developers • NOBODY read and/or execute

  21. Security Recommendations for IBM HTTP Server Configure ZENDCODE instance to control access to secure applications: • Configure it to require users to identify themselves (client authentication) • Configure it to determine if the authenticated user should be given access to the requested application (client authorization) • Configure it to use SSL to encrypt data that travels between the client user and the ZENDCODRE HTTP Server instance (server authentication) • This requires the IBM HTTP Server to have a server digital certificate. Some configuration is required with the Digital Certificate Manager. • Note: All data between the IBM HTTP Server and the Apache server is not encrypted. • Configure it by adding an alias to hide the real directory name where PHP applications exist and to shorten the URL length • Use an alias

  22. Security Recommendations for PHP Developers • Always use .php for the file extension for PHP application files. • Using other extensions causes the Apache server to send back the file source code rather than running the PHP application. • Always store backup copies of files in a separate directory from the directories that the IBM HTTP Server is configured to serve from. • Hackers often try to view PHP source code by requesting your PHP application using .BAK extension. • Always do input form validation to avoid SQL injection attacks. • When using user-supplied data as part of an SQL statement, you should check that the user-supplied value does not contain SQL escape characters. • SQL escape characters allow hackers to append their own SQL statements. • Read more on http://en.wikipedia.org/wiki/Sql_injection

  23. Security Recommendations for PHP Applications If your application needs to know the requesting user to perform user-specific operations, there are several methods: • PHP code can access the user name and password using server environment variables: PHP_AUTH_USER and PHP_AUTH_PW • echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>"; • echo "<p>Your password is {$_SERVER['PHP_AUTH_PW']} .</p>"; • www.php.net/manual/en/reserved.variables.php#reserved.variables.server • Use session support in PHP code to store user data needed by multiple subsequent URL invocations. • A user accessing your web site is assigned a unique id (or session id) which is stored in a cookie on the user side or is propagated in the URL. • http://www.php.net/manual/en/ref.session.php • PHP code can perform its own user authentication using standard HTTP header authentication mechanism. This requires manual Apache server configuration. • http://httpd.apache.org/docs/1.3/howto/auth.html • http://www.zend.com/manual/features.http-auth.php NOTE: When using the toolkit to access System i5 files, objects, and DB2, you can pass in a specific user name and password. • Ex. db2_connect(user, pwd, …………)

  24. Configuration Preparation

  25. System i Software Prerequisites (V5R4) • 5722-DG1 IBM HTTP Server for iSeries • Required to serve files and applications and to configure security. • 5722-SS1 Option 34 Digital Certificate Manager (DCM) • Required for creating and managing digital certificates for the HTTP server. • NOTE: If you support a Web server today, you will likely have both of these products installed and configured. • If not, installing the Zend product will install them for you.

  26. Security Roles • PHP application developer documents security recommendations for a PHP application. • System administrator installs the PHP application in IFS and secures the files in IFS. • Security is configured using IFS security features. • Web administrator configures security for the PHP application. • Security is configured on the IBM HTTP server.

  27. Security Template • Application name: _________________________________________ • Directory/file to protect: ____________________________________ • Alias name for URL: _______________________________________ • Allow secure connections (using SSL for encryption) • Optional (http and https allowed) • Forced (only https is allowed) • Never (only http is allowed) • Method of identification and authentication • OS/400 user profile (INTRANET, EXTRANET only) Text used when prompting for user name: ________________________________ • Client digital certificate • Internet user name • Store in validation list: ____________________________________ (library/vldl) • Store in LDAP directory • Limit access to a subset of authenticated users Groups allowed/not allowed: _______________________________________ Users allowed/not allowed: ________________________________________ IP addresses allowed/not allowed: __________________________________

  28. Security Configuration Steps

  29. Security Template • Application name: __________myphpinfo______________________ • Directory/file to protect: _____/www/zendcore/protected_________ • Alias name for URL: ________mysecurePHPapps_______________ • Allow secure connections (using SSL for encryption) • Optional (http and https allowed) • Forced (only https is allowed) • Never (only http is allowed) • Method of identification and authentication • OS/400 user profile (INTRANET, EXTRANET only) Text used when prompting for user name: ________________________________ • Client digital certificate • Internet user name • Store in validation list: __________myvldls/phpvldl____________ (library/vldl) • Store in LDAP directory • Limit access to a subset of authenticated users Groups allowed/not allowed: _______________________________________ Users allowed/not allowed: ________________________________________ IP addresses allowed/not allowed: __________________________________

  30. Native i5/OS Security Configuration • Create IFS directory for storing applications requiring security • Set authority for the directory and files • PUBLIC must be excluded in order • to protect the application • PHP developers need all access • NOBODY needs read and execute

  31. IBM HTTP Server Security Configuration • In a Web browser, bring up the i5/OS Tasks Page • http://hostname:2001 • Enter your Webmaster user profile and password 3. Click HTTP Servers 4. Select ZENDCORE - Apache 2. Click

  32. Add Directory to the Server 1. Click Add a Directory to the Web 2. Click Next 3. Select Static web pages and files 4. Enter Directory and click Next 5. Enter Alias and click Next, then Finish

  33. Secure the Directory: Authentication 1. Select the directory 2. Click Security 3. Select Internet users in validation list 4. Enter Authentication name 5. Enter Validation list

  34. Secure the Directory: Control Access 1. Select Control Access tab 2. Leave the defaults 3. Click OK

  35. Create Validation List and Internet User • If you aren’t using validation lists yet today, you can create one for testing. 1. Select Advanced tab 2. Select Internet Users 3. Click Add Internet User 4. Enter values, click Apply

  36. Enable Secure Transactions: Create Secure Port • Configure the server to allow SSL to be used for secure transactions. 1. Select Global configuration 2. Click General Server Configuration 3. Add new port number

  37. Enable Secure Transactions: Create Virtual Host 1. Click Virtual Hosts 2. Select IP-based tab 3. Add same secure port

  38. Enable Secure Transactions: Enable SSL 1. Select the Virtual Host 2. Click Security 3. Select SSL with Certificate Authentication 4. Select Enabled 5. Select the default application name

  39. Configuring Digital Certificates

  40. Go To Digital Certificate Manager (DCM) 1. Select Related Links 2. Select Digital Certificate Manager

  41. DCM: Select Certificate Store 1. Click Select a Certificate Store 2. Select *SYSTEM, then click Continue 3. Enter the password, then click Continue

  42. DCM: Select Server Application 1. Click Work with server applications 2. Select the ZENDCORE application name 3. Click Work with Application

  43. DCM: Assign Certificate to ZENDCORE 1. Click Update Certificate Assignment 2. Select the certificate 3. Click Assign New Certificate

  44. DCM: Trust Certificate Authority 1. Click Define CA Trust List 2. Select Trust All 3. Click OK

  45. Test the Security of the Application • Start and stop the ZENDCORE server instance • Request the application • https://hostname:9089/securePHPapps/secureInfo.php • Enter the user and password (in our example use a username and password stored in the validation list) • The application web page will then be displayed.

  46. Summary • Use the default PHP environment for prototyping, public applications, and applications using public data. • Once you have a PHP application that you need to secure, change the default HTTP Server configuration for the ZENDCORE instance. • Your Webmaster will use the same IBM Web Administration Tool to secure PHP applications using the same techniques used for securing other Web applications and files.

More Related