PHP Security Ryan Dunn Jason Pack. Outline PHP Overview PHP Overview Common Security Issues Common Security Issues Advanced Security Issues Advanced Security.

Slides:



Advertisements
Similar presentations
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
Advertisements

Page 1 PHP, HTML, STATE Achmad Arwan, S.Kom. Page 2 PHP ( PHP: Hypertext Preprocessor) A programming language devised by Rasmus Lerdorf in 1994 for building.
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
BY: ALBERTO CABEZAS 4/19/2010. INTRODUCTION: PHP is considered today as one of the most famous scripting languages. PHP is widely used as a general purpose.
Information Networking Security and Assurance Lab National Chung Cheng University The Ten Most Critical Web Application Security Vulnerabilities Ryan J.W.
Apache Tomcat Server – installation & use Server-side language-- use Java Server Pages Contrast Client-side languages HTML Forms Servers & Server-side.
How Clients and Servers Work Together. Objectives Learn about the interaction of clients and servers Explore the features and functions of Web servers.
Hypertext Transport Protocol CS Dick Steflik.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Chapter 6: Hostile Code Guide to Computer Network Security.
Web Page A page displayed by the browser. Website Collection of multiple web pages Web Browser: A software that displays web pages on client computer.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PHP Security.
Web technologies and programming cse hypermedia and multimedia technology Fanis Tsandilas April 3, 2007.
Web Hacking 1. Overview Why web HTTP Protocol HTTP Attacks 2.
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
Web Servers1-1 Web Servers Xingquan (Hill) Zhu
Security.NET Chapter 1. How Do Attacks Occur? Stages of attack Examples of attacker actions 1. FootprintRuns a port scan on the firewall 2. PenetrationExploits.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Principles of Computer Security: CompTIA Security + ® and Beyond, Third Edition © 2012 Principles of Computer Security: CompTIA Security+ ® and Beyond,
PHP Hypertext PreProcessor. Documentation Available SAMS books O’Reilly Books.
FTP (File Transfer Protocol) & Telnet
Web Application Access to Databases. Logistics Test 2: May 1 st (24 hours) Extra office hours: Friday 2:30 – 4:00 pm Tuesday May 5 th – you can review.
Ladd Van Tol Senior Software Engineer Security on the Web Part One - Vulnerabilities.
CSC 2720 Building Web Applications Getting and Setting HTTP Headers (With PHP Examples)
WebServer A Web server is a program that, using the client/server model and the World Wide Web's Hypertext Transfer Protocol (HTTP), serves the files that.
USING PERL FOR CGI PROGRAMMING
Dyalog’09. Overview of MildServer Morten Kromberg Dyalog’09 – Princeton, NJ.
Technical Review - PHP Jang Jaeseok. Overview Introduction  What is PHP?  History of PHP  What can do with PHP?  Advantages of PHP PHP syntax.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
School of Computing and Information Systems CS 371 Web Application Programming Security Avoiding and Preventing Attacks.
Website Development with PHP and MySQL Saving Data.
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflows can be triggered by inputs that are designed to execute code, or alter the way the program.
PHP Open source language for server-side scripting Works well with many databases (e.g., MySQL) Files end in.php,.php3 or.phtml Runs on all major platforms.
SQL INJECTIONS Presented By: Eloy Viteri. What is SQL Injection An SQL injection attack is executed when a web page allows users to enter text into a.
Building Secure Web Applications With ASP.Net MVC.
Web Database Programming Week 7 Session Management & Authentication.
Form Data Encoding GET – URL encoded POST – URL encoded
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
Security Issues with PHP  PHP installation  PHP programming Willa Zhu & Eugene Burger.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
5 th ed: Chapter 17 4 th ed: Chapter 21
Overview of Servlets and JSP
Writing secure Flex applications  MXML tags with security restrictions  Disabling viewSourceURL  Remove sensitive information from SWF files  Input.
Introduction to CGI PROG. CGI stands for Common Gateway Interface. CGI is a standard programming interface to Web servers that gives us a way to make.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0.
Web Programming with PHP (3) Superglobals, Form & File processing.
The Common Gateway Interface (CGI) Pat Morin COMP2405.
Web Database Programming Using PHP
PHP (Session 2) INFO 257 Supplement.
Building Secure ColdFusion Applications
Introduction to Dynamic Web Programming
HTTP – An overview.
World Wide Web policy.
Web Database Programming Using PHP
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
PHP / MySQL Introduction
PHP: Security issues FdSc Module 109 Server side scripting and
PHP Forms and Databases.
Presentation transcript:

PHP Security Ryan Dunn Jason Pack

Outline PHP Overview PHP Overview Common Security Issues Common Security Issues Advanced Security Issues Advanced Security Issues Easiest Ways to Secure PHP? Easiest Ways to Secure PHP? Examples Examples

PHP Overview Originally designed as a small set of Perl scripts by Rasmus Lerdorf in 1994 Originally designed as a small set of Perl scripts by Rasmus Lerdorf in 1994 PHP is now a server-side, HTML-embedded, cross-platform scripting language PHP is now a server-side, HTML-embedded, cross-platform scripting language The most deployed server-side scripting language, running on around 9 of the 37 million domains in a April 2002 Netcraft survey. The most deployed server-side scripting language, running on around 9 of the 37 million domains in a April 2002 Netcraft survey. PHP's own figures show PHP usage (measured on a per-domain basis) growing at around 5% per month. PHP's own figures show PHP usage (measured on a per-domain basis) growing at around 5% per month.

PHP Popularity

PHP Security Overview PHP interpreter has potential to access the entire host PHP interpreter has potential to access the entire host By default, PHP makes all variables globally accessible by name, including session variables and cookies By default, PHP makes all variables globally accessible by name, including session variables and cookies

Common Security Issues GET vs. POST GET vs. POST Buffer Overflows Buffer Overflows SQL Injections SQL Injections Disabling PHP Error Messages Disabling PHP Error Messages Validating the Session Validating the Session Included Files Extension Included Files Extension Comments in HTML Source Comments in HTML Source

GET vs. POST (1) GET – data is passed by appending the variable/value pair to the URL GET – data is passed by appending the variable/value pair to the URL Truncated after 8,192 charactersTruncated after 8,192 characters Even SSL will not encrypt dataEven SSL will not encrypt data Raw HTTP Transmission: Raw HTTP Transmission: GET HTTP/1.0 Accept: image/gif, image/x-xbitmap, image/jpeg, */* Accept-Language: en-us User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461) Host: Connection: keep-alive

GET vs. POST (2) POST – variables sent in body of URL request POST – variables sent in body of URL request No size limitNo size limit SSL will encrypt the dataSSL will encrypt the data

GET vs. POST (3) POST Raw HTTP Transmission: POST Raw HTTP Transmission: POST /process.php HTTP/1.0 Accept: image/gif, image/x-xbitmap, image/jpeg, */* Accept-Language: en-us Content-Type: application/x-www-form-urlencoded User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461) Host: Content-Length: 94 Pragma: no-cache Connection: keep-alive yourname=fred+smith comment=I+have+no+comment

Buffer Overflows No runtime memory allocation No runtime memory allocation No pointers No pointers Thus, no buffer overflows created by PHP code Thus, no buffer overflows created by PHP code Overflows limited to PHP interpreter and its extensions Overflows limited to PHP interpreter and its extensions Stay on top of PHP updates to avoid issues Stay on top of PHP updates to avoid issues

SQL Injections PHP programmers often take user input directly to construct SQL queries PHP programmers often take user input directly to construct SQL queries Malicious users can exploit this by entering “; malicious SQL code” in the $username field Malicious users can exploit this by entering “; malicious SQL code” in the $username field mysql_db_query ($DB, "SELECT something FROM table WHERE name=$username");

Disabling PHP Error Messages By default, PHP will dump error messages to the client’s browser By default, PHP will dump error messages to the client’s browser Error messages can contain sensitive information Error messages can contain sensitive information

Validating the Session Store status variables as session variable or a cookie Store status variables as session variable or a cookie Session variables are less likely to be compromised since they are stored on the server Session variables are less likely to be compromised since they are stored on the server

Included Files Extension A common PHP practice is to name included files with the ‘.inc’ extension A common PHP practice is to name included files with the ‘.inc’ extension Malicious users can access the entire file’s content through a direct reference in the URL Malicious users can access the entire file’s content through a direct reference in the URL Apache does not know to encode ‘.inc’ files even though they are PHP scripts, so it displays it in plain text Apache does not know to encode ‘.inc’ files even though they are PHP scripts, so it displays it in plain text

Comments in HTML Source Commenting code is important, but beginning PHP programmers may put sensitive information in their comments for debugging purposes Commenting code is important, but beginning PHP programmers may put sensitive information in their comments for debugging purposes If placed improperly these comments could be output in HTML source code If placed improperly these comments could be output in HTML source code

Advanced Security Issues Superglobals Superglobals Encrypted Scripting Encrypted Scripting Safe Mode Safe Mode

Superglobals (1) Superglobals are pre-defined arrays that store variable/value pairs Superglobals are pre-defined arrays that store variable/value pairs There are 9 different arrays There are 9 different arrays $_GET[…] $_SERVER[…]$_GET[…] $_SERVER[…] $_POST[…]$_FILES[…]$_POST[…]$_FILES[…] $_COOKIE[…]$_ENV[…]$_COOKIE[…]$_ENV[…] $_REQUEST[…]$_SESSION[…]$_REQUEST[…]$_SESSION[…] $_GLOBAL[…]$_GLOBAL[…]

Superglobals (2) Superglobals are useful because you know the value in the variable was obtained from a specific source Superglobals are useful because you know the value in the variable was obtained from a specific source For Example:For Example: $_POST[username] $_POST[username] vs. vs. $username $username

Encrypted Scripting It is possible to sniff the packets exchanged between the browser and the server It is possible to sniff the packets exchanged between the browser and the server PHP provides no method to encrypt the transmission of the data (but the data itself can be encrypted) PHP provides no method to encrypt the transmission of the data (but the data itself can be encrypted) Installing SSL on Apache allows your transmission to be encrypted Installing SSL on Apache allows your transmission to be encrypted

Safe Mode PHP safe mode makes it so that it can only execute scripts in a restricted environment PHP safe mode makes it so that it can only execute scripts in a restricted environment Execution of scripts is restricted to defined directoriesExecution of scripts is restricted to defined directories Scripts cannot call programs outside defined directoriesScripts cannot call programs outside defined directories Provides “damage control” if application is compromised Provides “damage control” if application is compromised

Easiest Ways to Secure PHP? Never trust user input! Never trust user input! Look beyond application’s intended use Look beyond application’s intended use Stay current on PHP updates/syntax Stay current on PHP updates/syntax Be aware of PHP’s scope Be aware of PHP’s scope NEVER TRUST USER INPUT!!! NEVER TRUST USER INPUT!!!

References & / & /