Build it, Break it, Fix it Build-it Lecture Prof. Eric Bodden - - PowerPoint PPT Presentation

build it break it fix it
SMART_READER_LITE
LIVE PREVIEW

Build it, Break it, Fix it Build-it Lecture Prof. Eric Bodden - - PowerPoint PPT Presentation

Build it, Break it, Fix it Build-it Lecture Prof. Eric Bodden Build It, Break It, Fix It SS 17 Today Introduction n Theoretical Part: How to Build Secure Software n Brief Problem Overview n Setup HowTo for Phase I n 2 Prof. Eric


slide-1
SLIDE 1

Build-it Lecture

Build it, Break it, Fix it

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17
slide-2
SLIDE 2

Today

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

2

n

Introduction

n

Theoretical Part: How to Build Secure Software

n

Brief Problem Overview

n

Setup HowTo for Phase I

slide-3
SLIDE 3

General Setup

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

3

n

Group Project with groups of four or five students

n

Three Phases:

n

1st Phase: Each group implements software according to a specification

n

2nd Phase: Each group examines the implementations of the other groups, searches for vulnerabilites and writes exploits.

n

3rd Phase: Each group receives the vulnerability reports, has to fix them and write a report.

slide-4
SLIDE 4

Organisation

Appointments

n

31.07.2017 10 AM s.t. - 3 PM Kickoff „Build It"

n

03.08.2017 10 AM s.t. - 1 PM Q&A session 1 (voluntary)

n

07.08.2017 10 AM s.t. - 3 PM Intermediate presentations + Kickoff „Break It"

n

10.08.2017 10 AM s.t. - 1 PM Q&A session 2 (voluntary)

n

14.08.2017 10 AM s.t. - 3 PM Intermediate presentations + Kickoff „Fix It"

n

17.08.2017 10 AM s.t. - 1 PM Q&A session 3 (voluntary)

n

21.08.2017 10 AM s.t. - 1 PM Final presentations

n

21.08.2017 11:59 PM Deadline for the final report

Examination

n Consists of your practical contest participation, the final report, the presentations and an oral exam n Make an appointment for your oral exam with Prof. Bodden

Slides available online

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

4

slide-5
SLIDE 5

Organisation

Deliverables

n

2 Intermediate Presentations: 10min talk, summarise your work of the previous phase

n

Final Presentation: 15min talk, summarise your overall work of all phases

n

Final report: max. 10 pages, write about your implementation, your breaking approach, your bugs and their fixes and lessons learned

n

Oral examination: Knowledge about theoretical parts and about your group‘s implementation, breaks and fixes

Slides available online

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

5

slide-6
SLIDE 6

General Advice

n

Challenge yourself, challenge the others, expect to be challenged

n

Do not start working on the Saturday before the deadline

n

Raise your questions in time and use the course mailing list, so that others may benefit from the answers as well. Please participate and answer questions for others when you know the answer. Mailing List: bibifi@lists.uni-paderborn.de

n

Make use of the Q/A sessions and come early, as we may leave earlier if there is no demand

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

6

Rules

n

No plagiarism (zero tolerance)

n

No deadline extensions

n

Do not attack the infrastructure

n

Allowed Programming Languages: C, Python, Java

slide-7
SLIDE 7
  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

7

How to Build Secure Software

slide-8
SLIDE 8

Why do we care?

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

8

slide-9
SLIDE 9

How risky can it be to use Adobe Flash Player? 2011 Attack on RSA and U.S. Weapon Manufacturers

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

9

http://www.f-secure.com/weblog/archives/00002226.html http://www.nytimes.com/2011/06/08/business/08security.html?pagewanted=all http://www.informationweek.com/news/government/security/232700341 1: Social engineering & phishing ▪March 3: Fake email to some RSA employees: [2011 Recruitment plan.xls] with embedded flash zero-day CVE-2011-0609 in Adobe Flash Player. ▪Planted “Poison Ivy” trojan horse. 2: Digital Shoulder Surfing ▪Poison Ivy connects back to control server, giving full control to attacker. ▪Attacker gradually moves towards higher value accounts and data. 4: Exploiting compromised SecureID to break into the target systems at defence industry. ▪June 3: Lockheed discloses a blocked attack, which exploited the breach at RSA. ▪RSA announced replacement program for tokens (>40M tokens worldwide, Lockheed > 45’000). ▪August 2011: RSA acknowledge immediate 66M$ for recovery. ▪March 27, 2012: NSA attributes attack to Chinese hackers 3: Collecting SecureID secret seed records, downloading them from staging server. ▪RSA issues warning on March 17 ▪Unusually fast (e.g., attack on Nortel went unnoticed for more then 10 years)

slide-10
SLIDE 10

What does “Security” mean for Software and Information Systems?

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

10

slide-11
SLIDE 11

Security is Not a Set of Features

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

n

Secure is an emergent property of software

n

“Being dry” in a tent in the rain

n

Being secure is the result of many, many factors, not one feature (e.g. encryption)

n

…so requirements documents should not just be a list of features

11

slide-12
SLIDE 12
  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

12

Confidentiality The system must not disclose any information intended to be hidden, e.g., your credit card information on a website.

Note: open source software can still be confidential.

Availability The system must be able to be available and

  • perational to users, e.g., bringing down

Amazon.com

Any system performance degradation that can be triggered by a user can be used for denial of service attacks

Integrity The system must not allow assets to be subverted by unauthorized users, e.g., changing a prisoner’s release date.

We must be able trust what is in the system The data being stored The functionality being executed

Core Security Goals

The CIA Triad

slide-13
SLIDE 13

Threat Classification

Spoofing

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

13

Authentication

“Pretending to be something or someone other than yourself.”

[Shostack, A. (2014). Threat modeling : designing for security., Indianapolis, Ind. : Wiley.] n

IP Spoofing

n

Set source IP address to some other IP

n

E-Mail Spoofing

n

Replace sender address

n

In SMTP, “From” is not checked

slide-14
SLIDE 14

Threat Classification

Tampering

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

14

Integrity

n

“Web Tampering” [owasp.org] “Modifying something on disk, on a network, or in memory.”

[Shostack, A. (2014). Threat modeling : designing for security., Indianapolis, Ind. : Wiley.]

<input type=”hidden” id=”1008” name=”cost” value=”70.00”> http://www.attackbank.com/savepage.asp?nr=147&status=read http://www.attackbank.com/savepage.asp?nr=147&status=del

slide-15
SLIDE 15

Threat Classification

Repudiation

Confirmation

n

Deleting Logs

n

Using symmetric keys for signing

n

Both parties can dispute the signing

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

15

“Claiming that you didn’t do something, or were not

  • responsible. Repudiation can be honest or false, and the key

question for system designers is, what evidence do you have?”

[Shostack, A. (2014). Threat modeling : designing for security., Indianapolis, Ind. : Wiley.]

slide-16
SLIDE 16

Threat Classification

Information Disclosure

Confidentiality

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

16

“Providing information to someone not authorized to see it.”

[Shostack, A. (2014). Threat modeling : designing for security., Indianapolis, Ind. : Wiley.]

slide-17
SLIDE 17

Threat Classification

Denial of Service

Availability

n

Any system performance degradation that can be triggered by an user can be used for denial of service attacks, e.g., too many server requests

n

Blog of security blogger Brian Krebs was taken down in September 2016

n

DNS services of Dyn were attacked in October 2016

n

Many prominent websites were not reachable

n

Botnet of thousands of IoT devices, e.g., IP-cameras

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

17

“Absorbing resources needed to provide service.”

[Shostack, A. (2014). Threat modeling : designing for security., Indianapolis, Ind. : Wiley.]

slide-18
SLIDE 18

Threat Classification

Elevation of privilege

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

18

Authorization

n

Library for image processing

n

Used by many websites

n

“Image Tragic”

n

Upload a compromised SVG

n

Execute code with the privileges of the calling server process, e.g., deleting all images “Allowing someone to do something they’re not authorized to do.”

[Shostack, A. (2014). Threat modeling : designing for security., Indianapolis, Ind. : Wiley.]

slide-19
SLIDE 19

Threat Classification

Summary

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

19

Authorization Availability Confidentiality Confirmation Integrity Authentication

Spoofing Tampering Repudiation Information Disclosure Denial of Service Elevation of Privilege

slide-20
SLIDE 20

Composability

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

20

Component A Component B

+

Component AB Secure Secure

+

Secure Insecure

Sometimes…

Security is usually not preserved under composition!

slide-21
SLIDE 21

At which point in the development can we apply security?

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

21

At which point in the development can we introduce insecurity?

slide-22
SLIDE 22

Software Development Lifecycle – Potentials for Insecurity

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

22

Requirements and Use Cases Architecture And Design Test Plans Code Test and Test Results Feedback from the Field Incomplete Incomplete Flawed

Overlooking vuln. Bad Configuration

slide-23
SLIDE 23

Security Touchpoints

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

23

Requirements and Use Cases Architecture And Design Test Plans Code Test and Test Results Feedback from the Field

slide-24
SLIDE 24

Think Evil: Consider Attacker’s Point of View

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

24

n

What could be interesting for attackers?

n

What needs to be protected?

n

Which of the security goals need to be achieved for

n

What are the capabilities of attackers?

n

What shall attackers with those capabilities be able to achieve at most?

This is the fundamental aspect to consider for security.

slide-25
SLIDE 25
  • Misc. Philosophies & Proverbs
  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

n

Defence in depth

n

If they break into this, they can’t get any farther

n

Think Middle-Age castles

n

Original meaning of “firewall”, not today’s firewall

n

Least privilege

n

Every user or module is given the least amount of privilege they need

n

Evil: sudo chmod –R a+rw /

25

<?php $host = 'localhost'; $userID = 'root'; $password = 'password'; $db = mysql_connect($host, $userID, $password) or die ('Error connecting to mysql'); $name = 'testdatabase'; mysql_select_db($name); $sql="SELECT * FROM theTable"; $result=mysql_query($sql); ?>

Source: OWASP.org

slide-26
SLIDE 26

More Misc. Philosophies & Proverbs

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

n

Fail securely

n

Exceptions put the system into weird states

n

Error message information leak

n

Take care of those exceptions properly!

n

No Security by Obscurity

n

You can’t rely upon being obscure to be secure

n

Crowds are good at guessing

n

Insiders are corruptible

n

Exceptions?

n

Passwords, encryption keys, ASLR

26

"If the Rebels have obtained a complete technical readout of this station it is possible, however unlikely, that they might find a weakness, and exploit it." "The plans you refer to will soon be back in our hands." ―General Cassio Tagge and Darth Vader (Star Wars, 1977)

try {

  • penDbConnection();

} catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), '\n'; echo 'Check credentials in config file at: ', $Mysql_config_location, '\n'; }

Source: cwe.mitre.org

slide-27
SLIDE 27

Even More Misc. Philosophies & Proverbs

n

Detect and record

n

Even if you can’t always sift through that data ahead of time

n

Post-mortem analysis

n

Don’t trust [input | environment | dependencies | *]

n

Know what to trust

n

Know whom to trust

n

Know how to trust

n

Keep it simple and stupid (KISS)

n

You aren’t gonna need it (YAGNI)

n

Speculative generality can be risky

n

Minimise the attack surface

n

Write readable, clear code! Unreadable code is broken code.

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

27

slide-28
SLIDE 28

Validating Input

n

Input validation is blocking bad inputs

n

Black list, also known as sanitization

n

Enumerate the bad stuff

n

Don’t allow anything on the blacklist

n

Drawback: infinite, easy to get around

n

Straightforward approach

n

White list

n

Only accept known good input

n

Often done with regular expressions

n

Sometimes not possible to block certain characters

n

Recommendation: do both, but prefer a whitelist

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

28

slide-29
SLIDE 29

Input in Many Forms

n

Not always strings and numbers

n

Consider: images with metadata

n

PHP had many issues with EXIF JPEG metadata

n

Adobe Acrobat & embedded fonts

n

Java with ICC and BMP http://recxltd.blogspot.com/2012/01/bmp-and-icc-standard- tale-in.html

n

http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-2789

n

Videos, music, radio signals…!

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

29

slide-30
SLIDE 30

Sanitising Input

n

Instead of blocking input, sanitise it

n

All input comes in, but it’s manipulated

n

Convert it to something that won’t be interpreted as code

n

Usually utilises escape characters

n

e.g. Java

n

“ is \”

n

Drawback: need to know everything to escape

n

Very blacklist-like

n

False positives are also annoying

n

Need to remember to do it… everywhere

n

Field of active research: New compilers and other tools may come to the rescue

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

import static

  • rg.apache.commons.lang3.StringEscapeUtils.escapeHtml4;

// ... String escaped = escapeHtml4(source);

30

slide-31
SLIDE 31

Error Handling

n

“This won’t ever fail” – source for evil bugs!

n

Most Methods/Functions may fail!

n

If you don’t know, whether or how, look it up!

n

Assess the criticality of the possible failure!

n

Handle failures properly! Do not “work around” critical failures!

n

Error handling can become a noticeable amount of code!

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

31

slide-32
SLIDE 32

Exception Handling

n

Most weird, unexpected behavior results in an exception

n

Handle the exceptions you know about

n

Know that sometimes some get away

n

Design your system to handle exceptions at the top-level

n

E.g. Java à catch Throwable, not Exception

n

For maintainability & complexity:

n

Avoid promoting unnecessarily e.g. “throws Exception”

n

Deal with related exceptions in one place, near the problem e.g. wrapper around private methods in a class

n

Sheer laziness:

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

try{something();} catch{}

If you do this in this course, you will fail.

32

slide-33
SLIDE 33

Just re-throwing exceptions may leak information

n

CWE-209: Information Exposure Through an Error Message

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

try {

  • penDbConnection();

} //print exception message that includes //exception message and configuration file location catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), '\n'; echo 'Check credentials in config file at: ', $Mysql_config_location, '\n'; }

33

slide-34
SLIDE 34

Debugging and Development Constructs

n

Temporarily needed code during development can become a big problem if it is forgotten to be removed

n

Be conscious about such code

n

Mark it explicitly in comments

n

Search for and fix it before releasing the program

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

34

slide-35
SLIDE 35

finally

n

Don’t forget about the finally clause!

n

Anything in the finally clause gets executed no matter what happens

n

Good for cleanup of resources

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

public void something() { Connection conn = null; try { conn = getConnection(); /* do db stuff */ } catch (SQLException e) { /* handle it */ } finally { DBUtil.closeConnection(conn); } }

35

slide-36
SLIDE 36

Tidy up after yourself

n

Release resources you created and don’t need anymore!

n

Yes, Java has a GC.

n

Yes, it does clean up after you.

n

No, it does not clean up everything.

n

Other languages may not have a GC. For example, C has none and will never have one.

n

Actively think about object’s lifetime when you create it

n

Keep in mind: memory exhaustion leads to Denial of Service!

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

36

slide-37
SLIDE 37

Think of the Children

n

Subclassing overrides methods

n

In untrusted API situations, make sure you can’t be extended and have a sensitive method overridden

n

Use the final keyword:

n

Malicious subclasses can override the finalize() method to resurrect objects.

n

http://www.ibm.com/developerworks/library/j-fv/

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

public final class Countdown{} public final class String{}

37

slide-38
SLIDE 38

Cloning is Insecure

n

Every Java object has a clone() method

n

Often error-prone

n

Doesn’t do what you think it does

n

Most people don’t abide by the contract

n

Even the Java architects don’t like it

n

The Java Language Secure Coding Guidelines from Oracle recommend not using java.lang.Cloneable entirely

n

Recommendation: Override the clone method to make classes unclonable unless required

n

Problem: Cloning allows an attacker to instantiate a class without running any of the class constructors.

n

Use your own copy mechanism if needed

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

38

slide-39
SLIDE 39

Immutability in OO

n

Setters are evil (except the Irish kind)

n

What if we construct, run, set, then run again?

n

Unnecessarily increases complexity

n

Violates encapsulation

n

Don’t just throw setters in if you don’t have a reason

n

Beans are one exception to this rule

n

Functionality is only get & set

n

Little other functionality

n

Mapping to validation

n

Mapping to relations

n

Generally prefer immutability where possible

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

39

slide-40
SLIDE 40

Concurrency is Always a Risk

n

Treat anything concurrent with initial distrust

n

Race conditions à Denial of Service

n

Shared memory à Potential Leakage

n

Weird circumstances à Potential Tampering

n

Concurrency is ubiquitous: webapps, databases, GUIs, games, etc.

n

Common poor assumptions

n

“There will be only one copy of this thread”

n

“There will only be X threads”

n

“Nobody knows about my mutability”

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

40

slide-41
SLIDE 41

Advice for Concurrency

n

Create a concurrency concept and keep it as simple as possible, but as complex as needed.

n

Document the concurrency concept!

n

Make use of synchronization primitives!

n

Synchronization needs to protect data, not code!

n

Challenge: minimizing serial execution time while doing synchronization right

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

41

slide-42
SLIDE 42

Serial Killer

n

Serialization is often unnecessary, difficult to get right

n

Deserializing is essentially constructing an object without executing the constructor

n

If your system uses it, don’t assume the constructor will be executed

n

Can reverse-engineer to violate constructor post-conditions

n

Also, serialized != encrypted

n

Confidentiality disclosure

n

Use transient for variables that don’t need serialization e.g. environment info, timestamps, keys

n

OWASP recommends:

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

private final void readObject(ObjectInputStream in) throws java.io.IOException { throw new java.io.IOException("Class cannot be deserialized"); }

42

slide-43
SLIDE 43

Summary

n

Think about security from the beginning

n

Keep your code simple

n

Handle failures properly

n

Don’t trust input

n

Be very careful with error output

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

43

slide-44
SLIDE 44

Brief Problem Overview

Disclaimer: Only the specification document is binding! The information provided here is meant as an introduction.

n

An art gallery wants to log, which persons entered the gallery and its rooms and when they did so

n

… in a “secure” way.

n

The software to be implemented consists of two programs “logappend” and “logread”

n

logappend: add information to the log file in a controlled way

n

logread: read information from the log file and perform various statistics

n

Obfuscation is not allowed!

n

No bogus code (method calls, classes, unnecessary variables, etc..)

n

No identifier renaming

n

No encrypted source code

n

n

Obfuscated submissions will be disqualified!

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

44

slide-45
SLIDE 45

Built-it Phase

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

45

n

Register at the course platform: https://bibifi.cs.upb.de/

n

Please fill out the registration form!

n

Build groups of four people and register as such at the course platform (/profile/Teams)

n

Register as team to the „S2017“ contest (announcements/sign up)

n

Come to us if you cannot find a group or your group is too small!

n

Create a git repository for your group on the University GitLab: https://git.cs.upb.de

n

Grant user „Birkhard Bifi“ reporter access to that repo

n

Grant everyone in your group at least developer access

n

Register the team repository at the course platform (announcements/participants)

slide-46
SLIDE 46

Built-it Phase

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

46

n

Your code goes into the build directory in your repository root!

n

Further information on the Gallery problem and usage of the infrastructure can be found in the specification: https://bibifi.cs.upb.de/static/doc/s2017/spec/index.html

n

Should by now be linked in the announcements

n

Read carefully, everything you need is there! Ask if unsure after second read through.

n

Your implementations will be tested against our oracle implementation

n

We have test cases for correctness, performance and optional features that are executed on each commit to your repository

n

If you are unsure about the expected behaviour of your application, you can always ask the oracle for the correct answer (explained in specification)

slide-47
SLIDE 47

Built-it Phase

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

47

n

Please use the VM to make sure your Makefile and executables work before complaining about the infrastructure

n

The infrastructure will provide you only with the information printed to stdout

n

If nothing is printed, chances are high that your Makefile is broken!

n

Again, read the specification carefully to reveal possible mistakes of your implementation or check-in process!

n

A lot of contest points can be achieved during the Build-it phase, make sure you use the time and implement as much as you can!

n

Every break of your implementation will loose you points

n

Last but not least:

HAVE FUN!

slide-48
SLIDE 48

2nd Phase

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

48

n

How to submit your exploits?

n

Bibif….upb.de

n

Demo on how to do that.

n

slide-49
SLIDE 49

3rd Phase

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

49

n

How to submit your reports?

n

Bibif….upb.de or email?

slide-50
SLIDE 50

Lecture Schedule (preliminary)

Date Topic Lecturer 31.07. Build-it Lecture Martin, Manuel 03.08. Q&A with supervisors (optional) All three of us 07.08. Build-it Presentations & Break-it Lecture Stefan 10.08. Q&A with supervisors (optional) All three of us 14.08. Break-it Presentations & Fix-it Lecture Martin 17.08. Q&A with supervisors (optional) Martin & Manuel 19.08. Submission of final reports 20.08. Final Presentations

  • Prof. Eric Bodden – Build It, Break It, Fix It SS 17

50