Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup fail2ban to cover wings.md #468

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions community/Wings Fail2ban Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

Fail2ban is a program that works with iptables to better secure your server and services from brute force login attempts

### Step 1: if you havent already Using your preferred package manager instal Fail2Ban
### Step 1: instal Fail2Ban
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be install here.

(to my best knowledge, iptables will come with fail2ban when you install it, but if not install that too)
Chronic-Reflexes marked this conversation as resolved.
Show resolved Hide resolved

`apt-get install fail2ban`

### Step 2: After you install Fail2Ban Copy some files, If you already have local files, skip these steps
#### We have to copy .conf to .local files, as .conf may be wiped with updates. Local files will persist
### Step 2: Copy some files, If you already have local files skip this
#### We have to copy .conf to .local files, as Local files will persist through updates

`cd /etc/fail2ban`
`cp fail2ban.conf fail2ban.local`
`cp jail.conf jail.local`

### Step 3 Copy some text into the new local files using your favorite text editor, here we're going to be using nano
### Step 3 Copy some text into the new local files

`nano /etc/fail2ban/jail.local`

scroll down until you see the actual jail portion of the file, input this text below the [SSHD] block, save it and exit

[wings]
enabled = true
port = 2022
logpath = /var/log/pterodactyl/wings.log
maxretry = 4
findtime = 3600
bantime = -1
backend = systemd

```
[wings]
enabled = true
port = 2022
logpath = /var/log/pterodactyl/wings.log
maxretry = 4
findtime = 3600
bantime = -1
backend = systemd
```

### Step 4: Create the filter file and copy some more text

Expand All @@ -37,41 +37,46 @@ scroll down until you see the actual jail portion of the file, input this text b
`nano wings.conf`

Copy this text into the newly created file, Save then exit
```
# Fail2Ban filter for wings (Pterodactyl daemon)
#
#
#
# "WARN: [Sep 8 18:51:00.414] failed to validate user credentials (invalid format) ip=<HOST>:51782 subsystem=sftp username=logout"
#

# Fail2Ban filter for wings (Pterodactyl daemon)
#
#
#
# "WARN: [Sep 8 18:51:00.414] failed to validate user credentials (invalid format) ip=<HOST>:51782 subsystem=sftp username=logout"
#

[INCLUDES]

before = common.conf

[Definition]
[INCLUDES]

before = common.conf

_daemon = wings
[Definition]

failregex = failed to validate user credentials \([^\)]+\) ip=<HOST>:.* subsystem=sftp username=.*$
_daemon = wings

ignoreregex =
failregex = failed to validate user credentials \([^\)]+\) ip=<HOST>:.* subsystem=sftp username=.*$

[Init]
ignoreregex =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, in order to increase the search performance from the systemd backend, it is great to add a journalmatch. Anyway, without it, I had a warning that told me this parameter was missing. Here is what I have done by my side: journalmatch = _SYSTEMD_UNIT=wings.service + _COMM=wings

datepattern = \[%%b %%d %%H:%%M:%%S.%%f\]
[Init]

datepattern = \[%%b %%d %%H:%%M:%%S.%%f\]
```

### Step 5 enable the Fail2ban service to boot on startup and your done :D
### Step 5: Enable Fail2ban service

`systemctl enable fail2ban`


Notes:
#### Notes:
The rules applied to wings are fairly strict so if you feel like you need to adjust them, the settings are as follows
Max retry is the number of failed attempts someone can do within the time defined in "findtime" before they are banned

example: maxretry = 4 with findtime = 3600 with bantime = -1

this will allow 4 failed login attempts within 3600 seconds (1 hour) before permanently banning someone
There are different time modifiers you can use, Most people will be using dd (day) mm (month) yy (year)
I do suggest you read up on fail2ban docs, you can get highly customised protection from custom configuration
https://manpages.debian.org/testing/fail2ban/jail.conf.5.en.html#TIME_ABBREVIATION_FORMAT



Expand Down