Transcript
Page 1: OWASP Top 10 at International PHP Conference 2014 in Berlin

Tobias Zander | @airbone42

OWASP Top 10

Page 2: OWASP Top 10 at International PHP Conference 2014 in Berlin
Page 3: OWASP Top 10 at International PHP Conference 2014 in Berlin

Current state of security

Page 4: OWASP Top 10 at International PHP Conference 2014 in Berlin

Open Web Application

Security Project

Page 5: OWASP Top 10 at International PHP Conference 2014 in Berlin

The Top 10 Most

Critical Web

Application Security

RisksNot just Vulnerabilities

Page 6: OWASP Top 10 at International PHP Conference 2014 in Berlin
Page 7: OWASP Top 10 at International PHP Conference 2014 in Berlin

http://xkcd.com/327/

Page 8: OWASP Top 10 at International PHP Conference 2014 in Berlin

Don‘t try this at home!

http://funfive.net/drop-database-license-plate/2670.html

Page 9: OWASP Top 10 at International PHP Conference 2014 in Berlin

Prepared Statements$stmt = $mysqli->prepare(

'UPDATE users

SET email = ?

WHERE id = 123'‚

);

$stmt->bind_param(

's',

$email

);

Page 10: OWASP Top 10 at International PHP Conference 2014 in Berlin

DBA

$q = Doctrine_Query::create()

->update('Account')

->set('email', '[email protected]')

->where(

'username LIKE ?',

$username

);

$username = 'A%';

Page 11: OWASP Top 10 at International PHP Conference 2014 in Berlin

Time-based

SELECT IF(

SUBSTRING(

user_password, 1, 1

) = CHAR(65),

BENCHMARK(

5000000,

ENCODE(‘foo', ‘bar')

),

null

)

FROM users

WHERE user_id = 1;

Page 12: OWASP Top 10 at International PHP Conference 2014 in Berlin

Injection

• Use prepared statements

• Or stored procedures

• Check for wildcards

www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet

Page 13: OWASP Top 10 at International PHP Conference 2014 in Berlin

eBay

https://twitter.com/kennwhite/status/470545973547397120/photo/1/large

Page 14: OWASP Top 10 at International PHP Conference 2014 in Berlin

Online-Banking Newsletter

Sollte Ihr Kennwort Sonderzeichen

enthalten, bitten wir Sie, Ihr Kennwort zu

ändern. Durch die technische Umstellung

auf das neue Online-Banking werden nur

noch Kennwörter zugelassen, die

bestimmte Sonderzeichen erlauben. Die

zugelassenen Sonderzeichen im

Kennwort lauten: # ? * + - .

Page 15: OWASP Top 10 at International PHP Conference 2014 in Berlin

Broken Authentication

• Don‘t limit password strength

• Force long and complex passwords

• Check error messages

• Prevent brute-force-attacks

www.owasp.org/index.php/Authentication_Cheat_Sheet

Page 16: OWASP Top 10 at International PHP Conference 2014 in Berlin

Session Hijacking

Session ID: abcde

Mr. Evil

Page 17: OWASP Top 10 at International PHP Conference 2014 in Berlin

Session Fixation

Mr. Evil

Lin

k

Predefined Session ID

Page 18: OWASP Top 10 at International PHP Conference 2014 in Berlin

Broken Session Management

session.use_trand_sid = Off

session.use_only_cookies = On

session.cookie_secure = On

session.cookie_httponly = On

session.hash_function = sha512

Page 19: OWASP Top 10 at International PHP Conference 2014 in Berlin

Broken Session Management

• Don‘t expose session ids

• Probably bind sessions to IP

• Reduce Session-Lifetime

• Regenerate Session-Ids

www.owasp.org/index.php/Session_Management_Cheat_Sheet

Page 20: OWASP Top 10 at International PHP Conference 2014 in Berlin
Page 21: OWASP Top 10 at International PHP Conference 2014 in Berlin

XSS

echo '<input

type="text"

name="foo"

value="' .

htmlspecialchars(

$string

ENT_QUOTES|

ENT_SUBSTITUTE|

ENT_DISALLOWED,

'UTF-8'

) .

'">';

Page 22: OWASP Top 10 at International PHP Conference 2014 in Berlin

XSS

$value = '</script>';

echo json_encode(

$value

);

Page 23: OWASP Top 10 at International PHP Conference 2014 in Berlin
Page 24: OWASP Top 10 at International PHP Conference 2014 in Berlin

XSS

• Escape output by context

– htmlspecialchars

– json_encode

– …

• Content-Security-Policy

• X-XSS-Protection

• Template engine

Page 25: OWASP Top 10 at International PHP Conference 2014 in Berlin

Insecure Object Reference

<select>

<option value="2">

moderator

</option>

<option value="3">

editor

</option>

</select>

Page 26: OWASP Top 10 at International PHP Conference 2014 in Berlin

Insecure Object Reference

<select>

<option value="random-ref-x">

moderator

</option>

<option value="random-ref-y">

editor

</option>

</select>

Page 27: OWASP Top 10 at International PHP Conference 2014 in Berlin

Insecure Object Reference

• Validate user input

• Use indirect object references

• Check access permissions

Page 28: OWASP Top 10 at International PHP Conference 2014 in Berlin

Security Misconfiguration

<Directory "/var/www">

AllowOverride All

</Directory>

memory_limit = 1024M

allow_url_fopen = On

allow_url_include = On

;open_basedir =

Page 29: OWASP Top 10 at International PHP Conference 2014 in Berlin

Security Misconfiguration

<Directory "/var/www">

AllowOverride None

Options -Indexes

</Directory>

memory_limit = 128M

log_errors = On

allow_url_fopen = Off

allow_url_include = Off

open_basedir = /var/www/app

Page 30: OWASP Top 10 at International PHP Conference 2014 in Berlin

Security Misconfiguration

• Keep your system up-to-date

• Remove setup/deployment routines

• Disable exposure of sensitive data

• Review server settings

• github.com/ioerror/duraconf

Page 31: OWASP Top 10 at International PHP Conference 2014 in Berlin

Fucking rainbow tableshttp://edwardhotspur.wordpress.com/tag/devil-bunny/

Page 32: OWASP Top 10 at International PHP Conference 2014 in Berlin

PHP 5.5

password_hash($password);

if (password_verify($password, $hash)) {

// Success!} else {

// Failed :(}

Page 33: OWASP Top 10 at International PHP Conference 2014 in Berlin

SSDE - Password encryption

• Add a salt

• Use different salts

• Use a strong algorithm (NOT md5)

• Use password_hash in PHP 5.5

• github.com/ircmaxell/password_compat

Page 34: OWASP Top 10 at International PHP Conference 2014 in Berlin

SSDE - PHP Exposureexpose_php Off

Remove

phpinfo();

Page 35: OWASP Top 10 at International PHP Conference 2014 in Berlin

SSDE - Secure URLs

• Use TLS for all pages

• Use Secure Cookie Flag

• Keep sensitive data out of the URL

Page 36: OWASP Top 10 at International PHP Conference 2014 in Berlin

class AdminController {

public function editAction() {

$this->model

->save($this->formData);

}

}

Page 37: OWASP Top 10 at International PHP Conference 2014 in Berlin

Missing Function Level AC

class AdminController {

public function editAction() {

if (!$this->_isAllowed()) {

throw new Exception(

'insufficient privileges'

);

}

Page 38: OWASP Top 10 at International PHP Conference 2014 in Berlin

Missing Function Level AC

• Standard should disallow all access

• Use roles to keep ACL simple

• ACL model should be very flexible

• Check privileges on each step

Page 39: OWASP Top 10 at International PHP Conference 2014 in Berlin

class BankaccountController {

public function transferAction() {

if ($this->_isAllowed()) {

$this->transfer(

$amount,

$account

);

}

}

}

Page 40: OWASP Top 10 at International PHP Conference 2014 in Berlin

Cross Site Request Forgery

Login / create session

Vis

itw

ebsite

Request a

pp…

… through victim‘s browser

evil.com

sensitive.com

Page 41: OWASP Top 10 at International PHP Conference 2014 in Berlin

CSRF

class BankaccountController {

public function transferAction() {

$this->validateToken();

if ($this->_isAllowed()) {

$this->transfer(

$amount,

$account

);

}

}

}

Page 42: OWASP Top 10 at International PHP Conference 2014 in Berlin

Infected

profile

TOKEN

My profile

Page 43: OWASP Top 10 at International PHP Conference 2014 in Berlin

Authenticate user

Page 44: OWASP Top 10 at International PHP Conference 2014 in Berlin

CSRF

• Use One-Time-Token and secure it

• Authenticate user

– Credentials

– Captcha

www.owasp.org/index.php/CSRF_Prevention_Cheat_Sheet

Page 45: OWASP Top 10 at International PHP Conference 2014 in Berlin
Page 46: OWASP Top 10 at International PHP Conference 2014 in Berlin
Page 47: OWASP Top 10 at International PHP Conference 2014 in Berlin

Known Vulnerabilities

• Review third party libraries

• Keep libraries up-to-date -

http://www.versioneye.com/

• Check:

– mailing lists

– boards

– news- and vendor-sites

Page 48: OWASP Top 10 at International PHP Conference 2014 in Berlin

Redirects and Forwards

Page 49: OWASP Top 10 at International PHP Conference 2014 in Berlin

Redirects and Forwards

$allowedDomains = array('good.com',

'better.com');

if (!in_array(

$url,

$allowedDomains

)) {

throw new Exception('invalid redirect');

}

$this->_redirectUrl($url);

Page 50: OWASP Top 10 at International PHP Conference 2014 in Berlin

http://www.lolhome.com/funny-picture-620770644.html

Page 51: OWASP Top 10 at International PHP Conference 2014 in Berlin

Improper Error Handling

Page 52: OWASP Top 10 at International PHP Conference 2014 in Berlin

DoS

Page 53: OWASP Top 10 at International PHP Conference 2014 in Berlin

Security by Obscurity

Page 54: OWASP Top 10 at International PHP Conference 2014 in Berlin

Insecure File Uploads

Page 55: OWASP Top 10 at International PHP Conference 2014 in Berlin

Malicious File

Execution

Page 56: OWASP Top 10 at International PHP Conference 2014 in Berlin

Mail Header Injection

Page 57: OWASP Top 10 at International PHP Conference 2014 in Berlin

Source Code

Revelation

Page 58: OWASP Top 10 at International PHP Conference 2014 in Berlin

Hardcoded

Credentials

Page 59: OWASP Top 10 at International PHP Conference 2014 in Berlin

Clickjacking

Page 60: OWASP Top 10 at International PHP Conference 2014 in Berlin

Buffer Overflows

Page 61: OWASP Top 10 at International PHP Conference 2014 in Berlin

XML External Entity

Page 62: OWASP Top 10 at International PHP Conference 2014 in Berlin

Perfect Pixel Timing

Page 63: OWASP Top 10 at International PHP Conference 2014 in Berlin

• OWASP Top 10

• CWE/SANS Top 25

• PCI DSS

• Zed Attack Proxy

• Metasploit

• WireShark

• BeEF

http://amzn.to/1vKNLqM

Page 64: OWASP Top 10 at International PHP Conference 2014 in Berlin

Trust noone!

www.owasp.org security.stackexchange.com

http://www.glittercats.com/image/30189/cute-cats-wallpapers-colorful-wallpaper

Page 65: OWASP Top 10 at International PHP Conference 2014 in Berlin

Tobias Zander | @airbone42

Questions?

Page 66: OWASP Top 10 at International PHP Conference 2014 in Berlin

Tobias Zander | @airbone42

Thanks!


Recommended