Slide 1

Slide 1 text

Security Monitoring! With Open Source ! Penetration Testing! Tools Gareth Rushgrove

Slide 2

Slide 2 text

Who (Who is this person?)

Slide 3

Slide 3 text

@garethr

Slide 4

Slide 4 text

UK Government Digital Service

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

How did it come to this, that the government has one of the most exciting start-ups in the UK?!

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

The Problem (Why talk about security monitoring)

Slide 9

Slide 9 text

The continuous delivery argument Gareth Rushgrove

Slide 10

Slide 10 text

How often do you change your applications? Gareth Rushgrove

Slide 11

Slide 11 text

Gareth Rushgrove How often do you conduct penetration tests?

Slide 12

Slide 12 text

The security is part of quality assurance argument Gareth Rushgrove

Slide 13

Slide 13 text

Testing used to be manual, slow and expensive Gareth Rushgrove

Slide 14

Slide 14 text

Testing is now automated, fast and done on every commit Gareth Rushgrove

Slide 15

Slide 15 text

Security testing is still mainly manual, slow and expensive Gareth Rushgrove

Slide 16

Slide 16 text

This presentation (What to expect from this talk)

Slide 17

Slide 17 text

Reactive security monitoring Gareth Rushgrove 1

Slide 18

Slide 18 text

Monitoring security in development Gareth Rushgrove 2

Slide 19

Slide 19 text

Proactive security testing Gareth Rushgrove 3

Slide 20

Slide 20 text

Gareth Rushgrove 4 What you can do

Slide 21

Slide 21 text

Gareth Rushgrove WARNING. Code in this presentation works but isn’t always pretty

Slide 22

Slide 22 text

Reactive monitoring (Watch for weirdness)

Slide 23

Slide 23 text

rkhunter Gareth Rushgrove

Slide 24

Slide 24 text

Gareth Rushgrove

Slide 25

Slide 25 text

rkhunter \ --check \ --no-mail-on-warning \ --skip-keypress Gareth Rushgrove

Slide 26

Slide 26 text

Tuxtendo Rootkit [ Not found ] URK Rootkit [ Not found ] Vampire Rootkit [ Not found ] VcKit Rootkit [ Not found ] Volc Rootkit [ Found ] Xzibit Rootkit [ Not found ] X-Org SunOS Rootkit [ Not found ] zaRwT.KiT Rootkit [ Not found ] ZK Rootkit [ Not found ] Performing additional rootkit checks Suckit Rookit additional checks [ OK ] Checking for possible rootkit files and directories [ None found ] Checking for possible rootkit strings [ None found ] Gareth Rushgrove

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Gareth Rushgrove

Slide 29

Slide 29 text

rkhunter \ --check \ --nocolors \ --no-mail-on-warning \ --skip-keypress \ --no-summary | rkhunter-librato.py Gareth Rushgrove

Slide 30

Slide 30 text

Gareth Rushgrove

Slide 31

Slide 31 text

Gareth Rushgrove

Slide 32

Slide 32 text

def test_beastkit_not_installed(): assert (metric("beastkit_rootkit") == 0) Gareth Rushgrove

Slide 33

Slide 33 text

>> nosetests -v rkhunter-librato-test.py rkhunter-libratoo-test.test_beastkit_not_installed ... ok --------------------------------------------------------- Ran 1 test in 1.585s OK Gareth Rushgrove

Slide 34

Slide 34 text

Nginx Naxsi Gareth Rushgrove

Slide 35

Slide 35 text

Web Application Firewall Gareth Rushgrove

Slide 36

Slide 36 text

Gareth Rushgrove

Slide 37

Slide 37 text

SecRulesEnabled; DeniedUrl "/RequestDenied"; CheckRule "$SQL >= 8" BLOCK; CheckRule "$RFI >= 8" BLOCK; CheckRule "$TRAVERSAL >= 4" BLOCK; CheckRule "$EVADE >= 4" BLOCK; CheckRule "$XSS >= 8" BLOCK; Gareth Rushgrove

Slide 38

Slide 38 text

2013/09/18 08:59:57 [error] 891#0: *6 NAXSI_FMT: ip=192.168.50.20&server=victim&uri=/pictures/ search.php&total_processed=14&total_blocked=7&zo ne0=ARGS&id0=1007&var_name0=query, client: 192.168.50.20, server: localhost, request: "GET /pictures/search.php?query=--%3E+ %3Csome_dangerous_input_a1056fd2f0ffbb7f18fec9bd 33257e12ab5e0494b33011967bcbcbc5699408eb%2F%3E+ %3C%21-- HTTP/1.1", host: "victim" ! Gareth Rushgrove

Slide 39

Slide 39 text

id0=1007 Gareth Rushgrove

Slide 40

Slide 40 text

SQL Injection Gareth Rushgrove

Slide 41

Slide 41 text

Gareth Rushgrove

Slide 42

Slide 42 text

grok { type => "nginx_error" match => ["message", " ip=%{IP:client_ip}& server=%{IP:server_ip}& uri=%{PATH:uri}& total_processed=%{NUMBER:total_processed}& total_blocked=%{NUMBER:total_blocked}& zone0=%{WORD:zone}& id0=%{NUMBER:id}"] } Gareth Rushgrove

Slide 43

Slide 43 text

Gareth Rushgrove

Slide 44

Slide 44 text

Fail2Ban Gareth Rushgrove

Slide 45

Slide 45 text

Gareth Rushgrove

Slide 46

Slide 46 text

[ssh] enabled = true port = ssh filter = sshd logpath = /var/log/auth.log maxretry = 3 [ssh-ddos] enabled = true port = ssh filter = sshd-ddos logpath = /var/log/auth.log maxretry = 6 Gareth Rushgrove

Slide 47

Slide 47 text

[ssh-ddos] Ban 192.168.50.20 Gareth Rushgrove

Slide 48

Slide 48 text

[nginx-naxsi] enabled = true port = http,https filter = nginx-naxsi logpath = /var/log/nginx/*error.log maxretry = 2 Gareth Rushgrove

Slide 49

Slide 49 text

grok { type => "naxsi_fail2ban" match => ["message", " WARNING \[nginx-naxsi\] %{WORD:action} %{IP:ip}" ] } Gareth Rushgrove

Slide 50

Slide 50 text

Auditd Gareth Rushgrove

Slide 51

Slide 51 text

Auditd in less than 2 minutes. Maybe. Gareth Rushgrove

Slide 52

Slide 52 text

-a exit,always -S mkdir Gareth Rushgrove

Slide 53

Slide 53 text

type=CWD msg=audit(1379493067.779:57): cwd="/tmp" type=PATH msg=audit(1379493067.779:57): item=0 name="vagrant-puppet" inode=20 dev=fc:00 mode=041777 ouid=0 ogid=0 rdev=00:00 type=SYSCALL msg=audit(1379493067.779:58): arch=c000003e syscall=83 success=yes exit=0 a0=7fff172d0e5e a1=1ed a2=1ed a3=7fff172cf910 items=2 ppid=1239 pid=1241 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=21 comm="mkdir" exe="/bin/mkdir" key=(null) type=CWD msg=audit(1379493067.779:58): cwd="/tmp/ vagrant-puppet" Gareth Rushgrove

Slide 54

Slide 54 text

cwd="/tmp" Gareth Rushgrove

Slide 55

Slide 55 text

syscall=83 Gareth Rushgrove

Slide 56

Slide 56 text

sys_symlink Gareth Rushgrove

Slide 57

Slide 57 text

Gareth Rushgrove

Slide 58

Slide 58 text

comm="mkdir" Gareth Rushgrove

Slide 59

Slide 59 text

cwd="/tmp/vagrant-puppet" Gareth Rushgrove

Slide 60

Slide 60 text

aureport or ausearch and something Gareth Rushgrove

Slide 61

Slide 61 text

Security in development (Monitor development too)

Slide 62

Slide 62 text

Monitor security in your pipeline Gareth Rushgrove

Slide 63

Slide 63 text

Virus scan your artefacts Gareth Rushgrove

Slide 64

Slide 64 text

Gareth Rushgrove ClamAV + Jenkins

Slide 65

Slide 65 text

Gareth Rushgrove

Slide 66

Slide 66 text

Gareth Rushgrove Get data to Graphite

Slide 67

Slide 67 text

Static analysis Gareth Rushgrove

Slide 68

Slide 68 text

Brakeman for Ruby on Rails Gareth Rushgrove

Slide 69

Slide 69 text

Gareth Rushgrove

Slide 70

Slide 70 text

Gareth Rushgrove

Slide 71

Slide 71 text

Vulnerabilities in dependencies Gareth Rushgrove

Slide 72

Slide 72 text

Gareth Rushgrove OWASP dependency check

Slide 73

Slide 73 text

Gareth Rushgrove Ruby security advisories

Slide 74

Slide 74 text

Gareth Rushgrove Bundler audit

Slide 75

Slide 75 text

> bundler-audit ! Name: actionpack Version: 3.2.10 Advisory: OSVDB-91452 Criticality: Medium URL: http://www.osvdb.org/show/osvdb/91452 Title: XSS vulnerability in sanitize_css in Action Pack Solution: upgrade to ~> 2.3.18, ~> 3.1.12, >= 3.2.13 Gareth Rushgrove

Slide 76

Slide 76 text

Gareth Rushgrove

Slide 77

Slide 77 text

it "should have no vulnerable gems" do @issues.should have(0).items end Gareth Rushgrove

Slide 78

Slide 78 text

rspec audit-rspec.rb -f d my application dependencies should have no vulnerable gems (FAILED - 1) should have a safe version of ruby on rails ! Finished in 0.03949 seconds 2 examples, 1 failure Gareth Rushgrove

Slide 79

Slide 79 text

Aside: penetration testing tools (State of open source)

Slide 80

Slide 80 text

Skipfish, nikto, w3af, garmr, sslyze, owasp zap, arachni, sqlmap, sslscan, TLSSLed, slowhttptest, DIRB, SQLiBF Gareth Rushgrove

Slide 81

Slide 81 text

BackTrack Gareth Rushgrove

Slide 82

Slide 82 text

The problem with distributing software as a Linux distribution Gareth Rushgrove

Slide 83

Slide 83 text

Configuration management + Vagrant Gareth Rushgrove

Slide 84

Slide 84 text

Penetration testing tools

Slide 85

Slide 85 text

Vulnerable web apps

Slide 86

Slide 86 text

Source code

Slide 87

Slide 87 text

Puppet module

Slide 88

Slide 88 text

Proactive monitoring (Attack yourself)

Slide 89

Slide 89 text

Gareth Rushgrove

Slide 90

Slide 90 text

nmap monitorama.eu Gareth Rushgrove

Slide 91

Slide 91 text

Starting Nmap 5.21 ( http://nmap.org ) at 2013-09-18 15:09 BST Nmap scan report for monitorama.eu (141.101.116.49) Host is up (0.17s latency). Hostname monitorama.eu resolves to 2 IPs. Only scanned 141.101.116.49 Not shown: 998 filtered ports PORT STATE SERVICE 80/tcp open http 8080/tcp open http-proxy Nmap done: 1 IP address (1 host up) scanned in 24.18 seconds Gareth Rushgrove

Slide 92

Slide 92 text

Gareth Rushgrove

Slide 93

Slide 93 text

it "should have one port open" do @open_ports.should have(1).items end Gareth Rushgrove

Slide 94

Slide 94 text

it "should have port 80 open" do @open_ports.should contain(80) end Gareth Rushgrove

Slide 95

Slide 95 text

Gareth Rushgrove

Slide 96

Slide 96 text

1) the monitorama.eu website should have one port open Failure/Error: @open_ports.should have(1).items expected 1 items, got 12 # ./nmap-rspec.rb:24:in `block (2 levels) in ' ! Finished in 2.47 seconds 2 examples, 1 failure Gareth Rushgrove

Slide 97

Slide 97 text

Arachni Gareth Rushgrove

Slide 98

Slide 98 text

Gareth Rushgrove

Slide 99

Slide 99 text

Web application security scanner Gareth Rushgrove

Slide 100

Slide 100 text

arachni http://victim --modules=xss Gareth Rushgrove

Slide 101

Slide 101 text

+ +[+] 2 issues were detected. + +[+] [1] Trusted -- Cross-Site Scripting (XSS) +[~] ~~~~~~~~~~~~~~~~~~~~ +[~] ID Hash: +[~] Severity: High +[~] URL: http://victim/pictures/search.php +[~] Element: form +[~] Method: GET +[~] Tags: xss, regexp, injection, script +[~] Variable: query +[~] Description: +[~] Client-side code (like JavaScript) can be injected + into the web application which is then returned to + the user's browser. This can lead to a compromise + of the client's system or serve as a pivoting + point for other attacks. + Gareth Rushgrove

Slide 102

Slide 102 text

Gareth Rushgrove

Slide 103

Slide 103 text

OWASP ZAP Gareth Rushgrove OWASP ZAP

Slide 104

Slide 104 text

Gareth Rushgrove

Slide 105

Slide 105 text

Spider an entire site Gareth Rushgrove

Slide 106

Slide 106 text

Record session via HTTP proxy Gareth Rushgrove

Slide 107

Slide 107 text

./zap.sh -daemon Gareth Rushgrove

Slide 108

Slide 108 text

Gareth Rushgrove Python API

Slide 109

Slide 109 text

Gareth Rushgrove

Slide 110

Slide 110 text

zap = ZAP() zap.openurl(TARGET) zap.start_spider(TARGET) zap.start_scan(TARGET) Gareth Rushgrove

Slide 111

Slide 111 text

http://victim/pictures/search.php +------+----------------------------------+ | Risk | Description | +------+----------------------------------+ | High | Cross Site Scripting (Reflected) | +------+----------------------------------+ http://victim/css/ +--------+--------------------+ | Risk | Description | +--------+--------------------+ | Medium | Directory browsing | +--------+--------------------+ http://victim/users/login.php +---------------+---------------------------------------+ | Risk | Description | +---------------+---------------------------------------+ | Informational | X-Frame-Options header not set | | Low | Cookie set without HttpOnly flag | | Low | Password Autocomplete in browser | | Low | X-Content-Type-Options header missing | | Medium | Application Error disclosure | +---------------+---------------------------------------+ Gareth Rushgrove

Slide 112

Slide 112 text

Gauntlt Gareth Rushgrove

Slide 113

Slide 113 text

Gareth Rushgrove

Slide 114

Slide 114 text

Cucumber + security tool integrations Gareth Rushgrove

Slide 115

Slide 115 text

Officially supports! curl, nmap, sslyze, sqlmap, garmr Gareth Rushgrove

Slide 116

Slide 116 text

Gareth Rushgrove

Slide 117

Slide 117 text

$ gauntlt methods.attack Gareth Rushgrove

Slide 118

Slide 118 text

Gareth Rushgrove

Slide 119

Slide 119 text

Support in master dirb, arachni Gareth Rushgrove

Slide 120

Slide 120 text

Gareth Rushgrove

Slide 121

Slide 121 text

$ gauntlt xss.attack Gareth Rushgrove

Slide 122

Slide 122 text

Conclusions (You convinced me, now what?)

Slide 123

Slide 123 text

Gareth Rushgrove Use security monitoring to build and maintain checklists 1

Slide 124

Slide 124 text

Gareth Rushgrove Use penetration tests to discover how attackers work 2

Slide 125

Slide 125 text

Get security (monitoring) into your development pipeline Gareth Rushgrove 3

Slide 126

Slide 126 text

Gareth Rushgrove Help with packaging and configuration management 4

Slide 127

Slide 127 text

Gareth Rushgrove 5 Help integrate security tools with monitoring systems

Slide 128

Slide 128 text

Gareth Rushgrove Get security together with developers and operations 6

Slide 129

Slide 129 text

Questions? (And thanks for listening)