Git Product home page Git Product logo

fail2rest's Introduction

fail2rest

Overview

fail2rest is a small REST server that aims to allow full administration of a fail2ban server via HTTP

fail2rest will eventually be used as a backend to a small web app to make fail2ban administration and reporting easier.

Requirements

fail2rest is written in Golang, so it requires a working Golang installation. If you have never used Golang before install it from your package manager, and then follow these instructions to setup your enviroment.

Some libraries currently are not building on older versions of Go, I recommend running the newest stable of Golang.

Installing

Once you have a working Golang installation all you need to do is run

go get -v github.com/sean-der/fail2rest
go install -v github.com/sean-der/fail2rest

fail2rest will now be available as a binary in your GOPATH, you can run 'fail2rest' from the command line, or copy it somewhere else to make it available to all users.

Use whereis fail2rest to locate your fail2rest binary. Next you need to configure fail2rest, and then finally make it a system service.

Configuration

fail2rest is configured via config.json, the default is located here. To load your config.json you use the --config flag fail2rest --config=my_config.json

fail2rest has two options that be configured via config.json

  • Fail2banSocket - The path to the fail2ban socket, can usually be found via grep socket /etc/fail2ban/fail2ban.conf you also have to run fail2rest as a user who has permissions to use this socket
  • Addr - The address that fail2rest is served upon, it is usually best so serve to the loopback, and then allow access via nginx see an example config in the fail2web repository

The default configuration file used by init-scripts is /etc/fail2rest.json. You should download the config to your /tmp/ dir and modify it to your needs.

cd /tmp/
wget https://raw.githubusercontent.com/sean-der/fail2rest/master/config.json

Once you finished editing the configuration file, you should move it from /tmp/config.json to /etc/fail2rest.json executing mv /tmp/config.json /etc/fail2rest.json

Running

Once you have a config.json all you need to do is run fail2rest --config config.json

However, fail2rest is designed to run as a service, so init scripts are provided that allow easy management of fail2rest. They can be found here Download the appropriate init file your Distribution. You may need to customize your init script to load your config.json, but most scripts default to /etc/fail2rest.json

Service

systemd

To run as a service you can either copy or create symlinks for systemd and the fail2rest binary. The systemd file shold be added to /etc/systemd/system/fail2rest.service and the the binary to /usr/bin/fail2rest. This scenario will use the symlinks in order to always use the latest files. You should run the commands with sudo if not logged in as root:

ln -s $GOPATH/bin/fail2rest /usr/bin/

Debian

ln -s $GOPATH/src/github.com/sean-der/fail2rest/init-scripts/systemd /etc/systemd/system/fail2rest.service

Other Linux

ln -s $GOPATH/src/github.com/sean-der/fail2rest/init-scripts/systemd /usr/lib/systemd/system/fail2rest.service

Enable fail2rest service to run at startup

systemctl enable fail2rest.service

Run the following systemd command to start the fail2rest service

systemctl start fail2rest.service

Verify that the fail2rest service it is active and running

systemctl status fail2rest.service

License

The MIT License (MIT)

Copyright (c) 2014 Sean DuBois

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

fail2rest's People

Contributors

djengineerllc avatar sean-der avatar

Stargazers

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

Watchers

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

fail2rest's Issues

Install errors on Debian Wheezy

After running go install -v github.com/Sean-Dir/fail2rest

Both have to do with the mattn/go-sqlite3 github
go1.go:650 undefined strings.TrimSuffix
go1.go:652 undefined time.ParseInLocation

Fail2Rest API - Adding a Match Parameter

Dear @Sean-Der ,

would there be a way for you to add a Match-Parameter to the REST-API?
This way, it would be easier for me to reconstruct the reason a user was banned by the attached system.

Thanks in advance!
Maik

Fully implement error handling

Currently many errors are uncaught, someone needs to write a single error generator function and have everyone call it.

Running fail2ban 0.9.:

Dear Sean,
Sorry to have to do this, but it seems that fail2rest doesn't work with the latest fail2ban 0.9.1. I actually went out of my way to get one of the latest versions of fail2ban available on Debian, because fail2rest gave me a message about presistent bans not being available on older version. But afterwards got the following problem:
Unknown opcode 149 (�) at position 2: '\u0095'
http://puu.sh/cP9G4/f17ae54d50.png

Checking the api request it was actually the first request /api/global/status that reported back with an error:
{"Error":"Unknown opcode 149 (�) at position 2: '\u0095'"}

About my version:
:/var/log# fail2ban-client --version
Fail2Ban v0.9.1

Copyright (c) 2004-2008 Cyril Jaquier, 2008- Fail2Ban Contributors
Copyright of modifications held by their respective authors.
Licensed under the GNU General Public License v2 (GPL).

Written by Cyril Jaquier [email protected].
Many contributions by Yaroslav O. Halchenko [email protected].

Before I wanted to send in this issue I actually re-built fail2rest fully from this repository, but that sadly didn't fix it.

Would love to hear your ideas

whereis fail2rest shows no location

Installing fail2rest went fine with go1.4. Although when I execute the whereis command nothing is shown. So I have no clue where I should put the configuration file. Any help?

I do have fail2go.a in my pkg folder. But that's it.

Query for a specific IP ?

Hello,
First, thank you for fail2rest/fail2web, these are great tools ! :)

I am trying to implement a simple HTML form with an IP address + recaptcha and then an ajax call to fail2rest to query if the IP is banned or not (whatever the jail). The next step would be to display the IP status and make another call to unban the IP if necessary.

I have found two endpoints that could help for step one :

  • GET /fail2web/api/global/bans => This works, but it's very slow because it returns all IP addresses, and a very verbose attribute "Matches" containing logs. Is there a way to get a response for a specific IP address here ? And/or to remove the Matches attributes in order to reduce load ?

  • GET /fail2web/api/whois/{IP} => This only returns a whois, there is no banned or not information.

Could you please tell me how could I achieve a simple query by IP address ?

For step two, I suppose I can use the following endpoint to unban the IP address ?
DELETE /fail2web/api/jail/{jailName}/bannedip with {data: {IP: '...'}}

Or maybe you have a better suggestion ?

Thank you again :)
Mathieu.

Error

go install -v github.com/Sean-Der/fail2rest
github.com/kisielk/og-rek

github.com/kisielk/og-rek

src/github.com/kisielk/og-rek/ogorek.go:677: reflect.TypeOf(key).Comparable undefined (type reflect.Type has no field or method Comparable)
src/github.com/kisielk/og-rek/ogorek.go:870: reflect.TypeOf(k).Comparable undefined (type reflect.Type has no field or method Comparable)
src/github.com/kisielk/og-rek/ogorek.go:897: reflect.TypeOf(key).Comparable undefined (type reflect.Type has no field or method Comparable)

pong request works status fails

Pong request works fine but status request failed, is empty.

[""]
centos 7
Fail2ban 0.9.2
Latest fail2rest.
This way fail2web gives an error:
404 Page Not Found - Couldn't contact fail2rest

nginx is used as webserver. nothing changed in configuration at all. What am i doing wrong.

All look fine if i open /api/jail/ssh the next output is shown.
{"Error":"UnknownJailException: ssh"}
This is as expected.

/api/ results in the 404 not found also.
should it be redirected or something?

regards,
Vincent

can't enable service

Hello,

I have migrate my serveur to Ubuntu 16.04.1 LTS and make a new installation of fail2rest on it.

Everything is ok the service work fine but I have a probléme for enable it on reboot of the server.

systemctl enable fail2rest.service
Failed to execute operation: Invalid argument

Do you have an idea ?

Regards.

fail2rest out of memory killed process

Hi,

I install fail2rest/fail2web on a centOS 7 and after I start fail2rest in anout a minute consume 4GB RAM and 4GB SWAP until process killed...

I follow the instructions on your site and use defauit config, I see it has only two options anyway...

feature request : port of a jail

Hello,

It's not really an issue but I don't know how to make a feature request so excuse me if it's not the good place.

Today I have 3 jail with http, 1 with ssh and 1 with mail protocol. I want to make a report with all ip banned from http but I can't find the port of jail in FAIL2REST. Can you please add it in /jail/jail_name or in /global/status ?

Thanks

Package missing

Hello,

A pakage is missing :

# go install -v github.com/Sean-Der/fail2rest
/root/go/src/github.com/mattn/go-sqlite3/sqlite3.go:189:2: cannot find package "context" in any of:
        /usr/lib/go-1.6/src/context (from $GOROOT)
        /root/go/src/context (from $GOPATH)

How to fix this ?

Unknown opcode

Hello,

I have a bug with fail2rest on a jail.
Unknown opcode 114 (r) at position 527: 'r'

Regards,
Rémy

Can't get fail2rest to run on CentOS

I setup golang and sucessfully created a fail2rest binary but when I start it:

fail2rest --config /etc/fail2rest.json

The command line prompt just hangs and doesn't return.

My config file is the same as the example:

{
"Addr": "127.0.0.1:5000",
"Fail2banSocket": "/var/run/fail2ban/fail2ban.sock"
}

I verified that is the correct location of the fail2bansock.

Any ideas of what to check?

I think the issue may be related to port 5000. It seems to be closed and I haven't been able to open it yet in IPtables.

fail2rest stop working after fail2ban update from 0.9.1 to 0.9.3

Hello,

I have update my fail2ban from 0.9.1 to 0.9.3 today.

My problem is after this operation fail2rest don't work.
My fail2ban and Fail2rest service are running but I have no answer on the adress of fail2rest It wait and no answer.

I have update Fail2rest to the last version with "go get -u github.com/Sean-Der/fail2rest && go install -v github.com/Sean-Der/fail2rest" but I still have my problem.

Fail2ban is runing correctly :
fail2ban-client status
Status
|- Number of jail: 8
`- Jail list: apache-badbots, ckeditor-connector, mail-login-sasl, scripts-setup, sshd, wordpress-config, wordpress-login, wordpress-xmlrpc

I haven't see fail2rest log I don't know if it exist.

Regards.

Write design doc for URL layout

Currently API calls are just being implemented ad-hoc with a soft guidance by existing calls, I need to add a guide with a definite design

interface conversion fail2go.(*Conn).JailStatus

Hi all, here is what is in the logs:

fail2rest[2897]: 2022/06/01 10:01:29 http: panic serving 127.0.0.1:35724: interface conversion: interface {} is ogórek.Call, not string
fail2rest[2897]: goroutine 405 [running]:
fail2rest[2897]: net/http.(*conn).serve.func1(0xc000076c80)
fail2rest[2897]: /usr/lib/go-1.15/src/net/http/server.go:1801 +0x147
fail2rest[2897]: panic(0x878fa0, 0xc000176540)
fail2rest[2897]: /usr/lib/go-1.15/src/runtime/panic.go:975 +0x47a
fail2rest[2897]: github.com/Sean-Der/fail2go.interfaceSliceToStringSlice(0xc00040a490, 0x1, 0x1, 0xc00040a4f0, 0x1, 0x1)
fail2rest[2897]: /root/go/src/github.com/Sean-Der/fail2go/utils.go:5 +0x16f
fail2rest[2897]: github.com/Sean-Der/fail2go.(*Conn).JailStatus(0xc000090dd0, 0xc0003bc06a, 0x4, 0x4, 0xc000072088, 0x30, 0x8a9960, 0xc00003a9a0, 0x414fb0, 0xc0000f6360, ...)
fail2rest[2897]: /root/go/src/github.com/Sean-Der/fail2go/jail.go:24 +0x3b7
fail2rest[2897]: main.jailGetHandler(0x944200, 0xc00011e0e0, 0xc000053000, 0xc000090dd0)
fail2rest[2897]: /root/go/src/github.com/Sean-Der/fail2rest/jail.go:16 +0x91
fail2rest[2897]: main.jailHandler.func10(0x944200, 0xc00011e0e0, 0xc000053000)
fail2rest[2897]: /root/go/src/github.com/Sean-Der/fail2rest/jail.go:255 +0x48
fail2rest[2897]: net/http.HandlerFunc.ServeHTTP(0xc000091830, 0x944200, 0xc00011e0e0, 0xc000053000)
fail2rest[2897]: /usr/lib/go-1.15/src/net/http/server.go:2042 +0x44
fail2rest[2897]: github.com/gorilla/mux.(*Router).ServeHTTP(0xc0000f8000, 0x944200, 0xc00011e0e0, 0xc000052b00)
fail2rest[2897]: /root/go/src/github.com/gorilla/mux/mux.go:212 +0xd3
fail2rest[2897]: net/http.(*ServeMux).ServeHTTP(0xb74140, 0x944200, 0xc00011e0e0, 0xc000052b00)
fail2rest[2897]: /usr/lib/go-1.15/src/net/http/server.go:2417 +0x1ad
fail2rest[2897]: net/http.serverHandler.ServeHTTP(0xc00011e000, 0x944200, 0xc00011e0e0, 0xc000052b00)
fail2rest[2897]: /usr/lib/go-1.15/src/net/http/server.go:2843 +0xa3
fail2rest[2897]: net/http.(*conn).serve(0xc000076c80, 0x944d00, 0xc0000a6740)
fail2rest[2897]: /usr/lib/go-1.15/src/net/http/server.go:1925 +0x8ad
fail2rest[2897]: created by net/http.(*Server).Serve
fail2rest[2897]: /usr/lib/go-1.15/src/net/http/server.go:2969 +0x36c

this happens when the address gets banned

~$ fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 5
| - File list: /var/log/auth.log - Actions
|- Currently banned: 1
|- Total banned: 2
`- Banned IP list: BAN-IP-ADDR

~$ go version
go version go1.15.15 linux/amd64
~$ cat /etc/debian_version
11.2
~$ fail2ban-server --version
Fail2Ban v0.11.2

How to use the init-scripts

As the title sais, should be added to documentation how to use the debian.sh and the systemd files.

For debian.sh I beleive it should be moved to /etc/init.d/fail2restd but for systemd I have no clue. Can you please help me with using the systemd script?

Thanks.

Interface conversion on /jail/ssh

2014/07/09 17:34:18 http: panic serving 127.0.0.1:53021: interface conversion: interface is ogórek.Call, not string
goroutine 21 [running]:
net/http.func·011()
        /usr/lib/go/src/pkg/net/http/server.go:1100 +0xb7
runtime.panic(0x6c1ba0, 0xc208040800)
        /usr/lib/go/src/pkg/runtime/panic.c:248 +0x18d
github.com/Sean-Der/fail2go.(*Conn).JailUseDNS(0xc2080007e0, 0xc20803eb0a, 0x3, 0x0, 0x0, 0x0, 0x0)
        /usr/lib/go/src/pkg/github.com/Sean-Der/fail2go/jail.go:118 +0x1a9
main.jailGetHandler(0x2b7c1dccfb68, 0xc2080506e0, 0xc208026680, 0xc2080007e0)
        /root/public_html/fail2rest/jail.go:23 +0x36f
main.func·011(0x2b7c1dccfb68, 0xc2080506e0, 0xc208026680)
        /root/public_html/fail2rest/jail.go:236 +0x47
net/http.HandlerFunc.ServeHTTP(0xc208076f50, 0x2b7c1dccfb68, 0xc2080506e0, 0xc208026680)
        /usr/lib/go/src/pkg/net/http/server.go:1235 +0x40
github.com/gorilla/mux.(*Router).ServeHTTP(0xc208018230, 0x2b7c1dccfb68, 0xc2080506e0, 0xc208026680)
        /usr/lib/go/src/pkg/github.com/gorilla/mux/mux.go:98 +0x292
net/http.(*ServeMux).ServeHTTP(0xc208022720, 0x2b7c1dccfb68, 0xc2080506e0, 0xc208026680)
        /usr/lib/go/src/pkg/net/http/server.go:1511 +0x1a3
net/http.serverHandler.ServeHTTP(0xc2080045a0, 0x2b7c1dccfb68, 0xc2080506e0, 0xc208026680)
        /usr/lib/go/src/pkg/net/http/server.go:1673 +0x19f
net/http.(*conn).serve(0xc20804e500)
        /usr/lib/go/src/pkg/net/http/server.go:1174 +0xa7e
created by net/http.(*Server).Serve
        /usr/lib/go/src/pkg/net/http/server.go:1721 +0x313
go version go1.3 linux/amd64

On Debian GNU/Linux Wheezy, using golang from Jessie.

The HTTP request was the following:

GET /jail/ssh HTTP/1.1
User-Agent: curl/7.26.0
Host: localhost:5000
Accept: */*

config.json:

{
  "Addr": "127.0.0.1:5000",
  "Fail2banSocket": "/var/run/fail2ban/fail2ban.sock"
}

cat /etc/fail2ban/fail2ban.conf | grep ^socket:

socket = /var/run/fail2ban/fail2ban.sock

installation problem on Ubuntu 20.04

Hello,

I used Fail2Rest on my old server and now I try to install it on my new server because I migrate it.
I have made all the installation with no error, Fail2Rest service is active but it seems that the server is not listening on port 5010.
Can you help me ?

Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-77-generic x86_64)
go version go1.16.5 linux/amd64

fail2ban-client status
Status
|- Number of jail: 1
`- Jail list: sshd

service fail2rest status
● fail2rest.service - fail2ban REST server
Loaded: loaded (/etc/systemd/system/fail2rest.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-06-29 17:57:59 CEST; 12min ago
Docs: man:fail2rest(1)
Main PID: 8768 (fail2rest)
Tasks: 6 (limit: 76742)
Memory: 1.7M
CGroup: /system.slice/fail2rest.service
└─8768 /usr/bin/fail2rest -config=/etc/fail2rest.json

Jun 29 17:57:59 vil.fluoo.com systemd[1]: Started fail2ban REST server.

cat /etc/fail2rest.json
{
"Addr": "127.0.0.1:5000",
"Fail2banSocket": "/var/run/fail2ban/fail2ban.sock"
}

ss -l | grep 5010
(Nothing here)

On my old server :
ss -l | grep 5010
tcp LISTEN 0 128 127.0.0.1:5010 :

Regards.

Chances on an update? :)

Hi

I stumbled across this by accident looking for a fail2ban GUI, and was fiddling with some docker images that try to implement your fail2web and fail2rest code.

Whilst fail2web starts up, and does talk to fail2rest (I managed to get /api/whois to behave) - any other call returns "invalid pickle version" - as it seems fail2ban 0.11.1 has switched up versions.

Is it possible you may update this to use the newer versions of Pickle?

[SOLVED] Error installing (sqlite3)

Hello,

After issuing "go install -v github.com/Sean-Der/fail2rest" I get the error:

"sqlite3.go:157[/tmp/go-build197093546/github.com/mattn/go-sqlite3/_obj/sqlite3.cgo1.go:115]: function ends without a return statement"

Any clue how to get past this?

Thank you

Run problem

make run command fail with :

go run *.go
failed to open config: open /tmp/go-build269890024/command-line-arguments/_obj/config.json: no such file or directory
exit status 1
make: *** [run] Error 1

Any idea ?

Thanks

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.