security theatre (php leuven)

159
Security Theatre @thomas_shone Image by Matt McGee released under CC BY-ND 2.0

Upload: xsist10

Post on 20-Jan-2017

148 views

Category:

Technology


1 download

TRANSCRIPT

Page 2: Security Theatre (PHP Leuven)

Booking.comW

E ARE HIRING

Work @ Booking: http://grnh.se/seomt7

Page 3: Security Theatre (PHP Leuven)

Illusion

Page 4: Security Theatre (PHP Leuven)

Denial

Page 5: Security Theatre (PHP Leuven)

I know about OWASP!

Page 6: Security Theatre (PHP Leuven)

If you are hacked via OWASP Top 10, you’re not allowed to call it “advanced” or “sophisticated”

@thegrugq

Reference: https://twitter.com/thegrugq/status/658991205816995840

Page 7: Security Theatre (PHP Leuven)

But I use antivirus!

Page 8: Security Theatre (PHP Leuven)

Crypting services makes most antivirus techniques useless

Reference: http://krebsonsecurity.com/2014/05/antivirus-is-dead-long-live-antivirus/

Page 9: Security Theatre (PHP Leuven)
Page 10: Security Theatre (PHP Leuven)

Let us put an unsecured node.js server on your personal

computer

TrendMicro Antivirus on WindowsJan 2016

https://code.google.com/p/google-security-research/issues/detail?id=693

Page 11: Security Theatre (PHP Leuven)

Remote code-executions via your mail client downloading an

email

Sophos AntivirusJune 2015

https://lock.cmpxchg8b.com/sophailv2.pdf

Page 12: Security Theatre (PHP Leuven)
Page 13: Security Theatre (PHP Leuven)

Internet of Things

Page 14: Security Theatre (PHP Leuven)
Page 15: Security Theatre (PHP Leuven)
Page 16: Security Theatre (PHP Leuven)

Reference: https://www.yahoo.com/tech/dutch-consumer-group-demands-samsung-151703102.html

Page 17: Security Theatre (PHP Leuven)

We’re all bad at security

Page 18: Security Theatre (PHP Leuven)

Users are bad at security

Page 19: Security Theatre (PHP Leuven)

Developers are bad at security

Reference: https://github.com/

Page 20: Security Theatre (PHP Leuven)

Hackers are bad at security

Page 21: Security Theatre (PHP Leuven)

A study in scarlet

Page 22: Security Theatre (PHP Leuven)

43 applications, libraries and frameworksover 4,800 versionsover 10 million files

Page 23: Security Theatre (PHP Leuven)

255,000 scansAbout 6k/month from June 2012 - Nov 2015

Page 24: Security Theatre (PHP Leuven)

ResultsJuly 2015

Page 25: Security Theatre (PHP Leuven)

Most popular softwareIt’s not what you think

Page 26: Security Theatre (PHP Leuven)
Page 27: Security Theatre (PHP Leuven)
Page 28: Security Theatre (PHP Leuven)
Page 29: Security Theatre (PHP Leuven)

How bad is it?

Page 30: Security Theatre (PHP Leuven)
Page 31: Security Theatre (PHP Leuven)
Page 32: Security Theatre (PHP Leuven)
Page 33: Security Theatre (PHP Leuven)

Why is it so bad?

Page 34: Security Theatre (PHP Leuven)
Page 35: Security Theatre (PHP Leuven)
Page 36: Security Theatre (PHP Leuven)
Page 37: Security Theatre (PHP Leuven)
Page 38: Security Theatre (PHP Leuven)
Page 39: Security Theatre (PHP Leuven)

I have seen thingsPh'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn

Page 40: Security Theatre (PHP Leuven)
Page 41: Security Theatre (PHP Leuven)

Versioning Hell1.3-final-beta6-pre-patch3

Page 42: Security Theatre (PHP Leuven)

OpenXBackdoored for almost a year

Page 43: Security Theatre (PHP Leuven)
Page 44: Security Theatre (PHP Leuven)

Lessons Learnt

Page 45: Security Theatre (PHP Leuven)

VersioningProjects with bad versioning also have some

of the worst security issues

Page 46: Security Theatre (PHP Leuven)

Automatic PatchingIf your software comes with automatic

upgrading, people will use it

Page 47: Security Theatre (PHP Leuven)

Plugins and TemplatesIf an update needs manual changes for

plugins or template, no one updates

Page 48: Security Theatre (PHP Leuven)

Patch Fatigue Exists

Image by Aaaron Jacobs released under CC BY-SA 2.0

Page 49: Security Theatre (PHP Leuven)

Anger

Image by Josh Janssen released under CC BY-ND 2.0

Page 50: Security Theatre (PHP Leuven)

Why doesn’t someone do something about it?

Page 51: Security Theatre (PHP Leuven)

Private industry keep threatening security researchers

Page 52: Security Theatre (PHP Leuven)

"How many Fortune 500 companies are hacked right now?

Answer, 500."Mikko Hypponen, CRO of F-Secure

Reference: https://twitter.com/mikko/status/184329161257652227

Page 53: Security Theatre (PHP Leuven)

Why don’t we have some form of standard?

Page 54: Security Theatre (PHP Leuven)

We have ISO 27001/2, ISO 15408, RFC 2196, PCI DSS, NIST, …

Reference: https://en.wikipedia.org/wiki/Cyber_security_standards

Page 55: Security Theatre (PHP Leuven)

Why doesn’t the government do something about it?

Page 56: Security Theatre (PHP Leuven)

A Ukrainian power plant was hacked & shutdown because

someone had macros enabled in Excel

Reference: https://t.co/PA7cDQC9EI

Page 57: Security Theatre (PHP Leuven)
Page 58: Security Theatre (PHP Leuven)

NSA: We’re just upgrading your megaflops, promise.

Page 59: Security Theatre (PHP Leuven)

Reference: https://t.co/PA7cDQC9EIImage by Unknown released into the Public Domain

Page 60: Security Theatre (PHP Leuven)

Bargaining

Image by Jeroen Moes released under CC BY-SA 2.0

Page 61: Security Theatre (PHP Leuven)

But what if we installed advanced IDSs, WAFs and

specialised network hardware

Page 62: Security Theatre (PHP Leuven)

We probably only knew about one of the two backdoors in our

system

Juniper NetworksDec 2015

http://www.wired.com/2015/12/juniper-networks-hidden-backdoors-show-the-risk-of-government-backdoors/

Page 63: Security Theatre (PHP Leuven)

IDSs produce reports. Managers likes reports: it helps them feel like they can "manage" security

http://security.stackexchange.com/questions/12164/how-effective-is-an-ids-at-catching-targeted-attacks

Page 64: Security Theatre (PHP Leuven)

We’ll start following prescribed security standards

Page 65: Security Theatre (PHP Leuven)

That’s great for your insurance premiums

Page 66: Security Theatre (PHP Leuven)

Depression

Page 67: Security Theatre (PHP Leuven)

Ninety percent of everything is crap.

Sturgeon's law

Reference: https://en.wikipedia.org/wiki/Sturgeon%27s_law

Page 68: Security Theatre (PHP Leuven)

Acceptance

Image by Stephan Brunet released under CC BY-SA 3.0

Page 69: Security Theatre (PHP Leuven)

Effective?

Page 70: Security Theatre (PHP Leuven)

Most of our security practices are ineffective

Page 71: Security Theatre (PHP Leuven)

We do security in isolation

Page 72: Security Theatre (PHP Leuven)

Holistic

Page 73: Security Theatre (PHP Leuven)

Hardware

Drivers

Services

Your Dependencies

Operating System

Your Software

Humans

Network / Internet

Area of Influence

Page 74: Security Theatre (PHP Leuven)

Drivers

Services

Operating System203.5M LoC

Area of Influence

Hardware

Disclaimer: Numbers generated using cloc (Service LoC limited to latest releases of MySQL, Apache and PHP)

Page 75: Security Theatre (PHP Leuven)

Operating SystemArea of Influence

Humans DNA7B LoC

Source: http://www.examiner.com/article/dna-the-ultimate-source-code

Page 76: Security Theatre (PHP Leuven)

Hardware

Drivers

Services

Your Dependencies

Operating System

Your Software

Humans

Network / Internet

HR/Training/LART device

System Administrators

Downstream Providers

Page 78: Security Theatre (PHP Leuven)

Image by Albert Bridge released under CC BY-SA 2.0

Surface Area

Page 80: Security Theatre (PHP Leuven)

Mitigation

Image by Pivari.com released under CC BY-SA 3.0

Page 81: Security Theatre (PHP Leuven)

Trust

Page 82: Security Theatre (PHP Leuven)

Trust?

Page 83: Security Theatre (PHP Leuven)

Be aware of what you’re trusting

Page 84: Security Theatre (PHP Leuven)

The hardest part of security is not writing

secure code

Page 85: Security Theatre (PHP Leuven)

It’s understanding where you misplace

your trust

Page 86: Security Theatre (PHP Leuven)

Trust is a chain

Page 87: Security Theatre (PHP Leuven)

I trust my computer is not compromised

Up-to-date patches

TRUST

Page 88: Security Theatre (PHP Leuven)

I trust that the software is without vulnerability

Vulnerability research and security updates

TRUST

Page 89: Security Theatre (PHP Leuven)

I trust that the software is configured properly

Automated provisioning

TRUST

Page 90: Security Theatre (PHP Leuven)

I trust that the network is configured properly and secure

Good system administrators

TRUST

Page 91: Security Theatre (PHP Leuven)

I trust you are who you say you are

TLS Certificate Peer Verification or Authentication

TRUST

Page 92: Security Theatre (PHP Leuven)

I trust you are allowed to talk to me about this topic

Authorization

TRUST

Page 93: Security Theatre (PHP Leuven)

I trust that what you send me hasn’t been tampered with

Hashes, CRCs or signatures

TRUST

Page 94: Security Theatre (PHP Leuven)

I trust that what we talk about is just between us

Public and private keys

TRUST

Page 95: Security Theatre (PHP Leuven)

I trust your computer is not compromised

????

TRUST

Page 96: Security Theatre (PHP Leuven)

I trust that what we talk about won’t be share with others

Contracts, Legalities, Terms of use, ????

TRUST

Page 97: Security Theatre (PHP Leuven)

I trust that the user won’t be the weak link

Training and procedures

TRUST

Page 98: Security Theatre (PHP Leuven)

Turn your chain into a mesh

Image by ineverfinishanyth released under CC BY-NC-SA 2.5

Page 99: Security Theatre (PHP Leuven)

Common Mistakes

Page 100: Security Theatre (PHP Leuven)

WeakeningCompromising encryption or hashing is

about reducing time to crack

Page 101: Security Theatre (PHP Leuven)

ImplementationA bad implementation helps reduce the time

to crack

Page 102: Security Theatre (PHP Leuven)

Authentication

Page 103: Security Theatre (PHP Leuven)

2 Factor Authenticationcomposer require pragmarx/google2fa

Page 104: Security Theatre (PHP Leuven)

OAuth2composer require league/oauth2-client

Page 105: Security Theatre (PHP Leuven)

Sessions

Page 106: Security Theatre (PHP Leuven)

Image by Wouter van Emmerik released under CC BY-SA 3.0

Never roll your own

Page 107: Security Theatre (PHP Leuven)

if (strstr($_SERVER['QUERY_STRING'],'session_to_unset') != false){ parse_str($_SERVER['QUERY_STRING']); session_write_close(); session_id($session_to_unset); session_start(); $_SESSION = array(); session_write_close(); session_destroy(); exit;}

MistakesDeep understanding of the language

CODE SAMPLE

Reference: http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-2505

Page 108: Security Theatre (PHP Leuven)

if (strstr($_SERVER['QUERY_STRING'],'session_to_unset') != false){ parse_str($_SERVER['QUERY_STRING']); session_write_close(); session_id($session_to_unset); session_start(); $_SESSION = array(); session_write_close(); session_destroy(); exit;}

MistakesDeep understanding of the language

CODE SAMPLE

Reference: http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-2505

Writes $_SESSION to disk

Page 109: Security Theatre (PHP Leuven)

if (strstr($_SERVER['QUERY_STRING'],'session_to_unset') != false){ parse_str($_SERVER['QUERY_STRING']); session_write_close(); session_id($session_to_unset); session_start(); $_SESSION = array(); session_write_close(); session_destroy(); exit;}

MistakesDeep understanding of the language

CODE SAMPLE

Extracts URL parameters into the namespace.

session_to_unset=a becomes $session_to_unset = “a”;

Reference: http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-2505

Page 110: Security Theatre (PHP Leuven)

Encryption

Page 111: Security Theatre (PHP Leuven)

Image by Wouter van Emmerik released under CC BY-SA 3.0

Never roll your own

Page 112: Security Theatre (PHP Leuven)
Page 113: Security Theatre (PHP Leuven)

Avoid old tutorials on encryption

https://gist.github.com/paragonie-scott/e9319254c8ecbad4f227

Page 114: Security Theatre (PHP Leuven)

Failed: Error Number: 60. Reason: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

// Many old tutorials and posts suggest disabling peer verificationscurl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

// Thankfully PHP 5.6+ handles CA certificate location automatically// now thanks to https://wiki.php.net/rfc/improved-tls-defaults and// Daniel Lowrey

Avoid advice like thisWeakening security for convenience

CODE SAMPLE

Page 115: Security Theatre (PHP Leuven)

Hashing

Page 116: Security Theatre (PHP Leuven)

Image by Wouter van Emmerik released under CC BY-SA 3.0

Never roll your own

Page 117: Security Theatre (PHP Leuven)

One way encodingComparisons / Integrity Checks

Page 118: Security Theatre (PHP Leuven)

Weak hash functions+/- 690GB rainbow tables

Reference: http://project-rainbowcrack.com/table.htm

Page 119: Security Theatre (PHP Leuven)

1,406,470,543Number of accounts publicly leaked

Reference: https://haveibeenpwned.com/

Page 120: Security Theatre (PHP Leuven)

$password = 'rasmuslerdorf';$hash = '$2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a';

// Is this call safe?if (crypt($password, $hash) === $hash) { echo 'Password is correct';}// What about this one?if (password_verify($password, $hash)) { echo 'Password is correct';}

Bad implementationWhere is the weakness?

CODE SAMPLE

Page 121: Security Theatre (PHP Leuven)

Timing AttacksBrute forcing cryptographic functions via

time taken to execute

Page 122: Security Theatre (PHP Leuven)

$string1 = 'abcd';$string2 = 'abce';$string3 = 'acde';

for ($i=0; $i<10000; $i++) { ($string1 === $string2); }// Time taken: 0.008344

for ($i=0; $i<10000; $i++) { ($string1 === $string3); }// Time taken: 0.006923

Timing AttacksHow it works

CODE SAMPLE

Page 123: Security Theatre (PHP Leuven)

Timing attacks can be used to work out if an account exists [...].

@troyhunt, haveibeenpwned.com

Reference: https://t.co/5WkQ48suj7

Page 124: Security Theatre (PHP Leuven)

Well actuallyAmount of randomness matters

Reference: http://blog.ircmaxell.com/2012/12/seven-ways-to-screw-up-bcrypt.html

Page 125: Security Theatre (PHP Leuven)

$password = 'rasmuslerdorf';$hash = '$2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a';

// Check the passwordif (password_verify($password, $hash)) { echo 'Password is correct'; if (password_needs_rehash($hash, PASSWORD_DEFAULT)) { // Rehash and store in database $new_password = password_hash($password, PASSWORD_DEFAULT); }}

RehashBuild it into your flow

CODE SAMPLE

Page 126: Security Theatre (PHP Leuven)

Randomness

Page 127: Security Theatre (PHP Leuven)

Image by Wouter van Emmerik released under CC BY-SA 3.0

Never roll your own

Page 128: Security Theatre (PHP Leuven)

Non-deterministic randomness is critical in encryption

Used for key generation and nonces

Page 129: Security Theatre (PHP Leuven)

Non-deterministic randomness is hard

Dual_EC_DRBG was in use for 7 years

Page 130: Security Theatre (PHP Leuven)

// NOT cryptographically securerand();

// Cryptographically secure (uses OS-specific source)random_int();

// Cryptographically secure (uses OS-specific source)random_bytes();

// Cryptographically secure (uses OpenSSL library)openssl_random_pseudo_bytes();

Random in codeKnow the source

CODE SAMPLE

Page 131: Security Theatre (PHP Leuven)

Information Disclosure

Page 132: Security Theatre (PHP Leuven)

HEAD http://example.com/index.php200 OKConnection: closeDate: Sat, 26 Dec 2015 13:52:01 GMTServer: ApacheContent-Type: text/html; charset=UTF-8Client-Date: Sat, 26 Dec 2015 13:52:01 GMTClient-Peer: 192.168.0.101:80Client-Response-Num: 1X-Powered-By: PHP/5.5.11

Information DisclosureEvery piece of information can be leveraged

LOG SAMPLE

Page 133: Security Theatre (PHP Leuven)

HEAD http://example.com/index.php200 OKConnection: closeDate: Sat, 26 Dec 2015 13:52:01 GMTServer: ApacheContent-Type: text/html; charset=UTF-8Client-Date: Sat, 26 Dec 2015 13:52:01 GMTClient-Peer: 192.168.0.101:80Client-Response-Num: 1X-Powered-By: PHP/5.5.11

Information DisclosureEvery piece of information can be leveraged

LOG SAMPLE

Page 134: Security Theatre (PHP Leuven)

Warning: require(assets/includes/footer.php) [function.require]: failed to open stream: No such file or directory in /home/user/path/to/assets/includes/operations.php on line 38

Fatal error: require() [function.require]: Failed opening required 'assets/includes/footer.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/user/path/to/assets/includes/operations.php on line 38

Information DisclosureEvery piece of information can be leveraged

LOG SAMPLE

Page 135: Security Theatre (PHP Leuven)

Social Engineering

Page 136: Security Theatre (PHP Leuven)

Weak password reset processes

Can you Google the answer?How do you handle customer support reset?

Page 137: Security Theatre (PHP Leuven)

Customer support training

Convenience vs Security

Page 138: Security Theatre (PHP Leuven)

@N’s (Naoki Hiroshima) Story

How do you mitigate against this?

Page 139: Security Theatre (PHP Leuven)

Hope

Image by Jenny released under CC BY-NC-ND 2.0

Page 140: Security Theatre (PHP Leuven)

Holistic

Page 141: Security Theatre (PHP Leuven)

A.B.C.

Page 142: Security Theatre (PHP Leuven)

Always Be C Patching

Page 143: Security Theatre (PHP Leuven)

Patching StrategyIf a dependency prevents updating, resolve it

now

Page 144: Security Theatre (PHP Leuven)

Version properlyMajor.Minor.Patch. How hard is that?

Page 145: Security Theatre (PHP Leuven)

Don’t become comfortable

Comfort breeds contempt

Page 146: Security Theatre (PHP Leuven)

ReadKnow about new threats and best practice

changes

Page 147: Security Theatre (PHP Leuven)

Training StrategyHave a process for dealing with account

locks and resets

Page 148: Security Theatre (PHP Leuven)

Compromise StrategyHave a plan before you need it

Page 149: Security Theatre (PHP Leuven)

InformationOnly store what you really need

Page 150: Security Theatre (PHP Leuven)

Mistakes will be madeLearn from them

Page 151: Security Theatre (PHP Leuven)

Rate limitBuilt it now, or you’ll have to build it while an

incident is underway

Page 152: Security Theatre (PHP Leuven)

Monitor everythingYou’re more likely to be alerted by a graph

spiking than your IDS

Page 153: Security Theatre (PHP Leuven)

Decouple rolesDatabases, servers, domains, roles, ...

Page 154: Security Theatre (PHP Leuven)

Composer everythingThere is no excuse anymore

Page 155: Security Theatre (PHP Leuven)

Decouple plugins/templates

Updates should be simple

Page 156: Security Theatre (PHP Leuven)

Get behind PSR-9 & 10http://www.php-fig.org/psr/

Page 158: Security Theatre (PHP Leuven)

Thank youFeel free to DM me on @thomas_shone with questions

Page 159: Security Theatre (PHP Leuven)

$string1 = 'abcd';$string2 = 'abce';$status = 0;

if (mb_strlen($string1, '8bit') != mb_strlen($string2, '8bit')) { return false;}for ($i = 0; $i < mb_strlen($string1, '8bit'); $i++) { $status|= (ord($string1[$i]) ^ ord($string2[$i]));}return $status === 0;

Timing AttacksHow it works

CODE SAMPLE