Make sure that no user has no password and even less a password identical to the login (very common!!).
TFTP (Trivial File Transfer Protocol) is a simplified FTP service , it is used in particular for booting X terminals. It does not require any authentication, anyone can connect and read what they want.
So I advise you to disable everything that revolves around FTP and to favor SFTP provided with OpenSSH .
/ 10 GB
/usr 10 GB at least
/var 5 GB
/home 10 GB per user at least
swap 2*RAM size at least
/usr/local at least 10 GB (to store your apps)
Once the installation is complete, activate the system update automatically or not, these updates correct security holes. These patches are essential to properly secure a system, if you have not activated the automatic update, you must regularly monitor their release. Be aware that there are mailing lists on this subject that will automatically notify you of the release of a new patch. Personally I have not activated the automatic update because I prefer to control the installation of packages, some of which can cause regressions, it is necessary to analyze on a case-by-case basis.
I advise you to keep an administrator's notebook where you will note each of your system manipulations, it can be a bit schoolboyish, even tedious, but it can be extremely useful in certain cases. A simple text file (400 root owner rights) with a copy and paste of the commands (and the results that go with them), and a few annotations should do the trick.
Systemd is a super daemon that allows you to launch a whole bunch of other daemons (or services) all by itself. It is based on what we call units, there are several kinds
automount : for filesystems mounted with automount
device : for devices (special files)
mount : for filesystems mounted (using /etc/fstab or on the fly (USB stick, ...)
path : for scripts and exe indicated by their path
service : for daemons
socket : for sockets
swap : for swap
target : for groups of several units (for example network.target manages all my network related services)
To stop a unit you will have to type
systemctl stop nom-du-service
and to deactivate it (that is to say that it will no longer launch at the next startup) you will have to type
systemctl disable service-nameor even via the more universal webmin
pwconv
In the password
field of /etc/passwd (the second one) you should find an x, a file /etc/shadow has been created containing the encrypted
passwords.
Now we will delete as much
as possible all the useless system accounts, if you don't need
them, delete them, because they are so many entry points for
hackers. The following system accounts are necessary:
root, bin, daemon, adm, lp (if you have a printing system), mail (if mail
server), news (if news server), uucp (if you use
UUCP), nobody
These are optional:
games, gopher, halt, sync, shutdown, operator, ftp (if anonymous FTP server), lists, xfs.
Do the same for the other commands.
NOTES : - Remember that a user can very well belong to two groupsAs for root, you must take
some precautions:
- you must not add the . (current
directory) in the root PATH, because if by misfortune someone
creates a script with executable rights in /tmp called rm containing:
#!/bin/bash
rm -Rf /
If root has the misfortune to type rm while in /tmp , this is the script that can be called (following the order of the paths in the PATH) and poof! no more system.
touch /.rhosts
/etc/hosts.equiv
chmod 0 /.rhosts
/etc/hosts.equiv
To find .rhosts in users' home directories, type:
find /home -name .rhosts -print
Shorewall configuration level , this gives this, all the files are under /etc/shorewall , that's it for the zones file
# Shorewall version 4 – Zones File
#
# For information about this file, type “man shorewall-zones”
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-zones.html
#
#############################################################################
#ZONE TYPE OPTIONS IN OUT
# OPTIONS OPTIONS
fw firewall
lan ipv4
the fw zone corresponds to the server that acts as a firewall, the lan zone corresponds indifferently to the internet and the local network. Here is now the interfaces file
# Shorewall version 4 – Interfaces File
#
# For information about entries in this file, type “man shorewall-interfaces”
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-interfaces.html
#
#############################################################################
##############################################################################
#INTERFACE OPTIONS ZONE OPTIONS
lan eno2 –
my network card used is defined by eno2 , my eno1 card is not used, the ifconfig -a command allows you to know the name of its network interfaces. the hosts file is empty (or almost)
# Shorewall version 4 – Hosts file
#
# For information about entries in this file, type “man shorewall-hosts”
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-hosts.html
#
############################################################################
#HOST ZONE OPTIONS
the policy file defines the default rules
# Shorewall version 4 – Policy File
#
# For information about entries in this file, type “man shorewall-policy”
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-policy.html
#
#############################################################################
#SOURCE DEST POLICY LOG LIMIT: CONNLIMIT:
fw lan ACCEPT
all all REJECT info
basically all frames from the server to the internet are accepted and all others are rejected, so you need to define some exceptions with the rules file here
# Shorewall version 4 – Rules File
#
# For information on the settings in this file, type “man shorewall-rules”
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-rules.html
#
############################################################################################### ###############################################################################################
#ACTION SOURCE DEST PROTO DEST SOURCE ORIGINAL RATE USER/ MARK CONNLIMIT TIME HEADERS SWITCH HELPER
# PORT(S) PORT(S) DEST LIMIT GROUP
ACCEPT fw lan icmp
ACCEPT lan:192.168.1.0/24 fw tcp 22,25,80,111,389,995,2049,3306,10000
ACCEPT lan:192.168.1.0/24 fw udp 111.2049
ACCEPT lan:192.168.1.0/24 fw icmp
DNS(ACCEPT) fw lan
Machines on the local network with address 192.168.1.X are allowed to access the server on port 22 ( OpenSSH ), 25 ( SMTP ), 80 ( Apache/httpd ), 111 ( portmapper ), 389 ( OpenLDAP ), 995 ( POP3s ), 2049 ( NFS ), 3306 ( MySQL ) and 10000 ( Webmin ). DNS queries from the server to the internet are also allowed and pings are also allowed .
Now the server can still be reached via client stations and these must also be protected. I have limited the traffic to and from the internet to the strict minimum, always with shorewall . Example of configuration of a client connected via an RJ45 interface that can be pinged, zones file
# Shorewall version 4 – Zones File
#
# For information about this file, type “man shorewall-zones”
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-zones.html
#
#############################################################################
#ZONE TYPE OPTIONS IN OUT
# OPTIONS OPTIONS
net ipv4
fw firewall
interfaces file
# Shorewall version 4 – Interfaces File
#
# For information about entries in this file, type “man shorewall-interfaces”
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-interfaces.html
#
#############################################################################
##############################################################################
#ZONE INTERFACE OPTIONS
net eno1 detect
empty hosts file , policy file
# Shorewall version 4 – Policy File
#
# For information about entries in this file, type “man shorewall-policy”
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-policy.html
#
#############################################################################
#SOURCE DEST POLICY LOG LIMIT: CONNLIMIT:
fw net ACCEPT
net all DROP info
all all REJECT info
and rules file
# Shorewall version 4 – Rules File
#
# For information on the settings in this file, type “man shorewall-rules”
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-rules.html
#
################################################################################################ ################################################################################################
#ACTION SOURCE DEST PROTO DEST SOURCE ORIGINAL RATE USER/ MARK CONNLIMIT TIME HEADERS SWITCH HELPER
# PORT(S) PORT(S) DEST LIMIT GROUP
ACCEPT net fw icmp 8 –
The purpose of this chapter is to explain to you how to set up lists of IP addresses recognized as being a potential threat. It turns out that certain entities are responsible for collecting these lists and making them available to the community. All that remains is to have them taken into account by the shorewall firewall which will block the IP addresses from the outset.
The source of this chapter is mainly the mageia wiki in English at https://wiki.mageia.org/en/Firewall or you can also consult this entry from the mageia forum.
This filtering is based on shorewall but also on the ipset tool . IPset allows you to store lists of IP addresses, but also networks, port numbers, MAC addresses or even combinations of all of these. Intrinsically IPtables on which shorewall is based could do the same thing, but IPset is optimized so that indexing and searching in the list is infinitely faster.
This page simply explains to you how IPset works.
IPset is linked to the Linux kernel, it will be necessary to install the following packages on a Mageiaurpmi xtables-addons xtables-geoip xtables-addons-kernel-desktop-latest
To see if IPset is well integrated, you will have to typeshorewall show capabilities | grep Ipset
This is the result
Ipset Match Counters
(IPSET_MATCH_COUNTERS): Available
Ipset Match
(IPSET_MATCH): Available
Ipset Match Nomatch
(IPSET_MATCH_NOMATCH): Available
For the lists of threatening IP addresses, we will use those of the abuseipdb and spamhaus sites . Now we will have to create an account for the first one and retrieve a key that we will use to download the list.
We will now create the following script /usr/bin/shorewall-vilains which will contain#!/bin/bash
# Script origin
#
https://wiki.mageia.org/en/Firewall
###########################
# Defining multiple
variables
# for IP address lists
SPAMHAUS_DROP="/usr/local/var/drop.txt"
SPAMHAUS_eDROP="/usr/local/var/edrop.txt"
ABUSE_DROP="/usr/local/var/abuseip.txt"
SPAMURL="https://www.spamhaus.org/drop/drop.txt"
eSPAMURL="https://www.spamhaus.org/drop/edrop.txt"
DROP_ADD_TO_FW="/usr/local/var/DROP2.txt"
eDROP_ADD_TO_FW="/usr/local/var/eDROP2.txt"
ABUSE_ADD_TO_FW="/usr/local/var/abuseipv4.txt"
SAVE_SPAM="/etc/shorewall/spamhaus"
SAVE_SPAME="/etc/shorewall/espamhaus"
SAVE_ABUSE="/etc/shorewall/abuseipdb"
# Name of lists for the
ABUSE
firewall="abusedrop";
SPAM="spamhausdrop";
SPAME="spamhausedrop";
#
echo ">>"
echo "Start: $(date)"
echo ">"
#
# Purge previous IP
#
echo "Creating ipset DROP
rules"
/usr/sbin/ipset -exist
create $ABUSE hash:net counters
/usr/sbin/ipset -exist
create $SPAM hash:net counters
/usr/sbin/ipset -exist
create $SPAME hash:net counters
echo "Purge old ipset DROP
rules"
/usr/sbin/ipset flush
$ABUSE
/usr/sbin/ipset flush
$SPAM
/usr/sbin/ipset flush
$SPAME
#
# ABUSEIPDB.com
echo "Download ABUSEIP
list and extract IPs"
curl -G
https://api.abuseipdb.com/api/v2/blacklist -d
confidenceMinimum=90 -H "Key:
we-indicate-here-the-key-retrieved-from-abuseipdb" -H
"Accept: text/plain" > $ABUSE_DROP
#clears IPv6
sed '/:/d' $ABUSE_DROP
> $ABUSE_ADD_TO_FW
echo "Updating ipset with
ABUSE list"
while read IP; do
/usr/sbin/ipset -exist add $ABUSE $IP
done <
"$ABUSE_ADD_TO_FW"
echo "IPSET save ABUSE
list"
/usr/sbin/ipset save
$ABUSE > $SAVE_ABUSE
# "The Spamhaus Project" -
https://www.spamhaus.org
#
echo ">"
echo "Downloading SPAMHAUS
DROP list and extracting IPs"
wget -q -O - "$SPAMURL"
> $SPAMHAUS_DROP
grep -v '^;'
$SPAMHAUS_DROP | cut -d ' ' -f 1 > $DROP_ADD_TO_FW
echo "Updating ipset with
SPAMHAUS DROP list"
while read IP; do
/usr/sbin/ipset -exist add $SPAM $IP
done <
"$DROP_ADD_TO_FW"
echo "Save ipset SPAMHAUS
list"
/usr/sbin/ipset save $SPAM
> $SAVE_SPAM
#
# "The Spamhaus Project" -
https://www.spamhaus.org
#
echo ">"
echo "Download SPAMHAUS
eDROP list and extract IPs"
wget -q -O - "$eSPAMURL"
> $SPAMHAUS_eDROP
grep -v '^;'
$SPAMHAUS_eDROP | cut -d ' ' -f 1 > $eDROP_ADD_TO_FW
echo "Updating ipset with
SPAMHAUS eDROP list"
while read IP; do
/usr/sbin/ipset -exist add $SPAME $IP
done <
"$eDROP_ADD_TO_FW"
echo "Save ipset with
eSPAMHAUS list"
/usr/sbin/ipset save
$SPAME > $SAVE_SPAME
#
# Activation of new lists
# by restarting the
firewall
#
echo ">"
echo "Restarting the
firewall"
echo "--------------- "
/usr/sbin/shorewall
restart
#
# Checks
#
echo " "
/usr/bin/systemctl status
--no-pager shorewall
echo " "
/usr/sbin/shorewall show
bl
echo " "
echo "Number of
spamhausDrop list lines"
/usr/sbin/ipset list
"$SPAM" | wc -l
echo "Number of
spamhauseDrop list lines"
/usr/sbin/ipset list
"$SPAME" | wc -l
echo "Number of abusedrop
list lines"
/usr/sbin/ipset list
"$ABUSE" | wc -l
echo ">"
echo End: $(date)
echo ">>"
he is given execution rights
chmod 755 /usr/bin/shorewall-villains
This is what it looks like when you launch it
>>
Start: Sun Sep 5 08:10:50
CEST 2021
>
Creation of ipset DROP
rules
We purge the old ipset
DROP rules
Download ABUSEIP list and
extract IPs
% Total % Received
% Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 139k 0 139k 0 0 185k
0 --:--:-- --:--:-- --:--:-- 185k
Update ipset with ABUSE
list
Update firewall with ABUSE
rules
Backup ipset of ABUSE list
>
Download SPAMHAUS DROP
list and extract IPs
Update ipset with SPAMHAUS
DROP list
Backup ipset of SPAMHAUS
list
>
Download SPAMHAUS eDROP
list and extract IPs
Update ipset with SPAMHAUS
eDROP list
Backup ipset with
eSPAMHAUS list
>
Restarting the firewall
---------------
Compiling using Shorewall
5.2.3.3...
Processing
/etc/shorewall/params ...
Processing
/etc/shorewall/shorewall.conf...
Loading Modules...
Compiling
/etc/shorewall/zones...
Compiling
/etc/shorewall/interfaces...
Determining Hosts in
Zones...
Locating Action Files...
Compiling
/etc/shorewall/policy...
Running
/etc/shorewall/initdone...
Compiling TCP Flags
filtering...
Compiling Kernel Route
Filtering...
Compiling Martian
Logging...
Compiling MAC Filtration
-- Phase 1...
Compiling
/etc/shorewall/blrules...
Compiling
/etc/shorewall/rules...
Compiling
/etc/shorewall/conntrack...
Compiling
/etc/shorewall/tunnels...
Compiling MAC Filtration
-- Phase 2...
Applying Policies...
Generating Rule Matrix...
Creating iptables-restore
input...
Shorewall configuration
compiled to /var/lib/shorewall/.restart
Stopping Shorewall....
Processing
/etc/shorewall/stop ...
Processing
/etc/shorewall/tcclear ...
Preparing iptables-restore
input...
Running
/sbin/iptables-restore --wait 60...
Processing
/etc/shorewall/stopped ...
done.
Starting Shorewall....
Initializing...
Processing
/etc/shorewall/init ...
Processing
/etc/shorewall/tcclear ...
Setting up Route
Filtering...
Setting up Martian
Logging...
Setting up Proxy ARP...
Preparing iptables-restore
input...
Running
/sbin/iptables-restore --wait 60...
Processing
/etc/shorewall/start ...
Processing
/etc/shorewall/started ...
done.
● shorewall.service -
Shorewall IPv4 firewall
Loaded:
loaded (/usr/lib/systemd/system/shorewall.service; disabled;
vendor preset: enabled)
Active:
active (exited) since Sat 2021-09-04 20:00:07 CEST; 12h ago
Process: 5834
ExecStart=/sbin/shorewall $OPTIONS start $STARTOPTIONS
(code=exited, status=0/SUCCESS)
Main PID: 5834
(code=exited, status=0/SUCCESS)
Sep 04 20:00:07
mana.kervao.fr shorewall[5834]: Setting up Martian
Logging...
Sep 04 20:00:07
mana.kervao.fr shorewall[5834]: Setting up Proxy ARP...
Sep 04 20:00:07
mana.kervao.fr shorewall[5834]: Preparing iptables-restore
input...
Sep 04 20:00:07
mana.kervao.fr shorewall[5834]: Running
/sbin/iptables-restore --wait 60...
sept. 04 20:00:07
mana.kervao.fr shorewall[5834]: Processing
/etc/shorewall/start ...
Sep 04 20:00:07
mana.kervao.fr shorewall[5834]: ipset v7.10: Set cannot be
created: set with the same name already exists
Sep 04 20:00:07
mana.kervao.fr shorewall[5834]: ipset v7.10: Set cannot be
created: set with the same name already exists
Sep 04 20:00:07
mana.kervao.fr shorewall[5834]: Processing
/etc/shorewall/started ...
Sep 04 20:00:07
mana.kervao.fr shorewall[5834]: done.
Sep 04 20:00:07
mana.kervao.fr systemd[1]: Started Shorewall IPv4 firewall.
Shorewall 5.2.3.3
blacklist chains at mana.kervao.fr - Sun Sep 5 08:11:15 CEST
2021
Chain dynamic (4
references)
pkts bytes target
prot opt in out source
destination
Chain lan-fw~ (1
references)
pkts bytes target
prot opt in out source
destination
0 0
~log0 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
abusedrop src
0 0
~log2 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
spamhausdrop src
0 0
~log4 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
spamhausedrop src
Chain lan-vpn~ (1
references)
pkts bytes target
prot opt in out source
destination
0 0
~log1 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
abusedrop src
0 0
~log3 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
spamhausdrop src
0 0
~log5 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
spamhausedrop src
Number of lines in
spamhausDrop list
1054
Number of lines in
spamhauseDrop list
78
Number of lines in
abusedrop list
10007
>
End: Sun Sep 5 08:11:15
CEST 2021
>>
Now to have the lists updated daily, you just need to create a link under /etc/cron.daily
ln -s /usr/bin/shorewall-villains /etc/cron.daily/
The "control" lines of the script allow you to check that everything is working properly, we find in particular the command
shorewall show bl
who gives
Shorewall 5.2.3.3 blacklist
chains at mana.kervao.fr - Sat Sep 4 20:04:25 CEST 2021
Chain dynamic (4
references)
pkts bytes target
prot opt in out source
destination
Chain lan-fw~ (1
references)
pkts bytes target
prot opt in out source
destination
0 0
~log0 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
abusedrop src
0 0
~log2 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
spamhausdrop src
0 0
~log4 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
spamhausedrop src
Chain lan-vpn~ (1
references)
pkts bytes target
prot opt in out source
destination
0 0
~log1 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
abusedrop src
0 0
~log3 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
spamhausdrop src
0 0
~log5 all -- * * 0.0.0.0/0 0.0.0.0/0 [goto] match-set
spamhausedrop src
and the ipset list command lists the banned IP addresses, this gives
Name: abusedrop
Type: hash:net
Revision: 6
Header: family inet
hashsize 4096 maxelem 65536
Size in memory: 268360
References: 2
Number of entries: 9998
Members:
42.193.0.6
192.241.221.234
98.214.176.181
43.128.89.158
167.99.132.148
(...)
Name: spamhausdrop
Type: hash:net
Revision: 6
Header: family inet
hashsize 1024 maxelem 65536 counters
Size in memory: 86848
References: 2
Number of entries: 1046
Members:
102.212.224.0/19 packets 0
bytes 0
204.87.136.0/24 packets 0
bytes 0
206.197.29.0/24 packets 0
bytes 0
168.151.0.0/22 packets 0
bytes 0
199.26.207.0/24 packets 0
bytes 0
(...)
Name: spamhausedrop
Type: hash:net
Revision: 6
Header: family inet
hashsize 1024 maxelem 65536 counters
Size in memory: 9280
References: 2
Number of entries: 70
Members:
43.57.0.0/16 packets 0
bytes 0
120.64.0.0/16 packets 0
bytes 0
46.148.120.0/24 packets 0
bytes 0
120.67.0.0/16 packets 0
bytes 0
204.141.204.0/24 packets 0
bytes 0
91.208.245.0/24 packets 0
bytes 0
45.143.136.0/22 packets
0 bytes 0
91.243.93.0/24 packets 0
bytes 0
(...)
Name: ifw_wlTo ensure that these lists are maintained upon reboot, you will need to modify the /etc/shorewall/init file by adding
# Restore
Abuseipdb and Spamhauss lists
if [ -f
/etc/shorewall/abuseipdb ]; then
ipset destroy
abusedrop
ipset -file
/etc/shorewall/abuseipdb restore
fi
if [ -f
/etc/shorewall/spamhaus ]; then
ipset destroy
spamhausdrop
ipset -file
/etc/shorewall/spamhaus restore
fi
if [ -f
/etc/shorewall/espamhaus ]; then
ipset destroy
spamhausedrop
ipset -file
/etc/shorewall/espamhaus restore
fi
You can
manually add an IP address by typing (you will need to specify
the name of a list)
ipset add spamhaus ip-address
and remove an
address
ipset from
spamhaus ip address
It is also useful to take a snapshot of your system and do a regular check to see if nothing has changed, MSEC does this very well under Mageia, for the record MSEC means Mandriva Security Settings, it is accessed via the Mageia control center (CCM). From this page you have access to the reports, these can also be sent to an email.
[ Back to FUNIX home page ] | [ Back to top of page ] |