Fail2ban

From CVL Wiki

(Difference between revisions)
Jump to: navigation, search
(Installing Fail2ban)
Line 67: Line 67:
 
# Choose '''yes''' to start PF rules at startup
 
# Choose '''yes''' to start PF rules at startup
  
 
+
If you are using the ECE Crashplan app, please add a custom rule to Icefloor
 +
# Open '''IceFloor'''
 +
# Open the '''Firewall''' tab
 +
# Under the '''Services in selected Address Group''' box, click the '''pencil''' icon
 +
# Click '''Add new custom service'''
 +
# Enter "Crashplan" and "4242" for the '''Service Name''' and '''Ports''', and click '''Add service'''
 +
# Close the '''Add or Remove services...''' window
 +
# Now select the '''+''' (plus) icon under Services, and select the '''Crashplan''' service you created
 +
# Enter your '''login''' password, click '''Apply''', and enter your '''login''' password again.
  
 
====Install MacPorts====
 
====Install MacPorts====
 
add the below line to /opt/local/etc/fail2ban/filters.d/ssh.conf
 
add the below line to /opt/local/etc/fail2ban/filters.d/ssh.conf
 
  ^%(__prefix_line)s(?:error: PAM: )?unknown user for illegal user .* from <HOST>( via \S+)?\s*$
 
  ^%(__prefix_line)s(?:error: PAM: )?unknown user for illegal user .* from <HOST>( via \S+)?\s*$

Revision as of 12:21, 8 December 2014

Contents

Fail2ban

We use the package fail2ban on all of our linux machines to help prevent ssh password brute-forcing. This package will block an IP address after a certain number (usually 10) of failed attempts.

Removing Fail2ban Block

If your address has been accidentally blocked on a server, and you are able to log in and control the server (usually via a different computer) you can remove your banned IP address from iptables.

To unban an IP address manually, it is necessary to know the chain name and the rule number. The following command can be used to acquire this information:

Code:

iptables -L -n --line-numbers

The relevant bits are at the end of the output. Here is an example chain with attendant rules:

Code:

Chain fail2ban-ssh (1 references)
num  target     prot opt source               destination
1    DROP       all  --  204.110.13.107       anywhere
2    DROP       all  --  1.234.20.21          anywhere
3    DROP       all  --  gw-tair-rp.rel.com.ua  anywhere
4    RETURN     all  --  anywhere             anywhere

In this example, three (3) IP addresses have been banned via the SSH jail (these are the DROP rules).

To unban an IP address, you would run the following command:

Code:

iptables -D [chain-name] [line-number]

To unban the IP address 1.234.20.21 (see above), the command would be:

Code:

iptables -D fail2ban-ssh 2

Reference: http://www.howtoforge.com/forums/showthread.php?t=51366&page=2


Installing Fail2ban

OS X

This is an advanced setup, and requires using the terminal to install and modify files.

Install IceFloor

IceFloor is an open-source graphical front-end for pf, the default built-in firewall for OS X.

  1. Download and install IceFloor: http://www.hanynet.com/icefloor/
  2. Open IceFloor and enter your login password
  3. Read the Welcome Wizard and skip installing the IceFloor Menulet
  4. Open the Options tab
  5. Check the Enable Emerging Threats... line and Enable <sshguard>... line
  6. Open the Help tab and click on Configuration Wizard
  7. Enter your login password and click Continue
  8. On the "Allow Inbound Connections" page, select the following and click Next
    • Remote login (SSH)
    • iChat, Message and iPhoto
    • ICMP protocol
    • If you use iTunes, you should also enable iTunes sharing and Airplay
  9. On the "Allow outbound connections" page, leave the default Allow all outbound connection and click Next
    • If you are sure of what you are doing, you can limit outbound connections...doing this has the most chance of breaking something
  10. Check Enable Emerging Threats protection and click Save configuration
  11. Enter your login password
  12. Click the Start PF button and agree to the warning
  13. Enter your login password again...
  14. Choose yes to start PF rules at startup

If you are using the ECE Crashplan app, please add a custom rule to Icefloor

  1. Open IceFloor
  2. Open the Firewall tab
  3. Under the Services in selected Address Group box, click the pencil icon
  4. Click Add new custom service
  5. Enter "Crashplan" and "4242" for the Service Name and Ports, and click Add service
  6. Close the Add or Remove services... window
  7. Now select the + (plus) icon under Services, and select the Crashplan service you created
  8. Enter your login password, click Apply, and enter your login password again.

Install MacPorts

add the below line to /opt/local/etc/fail2ban/filters.d/ssh.conf

^%(__prefix_line)s(?:error: PAM: )?unknown user for illegal user .* from <HOST>( via \S+)?\s*$
Views
Personal tools
Support