Secure PHP Coding Practices @jeffchannell
Why Should I Care? Loss of reputation (to you as a developer)
Financial Loss
Disclosure of Information
Damage to other sites
Basic Guidelines Trust Nothing Escape for the occasion
Understand different exploitation techniques
Who is this guy? Web developer with Anything Digital Security researcher
Discovered numerous vulnerabilities, primarily in Joomla! extensions
Common Vulnerability Types Information Disclosure
SQL Injection
Code Execution
Cross Site Scripting (XSS)
Cross Site Request Forgery (CSRF)
Information Disclosure Reveals non-public information
Cannot be used by itself to gain access
Useful to an attacker
Generally involves absolute paths to files (Path Disclosure)
Error reporting generally includes paths
MySQL errors
SQL Injection Caused by passing user-supplied input directly into an SQL query
Allows an attacker to alter the query
Does not always divulge information directly (known as “Blind Injection”)
SQL Injection – Example 1 $id  = JRequest::getVar( 'id' ); $query  =  'SELECT id, title FROM #__foobar WHERE id = '  .  $id ; $db  = JFactory::getDbo(); $db ->setQuery( $query ); $results  =  $db ->loadObject();
SQL Injection – Example 1 User input is concatenated with the query
SQL Injection – Example 1 User input is concatenated with the query
A malicious user can exploit this using the following request: index.php?option=com_foobar&id= 0 union select 1,2
SQL Injection – Example 1 User input is concatenated with the query
A malicious user can exploit this using the following request: index.php?option=com_foobar&id= 0 union select 1,2 This causes the query to become: SELECT id, title FROM #__foobar WHERE id =  0 union select 1,2
SQL Injection – Example 1 $id  = JRequest::get Int ( 'id' ); $query  =  'SELECT id, title FROM #__foobar WHERE id = '  .  $id ; $db  = JFactory::getDbo(); $db ->setQuery( $query ); $results  =  $db ->loadObject();
SQL Injection – Example 2 $title  = JRequest::getVar( 'title' ); $query  =  'SELECT id, title FROM #__foobar WHERE title = \''  .  $title  .  '\'' ; $db  = JFactory::getDbo(); $db ->setQuery( $query ); $results  =  $db ->loadObject();

Jeff Channell - Secure PHP Coding Practices