pci compliance writing secure code

33
WRITING SECURE CODE TIMOTHY BOLTON

Upload: miva

Post on 16-Jul-2015

206 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Pci compliance   writing secure code

WRITING SECURE CODETIMOTHY BOLTON

Page 2: Pci compliance   writing secure code

A Briefer History of Tim

Lots of experience codingLots of experience writing insecure codeFocus on PCI Compliance w.r.t. Coding

Page 3: Pci compliance   writing secure code

Overview

ConceptsAttacks and MitigationsIncidence HandlingUsing this in your daily life

Page 4: Pci compliance   writing secure code

Concepts

General security expectationsConfidentiality of dataIntegrity of dataAvailability of data

Defense in depthPermission

Page 5: Pci compliance   writing secure code

Concepts

ConfidentialityThink “data leaks”, unprotected directories, access

control exploits.

IntegrityData tampering, Man in the browser attacks

AvailabilityDoS style attacks

Page 6: Pci compliance   writing secure code

Defense In Depth

Layered approaches work wellUse security where it makes sense to use it

Use file system permissions for directoriesUse a WAFUse database access control (GRANT ALL???)

Diagram the moving parts, sensitive data, and see where points of entry exist.

Page 7: Pci compliance   writing secure code

Defense In Depth

Least-privilege principleLayering of Access-control

URL based access-controlFile system & Server permissionsApplication (business logic)Data layerApplication Layer

Page 8: Pci compliance   writing secure code

Attacks and Midichlorians

We will focus on three types of attacksCross Site ScriptingCross Site Request ForgerySQL Injection

There are obviously many more, this is a small introduction.

Page 9: Pci compliance   writing secure code

XSS

Exploits the trust a USER has for a siteA basic attack is going to insert some

JavaScript in the page.

Page 10: Pci compliance   writing secure code

Cross Site Scripting (XSS)

PersistentReflectedDOM

Page 11: Pci compliance   writing secure code

Reflected Example

Coupons, coupons, coupons!Parameters from GET directly generating

content on the page.

Page 12: Pci compliance   writing secure code

Mitigation

Validate user inputEncode output (mvte instead of mvt)Miva does this with some fields already to

mitigate against XSS Persistence attacksUsually this is a case by case basis for how to

properly care for data and user-interaction.

Page 13: Pci compliance   writing secure code

Cross Site Request Forgery (CSRF)

Exploits the trust a SITE has for a browser.All browsers are vulnerable to CSRF attacksYou see these attacks in:

XMLHttpRequestsIframesImage tagsScript tags

Page 14: Pci compliance   writing secure code

CSRF Attacks

DDoSBandwidth ConsumptionComputationally expensive requests

Unauthorized ActionsForm submissionImages with malicious parameters

Page 15: Pci compliance   writing secure code

CSRF Attack Mitigation

Use POST instead of GET for formsMiva is a bit different here..Not bullet-proof by any means

Use Anti-CSRF tokensRegular Session TimeoutsCheck HTTP ReferrerCAPTCHAFlow Control

Page 16: Pci compliance   writing secure code

Anti-CSRF Tokens

It's just a simple 62 step process.Create an element on a form which is

required.This element is unique and not knownMust be present on form submission

Page 17: Pci compliance   writing secure code

CSRF Mitigation Chart

Slight Help Weak Medium Hulk Smash

Using POST *

Timeout *

HTTP

Referrer

* *

CAPTCHA * * * *

Flow Control * *

Anti-CSRF

Tokens

* * * *

Page 18: Pci compliance   writing secure code

Difference Betwixt XSS and CSRF

XSS – Exploits the trust a USER has with a siteCSRF – Exploits the trust a SITE has with a

browser

Page 19: Pci compliance   writing secure code

XSS & CSRF

XSS and CSRF are the “Clinton's” of Security Exploit PartnershipsLook at your inputs, look at your outputs,

look at your logs. See where attacks are coming from.

Page 20: Pci compliance   writing secure code

SQL Injection

MivaScript has parameterization built in.That doesn't always mean people use it.30% of sites in PCI Audits still have exposed

SQL Injection vulnerabilitiesCustom module development, and greater

access to lower level functionality bring this back to the surface.

Page 21: Pci compliance   writing secure code

What is SQL Injection

username=timusername=tim' OR 1=1; –?page=9?page=8+1

Page 22: Pci compliance   writing secure code

What can SQL Injection do?

Changing existing SQL queriesExtract data from the databaseAlter data and structure of databaseControl the host running the database, move

to other hosts on the networkGet webshells on board

Page 23: Pci compliance   writing secure code

SQL Injection Attacks

Non-blind SQL InjectionError messages help clue you in to what is happening

behind the scenes.

Blind SQL InjectionUse a “Yes” or “No” approach.“Yes” or “No” can also be determined via response time

if no visual outputMore difficult for the attacker, as there aren’t error

messages helping them.Testing with Blind SQL Injections:http://target.com/search.php?product=10Triggers our baseline “true” – Showing us product 10http://target.com/search.php?product=10’Triggers the “false” baseline

Page 24: Pci compliance   writing secure code

SQL Injection Attack Scenarios

Putting a webshell on boardhttp://target.com/search.php?query=‘

UNION SELECT “<?php system($_REQUEST[‘cmd’]);?>” INTO OUTFILE ‘/var/www/test/shell.php’ --Getting file contentshttp://target.com/search.php?query=‘

UNION SELECT 1, load_file(/etc/passwd) --Dropping Tableshttp://target.com/search.php?query=‘ ;

DROP TABLE users --

Page 25: Pci compliance   writing secure code

SQL Attack Mitigation

Set up different SQL users with different grants, and use them when performing that type of query.Sometimes using Stored Procedures makes

sense. Monitor SQL outbound connectionsTurn off error messages from SQL

Page 26: Pci compliance   writing secure code

Title

Parameterize your queriesIf you can’t then use mysql_escape_string around user-

generated input

When it makes sense:Only allow “known good” inputReject bad input

This is hard to do consistently:Bill Stinkface lives on 123 Union St.,

Chesapeake Drop, OR.

Page 27: Pci compliance   writing secure code

Incidence Handling

Remember Uncle Scar.. be preparedMonitor and detectContainmentEradicationRestorationWhat was learned?

Page 28: Pci compliance   writing secure code

Incidence Handling

Have a planKnow who owns what projectTalk to those who are affected

Page 29: Pci compliance   writing secure code

Daily Life

Implement Code ReviewsGet a WAF (web application firewall)Security at designDo not use weak hashing algorithmsUse unique salted hashesUse SSL for every page

Page 30: Pci compliance   writing secure code

Daily Life

Before going into production, do some pen testing in QAUse HSTS (HTTP Strict Transport Security)Join the list

https://hstspreload.appspot.com/Cut down your surface area of attack by

hardening your server

Page 31: Pci compliance   writing secure code

Daily Life

Set up a web application testing frameworkRun incidence response scenariosUse Anti-CSRF Tokens for forms

Page 32: Pci compliance   writing secure code

One Page Take Home

The order of operations for user-input and data validationClient side validationWeb Application Firewall (WAF)Anti-CSRF TokensValidation within codeCustomized validation for persistence layer

Page 33: Pci compliance   writing secure code

PRESENTER’S NAME