SlideShare a Scribd company logo
1 of 63
Download to read offline
AVOIDING THE OWASP
                             Top 10 security exploits




Friday, 2 November, 12
ME


                  Illustrator turned developer

                  Team Lead at FreshBooks

                  Lead developer of CakePHP

                  PHP developer for 7 years



Friday, 2 November, 12
SECURITY




Friday, 2 November, 12
SECURITY CONTINUUM




               (
           unusable
                                         )
                                       unrestricted




Friday, 2 November, 12
OWASP
                         Open Web Application Security Project




Friday, 2 November, 12
OWASP TOP 10




Friday, 2 November, 12
1
Friday, 2 November, 12
                         SQL INJECTION
                           ‘ OR 1=1 ‘--
RISKS



                  Permits query manipulation, and arbitrary SQL.

                  Bad guys can re-write your queries.




Friday, 2 November, 12
SQL INJECTION EXAMPLE

               $username = $_POST[‘username’];
               $password = $_POST[‘password’];

               $query = “SELECT * FROM user
                  WHERE username = ‘$username’
                  AND password = ‘$password’”;


               $user = $db->query($query);
Friday, 2 November, 12
USER INPUT

      $username = “root”;
      $password = “‘ OR 1 = 1 --”;




Friday, 2 November, 12
FINAL QUERY


   $query = “SELECT * FROM user
      WHERE username = ‘root’
      AND password = ‘‘ OR 1 = 1 --’”;




Friday, 2 November, 12
FINAL QUERY


   $query = “SELECT * FROM user
      WHERE username = ‘root’
      AND password = ‘‘ OR 1 = 1 --’”;




Friday, 2 November, 12
PREVENTION

                  Use an ORM or Database abstraction layer that
                  provides escaping. Doctrine, ZendTable, and
                  CakePHP all do this.

                  Use PDO and prepared statements.

                  Never put user data into a query.

                  Never use regular expressions, magic quotes, or
                  addslashes()


Friday, 2 November, 12
EXAMPLE (PDO)

                $query = “SELECT * FROM user
                   WHERE username = ?
                   AND password = ?”;

                $stmt = $db->prepare($query);
                $stmt->bindValue($username);
                $stmt->bindValue($password);
                $result = $db->execute();

Friday, 2 November, 12
2
Friday, 2 November, 12
                                            XSS
                         <script>alert(‘cross site scripting’);</script>
RISKS



                  Allows bad guys to do things as the person viewing a
                  page.

                  Steal identities, passwords, credit cards, hijack pages
                  and more.




Friday, 2 November, 12
XSS EXAMPLE



        <p>
         <?php echo $user[‘bio’]; ?>
        </p>




Friday, 2 November, 12
XSS EXAMPLE



        <p>
         <?php echo $user[‘bio’]; ?>
        </p>




Friday, 2 November, 12
You may be thinking, I can use regular expressions
                                 to fix this.




Friday, 2 November, 12
NO
Friday, 2 November, 12
PREVENTION



                  Regular expressions and strip_tags leave you
                  vulnerable.

                  The only solution is output encoding.




Friday, 2 November, 12
EXAMPLE

        <p>
         <?php echo htmlentities(
          $user[‘bio’],
          ENT_QUOTES,
          ‘UTF-8’
         ); ?>
        </p>


Friday, 2 November, 12
DANGERS


                  Manually encoding is error prone, and you will make
                  a mistake.

                  Using a template library like Twig that provides auto-
                  escaping reduces the chances of screwing up.

                  Encoding is dependent on context.



Friday, 2 November, 12
3             BROKEN AUTHENTICATION
                 & SESSION MANAGEMENT




Friday, 2 November, 12
                         /index.php?PHPSESSID=pwned
RISKS



                  Identity theft.

                  Firesheep was an excellent example.




Friday, 2 November, 12
SESSION FIXATION EXAMPLE

   <?php
   session_start();
   if (isset($_GET[‘sessionid’]) {
     session_id($_GET[‘sessionid’]);
   }




Friday, 2 November, 12
SESSION FIXATION EXAMPLE

   <?php
   session_start();
   if (isset($_GET[‘sessionid’]) {
     session_id($_GET[‘sessionid’]);
   }




Friday, 2 November, 12
PREVENTION


                  Rotate session identifiers upon login/logout

                  Set the HttpOnly flag on session cookies.

                  Use well tested / mature libraries for authentication.

                  SSL is always a good idea.



Friday, 2 November, 12
4                 INSECURE DIRECT OBJECT




Friday, 2 November, 12
                          REFERENCE
RISKS



                  Bad guys can access information they shouldn’t

                  Bad guys can modify data they shouldn’t.




Friday, 2 November, 12
BROKEN PASSWORD UPDATE

      <form action=”/user/update” method=”post”>
       <input type=”hidden” name=”userid” value=”4654” />
       <input type=”text” name=”new_password” />
       <button type=”submit”>Save</button>
      </form>




Friday, 2 November, 12
PREVENTION

                  Remember hidden inputs are not really hidden, and
                  can be changed by users.

                  Validate access to all things, don’t depend on things
                  being hidden/invisible.

                  If you need to refer to the current user, use session
                  data not form inputs.

                  Whitelist properties any form can update.


Friday, 2 November, 12
5
Friday, 2 November, 12
                         CROSS SITE REQUEST
                             FORGERY
                                (CSRF)
RISKS


                  Evil websites can perform actions for users logged
                  into your site.

                  Side effects on GET can be performed via images or
                  CSS files.

                  Remember the Gmail contact hack.



Friday, 2 November, 12
CSRF EXAMPLE


                  Your app


                                            Evil site




Friday, 2 November, 12
CSRF EXAMPLE


                  Your app


                                                Evil site

                         Login




Friday, 2 November, 12
CSRF EXAMPLE


                  Your app


                                                         Evil site

                         Login

                                    Accidentally visit

Friday, 2 November, 12
CSRF EXAMPLE


                  Your app         Submit form for evil


                                                          Evil site

                         Login

                                    Accidentally visit

Friday, 2 November, 12
PREVENTION



                  Add opaque expiring tokens to all forms.

                  Requests missing tokens or containing invalid tokens
                  should be rejected.




Friday, 2 November, 12
SAMPLE CSRF VALIDATION

    <?php
    if (!$this->validCsrfToken($data, ‘csrf’)) {
      throw new ForbiddenException();
    }




Friday, 2 November, 12
6
Friday, 2 November, 12
                             SECURITY
                         MISCONFIGURATION
RISKS



                  Default settings can be insecure, and intended for
                  development not production.

                  Attackers can use misconfigured software to gain
                  knowledge and access.




Friday, 2 November, 12
PREVENTION


                  Know the tools you use, and configure them
                  correctly.

                  Keep up to date on vulnerabilities in the tools you
                  use.

                  Remove/disable any services/features you aren’t using.



Friday, 2 November, 12
7             INSECURE CRYPTOGRAPHIC




Friday, 2 November, 12
                       STORAGE
                         md5(‘password’)
RISKS


                  Weak cryptographic storage can easily be cracked.

                  Keys can be exposed with encrypted data.

                  Backups can contain encrypted data & keys.

                  Compromised passwords can be used to obtain
                  information on other sites.



Friday, 2 November, 12
BAD PASSWORD HASHING



                  $password;

                  md5($password);

                  sha1($password);




Friday, 2 November, 12
BAD PASSWORD HASHING



                  $password;

                  md5($password);

                  sha1($password);




Friday, 2 November, 12
USE BCRYPT FOR
                           PASSWORDS
                         only you can prevent bad hashing




Friday, 2 November, 12
PREVENTION

                  Use strong hashing/encryption.

                  Use one way hashing for passwords. Never use
                  symmetric encryption for passwords.

                  Don’t collect data if you don’t need it.

                  Keep keys separate from data.

                  If you’re using symmetric encryption, be able to
                  rotate keys easily.

Friday, 2 November, 12
BCRYPT IN PHP

   // password hashing (bcrypt)
   $hashed = crypt(
    $pass,
    ‘$2a$10$asdkbisloqi.fidsliz.df190.d9f40’);

   // compare later
   $hashed = crypt($plaintext, $storedHash);

   // check for match
   $hashed === $storedHash


Friday, 2 November, 12
BCRYPT IN PHP

   // password hashing (bcrypt)
   $hashed = crypt(
    $pass,
    ‘$2a$10$asdkbisloqi.fidsliz.df190.d9f40’);

   // compare later
   $hashed = crypt($plaintext, $storedHash);

   // check for match
   $hashed === $storedHash


Friday, 2 November, 12
BCRYPT IN PHP

   // password hashing (bcrypt)
   $hashed = crypt(
    $pass,
    ‘$2a$10$asdkbisloqi.fidsliz.df190.d9f40’);

   // compare later
   $hashed = crypt($plaintext, $storedHash);

   // check for match
   $hashed === $storedHash


Friday, 2 November, 12
BCRYPT IN PHP

   // password hashing (bcrypt)
   $hashed = crypt(
    $pass,
    ‘$2a$10$asdkbisloqi.fidsliz.df190.d9f40’);

   // compare later
   $hashed = crypt($plaintext, $storedHash);

   // check for match
   $hashed === $storedHash


Friday, 2 November, 12
USE MCRYPT

  // encrypt (rijndael)
  $value = mcrypt_encrypt(
   ‘rijndael-256’,
   $secretKey, $ccnumber,‘cbc’, $iv
  );

  // decrypt
  $value = mcrypt_decrypt(
   ‘rijndael-256’,
   $secretKey, $encrypted,‘cbc’, $iv
  );

Friday, 2 November, 12
8                  FAILURE TO RESTRICT URL




Friday, 2 November, 12
                              ACCESS
RISK



                  Hidden things can easily be found.

                  Creative people will eventually find your hidden URLs

                  Security through obscurity is a terrible idea.




Friday, 2 November, 12
PREVENTION



                  Check access to all urls both when you generate
                  links and more importantly when handling requests.

                  Don’t rely on things staying hidden.




Friday, 2 November, 12
9              INSUFFICIENT TRANSPORT




Friday, 2 November, 12
                       LAYER PROTECTION
SSL/TLS
Friday, 2 November, 12
10              UNVALIDATED REDIRECTS &




Friday, 2 November, 12
                      FORWARDS
RISKS



                  Trusting user input for redirects opens phishing
                  attacks.

                  Breach of trust with your users.




Friday, 2 November, 12
PREVENTION




                  Don’t trust user data when handling redirects.




Friday, 2 November, 12
QUESTIONS?




Friday, 2 November, 12

More Related Content

What's hot

Practical django secuirty
Practical django secuirtyPractical django secuirty
Practical django secuirtyAndy Dai
 
2009 Barcamp Nashville Web Security 101
2009 Barcamp Nashville   Web Security 1012009 Barcamp Nashville   Web Security 101
2009 Barcamp Nashville Web Security 101brian_dailey
 
2013 05-03 - HTML5 & JavaScript Security
2013 05-03 -  HTML5 & JavaScript Security2013 05-03 -  HTML5 & JavaScript Security
2013 05-03 - HTML5 & JavaScript SecurityJohannes Hoppe
 
Django Web Application Security
Django Web Application SecurityDjango Web Application Security
Django Web Application Securitylevigross
 
PHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnPHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnSandro Zaccarini
 
Code obfuscation, php shells & more
Code obfuscation, php shells & moreCode obfuscation, php shells & more
Code obfuscation, php shells & moreMattias Geniar
 
Php web backdoor obfuscation
Php web backdoor obfuscationPhp web backdoor obfuscation
Php web backdoor obfuscationSandro Zaccarini
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php SecurityDave Ross
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Supporting Debian machines for friends and family
Supporting Debian machines for friends and familySupporting Debian machines for friends and family
Supporting Debian machines for friends and familyFrancois Marier
 
Easy logins for Ruby web applications
Easy logins for Ruby web applicationsEasy logins for Ruby web applications
Easy logins for Ruby web applicationsFrancois Marier
 
How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2Michał Kruczek
 
How to work with legacy code
How to work with legacy codeHow to work with legacy code
How to work with legacy codeMichał Kruczek
 
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013Michelangelo van Dam
 
Art of Web Backdoor - Pichaya Morimoto
Art of Web Backdoor - Pichaya MorimotoArt of Web Backdoor - Pichaya Morimoto
Art of Web Backdoor - Pichaya MorimotoPichaya Morimoto
 
주로사용되는 Xss필터와 이를 공격하는 방법
주로사용되는 Xss필터와 이를 공격하는 방법주로사용되는 Xss필터와 이를 공격하는 방법
주로사용되는 Xss필터와 이를 공격하는 방법guestad13b55
 

What's hot (20)

Practical django secuirty
Practical django secuirtyPractical django secuirty
Practical django secuirty
 
2009 Barcamp Nashville Web Security 101
2009 Barcamp Nashville   Web Security 1012009 Barcamp Nashville   Web Security 101
2009 Barcamp Nashville Web Security 101
 
2013 05-03 - HTML5 & JavaScript Security
2013 05-03 -  HTML5 & JavaScript Security2013 05-03 -  HTML5 & JavaScript Security
2013 05-03 - HTML5 & JavaScript Security
 
Django Web Application Security
Django Web Application SecurityDjango Web Application Security
Django Web Application Security
 
PHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnPHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vuln
 
Code obfuscation, php shells & more
Code obfuscation, php shells & moreCode obfuscation, php shells & more
Code obfuscation, php shells & more
 
Php web backdoor obfuscation
Php web backdoor obfuscationPhp web backdoor obfuscation
Php web backdoor obfuscation
 
Web Security
Web SecurityWeb Security
Web Security
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php Security
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Supporting Debian machines for friends and family
Supporting Debian machines for friends and familySupporting Debian machines for friends and family
Supporting Debian machines for friends and family
 
Easy logins for Ruby web applications
Easy logins for Ruby web applicationsEasy logins for Ruby web applications
Easy logins for Ruby web applications
 
How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2
 
How to work with legacy code
How to work with legacy codeHow to work with legacy code
How to work with legacy code
 
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
 
Art of Web Backdoor - Pichaya Morimoto
Art of Web Backdoor - Pichaya MorimotoArt of Web Backdoor - Pichaya Morimoto
Art of Web Backdoor - Pichaya Morimoto
 
Building Advanced XSS Vectors
Building Advanced XSS VectorsBuilding Advanced XSS Vectors
Building Advanced XSS Vectors
 
주로사용되는 Xss필터와 이를 공격하는 방법
주로사용되는 Xss필터와 이를 공격하는 방법주로사용되는 Xss필터와 이를 공격하는 방법
주로사용되는 Xss필터와 이를 공격하는 방법
 
URL to HTML
URL to HTMLURL to HTML
URL to HTML
 

Similar to Owasp top 10

Building Sencha Themes
Building Sencha ThemesBuilding Sencha Themes
Building Sencha ThemesSencha
 
Active Record Introduction - 3
Active Record Introduction - 3Active Record Introduction - 3
Active Record Introduction - 3Blazing Cloud
 
Introduction to Twig
Introduction to TwigIntroduction to Twig
Introduction to Twigmarkstory
 
Building Data Driven Products With Ruby - RubyConf 2012
Building Data Driven Products With Ruby - RubyConf 2012Building Data Driven Products With Ruby - RubyConf 2012
Building Data Driven Products With Ruby - RubyConf 2012Ryan Weald
 
Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Matt Aimonetti
 
PHP Server-side Breakout
PHP Server-side BreakoutPHP Server-side Breakout
PHP Server-side BreakoutSencha
 
Modern HTML & CSS Coding: Speed, Semantics & Structure
Modern HTML & CSS Coding: Speed, Semantics & StructureModern HTML & CSS Coding: Speed, Semantics & Structure
Modern HTML & CSS Coding: Speed, Semantics & StructureRaven Tools
 
YAML is the new Eval
YAML is the new EvalYAML is the new Eval
YAML is the new Evalarnebrasseur
 
Writing Secure Plugins — WordCamp New York 2009
Writing Secure Plugins — WordCamp New York 2009Writing Secure Plugins — WordCamp New York 2009
Writing Secure Plugins — WordCamp New York 2009Mark Jaquith
 

Similar to Owasp top 10 (10)

Building Sencha Themes
Building Sencha ThemesBuilding Sencha Themes
Building Sencha Themes
 
2013 - Mark story - Avoiding the Owasp
2013 - Mark story - Avoiding the Owasp2013 - Mark story - Avoiding the Owasp
2013 - Mark story - Avoiding the Owasp
 
Active Record Introduction - 3
Active Record Introduction - 3Active Record Introduction - 3
Active Record Introduction - 3
 
Introduction to Twig
Introduction to TwigIntroduction to Twig
Introduction to Twig
 
Building Data Driven Products With Ruby - RubyConf 2012
Building Data Driven Products With Ruby - RubyConf 2012Building Data Driven Products With Ruby - RubyConf 2012
Building Data Driven Products With Ruby - RubyConf 2012
 
Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010
 
PHP Server-side Breakout
PHP Server-side BreakoutPHP Server-side Breakout
PHP Server-side Breakout
 
Modern HTML & CSS Coding: Speed, Semantics & Structure
Modern HTML & CSS Coding: Speed, Semantics & StructureModern HTML & CSS Coding: Speed, Semantics & Structure
Modern HTML & CSS Coding: Speed, Semantics & Structure
 
YAML is the new Eval
YAML is the new EvalYAML is the new Eval
YAML is the new Eval
 
Writing Secure Plugins — WordCamp New York 2009
Writing Secure Plugins — WordCamp New York 2009Writing Secure Plugins — WordCamp New York 2009
Writing Secure Plugins — WordCamp New York 2009
 

More from markstory

Dependency injection in CakePHP
Dependency injection in CakePHPDependency injection in CakePHP
Dependency injection in CakePHPmarkstory
 
Safer, More Helpful CakePHP
Safer, More Helpful CakePHPSafer, More Helpful CakePHP
Safer, More Helpful CakePHPmarkstory
 
CakePHP - The Road Ahead
CakePHP - The Road AheadCakePHP - The Road Ahead
CakePHP - The Road Aheadmarkstory
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHPmarkstory
 
CakePHP mistakes made 2015
CakePHP mistakes made 2015CakePHP mistakes made 2015
CakePHP mistakes made 2015markstory
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3markstory
 
CakePHP 3.0 and beyond
CakePHP 3.0 and beyondCakePHP 3.0 and beyond
CakePHP 3.0 and beyondmarkstory
 
CakePHP mistakes made confoo 2015
CakePHP mistakes made confoo 2015CakePHP mistakes made confoo 2015
CakePHP mistakes made confoo 2015markstory
 
CakePHP mistakes made
CakePHP mistakes madeCakePHP mistakes made
CakePHP mistakes mademarkstory
 
Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014markstory
 
Road to CakePHP 3.0
Road to CakePHP 3.0Road to CakePHP 3.0
Road to CakePHP 3.0markstory
 
Performance and optimization
Performance and optimizationPerformance and optimization
Performance and optimizationmarkstory
 
CakePHP the yum & yuck
CakePHP the yum & yuckCakePHP the yum & yuck
CakePHP the yum & yuckmarkstory
 
Simple search with elastic search
Simple search with elastic searchSimple search with elastic search
Simple search with elastic searchmarkstory
 
Intro to continuous integration
Intro to continuous integration Intro to continuous integration
Intro to continuous integration markstory
 
Evented applications with RabbitMQ and CakePHP
Evented applications with RabbitMQ and CakePHPEvented applications with RabbitMQ and CakePHP
Evented applications with RabbitMQ and CakePHPmarkstory
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2markstory
 
PHPunit and you
PHPunit and youPHPunit and you
PHPunit and youmarkstory
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testingmarkstory
 

More from markstory (20)

Dependency injection in CakePHP
Dependency injection in CakePHPDependency injection in CakePHP
Dependency injection in CakePHP
 
Safer, More Helpful CakePHP
Safer, More Helpful CakePHPSafer, More Helpful CakePHP
Safer, More Helpful CakePHP
 
CakePHP - The Road Ahead
CakePHP - The Road AheadCakePHP - The Road Ahead
CakePHP - The Road Ahead
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
CakePHP mistakes made 2015
CakePHP mistakes made 2015CakePHP mistakes made 2015
CakePHP mistakes made 2015
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
 
PHP WTF
PHP WTFPHP WTF
PHP WTF
 
CakePHP 3.0 and beyond
CakePHP 3.0 and beyondCakePHP 3.0 and beyond
CakePHP 3.0 and beyond
 
CakePHP mistakes made confoo 2015
CakePHP mistakes made confoo 2015CakePHP mistakes made confoo 2015
CakePHP mistakes made confoo 2015
 
CakePHP mistakes made
CakePHP mistakes madeCakePHP mistakes made
CakePHP mistakes made
 
Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014Performance and optimization CakeFest 2014
Performance and optimization CakeFest 2014
 
Road to CakePHP 3.0
Road to CakePHP 3.0Road to CakePHP 3.0
Road to CakePHP 3.0
 
Performance and optimization
Performance and optimizationPerformance and optimization
Performance and optimization
 
CakePHP the yum & yuck
CakePHP the yum & yuckCakePHP the yum & yuck
CakePHP the yum & yuck
 
Simple search with elastic search
Simple search with elastic searchSimple search with elastic search
Simple search with elastic search
 
Intro to continuous integration
Intro to continuous integration Intro to continuous integration
Intro to continuous integration
 
Evented applications with RabbitMQ and CakePHP
Evented applications with RabbitMQ and CakePHPEvented applications with RabbitMQ and CakePHP
Evented applications with RabbitMQ and CakePHP
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2
 
PHPunit and you
PHPunit and youPHPunit and you
PHPunit and you
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testing
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 

Recently uploaded (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 

Owasp top 10

  • 1. AVOIDING THE OWASP Top 10 security exploits Friday, 2 November, 12
  • 2. ME Illustrator turned developer Team Lead at FreshBooks Lead developer of CakePHP PHP developer for 7 years Friday, 2 November, 12
  • 4. SECURITY CONTINUUM ( unusable ) unrestricted Friday, 2 November, 12
  • 5. OWASP Open Web Application Security Project Friday, 2 November, 12
  • 6. OWASP TOP 10 Friday, 2 November, 12
  • 7. 1 Friday, 2 November, 12 SQL INJECTION ‘ OR 1=1 ‘--
  • 8. RISKS Permits query manipulation, and arbitrary SQL. Bad guys can re-write your queries. Friday, 2 November, 12
  • 9. SQL INJECTION EXAMPLE $username = $_POST[‘username’]; $password = $_POST[‘password’]; $query = “SELECT * FROM user WHERE username = ‘$username’ AND password = ‘$password’”; $user = $db->query($query); Friday, 2 November, 12
  • 10. USER INPUT $username = “root”; $password = “‘ OR 1 = 1 --”; Friday, 2 November, 12
  • 11. FINAL QUERY $query = “SELECT * FROM user WHERE username = ‘root’ AND password = ‘‘ OR 1 = 1 --’”; Friday, 2 November, 12
  • 12. FINAL QUERY $query = “SELECT * FROM user WHERE username = ‘root’ AND password = ‘‘ OR 1 = 1 --’”; Friday, 2 November, 12
  • 13. PREVENTION Use an ORM or Database abstraction layer that provides escaping. Doctrine, ZendTable, and CakePHP all do this. Use PDO and prepared statements. Never put user data into a query. Never use regular expressions, magic quotes, or addslashes() Friday, 2 November, 12
  • 14. EXAMPLE (PDO) $query = “SELECT * FROM user WHERE username = ? AND password = ?”; $stmt = $db->prepare($query); $stmt->bindValue($username); $stmt->bindValue($password); $result = $db->execute(); Friday, 2 November, 12
  • 15. 2 Friday, 2 November, 12 XSS <script>alert(‘cross site scripting’);</script>
  • 16. RISKS Allows bad guys to do things as the person viewing a page. Steal identities, passwords, credit cards, hijack pages and more. Friday, 2 November, 12
  • 17. XSS EXAMPLE <p> <?php echo $user[‘bio’]; ?> </p> Friday, 2 November, 12
  • 18. XSS EXAMPLE <p> <?php echo $user[‘bio’]; ?> </p> Friday, 2 November, 12
  • 19. You may be thinking, I can use regular expressions to fix this. Friday, 2 November, 12
  • 21. PREVENTION Regular expressions and strip_tags leave you vulnerable. The only solution is output encoding. Friday, 2 November, 12
  • 22. EXAMPLE <p> <?php echo htmlentities( $user[‘bio’], ENT_QUOTES, ‘UTF-8’ ); ?> </p> Friday, 2 November, 12
  • 23. DANGERS Manually encoding is error prone, and you will make a mistake. Using a template library like Twig that provides auto- escaping reduces the chances of screwing up. Encoding is dependent on context. Friday, 2 November, 12
  • 24. 3 BROKEN AUTHENTICATION & SESSION MANAGEMENT Friday, 2 November, 12 /index.php?PHPSESSID=pwned
  • 25. RISKS Identity theft. Firesheep was an excellent example. Friday, 2 November, 12
  • 26. SESSION FIXATION EXAMPLE <?php session_start(); if (isset($_GET[‘sessionid’]) { session_id($_GET[‘sessionid’]); } Friday, 2 November, 12
  • 27. SESSION FIXATION EXAMPLE <?php session_start(); if (isset($_GET[‘sessionid’]) { session_id($_GET[‘sessionid’]); } Friday, 2 November, 12
  • 28. PREVENTION Rotate session identifiers upon login/logout Set the HttpOnly flag on session cookies. Use well tested / mature libraries for authentication. SSL is always a good idea. Friday, 2 November, 12
  • 29. 4 INSECURE DIRECT OBJECT Friday, 2 November, 12 REFERENCE
  • 30. RISKS Bad guys can access information they shouldn’t Bad guys can modify data they shouldn’t. Friday, 2 November, 12
  • 31. BROKEN PASSWORD UPDATE <form action=”/user/update” method=”post”> <input type=”hidden” name=”userid” value=”4654” /> <input type=”text” name=”new_password” /> <button type=”submit”>Save</button> </form> Friday, 2 November, 12
  • 32. PREVENTION Remember hidden inputs are not really hidden, and can be changed by users. Validate access to all things, don’t depend on things being hidden/invisible. If you need to refer to the current user, use session data not form inputs. Whitelist properties any form can update. Friday, 2 November, 12
  • 33. 5 Friday, 2 November, 12 CROSS SITE REQUEST FORGERY (CSRF)
  • 34. RISKS Evil websites can perform actions for users logged into your site. Side effects on GET can be performed via images or CSS files. Remember the Gmail contact hack. Friday, 2 November, 12
  • 35. CSRF EXAMPLE Your app Evil site Friday, 2 November, 12
  • 36. CSRF EXAMPLE Your app Evil site Login Friday, 2 November, 12
  • 37. CSRF EXAMPLE Your app Evil site Login Accidentally visit Friday, 2 November, 12
  • 38. CSRF EXAMPLE Your app Submit form for evil Evil site Login Accidentally visit Friday, 2 November, 12
  • 39. PREVENTION Add opaque expiring tokens to all forms. Requests missing tokens or containing invalid tokens should be rejected. Friday, 2 November, 12
  • 40. SAMPLE CSRF VALIDATION <?php if (!$this->validCsrfToken($data, ‘csrf’)) { throw new ForbiddenException(); } Friday, 2 November, 12
  • 41. 6 Friday, 2 November, 12 SECURITY MISCONFIGURATION
  • 42. RISKS Default settings can be insecure, and intended for development not production. Attackers can use misconfigured software to gain knowledge and access. Friday, 2 November, 12
  • 43. PREVENTION Know the tools you use, and configure them correctly. Keep up to date on vulnerabilities in the tools you use. Remove/disable any services/features you aren’t using. Friday, 2 November, 12
  • 44. 7 INSECURE CRYPTOGRAPHIC Friday, 2 November, 12 STORAGE md5(‘password’)
  • 45. RISKS Weak cryptographic storage can easily be cracked. Keys can be exposed with encrypted data. Backups can contain encrypted data & keys. Compromised passwords can be used to obtain information on other sites. Friday, 2 November, 12
  • 46. BAD PASSWORD HASHING $password; md5($password); sha1($password); Friday, 2 November, 12
  • 47. BAD PASSWORD HASHING $password; md5($password); sha1($password); Friday, 2 November, 12
  • 48. USE BCRYPT FOR PASSWORDS only you can prevent bad hashing Friday, 2 November, 12
  • 49. PREVENTION Use strong hashing/encryption. Use one way hashing for passwords. Never use symmetric encryption for passwords. Don’t collect data if you don’t need it. Keep keys separate from data. If you’re using symmetric encryption, be able to rotate keys easily. Friday, 2 November, 12
  • 50. BCRYPT IN PHP // password hashing (bcrypt) $hashed = crypt( $pass, ‘$2a$10$asdkbisloqi.fidsliz.df190.d9f40’); // compare later $hashed = crypt($plaintext, $storedHash); // check for match $hashed === $storedHash Friday, 2 November, 12
  • 51. BCRYPT IN PHP // password hashing (bcrypt) $hashed = crypt( $pass, ‘$2a$10$asdkbisloqi.fidsliz.df190.d9f40’); // compare later $hashed = crypt($plaintext, $storedHash); // check for match $hashed === $storedHash Friday, 2 November, 12
  • 52. BCRYPT IN PHP // password hashing (bcrypt) $hashed = crypt( $pass, ‘$2a$10$asdkbisloqi.fidsliz.df190.d9f40’); // compare later $hashed = crypt($plaintext, $storedHash); // check for match $hashed === $storedHash Friday, 2 November, 12
  • 53. BCRYPT IN PHP // password hashing (bcrypt) $hashed = crypt( $pass, ‘$2a$10$asdkbisloqi.fidsliz.df190.d9f40’); // compare later $hashed = crypt($plaintext, $storedHash); // check for match $hashed === $storedHash Friday, 2 November, 12
  • 54. USE MCRYPT // encrypt (rijndael) $value = mcrypt_encrypt( ‘rijndael-256’, $secretKey, $ccnumber,‘cbc’, $iv ); // decrypt $value = mcrypt_decrypt( ‘rijndael-256’, $secretKey, $encrypted,‘cbc’, $iv ); Friday, 2 November, 12
  • 55. 8 FAILURE TO RESTRICT URL Friday, 2 November, 12 ACCESS
  • 56. RISK Hidden things can easily be found. Creative people will eventually find your hidden URLs Security through obscurity is a terrible idea. Friday, 2 November, 12
  • 57. PREVENTION Check access to all urls both when you generate links and more importantly when handling requests. Don’t rely on things staying hidden. Friday, 2 November, 12
  • 58. 9 INSUFFICIENT TRANSPORT Friday, 2 November, 12 LAYER PROTECTION
  • 60. 10 UNVALIDATED REDIRECTS & Friday, 2 November, 12 FORWARDS
  • 61. RISKS Trusting user input for redirects opens phishing attacks. Breach of trust with your users. Friday, 2 November, 12
  • 62. PREVENTION Don’t trust user data when handling redirects. Friday, 2 November, 12