ipset - qccolab.com · title: microsoft powerpoint - ipset.pptx author: dkp created date: 4/11/2013...

22
Dynamic Firewalls with IPSet Chris Cooper Slides & Scripts: http://QCCoLab.com/ipset

Upload: others

Post on 25-Sep-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

Dynamic Firewalls with IPSetChris Cooper

Slides & Scripts:

http://QCCoLab.com/ipset

Page 2: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

Where this all Started

Page 3: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

MikroTik

• Linux Based

• Cheap

• Feature Rich

• Rugged

• Advanced

IPTables

Page 4: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

MikroTik

Page 5: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

IPSet

• Address Lists for IPTables

• IPSet project

– http://ipset.netfilter.org/

• Patch for Kernel 2.4.36

• Officially included in Kernel 2.6.39

• Nomatch & TC support added in 3.7

• Binary included in all major repos

Page 6: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

A List of Things

• IPSet can store many types of data

– IP – Single IP addresses

– Net – Variable length subnets (using CIDR)

– Ports – Lump multiple service ports together

– IP,Port – A specific port at a specific IP

– IP,port,IP – A specific connection

– IP,MAC – For your Layer 2 filtering needs

– Set – Group sets together (Yo, dawg…)

Page 7: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

Matching

• IPSet will match hosts inside networks

• Nomatch can be used for exceptions

Page 8: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

So What?

• IPSet Simplifies Rules

• Creates objects to work with

Page 9: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

Fail2Ban

• Fail2Ban – Bans IP’s that cause trouble

– http://www.fail2ban.org/

• Modular Design

• Watches logs for keys like failed logins

• Can take a variety of actions

– Default is IPTables rules to block

– Creates a long ugly list of block rules

Page 10: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

Fail2Ban

• IPSet support added very recently

• Not yet in any repos. Check GitHub

– action.d/iptables-ipset-proto4.conf

• IPSet is IPv6 friendly

– action.d/iptables-ipset-proto6.conf

vs

Oops. This refers

to the version of

IPSet used by

fail2ban.

Although IPSet

does still support

IPv6, fail2ban

does not.

Page 11: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

DenyHosts

• DenyHosts – Similar to fail2ban

– http://www.denyhosts.net/

• Centralized Server

Page 12: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

DenyHosts

• 12,000 IPTables rules is not practical

– Adds ~5ms latency to every connection

• Uses hosts.deny

– Requires tcpwrapper

– Stock Apache & OpenSSH not supported

– Only protects local services (not a firewall)

Page 13: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

It’s also Faster!

• IPSet’s Hash Tables are really fast

http://daemonkeeper.net/781/mass-blocking-ip-addresses-with-ipset/

Page 14: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

DenyHosts

• DenyHosts supports external scripts

• Add a quick script for setup

• PLUGIN_DENY PLUGIN_PURGE

• Just called for local trips (not database)

Page 15: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

DenyHosts

• Finally, add a script to cron

• Loads central databse entries

• Swap used for no interruption

Page 16: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

What Happened to Dynamic?

• IPSet supports timeouts

– Create rules that automatically expire

• Iptables rules can add entries to a set

– Create your own IPS systems inside netfilter

Page 17: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

Stop Brute Force Attempts

• Identify 3 SSH connections in 60 seconds

• Block the IP for 15 minutes

Page 18: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

Port Knocking

• Hit TCP 123

• Within 5 seconds hit TCP 1338

• Within 5 seconds hit UDP 1175

• Open access for 5 minutes

Page 19: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

More Ideas

• Detect & Block Port Scans

– UDP/TCP Port 0

– Look for invalid TCP Flags

• FIN,URG,PSH – Xmas Tree Scan

• FWSnort can convert Snort to IPTables

– Pick specific rules you understand

– http://www.cipherdyne.org/fwsnort/

• Beware of false positives!

Page 20: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

You can do more than DROP

• Be creative with targets

• DNAT

– Forward hostile hosts to a honeypot

• REDIRECT

– Redirect to a “Captive Portal” page until auth

– Warn users (Don’t be Comcast)

• LIMIT

– Rate limit new connections

Page 21: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

You can do more than DROP

• Mark packets for use with iproute2

– Route some users out a different connection

– Use statistic for source-based routing

• Throttle users with TC

– Detect p2p or bittorrent presence

• Easy to find, Hard to block

– Throttle all non-HTTP(s) traffic to dial-up

– Timeouts minimize false-positive impact

Page 22: ipset - qccolab.com · Title: Microsoft PowerPoint - ipset.pptx Author: DKP Created Date: 4/11/2013 9:47:09 PM

Questions?

• Chris Cooper

– Twitter: @CC_DKP

[email protected]

• Slides & Scripts:

– http://QCCoLab.com/ipset