Code Monkey home page Code Monkey logo

fds's Introduction

fds

Buy Me a Coffee

The go-to FirewallD CLI app that doesn't suck.

What is fds?

Firewall management is often a task that you do once at the time of setting up a server. But if you're maintaining a server like a PRO, you are monitoring logs, and blocking malicious users as they come, on a regular basis.

FirewallD is a great firewall software. It has the concepts of zones, sources, and supports IP sets. However, its client app, firewall-cmd is far from user-friendly when it comes to blocking and managing blocked IP addresses. Furthermore, if you also use Cloudflare firewall, you also want to propagate your blocked IP addresses to it for best protection.

fds is the CLI client for FirewallD/Cloudflare, that you'll love to use any day. It is an alternative, client for FirewallD.

Use it for simple or complex banning tasks, instead of firewall-cmd.

Look how simple things are with fds:

fds block <country name>
fds block 1.2.3.4

It makes the task of managing your FirewallD easy and human-friendly.

Installation on CentOS/RHEL, Fedora and Amazon Linux

First, install RPM repository configuration:

sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm

Free installation

For free installation and usage, disable the binary packages sub-repository, which contains non-essential dependencies for fds:

sudo yum -y install yum-utils
sudo yum-config-manager --disable getpagespeed-extras

Now you can install fds:

sudo yum -y install fds

Installation with subscription

By subscribing to the GetPageSpeed RPM repository, you gain access to a number of packages other than fds, as well support its development.

Simply run this command:

sudo yum -y install fds

The subscription ships with packages for IP prefixes' aggregation. fds can use those, and thus essentially overcome some serious FirewallD bugs.

So it's highly recommended to also run the following if you are a subscriber:

CentOS/RHEL 7 only

sudo yum -y install python2-aggregate6

CentOS/RHEL 8+, Fedora and Amazon Linux

sudo yum -y install python3-aggregate6

What fds can do

The fds is utility program for users of FirewallD. It is a helper to easily perform day-to-day firewall tasks:

  • block users of Tor
  • block countries
  • block arbitrary IP addresses
  • block the same over at Cloudflare

Integrations

By default, fds only operates with FirewallD.

To enable Cloudflare integration, run:

fds config 

Block Tor

You can block all Tor exit nodes by running:

fds block tor

Note that since these addresses constantly change, you may want to run this command in a cron.

Ban a single IP

fds block 1.2.3.4

This blocks IP address in a proper(©) fashion by ensuring that the IP is in a set named networkblock4, that the set is a source to FirewallD's drop zone. Using IP sets is the corner stone of consistent firewall management!

fds is also smart enough to break any existing connections originating from that IP address. Useful if malicious requests are in process.

You can specify base name of created/used IP set for blocking, by specifying it in --ipset, e.g. for banned4 (IPv4) or banned4 (IPv6), use:

fds block 1.2.3.4 --ipset banned

Ban a country or a continent

fds block <Country Name>
fds block China
fds block Asia

To block a country which has spaces in its name, use quotes:

fds block "Country Name"

You can list all country names available for blocking by running:

fds list countries

You can list all continents available for blocking by running:

fds list continents

--no-reload (-nr)

Use this optional flag to prevent FirewallD from being reloaded. This is only useful when adding multiple blocks, as it ensure faster blocking:

fds block 1.2.3.4 --no-reload
fds block 2.3.4.5 --no-reload
fds block Country1 --no-reload
...
fds block Country2

In the above example, we block some IP addresses and a few countries. The last block operation will reload FirewallD and actually apply our ban.

Alternatively, invoke all fds block with --no-reload option and invoke firewall-cmd --reload in the end.

List all blocked networks and countries

The following allows to easily see what is blocked:

fds list blocked

Unblock a country or IP/network

Use fds unblock ... like the following:

fds unblock China
fds unblock 1.2.3.4

Reset all bans

You can quickly remove all blocks (and by that, all IP sets associated with fds):

fds reset

Notes

The fds package automatically installs a cron job that syncs your blocked IP sets daily. So there is no need to do anything to ensure a country (or Tor) stays blocked.

Planned

See contributing guide for development setup (if not using packages).

Files

  • not in use: /etc/fds.conf (info on currently blocked countries or otherwise small data sets suitable for a single config file)
  • not in use: /var/lib/fds: zone files, (state data) + (info on what is currently blocked) (???)
  • /var/cache/fds: cachecontrol cache
  • /root/.cloudflare/cloudflare.cfg Cloudflare authentication

fds's People

Contributors

deepsourcebot avatar dvershinin avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fds's Issues

fds block hosting

Create hosting ASN database:

For each ASN

  1. Look up ASN using ipinfo.io free db
  2. Confirm it is "Content" type (means hosting): https://www.peeringdb.com/api/net?asn=63949
  3. Set up a database with worldwide hosting ASNs
def check_content_network_type(asn):
    peeringdb_api_url = f"https://peeringdb.com/api/net?asn={asn}"
    response = requests.get(peeringdb_api_url)
    response_json = response.json()
    
    if response_json["data"]:
        network_type = response_json["data"][0]["info_type"]
        return network_type == "Content"
    else:
        return False

Similiar existing datasets:

fds block should block all ASNs ranges by getting their IP sets + block simply as AS63949 on Cloudflare side (it supports specifying in this way)

FDS appears to caused a firewall issue, had to restore from backup due to time constraints.

First off, I really like the program. I'm bad at firewall management and this makes it very easy in concept.

That said, I ran into an issue this AM when I tried to block a subnet on a production server running centOS 8. I installed FDS yesterday so I'm assuming I was using the current version What I think happened (can't review logs because I had to restore the server from backup) is I forgot to add a subnet mask to a subnet. I then got a bunch of json looking stuff puked to screen. I then added the correct subnet mask and re-ran the command, same json stuff, reran the command again and it indicated it worked. Went through the list of subnets I needed to block and got the same json junk the first time and the normal output the second time. Then noticed the server wasn't accepting any incoming connections anymore. Checked the status of firewalld and it had a bunch of red warnings with the JSON looking content FDS had apparently tried to add as firewall rules. Since I don't know where those rules actually are to remove them manually I tried uninstalling firewalld. Still had no incoming connections and couldn't hit any of my services. Firewall seems to have been blocking everything and I couldn't figure out where those rules were to fix them. Was running out of time on my maintenance window so restored from backup to a point before I had installed FDS, which fixed the connection issue. This was on a Linode VPS I was SSHed into from across the country so I know there wasn't any hardware problem that might have overlapped with the weird stuff FDS did to the firewall rules as I never lost my SSH session. I also tried to unblock everything in FDS by going through my CLI log, that didn't work either. Sorry I don't have logs to send you, but I didn't do anything very odd so I imagine this will come up again if you can't replicate.

Really like the program in concept, hope to be able to use it in future. Wanted to let you know about the issue I ran into and to say thanks for your efforts to make firewall management easier.

fds block Asia crashes

Trying to do as title says on Centos 7.

Can send the entire output, but the last lines are as follows:
Starting new HTTP connection (1): www.ipdeny.com Downloaded /var/lib/fds/ge.zone: : 16KB [00:00, 30311.14KB/s] Done! Skipped update in Cloudflare as it was not set up. Run fds config? Traceback (most recent call last): File "/usr/bin/fds", line 9, in <module> load_entry_point('fds==0.0.37', 'console_scripts', 'fds')() File "/usr/lib/python2.7/site-packages/fds/fds.py", line 208, in main return action_block(args.value, args.ipset_name, reload=args.reload) File "/usr/lib/python2.7/site-packages/fds/fds.py", line 62, in action_block block_region(ip_or_country_name) File "/usr/lib/python2.7/site-packages/fds/fds.py", line 42, in block_region action_block(country.name, reload=False) File "/usr/lib/python2.7/site-packages/fds/fds.py", line 47, in action_block fw = FirewallWrapper() File "/usr/lib/python2.7/site-packages/fds/FirewallWrapper.py", line 67, in __init__ self.fw = FirewallClient() File "<string>", line 2, in __init__ File "/usr/lib/python2.7/site-packages/firewall/client.py", line 53, in handle_exceptions return func(*args, **kwargs) File "/usr/lib/python2.7/site-packages/firewall/client.py", line 2509, in __init__ path_keyword='path') File "/usr/lib64/python2.7/site-packages/dbus/bus.py", line 160, in add_signal_receiver self.add_match_string(str(match)) File "/usr/lib64/python2.7/site-packages/dbus/bus.py", line 398, in add_match_string BUS_DAEMON_IFACE, 'AddMatch', 's', (rule,)) File "/usr/lib64/python2.7/site-packages/dbus/connection.py", line 651, in call_blocking message, timeout) dbus.exceptions.DBusException: org.freedesktop.DBus.Error.LimitsExceeded: Connection ":1.28" is not allowed to add more match rules (increase limits in configuration file if required)

fds cron

The command should check all blocked countries/lists for update and refresh entries.
Package should install the cron task by default.

Onboarding

Instead of passing a ton of options (and knowing them), the easiest way to set up anything is going through a series of questions. E.g.

  1. Do you run http server (Y, default to that if detected NGINX install), otherwise default to N
  2. Do you want to block some countries (default to cn, sorry China)
  3. Running behind Cloudflare?, if yes then prompt for an API key, etc.

Changing Cloudflare API token

Hey,
is there a way to change the Cloudflare API token? I accidentally entered a wrong one and can't find a way to change it anywhere.
I tried running the config command again and uninstalling FDS including all files but nothing helped.

FDS Config Error

I am receiving an error when trying to run FDS Config on RHEL 8.3.

[root@mail ~]# fds config
Traceback (most recent call last):
File "/usr/bin/fds", line 11, in
load_entry_point('fds==0.0.19', 'console_scripts', 'fds')()
File "/usr/lib/python3.6/site-packages/fds/fds.py", line 191, in main
return action_config()
File "/usr/lib/python3.6/site-packages/fds/config.py", line 24, in action_config
open_web_if_webserver_running()
File "/usr/lib/python3.6/site-packages/fds/config.py", line 8, in open_web_if_webserver_running
from .utils import is_process_running, query_yes_no
File "/usr/lib/python3.6/site-packages/fds/utils.py", line 1, in
import psutil
ModuleNotFoundError: No module named 'psutil'

[root@mail ~]# fds --version
fds 0.0.19

Blocks to invasive

I just tested it on my server/gateway at home, works very well on blocking entire countries. To well.

It sure do block access from a specific country, but it also block outgoing connections to that country. If I block fx. US, I can not access anything coming from there (DuckDuckGo, GitHub etc). Option to accept RELATED ESTABLISHED connections should be allowed when initialized from "the inside", and only block access from new connections made from the outside.

Blocking whole Continents

Hi,

I would love to have an option to block complete continents. And also a deny-all option, meaning to block all and specifically unblock countries would be nice.

Greetings

Joe

Won't update, won't reinstall

In an attempt to get fds updated so I can use the new TOR blocking I tried
yum -y update fds
nothing to update
So, I figured I'd uninstall and reinstall
yum -y remove fds
yum -y install fds
no package found
I also did
yum -y reinstall https://extras.getpagespeed.com/release-latest.rpm
which it did, but still
yum install fds
results in no package found
Any ideas on how to get fds package to be found and install again?

Fail2ban action

Add a sample fail2ban action so that fds can be used as a block backend
fds as block action fail2ban

Sorry not an issue - request to add IP set

This will save me tons of time - thanks for that.
One request - I find many hackers come in via TOR - would be nice if you could include a set for this IP list also.
Thanks, Wes

Cloudflare - if not entitled to block, allow for using Challenge or JS Challenge (available in all plans)

Feature Request:

Since the country block is only available for certain plans, and not everyone may be subscribed to those, it would be nice to add the ability to set the configuration for fds to use the challenge option or js-challenge option for the country, or, add it as a CLI option (e.g. fds block Country1 challenge)

image

Maybe a future option will give the ability to add/update firewall rules with the country block, but, that's probably going to take a little more coding to make happen...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.