44
Our My first DDoS attack Velocity Europe 2011 – Berlin Cosimo Streppone Operations Lead

Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

Embed Size (px)

Citation preview

Page 1: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

Our My first DDoS attack

Velocity Europe 2011 – BerlinCosimo Streppone

Operations Lead

Page 2: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

<video of Mr. Wolf going to Jimmy's house in Pulp Fiction>this couldn't fit in the PDF... sorry.

http://www.youtube.com/watch?v=hsKv5d0sIlU

Page 3: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class
Page 4: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class
Page 5: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class
Page 6: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class
Page 7: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

my.opera.com/Ao-Trang-Oi/blog/

Page 8: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

nginx – secret sauces?

# Pavel's secret gzip tuning saucegzip on;gzip_disable msie6;gzip_min_length 1100;gzip_buffers 16 8k;gzip_comp_level 3;gzip_types text/plain application/xml application/x-javascript text/css;

Page 9: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

nginx – secret sauces?

# Michael's secret file cache sauceopen_file_cache max=1000 inactive=20s;open_file_cache_valid 30s;open_file_cache_min_uses 2;open_file_cache_errors on;

Page 10: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

nginx – antidos.conf

# More on https://calomel.org/nginx.htmlclient_header_timeout 5;client_body_timeout 10; ignore_invalid_headers on; send_timeout 10;

# To limit slowloris-like attacksclient_header_buffer_size 4k; large_client_header_buffers 4 4k;

Page 11: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

# Cut abusive established connections,# forcing clients to reconnectlocation ~ ^/Ao-Trang-Oi/blog/ { return 444;}

nginx – drop client connections

Page 12: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

nginx

backends

varnish

nginx – varnish caching

Page 13: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

iptraf

Page 14: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

GET /Ao-Trang-Oi/blog/show.dml/14715682 HTTP/1.1

User-Agent: 1.{RND 10}.{RND 10} Referrer: http://my.opera.com/Ao-Trang-Oi/ Cache-Control: no-cache Cookie: __utma=218314117.745395330 […] __utmz=218314117.1286774593. […] utmcsr=google|utmccn= […] utmctr=cach%20de%20hoc%20mon […]

<... random high speed junk follows ...>

tcpdump of anomalous traffic

Page 15: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

GET /Ao-Trang-Oi/blog/?startidx=1295 HTTP/1.1

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;) Gecko/20030624 Netscape/7.1 (ax) Accept: Accept=text/html,application/xhtml+xml,... Accept-Language: Accept-Language=en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: Accept-Charset=ISO-8859-1,... Referer: http://my.opera.com/Ao-Trang-Oi/blog/ Pragma: no-cache Keep-Alive: 300 ua-cpu: x86 Connection: close

tcpdump of anomalous traffic

Page 16: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

cosimo: we're seeing a pretty "interesting" problem within our nginx frontscosimo: there's a few hosts sending a legitimate HTTP GET requestcosimo: followed by a binary stream of random bytes that never endscosimo: this is just 1 request going on and oncosimo: is there some way to alter the nginx config to shut down these client connections?cosimo: the client is sending something like:cosimo: GET /blah HTTP/1.1cosimo: Host: ...cosimo: Etc: etc...cosimo: and then random bullshit vr: :) vr: this is nkiller2 vr: haproxy can fight this vr: you can set a timeout http-request vr: don't know if nginx can do thiscosimo: cool

OMGWTFBBQ!!!!11111“this is nkiller2”

#nginx, 14th October 2010

BLAH BLAH BLAH BLAH BLAH BLBLAH BLAH BLAH

Page 17: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

PHRACK#66

Page 18: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

tcp window zero?

Page 19: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

iptables -A -m u32 --u32 “6&0xFF=0x6 && 4&0x1FFF=0 && 0>>22&0x3C () 12&0xFFFF=0x0000” -j ZERO_WINDOW_RECENT

Page 20: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

u32 zero window filter

6 &0xFF =0x6

Page 21: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

4 &0x1FFF =0x0

u32 zero window filter

Page 22: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

u32 zero window filter

0>>22 &0x3C ()12 &0xFFFF =0x0

Page 23: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

0>>22 &0x3C ()12 &0xFFFF =0x0

??

u32 zero window filter

Page 24: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

0>>22&0...@12&0xFFFF=0x0000

Page 25: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

0>>22&0x3C@12&0xFFFF=0x0000

Page 26: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

0>>22& [EMAIL PROTECTED] &0xFFFF=0x0000

Page 27: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

0>>22&0x3C@12&0xFFFF=0x0000

Page 28: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

0>>22 &0x3C @12 &0xFFFF =0x0

u32 zero window filter

Page 29: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

iptables rules - logging

$ipt -N ZERO_WINDOW_RECENT

$ipt -A INPUT -m u32 --u32 "6&0xFF=0x6 && 4&0x1FFF=0 && 0>>22&0x3C@12&0xFFFF=0x0000" -j ZERO_WINDOW_RECENT

$ipt -A ZERO_WINDOW_RECENT -m recent --set --name ZERO_WINDOW

$ipt -A ZERO_WINDOW_RECENT -m recent --update --seconds 60 --hitcount 20 --name ZERO_WINDOW -j LOG --log-level info --log-prefix "ZeroWindow"

Page 30: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

~18k distinct IPs

Page 31: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

iptables rules - blocking

$ipt -N ZERO_WINDOW_RECENT$ipt -A INPUT -m u32 --u32 "6&0xFF=0x6 && 4&0x1FFF=0 && 0>>22&0x3C@12&0xFFFF=0x0000" -j ZERO_WINDOW_RECENT$ipt -A ZERO_WINDOW_RECENT -m recent –set --name ZERO_WINDOW

$ipt -A ZERO_WINDOW_RECENT -m recent –update --seconds 60 --hitcount 20 --name ZERO_WINDOW -j DROP

Page 32: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

nginx

backends

varnish

shields-up.vcl

non-cacheable content

cacheable content

Page 33: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

nginx

backends

varnish

HTTPS-only traffic

shields-up.vcl

all HTTP content

Page 34: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

nginx feels better

Page 35: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

10s

20s

0s

Pingdom response time

Page 36: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

End 29-Oct-2010

Page 37: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

Start 13-Oct-2010 End 29-Oct-2010

Packets/s seen by firewall

Page 38: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class
Page 39: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class
Page 40: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

¿Questions?

Page 41: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

What can we, as Ops, do better?

● Embrace failures and learn from them

● Be fast (no panic/blame, think Mr. Wolf)

● Coordinate (#ops, war rooms, ...)

● Take notes

● Learn TCP/IP

● Know your tools

(tcpdump, tcpflow, strace, nc, iptraf, …)

Page 42: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

my base_packages puppet module

class base_packages {

$packagelist = [ "ack-grep", "colordiff", "curl", "facter", "git-core", "htop", "iftop", "iptraf", "jed", "joe", "libwww-perl", "logrotate", "lsof", "make", "mc", "oprofile", "psmisc", "rsync", "screen", "svn", "sysstat", "tcpdump", "tcpflow", "telnet", "unzip", "vim", "zip" ]

package { $packagelist: ensure => "installed", }

}

Page 43: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

Thanks to...

● ithilgore (sock-raw.org) for writing nkiller2

● @vr in #nginx for pointing us at nkiller2

● David Falloon for his great “untested” idea

● marc.info for correctly handling “@” in ml

● SANS Institute for the TCP/IP references

● My team at Opera

Page 44: Our My first DDoS attack - O'Reilly Mediaassets.en.oreilly.com/1/event/74/Our First DDoS attack Presentation... · Our My first DDoS attack ... my base_packages puppet module class

Danke!