for developers linux security - cisofy...linux security for developers insights for building a...

85
Linux Security for Developers Insights for building a (more) secure world Michael Boelen [email protected] 14 January 2016

Upload: others

Post on 26-Sep-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Linux Securityfor Developers

Insights for building a (more) secure world

Michael [email protected] January 2016

Page 2: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

We Love Construction

Image source unknown 2

Page 3: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

And Magic!

Turning data into:- Useful output- Stable software- Nice services

Image source: renoairport.com 3

Page 4: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet
Page 5: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

● Spying● Internet of Things● Law

○ 2016 Dutch Data Protection Act○ 2017-2018 European data protection law

Why Invest in Security Now?

5

Page 6: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Agenda

● What can go wrong?

● What can we do?

● Strategies and Tools

6

Page 7: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Michael Boelen

● Open Source Security○ Rootkit Hunter (malware scan)

○ Lynis (security scan)

● 150+ blog posts at Linux-Audit.com

● Founder of CISOfy

7

Page 8: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

What can go wrong?

Page 9: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Passwords

Image source unknown

9

Page 11: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Creative Users

Image source unknown

11

Page 12: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet
Page 13: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

What can we do?

Page 14: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Solution

“Developers should become auditors of their creative work, and that of others.”

Michael Boelen, 14 January 2016

14

Page 15: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Improve in steps

● Level 1: Basics● Level 2: Take ownership● Level 3: Perform auditing

What can we do?

15

Page 16: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Level 1: The Basics

Page 17: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Input Validation

Validate!

● Trust nothing

● Double check

- Client = for active user- Server = for all users

17

Page 18: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Input Validation

Why Validate?Prevent data injection (SQL, RDF, OWL, SPARQL, SeRQL, RDQL, XML, JSON, etc.)

Where?Input forms, data imports

18

Page 19: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Data ProtectionEncryption:● Good Encryption solves a lot● Bad Knowledge required● Ugly Easy to implement incorrectly

19

Page 20: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Secure ProgrammingUsing universally unique identifier?

UUID1 = Host (MAC) + sequence + timeUUID4 = Random

20

Page 21: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Two-factor Authentication

Use● GitHub

Implement● Your apps?

21

Page 22: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Level 2: Take Ownership

Page 23: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

What?● The code● Development systems● Deployment● Production

Ownership

23

Page 24: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Hardening

Photo Credits: http://commons.wikimedia.org/wiki/User:Wilson44691

● Add new defenses

● Improve existing defenses

● Reduce weaknesses

24

Page 25: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Hardening

What to harden?

● Operating System

● Software + Configuration

● Access controls

25

Page 26: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

OS Hardening

Operating System:

● Services

● Users

● Permissions

26

Page 27: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Software Hardening

Software:

● Minimal installation

● Configuration

● Tuning

27

Page 28: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Access Hardening

Users and Access Controls:

● Who can access what

● Password policies

● Accountability

28

Page 29: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Data Hardening

Focus on data streams● Network (data in transit)

● Storage (data at rest)

● Access

29

Page 30: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Network Hardening

Traffic flows

● Is all incoming traffic needed?

● What about outgoing?

● IPv6?

30

Page 31: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

HTTP Hardening

HeaderX-Frame-Options SAMEORIGINAllow only iframe targets from our own domain

X-Frame-Options DENYDo not allow rendering in iframe

31

Page 32: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

HTTP Hardening

HeaderX-XSS-Protection 1; mode=blockBlock reflective XSS, avoid returning previous input (e.g. form)

32

Page 33: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

HTTP Hardening

HeaderX-Content-Type-Options nosniffDon't peek into server responses, consider text/html by default

33

Page 35: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Hardening

Myth: After hardening I’m done

35

Page 36: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Hardening

● Security should be an ongoing process

● Which means it is never finished

● New attacks = more hardening○ POODLE

○ Hearthbleed

36

Page 37: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Level 3: Perform Auditing

Page 38: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Myth

Auditing =

● A lot of work!

● Booooooring!

● And.. prone to errors...

38

Page 39: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Fact

Well, it can be.

39

Page 40: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Common Strategy

1. Audit

2. Get a lot of findings

3. Start hardening

4. …….

5. Quit40

Page 41: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Strategy (New)

1. Focus

2. Audit

3. Focus

4. Harden

5. Repeat!41

Page 42: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

1. Focus

● Determine what to scan

● Limit scope of systems / applications

42

Page 43: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

2. Audit

● Start small

● Collect data

43

Page 44: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

3. Focus

Determine hardening focus

● Impact

● Number

● Area (e.g. crypto)

44

Page 45: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

4. Harden

● Create implementation plan

● Perform lock down

● Document○ What, Why, How

○ Exceptions

45

Page 46: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

5. Repeat

● Keep measuring your actions

● Again:○ Ongoing process

○ Never finishes

○ New attacks

46

Page 47: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Questions?

Page 48: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Tools

Options:1. Guides2. Utilities

48

Page 49: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Benchmarks / Guides

● Center for Internet Security (CIS)

● NIST / NSA

● OWASP

● Vendors

49

Page 50: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Benchmarks / Guides

ProsFree to useDetailedYou are in control

50

ConsTime intensiveUsually no toolingLimited distributionsDelayed releases

Page 51: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

OWASP

Open Web Application Security Project

51

Page 52: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

OWASP

Security Knowledge Framework

52

Page 54: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

OWASP

54

Page 55: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Tools

Page 56: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Tools

Tools make life easier, right?

Not always...

56

Page 57: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Tools

Problem 1: There aren’t many

57

Page 58: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Tools

Problem 2: Usually outdated

58

Page 59: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Tools

Problem 3: Limited support

59

Page 60: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Tools

Problem 4: Hard to use

60

Page 61: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Introducing Lynis

Page 62: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Lynis

FreeOpen sourceShellSimpleFlexiblePortable

62

Page 63: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Lynis

Background● Since 2007● GPLv3● Requirements

○ Flexible○ Portable

63

Page 64: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Lynis

Goals● Perform a quick security scan● Collect data● Define next hardening steps

64

Page 65: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Lynis

Simple● No installation needed● Run with just one parameter● No configuration needed

65

Page 66: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Lynis

Flexibility● No dependencies*● Option to extend easily● Custom tests

* Besides common tools like awk, grep, ps

66

Page 67: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

How it works

1. Initialise

2. OS detection

3. Detect binaries

4. Run helpers/plugins/tests

5. Show report67

Page 68: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Bonus: Integration

● Deployment cycle● Create your own tests:

include/tests_custom

68

Page 69: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Running

1. lynis

2. lynis audit system

3. lynis audit system --quick

4. lynis audit system --quick --quiet

69

Page 70: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Auditing Code

Page 71: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Code Validation

Quick wins● Python: Pylint● Ruby: ruby-lint● Shell: shlint

71

Page 72: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Code Validation

Professional services● Pentesting● Code reviews

72

Page 73: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Auditing Repositories

Page 74: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

● Secret keys● Passwords● Unique IDs● Customers

Sensitive Data

74

http://blog.arvidandersson.se/2013/06/10/credentials-in-git-reposhttp://blog.nortal.com/mining-passwords-github-repositories/

Page 75: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Search your GitHub repos:extension:conf passwordextension:pem privatefilename:.bashrcfilename:.sshlanguage:ruby secretlanguage:python password

Sensitive Data

75

Page 76: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Hardening

Harden:● Your systems● Your code● Your sensitive data

76

Page 77: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Latest Developments

Page 78: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Developments

● Data protection laws

● OWASP

● New Rails security HTTP headers

● Internet of Things

● DevOps→SecDevOps / DevOpsSec78

Page 79: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Conclusions

Page 80: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Lesson 1: Continuous Auditing

Many small efforts =Big impact!

80

Page 81: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Lesson 2: Implement Lynis

#include lynis.sh

81

Page 82: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Lesson 3: Leverage Security

Security● Less: Crisis and Leaks● More: Development Time

82

Page 83: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

You Finished This Presentation

Success!

Page 84: for Developers Linux Security - CISOfy...Linux Security for Developers Insights for building a (more) secure world Michael Boelen michael.boelen@cisofy.com 14 January 2016 Spying Internet

Follow Me

● Twitter: @mboelen

● Personal website: michaelboelen.com

● Blog: linux-audit.com

84

Want More?