[LOG] Sécurité d'un serveur

Applications, problèmes de configuration réseau
Répondre
chindit
Daikyu
Messages : 76
Inscription : dim. 07 oct. 2012, 15:56

[LOG] Sécurité d'un serveur

Message par chindit »

Salut à tous

Pour une fois, il m'a pris l'envie de consulter le log de mon serveur et… ce que j'ai vu m'a fait me dresser les cheveux sur la tête…
En clair, j'ai fait ceci

Code : Tout sélectionner

sudo journalctl --since=today >> /tmp/log
Histoire de pouvoir consulter le log à mon aise.

Et j'ai quelques passages qui me posent problème:
1)Tentative d'intrusion SSH
Je trouve de très nombreuses tentatives d'intrusion SSH provenant d'une IP localisée à Hong-Kong.
Voici ce que le log me dit:

Code : Tout sélectionner

Jan 22 00:00:17 mon-serveur sshd[26546]: Failed password for root from 103.41.124.109 port 38507 ssh2
Jan 22 00:00:17 mon-serveur sshd[26546]: pam_tally(sshd:auth): Tally overflowed for user root
Jan 22 00:00:19 mon-serveur sshd[26546]: Failed password for root from 103.41.124.109 port 38507 ssh2
Jan 22 00:00:19 mon-serveur sshd[26546]: pam_tally(sshd:auth): Tally overflowed for user root
Jan 22 00:00:21 mon-serveur sshd[26546]: Failed password for root from 103.41.124.109 port 38507 ssh2
Jan 22 00:00:21 mon-serveur sshd[26546]: Disconnecting: Too many authentication failures for root from 103.41.124.109 port 38507 ssh2 [preauth]
Jan 22 00:00:21 mon-serveur sshd[26546]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=103.41.124.109  user=root
Jan 22 00:00:22 mon-serveur sshd[29389]: pam_tally(sshd:auth): Tally overflowed for user root
Et ce code se répète pendant un petit temps.
Bien entendu, l'accès root est interdit en SSH et j'ai bloqué l'IP via iptables

Code : Tout sélectionner

sudo iptables -A INPUT -s 103.41.124.109 -j DROP
Ma question est: que puis-je faire de plus pour sécuriser le serveur?

2)Mail de cron
Cron essaie de temps en temps d'envoyer un mail.

Code : Tout sélectionner

Jan 22 05:14:24 mon-serveur CROND[27892]: pam_unix(crond:session): session closed for user root
Jan 22 05:14:24 mon-serveur postfix/pickup[26075]: C16D49F76E: uid=0 from=<root>
Jan 22 05:14:24 mon-serveur postfix/cleanup[27993]: C16D49F76E: message-id=<20150122041424.C16D49F76E@mail.nomdedomaine.fr>
Jan 22 05:14:24 mon-serveur postfix/qmgr[462]: C16D49F76E: from=<root@nomdedomaine.fr>, size=5309, nrcpt=1 (queue active)
Jan 22 05:14:24 mon-serveur dovecot[380]: lmtp(27999): Connect from local
Jan 22 05:14:25 mon-serveur postfix/lmtp[27998]: C16D49F76E: to=<root@nomdedomaine.fr>, orig_to=<root>, relay=mail.nomdedomaine.fr[private/dovecot-lmtp], delay=83, delays=83/0.03/0.03/0.11, dsn=5.1.1, status=bounced (host mail.nomdedomaine.fr[private/dovecot-lmtp] said: 550 5.1.1 <root@nomdedomaine.fr> User doesn't exist: root@nomdedomaine.fr (in reply to RCPT TO command))
Jan 22 05:14:25 mon-serveur dovecot[380]: lmtp(27999): Disconnect from local: Successful quit
Jan 22 05:14:25 mon-serveur postfix/cleanup[27993]: 0F59FA0A86: message-id=<20150122041425.0F59FA0A86@mail.nomdedomaine.fr>
Jan 22 05:14:25 mon-serveur postfix/bounce[28004]: C16D49F76E: sender non-delivery notification: 0F59FA0A86
Jan 22 05:14:25 mon-serveur postfix/qmgr[462]: 0F59FA0A86: from=<>, size=7690, nrcpt=1 (queue active)
Jan 22 05:14:25 mon-serveur postfix/qmgr[462]: C16D49F76E: removed
Jan 22 05:14:25 mon-serveur dovecot[380]: lmtp(27999): Connect from local
Jan 22 05:14:25 mon-serveur postfix/lmtp[27998]: 0F59FA0A86: to=<root@nomdedomaine.fr>, relay=mail.nomdedomaine.fr[private/dovecot-lmtp], delay=0.07, delays=0.03/0/0/0.03, dsn=5.1.1, status=bounced (host mail.nomdedomaine.fr[private/dovecot-lmtp] said: 550 5.1.1 <root@nomdedomaine.fr> User doesn't exist: root@nomdedomaine.fr (in reply to RCPT TO command))
Jan 22 05:14:25 mon-serveur dovecot[380]: lmtp(27999): Disconnect from local: Successful quit
Jan 22 05:14:25 mon-serveur postfix/qmgr[462]: 0F59FA0A86: removed
Jan 22 05:15:01 mon-serveur crond[28005]: pam_unix(crond:session): session opened for user root by (uid=0)
Sauf que, comme vous le voyez, ça foire.
1)Qu'est-ce qu'il essaie de me dire?
2)Comment lui expliquer que, ses mails, il doit les envoyer à «admin@nomdedomaine.fr»?

Rtm fréquent
De temps en temps, il y a un cron fréquent pour RTM. Par exemple, il peut se déclenche 30 ou 40 fois d'affilée avec ces lignes:

Code : Tout sélectionner

Jan 22 05:22:02 mon-serveur CROND[28376]: pam_unix(crond:session): session closed for user root
Jan 22 05:23:01 mon-serveur crond[28419]: pam_unix(crond:session): session opened for user root by (uid=0)
Jan 22 05:23:01 mon-serveur CROND[28420]: (root) CMD (/usr/local/rtm/bin/rtm 39 > /dev/null 2> /dev/null)
Si je me souviens bien, RTM est utilisé par Cacti, que j'ai installé. Mais pourquoi se déclencher beaucoup, mais de temps en temps?
C'est normal?

Connexions SSH fermées
Je trouve quelques lignes sur des connexions fermées à partir d'IP louches.
Mais rien sur des connexions ouvertes. Qu'est-ce que ça veut dire? Que quelqu'un a fait «toc toc» sur le serveur puis est parti sans essayer de rentrer?

Code : Tout sélectionner

Jan 22 14:17:32 mon-server sshd[29882]: Connection closed by 14.141.13.34 [preauth]
Jan 22 14:17:34 mon-server sshd[29884]: Connection closed by 177.21.255.94 [preauth]
Connexion anonyme au FTP
Allez, on continue avec les intrusions…
Quelqu'un qui fait toctoc sur le FTP.
C'est bon si je vois ça ou je dois (encore) m'inquiéter?

Code : Tout sélectionner

Jan 22 14:34:41 mon-server proftpd[30732]: reverse.ip.fr (109-227-227-140.nts.su[109.227.227.140]) - FTP session opened.
Jan 22 14:34:41 mon-server proftpd[30732]: reverse.ip.fr (109-227-227-140.nts.su[109.227.227.140]) - USER anonymous: no such user found from 109-227-227-140.nts.su [109.227.227.140] to ::ffff:my.ip:21
Jan 22 14:34:42 mon-server proftpd[30732]: reverse.ip.fr (109-227-227-140.nts.su[109.227.227.140]) - FTP session closed.
Et enfin, dernier petit problème:
Répertoire $HOME introuvable
Ça, c'est «de ma faute». Enfin, c'est moi qui ai provoqué l'erreur.
Le service «shadow» est en erreur. Et si j'essaie de le lancer, j'obtiens l'erreur suivante:

Code : Tout sélectionner

Jan 22 18:51:39 mon-server pwck[13142]: user 'vmail': directory '/home/vmail' does not exist
Jan 22 18:51:39 mon-server pwck[13142]: user 'courier': directory '/home/courier' does not exist
Comment puis-je expliquer à Arch que ces deux utilisateurs ne doivent pas avoir de répertoire HOME, comme «http» ou «mysql»?

Voilà voilà…
Je pense que mon serveur a besoin d'un petit coup de fouet au niveau de la sécurité mais… heu… je vous avoue que la dernière fois que j'ai essayé de configurer iptables, je me suis pris les pieds dans le tapis et il n'y a plus rien qui marchait.
Alors, toute aide est la bienvenue pour dammer le pion à ces méchants pirates.

Un grand merci pour votre aide.
Chindit
Avatar de l’utilisateur
benjarobin
Maître du Kyudo
Messages : 17187
Inscription : sam. 30 mai 2009, 15:48
Localisation : Lyon

Re: [LOG] Sécurité d'un serveur

Message par benjarobin »

Bonsoir,

Alors je suis loin d'être un expert dans l'administration serveur, mais :
Pour le ssh et le FTP, à part changer le port par défaut, il est difficile de limiter ce genre de tentative d'intrusion.
Iptables ne pourra rien faire pour limiter la chose, sauf si tu bien sur tu n’autorise que certaines IP publique.
Par contre tu peux utiliser fail2ban, qui ban automatiquement les IP des ataquant en fonction de certaines règles.

Que cron essaye d'envoyer un email est normal, il faut pour cela configurer cron : voir Wiki.

Pour le service shadow qui est en erreur, il te faut pour cela modifier le home des users vmail et courier. Voir le contenu de /etc/passwd.
Il est recommandé d'utiliser les outils d'administration pour changer le chemin du home (usermod)
Zsh | KDE | PC fixe : core i7, carte nvidia
Titre d'un sujet : [Thème] Sujet (état) / Règles du forum
hopimet
Elfe
Messages : 996
Inscription : mer. 14 mars 2012, 22:48

Re: [LOG] Sécurité d'un serveur

Message par hopimet »

+1 pour fail2ban. Tu trouveras plein de tutos sur le web pour le configurer et globalement c'est assez facile à utiliser.

Attention aux tentatives de reverse mapping (vu mes logs c'est la grande mode en ce moment). Pour se protéger il faut ajouter une règle supplémentaire (qui n'est pas par défaut dans la configuration de fail2ban) :
http://www.debian-fr.org/fail2ban-adapt ... 40613.html

Pour avoir la persistance des règles dans iptables après un reboot tu peux te reporter ici :
http://zach.seifts.us/posts/2013/07/14/ ... persistent

Sinon, au cas où ce n'est pas déjà fait, je te conseille de configurer ta connexion ssh via une clé et de désactiver le log par mot de passe, de même que l'accès root.
chindit
Daikyu
Messages : 76
Inscription : dim. 07 oct. 2012, 15:56

Re: [LOG] Sécurité d'un serveur

Message par chindit »

Et ça continue…
J'ai encore un tas de tentatives de chinois, de coréens, etc.
Fail2ban est installé et activé mais je ne le vois pas dans le log et mon chinois préféré a frappé pendant 3h aux portes du serveur. Apparrement, quelque chose coince.
En attendant, j'ai (encore) bloqué son IP.

Sinon, j'ai découvert un truc étrange au niveau des mails:

Code : Tout sélectionner

Jan 23 04:42:05 mon-server postfix/smtpd[17053]: warning: hostname mailgate.sensenet.ch does not resolve to address 217.108.148.77
Jan 23 04:42:05 mon-server postfix/smtpd[17053]: connect from unknown[217.108.148.77]
Jan 23 04:42:09 mon-server postfix/smtpd[17053]: NOQUEUE: reject: RCPT from unknown[217.108.148.77]: 454 4.7.1 <joneslarry481@gmail.com>: Relay access denied; from=<admin@goodservers.com> to=<joneslarry481@gmail.com> proto=ESMTP helo=<CATS-GD1>
Jan 23 04:42:13 mon-server postfix/smtpd[17053]: lost connection after RCPT from unknown[217.108.148.77]
Jan 23 04:42:13 mon-server postfix/smtpd[17053]: disconnect from unknown[217.108.148.77]
C'est grave docteur?
Je vois que le spam n'a pas été envoyé (YESSS) mais est-ce que c'est une tentative aussi idiote que d'essayer tous les logins possibles et imaginables sur le SSH (dont le port vient de changer) ou bie est-ce que c'est plus grave?
Pour info, mon serveur mail (postfix+dovecot) exige une authentification pour la réception comme pour l'envoie, utilise DKIM et des connexions chiffrées en SSL/TLS pour Imap et STARTTLS pour smtp.
hopimet
Elfe
Messages : 996
Inscription : mer. 14 mars 2012, 22:48

Re: [LOG] Sécurité d'un serveur

Message par hopimet »

Salut,

Pour le mail je ne sais pas.

Pour fail2ban, peux tu poster tes fichiers de configurations. S'il y a eu plusieurs tentatives, l'IP aurait du être bannie à la 5e ou 6e normalement. Donc si ça ne l'a pas fait c'est qu'il y a un problème de conf. Sous réserve que fail2ban soit bien lancé.

Serait-il également possible de voir les logs de tentatives de connexion ssh ? Si, comme je l'ai dis plus haut, ils utilisent le reverse mapping, il faut modifier la conf de fail2ban, sinon il ne les voit pas.

Enfin, tu n'as pas dis si ton accès ssh root était désactivé de même que l'accès via mot de passe (à remplacer par une clé).

Personnellement, j'ai un serveur ssh sur le port 22 (car je ne peux pas faire autrement, si tu peux mettre un port non conventionnel ça réduira déjà la fréquence des attaques car le port 22 est naturellement le plus ciblé), donc attaqué en permanence par des PC zombies ou autres. Ce serveur est branché depuis 4 ans 24h/24 et je n'ai jamais eu d'intrusion avec fail2ban et identification par clé. En revanche les tentatives sont quotidiennes. Cela dit en rendant permanents les bannissements de fail2ban, la fréquence des attaques a diminué car on s'aperçoit que ce sont souvent les même IP ou plage d'IP qui reviennent (majoritairement Chine, mais aussi USA et plus récemment Ukraine)
chindit
Daikyu
Messages : 76
Inscription : dim. 07 oct. 2012, 15:56

Re: [LOG] Sécurité d'un serveur

Message par chindit »

hopimet a écrit :Pour fail2ban, peux tu poster tes fichiers de configurations. S'il y a eu plusieurs tentatives, l'IP aurait du être bannie à la 5e ou 6e normalement. Donc si ça ne l'a pas fait c'est qu'il y a un problème de conf. Sous réserve que fail2ban soit bien lancé.
J'ai tout laissé par défaut

Code : Tout sélectionner

cat /etc/fail2ban/fail2ban.conf 
# Fail2Ban main configuration file
#
# Comments: use '#' for comment lines and ';' (following a space) for inline comments
#
# Changes:  in most of the cases you should not modify this
#           file, but provide customizations in fail2ban.local file, e.g.:
#
# [Definition]
# loglevel = DEBUG
#

[Definition]

# Option: loglevel
# Notes.: Set the log level output.
#         CRITICAL
#         ERROR
#         WARNING
#         NOTICE
#         INFO
#         DEBUG
# Values: [ LEVEL ]  Default: ERROR
#
loglevel = INFO

# Option: logtarget
# Notes.: Set the log target. This could be a file, SYSLOG, STDERR or STDOUT.
#         Only one log target can be specified.
#         If you change logtarget from the default value and you are
#         using logrotate -- also adjust or disable rotation in the
#         corresponding configuration file
#         (e.g. /etc/logrotate.d/fail2ban on Debian systems)
# Values: [ STDOUT | STDERR | SYSLOG | FILE ]  Default: STDERR
#
logtarget = /var/log/fail2ban.log

# Option: socket
# Notes.: Set the socket file. This is used to communicate with the daemon. Do
#         not remove this file when Fail2ban runs. It will not be possible to
#         communicate with the server afterwards.
# Values: [ FILE ]  Default: /var/run/fail2ban/fail2ban.sock
#
socket = /var/run/fail2ban/fail2ban.sock

# Option: pidfile
# Notes.: Set the PID file. This is used to store the process ID of the
#         fail2ban server.
# Values: [ FILE ]  Default: /var/run/fail2ban/fail2ban.pid
#
pidfile = /var/run/fail2ban/fail2ban.pid

# Options: dbfile
# Notes.: Set the file for the fail2ban persistent data to be stored.
#         A value of ":memory:" means database is only stored in memory 
#         and data is lost when fail2ban is stopped.
#         A value of "None" disables the database.
# Values: [ None :memory: FILE ] Default: /var/lib/fail2ban/fail2ban.sqlite3
dbfile = /var/lib/fail2ban/fail2ban.sqlite3

# Options: dbpurgeage
# Notes.: Sets age at which bans should be purged from the database
# Values: [ SECONDS ] Default: 86400 (24hours)
dbpurgeage = 86400
Et fail2ban est bien lancé

Code : Tout sélectionner

systemctl status fail2ban
● fail2ban.service - Fail2Ban Service
   Loaded: loaded (/usr/lib/systemd/system/fail2ban.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2015-01-23 10:09:08 CET; 8h ago
     Docs: man:fail2ban(1)
  Process: 357 ExecStart=/usr/bin/fail2ban-client -x start (code=exited, status=0/SUCCESS)
 Main PID: 567 (fail2ban-server)
   CGroup: /system.slice/fail2ban.service
           └─567 /usr/bin/python /usr/bin/fail2ban-server -s /var/run/fail2ba...
hopimet a écrit :Serait-il également possible de voir les logs de tentatives de connexion ssh ? Si, comme je l'ai dis plus haut, ils utilisent le reverse mapping, il faut modifier la conf de fail2ban, sinon il ne les voit pas.
Hop, en voilà une tranche.
Le 219.quelque.chose est bloqué par iptables maintenant

Code : Tout sélectionner

Jan 23 00:00:49 mon-server sshd[1179]: Connection closed by 212.174.242.126 [preauth]
Jan 23 00:16:13 mon-server sshd[2201]: Connection closed by 78.230.72.111 [preauth]
Jan 23 00:41:44 mon-server sshd[3460]: Connection closed by 177.21.255.94 [preauth]
Jan 23 00:43:18 mon-server sshd[3549]: Connection closed by 212.174.242.126 [preauth]
Jan 23 01:11:21 mon-server sshd[5193]: Invalid user PlcmSpIp from 219.76.98.217
Jan 23 01:11:21 mon-server sshd[5193]: input_userauth_request: invalid user PlcmSpIp [preauth]
Jan 23 01:11:21 mon-server sshd[5193]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:11:21 mon-server sshd[5193]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:11:21 mon-server sshd[5193]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:11:23 mon-server sshd[5193]: Failed password for invalid user PlcmSpIp from 219.76.98.217 port 7176 ssh2
Jan 23 01:11:23 mon-server sshd[5193]: Connection closed by 219.76.98.217 [preauth]
Jan 23 01:14:14 mon-server sshd[5351]: Invalid user aaron from 219.76.98.217
Jan 23 01:14:14 mon-server sshd[5351]: input_userauth_request: invalid user aaron [preauth]
Jan 23 01:14:14 mon-server sshd[5351]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:14:14 mon-server sshd[5351]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:14:14 mon-server sshd[5351]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:14:16 mon-server sshd[5351]: Failed password for invalid user aaron from 219.76.98.217 port 59803 ssh2
Jan 23 01:14:16 mon-server sshd[5351]: Connection closed by 219.76.98.217 [preauth]
Jan 23 01:17:10 mon-server sshd[5517]: Invalid user admin from 219.76.98.217
Jan 23 01:17:10 mon-server sshd[5517]: input_userauth_request: invalid user admin [preauth]
Jan 23 01:17:10 mon-server sshd[5517]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:17:10 mon-server sshd[5517]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:17:10 mon-server sshd[5517]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:17:12 mon-server sshd[5517]: Failed password for invalid user admin from 219.76.98.217 port 33149 ssh2
Jan 23 01:17:13 mon-server sshd[5517]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:17:13 mon-server sshd[5517]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:17:14 mon-server sshd[5517]: Failed password for invalid user admin from 219.76.98.217 port 33149 ssh2
Jan 23 01:17:15 mon-server sshd[5517]: Connection closed by 219.76.98.217 [preauth]
Jan 23 01:17:15 mon-server sshd[5517]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:20:50 mon-server sshd[5685]: Invalid user admin from 219.76.98.217
Jan 23 01:20:50 mon-server sshd[5685]: input_userauth_request: invalid user admin [preauth]
Jan 23 01:20:50 mon-server sshd[5685]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:20:50 mon-server sshd[5685]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:20:50 mon-server sshd[5685]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:20:52 mon-server sshd[5685]: Failed password for invalid user admin from 219.76.98.217 port 35194 ssh2
Jan 23 01:20:53 mon-server sshd[5685]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:20:53 mon-server sshd[5685]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:20:55 mon-server sshd[5685]: Failed password for invalid user admin from 219.76.98.217 port 35194 ssh2
Jan 23 01:20:56 mon-server sshd[5685]: Connection closed by 219.76.98.217 [preauth]
Jan 23 01:20:56 mon-server sshd[5685]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:24:17 mon-server sshd[5861]: Invalid user admin from 219.76.98.217
Jan 23 01:24:17 mon-server sshd[5861]: input_userauth_request: invalid user admin [preauth]
Jan 23 01:24:17 mon-server sshd[5861]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:24:17 mon-server sshd[5861]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:24:17 mon-server sshd[5861]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:24:19 mon-server sshd[5861]: Failed password for invalid user admin from 219.76.98.217 port 37650 ssh2
Jan 23 01:24:19 mon-server sshd[5861]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:24:19 mon-server sshd[5861]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:24:21 mon-server sshd[5861]: Failed password for invalid user admin from 219.76.98.217 port 37650 ssh2
Jan 23 01:24:22 mon-server sshd[5861]: Connection closed by 219.76.98.217 [preauth]
Jan 23 01:24:22 mon-server sshd[5861]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:25:35 mon-server sshd[5941]: Connection closed by 212.174.242.126 [preauth]
Jan 23 01:26:11 mon-server sshd[5986]: Connection closed by 177.21.255.94 [preauth]
Jan 23 01:27:20 mon-server sshd[6032]: Invalid user administrator from 219.76.98.217
Jan 23 01:27:20 mon-server sshd[6032]: input_userauth_request: invalid user administrator [preauth]
Jan 23 01:27:20 mon-server sshd[6032]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:27:20 mon-server sshd[6032]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:27:20 mon-server sshd[6032]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:27:21 mon-server sshd[6032]: Failed password for invalid user administrator from 219.76.98.217 port 39239 ssh2
Jan 23 01:27:22 mon-server sshd[6032]: Connection closed by 219.76.98.217 [preauth]
Jan 23 01:30:00 mon-server sshd[6121]: Invalid user alex from 219.76.98.217
Jan 23 01:30:00 mon-server sshd[6121]: input_userauth_request: invalid user alex [preauth]
Jan 23 01:30:00 mon-server sshd[6121]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:30:00 mon-server sshd[6121]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:30:00 mon-server sshd[6121]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:30:02 mon-server sshd[6121]: Failed password for invalid user alex from 219.76.98.217 port 40798 ssh2
Jan 23 01:30:03 mon-server sshd[6121]: Connection closed by 219.76.98.217 [preauth]
Jan 23 01:32:46 mon-server sshd[6291]: Invalid user arbab from 219.76.98.217
Jan 23 01:32:46 mon-server sshd[6291]: input_userauth_request: invalid user arbab [preauth]
Jan 23 01:32:46 mon-server sshd[6291]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:32:46 mon-server sshd[6291]: pam_unix(sshd:auth): check pass; user unknown
Jan 23 01:32:46 mon-server sshd[6291]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=n219076098217.netvigator.com
Jan 23 01:32:48 mon-server sshd[6291]: Failed password for invalid user arbab from 219.76.98.217 port 42369 ssh2
Jan 23 01:32:49 mon-server sshd[6291]: Connection closed by 219.76.98.217 [preauth]
Jan 23 01:35:33 mon-server sshd[6458]: Invalid user backup from 219.76.98.217
Jan 23 01:35:33 mon-server sshd[6458]: input_userauth_request: invalid user backup [preauth]
Jan 23 01:35:33 mon-server sshd[6458]: pam_tally(sshd:auth): pam_get_uid; no such user
Jan 23 01:35:33 mon-server sshd[6458]: pam_unix(sshd:auth): check pass; user unknown
Vous remarquerez qu'il utilise des noms d'utilisateurs plausibles. Pas bête le pirate :)

hopimet a écrit :Enfin, tu n'as pas dis si ton accès ssh root était désactivé de même que l'accès via mot de passe (à remplacer par une clé).
SSH root désactivé. Normalement, il n'y a que le simple utilisateur qui a accès au SSH (normalement les utilisateurs type «mysql» ne savent pas. Si?). Les autres utilisateurs on un shell «/bin/false» pour bloquer le SSH.
Le port a été changé de 22 à 56.
L'accès se fait via mot de passe.
hopimet
Elfe
Messages : 996
Inscription : mer. 14 mars 2012, 22:48

Re: [LOG] Sécurité d'un serveur

Message par hopimet »

Merci, désolé j'étais absent.

En fait c'est le fichier /etc/fail2ban/jail.conf que je voudrais voir.
Et aussi /etc/fail2ban/filter.d/sshd.conf.
Et pendant qu'on y est les log de fail2ban : /var/log/fail2ban.log
chindit
Daikyu
Messages : 76
Inscription : dim. 07 oct. 2012, 15:56

Re: [LOG] Sécurité d'un serveur

Message par chindit »

hopimet a écrit :En fait c'est le fichier /etc/fail2ban/jail.conf que je voudrais voir.

Code : Tout sélectionner

cat jail.conf
#
# WARNING: heavily refactored in 0.9.0 release.  Please review and
#          customize settings for your setup.
#
# Changes:  in most of the cases you should not modify this
#           file, but provide customizations in jail.local file,
#           or separate .conf files under jail.d/ directory, e.g.:
#
# HOW TO ACTIVATE JAILS:
#
# YOU SHOULD NOT MODIFY THIS FILE.
#
# It will probably be overwritten or improved in a distribution update.
#
# Provide customizations in a jail.local file or a jail.d/customisation.local.
# For example to change the default bantime for all jails and to enable the
# ssh-iptables jail the following (uncommented) would appear in the .local file.
# See man 5 jail.conf for details.
#
# [DEFAULT]
# bantime = 3600
#
# [sshd]
# enabled = true
#
# See jail.conf(5) man page for more information



# Comments: use '#' for comment lines and ';' (following a space) for inline comments


[INCLUDES]

#before = paths-distro.conf
before = paths-debian.conf

# The DEFAULT allows a global definition of the options. They can be overridden
# in each jail afterwards.

[DEFAULT]

#
# MISCELLANEOUS OPTIONS
#

# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space separator.
ignoreip = 127.0.0.1/8

# External command that will take an tagged arguments to ignore, e.g. <ip>,
# and return true if the IP is to be ignored. False otherwise.
#
# ignorecommand = /path/to/command <ip>
ignorecommand =

# "bantime" is the number of seconds that a host is banned.
bantime  = 600

# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
findtime  = 600

# "maxretry" is the number of failures before a host get banned.
maxretry = 5

# "backend" specifies the backend used to get files modification.
# Available options are "pyinotify", "gamin", "polling", "systemd" and "auto".
# This option can be overridden in each jail as well.
#
# pyinotify: requires pyinotify (a file alteration monitor) to be installed.
#              If pyinotify is not installed, Fail2ban will use auto.
# gamin:     requires Gamin (a file alteration monitor) to be installed.
#              If Gamin is not installed, Fail2ban will use auto.
# polling:   uses a polling algorithm which does not require external libraries.
# systemd:   uses systemd python library to access the systemd journal.
#              Specifying "logpath" is not valid for this backend.
#              See "journalmatch" in the jails associated filter config
# auto:      will try to use the following backends, in order:
#              pyinotify, gamin, polling.
backend = auto

# "usedns" specifies if jails should trust hostnames in logs,
#   warn when DNS lookups are performed, or ignore all hostnames in logs
#
# yes:   if a hostname is encountered, a DNS lookup will be performed.
# warn:  if a hostname is encountered, a DNS lookup will be performed,
#        but it will be logged as a warning.
# no:    if a hostname is encountered, will not be used for banning,
#        but it will be logged as info.
usedns = warn

# "logencoding" specifies the encoding of the log files handled by the jail
#   This is used to decode the lines from the log file.
#   Typical examples:  "ascii", "utf-8"
#
#   auto:   will use the system locale setting
logencoding = auto

# "enabled" enables the jails.
#  By default all jails are disabled, and it should stay this way.
#  Enable only relevant to your setup jails in your .local or jail.d/*.conf
#
# true:  jail will be enabled and log files will get monitored for changes
# false: jail is not enabled
enabled = false


# "filter" defines the filter to use by the jail.
#  By default jails have names matching their filter name
#
filter = %(__name__)s


#
# ACTIONS
#

# Some options used for actions

# Destination email address used solely for the interpolations in
# jail.{conf,local,d/*} configuration files.
destemail = root@localhost

# Sender email address used solely for some actions
sender = root@localhost

# E-mail action. Since 0.8.1 Fail2Ban uses sendmail MTA for the
# mailing. Change mta configuration parameter to mail if you want to
# revert to conventional 'mail'.
mta = sendmail

# Default protocol
protocol = tcp

# Specify chain where jumps would need to be added in iptables-* actions
chain = INPUT

# Ports to be banned
# Usually should be overridden in a particular jail
port = 0:65535

#
# Action shortcuts. To be used to define action parameter

# Default banning action (e.g. iptables, iptables-new,
# iptables-multiport, shorewall, etc) It is used to define
# action_* variables. Can be overridden globally or per
# section within jail.local file
banaction = iptables-multiport

# The simplest action to take: ban only
action_ = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]

# ban & send an e-mail with whois report to the destemail.
action_mw = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
            %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s", protocol="%(protocol)s", chain="%(chain)s"]

# ban & send an e-mail with whois report and relevant log lines
# to the destemail.
action_mwl = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             %(mta)s-whois-lines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]

# See the IMPORTANT note in action.d/xarf-login-attack for when to use this action
#
# ban & send a xarf e-mail to abuse contact of IP address and include relevant log lines
# to the destemail.
action_xarf = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             xarf-login-attack[service=%(__name__)s, sender="%(sender)s", logpath=%(logpath)s, port="%(port)s"]


# Report block via blocklist.de fail2ban reporting service API
#
# See the IMPORTANT note in action.d/blocklist_de.conf for when to
# use this action. Create a file jail.d/blocklist_de.local containing
# [Init]
# blocklist_de_apikey = {api key from registration]
#
action_blocklist_de  = blocklist_de[email="%(sender)s", service=%(filter)s, apikey="%(blocklist_de_apikey)s"]

# Report ban via badips.com, and use as blacklist
#
# See BadIPsAction docstring in config/action.d/badips.py for
# documentation for this action.
#
# NOTE: This action relies on banaction being present on start and therefore
# should be last action defined for a jail.
#
action_badips = badips.py[category="%(name)s", banaction="%(banaction)s"]

# Choose default action.  To change, just override value of 'action' with the
# interpolation to the chosen action shortcut (e.g.  action_mw, action_mwl, etc) in jail.local
# globally (section [DEFAULT]) or per specific section
action = %(action_)s


#
# JAILS
#

#
# SSH servers
#

[sshd]

port    = ssh
logpath = %(sshd_log)s


[sshd-ddos]
# This jail corresponds to the standard configuration in Fail2ban.
# The mail-whois action send a notification e-mail with a whois request
# in the body.
port    = ssh
logpath = %(sshd_log)s


[dropbear]

port     = ssh
logpath  = %(dropbear_log)s


[selinux-ssh]

port     = ssh
logpath  = %(auditd_log)s
maxretry = 5


#
# HTTP servers
#

[apache-auth]

port     = http,https
logpath  = %(apache_error_log)s


[apache-badbots]
# Ban hosts which agent identifies spammer robots crawling the web
# for email addresses. The mail outputs are buffered.
port     = http,https
logpath  = %(apache_access_log)s
bantime  = 172800
maxretry = 1


[apache-noscript]

port     = http,https
logpath  = %(apache_error_log)s
maxretry = 6


[apache-overflows]

port     = http,https
logpath  = %(apache_error_log)s
maxretry = 2


[apache-nohome]

port     = http,https
logpath  = %(apache_error_log)s
maxretry = 2


[apache-botsearch]

port     = http,https
logpath  = %(apache_error_log)s
maxretry = 2


[apache-modsecurity]

port     = http,https
logpath  = %(apache_error_log)s
maxretry = 2

[apache-shellshock]

port    = http,https
logpath = $(apache_error_log)s
maxretry = 1

[nginx-http-auth]

ports   = http,https
logpath = %(nginx_error_log)s


# Ban attackers that try to use PHP's URL-fopen() functionality
# through GET/POST variables. - Experimental, with more than a year
# of usage in production environments.

[php-url-fopen]

port    = http,https
logpath = %(nginx_access_log)s %(apache_access_log)s


[suhosin]

port    = http,https
logpath = %(suhosin_log)s


[lighttpd-auth]
# Same as above for Apache's mod_auth
# It catches wrong authentifications
port    = http,https
logpath = %(lighttpd_error_log)s


#
# Webmail and groupware servers
#

[roundcube-auth]

port     = http,https
logpath  = /var/log/roundcube/userlogins


[openwebmail]

port     = http,https
logpath  = /var/log/openwebmail.log


[horde]

port     = http,https
logpath  = /var/log/horde/horde.log


[groupoffice]

port     = http,https
logpath  = /home/groupoffice/log/info.log


[sogo-auth]
# Monitor SOGo groupware server
# without proxy this would be:
# port    = 20000
port     = http,https
logpath  = /var/log/sogo/sogo.log


[tine20]

logpath  = /var/log/tine20/tine20.log
port     = http,https
maxretry = 5


#
# Web Applications
#
#

[guacamole]

port     = http,https
logpath  = /var/log/tomcat*/catalina.out

[monit]
#Ban clients brute-forcing the monit gui login
filter   = monit
port = 2812
logpath  = /var/log/monit


[webmin-auth]

port    = 10000
logpath = %(syslog_authpriv)s


#
# HTTP Proxy servers
#
#

[squid]

port     =  80,443,3128,8080
logpath = /var/log/squid/access.log


[3proxy]

port    = 3128
logpath = /var/log/3proxy.log

#
# FTP servers
#


[proftpd]

port     = ftp,ftp-data,ftps,ftps-data
logpath  = %(proftpd_log)s


[pure-ftpd]

port     = ftp,ftp-data,ftps,ftps-data
logpath  = %(pureftpd_log)s
maxretry = 6


[gssftpd]

port     = ftp,ftp-data,ftps,ftps-data
logpath  = %(syslog_daemon)s
maxretry = 6


[wuftpd]

port     = ftp,ftp-data,ftps,ftps-data
logpath  = %(wuftpd_log)s
maxretry = 6


[vsftpd]
# or overwrite it in jails.local to be
# logpath = %(syslog_authpriv)s
# if you want to rely on PAM failed login attempts
# vsftpd's failregex should match both of those formats
port     = ftp,ftp-data,ftps,ftps-data
logpath  = %(vsftpd_log)s


#
# Mail servers
#

# ASSP SMTP Proxy Jail
[assp]

port     = smtp,465,submission
logpath  = /root/path/to/assp/logs/maillog.txt


[courier-smtp]

port     = smtp,465,submission
logpath  = %(syslog_mail)s


[postfix]

port     = smtp,465,submission
logpath  = %(postfix_log)s


[sendmail-auth]

port    = submission,465,smtp
logpath = %(syslog_mail)s


[sendmail-reject]

port     = smtp,465,submission
logpath  = %(syslog_mail)s


[qmail-rbl]

filter  = qmail
port    = smtp,465,submission
logpath = /service/qmail/log/main/current


# dovecot defaults to logging to the mail syslog facility
# but can be set by syslog_facility in the dovecot configuration.
[dovecot]

port    = pop3,pop3s,imap,imaps,submission,465,sieve
logpath = %(dovecot_log)s


[sieve]

port   = smtp,465,submission
logpath = %(dovecot_log)s


[solid-pop3d]

port    = pop3,pop3s
logpath = %(solidpop3d_log)s


[exim]

port   = smtp,465,submission
logpath = %(exim_main_log)s


[exim-spam]

port   = smtp,465,submission
logpath = %(exim_main_log)s


[kerio]

port    = imap,smtp,imaps,465
logpath = /opt/kerio/mailserver/store/logs/security.log


#
# Mail servers authenticators: might be used for smtp,ftp,imap servers, so
# all relevant ports get banned
#

[courier-auth]

port     = smtp,465,submission,imap3,imaps,pop3,pop3s
logpath  = %(syslog_mail)s


[postfix-sasl]

port     = smtp,465,submission,imap3,imaps,pop3,pop3s
# You might consider monitoring /var/log/mail.warn instead if you are
# running postfix since it would provide the same log lines at the
# "warn" level but overall at the smaller filesize.
logpath  = %(postfix_log)s


[perdition]

port   = imap3,imaps,pop3,pop3s
logpath = %(syslog_mail)s


[squirrelmail]

port = smtp,465,submission,imap2,imap3,imaps,pop3,pop3s,http,https,socks
logpath = /var/lib/squirrelmail/prefs/squirrelmail_access_log


[cyrus-imap]

port   = imap3,imaps
logpath = %(syslog_mail)s


[uwimap-auth]

port   = imap3,imaps
logpath = %(syslog_mail)s


#
#
# DNS servers
#


# !!! WARNING !!!
#   Since UDP is connection-less protocol, spoofing of IP and imitation
#   of illegal actions is way too simple.  Thus enabling of this filter
#   might provide an easy way for implementing a DoS against a chosen
#   victim. See
#    http://nion.modprobe.de/blog/archives/690-fail2ban-+-dns-fail.html
#   Please DO NOT USE this jail unless you know what you are doing.
#
# IMPORTANT: see filter.d/named-refused for instructions to enable logging
# This jail blocks UDP traffic for DNS requests.
# [named-refused-udp]
#
# filter   = named-refused
# port     = domain,953
# protocol = udp
# logpath  = /var/log/named/security.log

# IMPORTANT: see filter.d/named-refused for instructions to enable logging
# This jail blocks TCP traffic for DNS requests.

[named-refused]

port     = domain,953
logpath  = /var/log/named/security.log


[nsd]

port     = 53
action   = %(banaction)s[name=%(__name__)s-tcp, port="%(port)s", protocol="tcp", chain="%(chain)s", actname=%(banaction)s-tcp]
           %(banaction)s[name=%(__name__)s-udp, port="%(port)s", protocol="udp", chain="%(chain)s", actname=%(banaction)s-udp]
logpath = /var/log/nsd.log


#
# Miscellaneous
#

[asterisk]

port     = 5060,5061
action   = %(banaction)s[name=%(__name__)s-tcp, port="%(port)s", protocol="tcp", chain="%(chain)s", actname=%(banaction)s-tcp]
           %(banaction)s[name=%(__name__)s-udp, port="%(port)s", protocol="udp", chain="%(chain)s", actname=%(banaction)s-udp]
           %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s"]
logpath  = /var/log/asterisk/messages
maxretry = 10


[freeswitch]

port     = 5060,5061
action   = %(banaction)s[name=%(__name__)s-tcp, port="%(port)s", protocol="tcp", chain="%(chain)s", actname=%(banaction)s-tcp]
           %(banaction)s[name=%(__name__)s-udp, port="%(port)s", protocol="udp", chain="%(chain)s", actname=%(banaction)s-udp]
           %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s"]
logpath  = /var/log/freeswitch.log
maxretry = 10


# To log wrong MySQL access attempts add to /etc/my.cnf in [mysqld] or
# equivalent section:
# log-warning = 2
#
# for syslog (daemon facility)
# [mysqld_safe]
# syslog
#
# for own logfile
# [mysqld]
# log-error=/var/log/mysqld.log
[mysqld-auth]

port     = 3306
logpath  = %(mysql_log)s
maxretry = 5


# Jail for more extended banning of persistent abusers
# !!! WARNING !!!
#   Make sure that your loglevel specified in fail2ban.conf/.local
#   is not at DEBUG level -- which might then cause fail2ban to fall into
#   an infinite loop constantly feeding itself with non-informative lines
[recidive]

logpath  = /var/log/fail2ban.log
port     = all
protocol = all
bantime  = 604800  ; 1 week
findtime = 86400   ; 1 day
maxretry = 5


# Generic filter for PAM. Has to be used with action which bans all
# ports such as iptables-allports, shorewall

[pam-generic]
# pam-generic filter can be customized to monitor specific subset of 'tty's
banaction = iptables-allports
logpath  = %(syslog_authpriv)s


[xinetd-fail]

banaction = iptables-multiport-log
logpath   = %(syslog_daemon)s
maxretry  = 2


# stunnel - need to set port for this
[stunnel]

logpath = /var/log/stunnel4/stunnel.log


[ejabberd-auth]

port    = 5222
logpath = /var/log/ejabberd/ejabberd.log


[counter-strike]

logpath = /opt/cstrike/logs/L[0-9]*.log
# Firewall: http://www.cstrike-planet.com/faq/6
tcpport = 27030,27031,27032,27033,27034,27035,27036,27037,27038,27039
udpport = 1200,27000,27001,27002,27003,27004,27005,27006,27007,27008,27009,27010,27011,27012,27013,27014,27015
action  = %(banaction)s[name=%(__name__)s-tcp, port="%(tcpport)s", protocol="tcp", chain="%(chain)s", actname=%(banaction)s-tcp]
           %(banaction)s[name=%(__name__)s-udp, port="%(udpport)s", protocol="udp", chain="%(chain)s", actname=%(banaction)s-udp]

# consider low maxretry and a long bantime
# nobody except your own Nagios server should ever probe nrpe
[nagios]

enabled  = false
logpath  = %(syslog_daemon)s     ; nrpe.cfg may define a different log_facility
maxretry = 1


[oracleims]
# see "oracleims" filter file for configuration requirement for Oracle IMS v6 and above
enabled = false
logpath = /opt/sun/comms/messaging64/log/mail.log_current
maxretry = 6
banaction = iptables-allports

[directadmin]
enabled = false
logpath = /var/log/directadmin/login.log
port = 2222

[portsentry]
enabled  = false
logpath  = /var/lib/portsentry/portsentry.history
hopimet a écrit :Et aussi /etc/fail2ban/filter.d/sshd.conf.

Code : Tout sélectionner

cat filter.d/sshd.conf
# Fail2Ban filter for openssh
#
# If you want to protect OpenSSH from being bruteforced by password
# authentication then get public key authentication working before disabling
# PasswordAuthentication in sshd_config.
#
#
# "Connection from <HOST> port \d+" requires LogLevel VERBOSE in sshd_config
#

[INCLUDES]

# Read common prefixes. If any customizations available -- read them from
# common.local
before = common.conf

[Definition]

_daemon = sshd

failregex = ^%(__prefix_line)s(?:error: PAM: )?[aA]uthentication (?:failure|error) for .* from <HOST>( via \S+)?\s*$
            ^%(__prefix_line)s(?:error: PAM: )?User not known to the underlying authentication module for .* from <HOST>\s*$
            ^%(__prefix_line)sFailed \S+ for .*? from <HOST>(?: port \d*)?(?: ssh\d*)?(: (ruser .*|(\S+ ID \S+ \(serial \d+\) CA )?\S+ %(__md5hex)s(, client user ".*", client host ".*")?))?\s*$
            ^%(__prefix_line)sROOT LOGIN REFUSED.* FROM <HOST>\s*$
            ^%(__prefix_line)s[iI](?:llegal|nvalid) user .* from <HOST>\s*$
            ^%(__prefix_line)sUser .+ from <HOST> not allowed because not listed in AllowUsers\s*$
            ^%(__prefix_line)sUser .+ from <HOST> not allowed because listed in DenyUsers\s*$
            ^%(__prefix_line)sUser .+ from <HOST> not allowed because not in any group\s*$
            ^%(__prefix_line)srefused connect from \S+ \(<HOST>\)\s*$
            ^%(__prefix_line)sReceived disconnect from <HOST>: 3: \S+: Auth fail$
            ^%(__prefix_line)sUser .+ from <HOST> not allowed because a group is listed in DenyGroups\s*$
            ^%(__prefix_line)sUser .+ from <HOST> not allowed because none of user's groups are listed in AllowGroups\s*$
            ^(?P<__prefix>%(__prefix_line)s)User .+ not allowed because account is locked<SKIPLINES>(?P=__prefix)(?:error: )?Received disconnect from <HOST>: 11: .+ \[preauth\]$
            ^(?P<__prefix>%(__prefix_line)s)Disconnecting: Too many authentication failures for .+? \[preauth\]<SKIPLINES>(?P=__prefix)(?:error: )?Connection closed by <HOST> \[preauth\]$
            ^(?P<__prefix>%(__prefix_line)s)Connection from <HOST> port \d+(?: on \S+ port \d+)?<SKIPLINES>(?P=__prefix)Disconnecting: Too many authentication failures for .+? \[preauth\]$

ignoreregex =

[Init]

# "maxlines" is number of log lines to buffer for multi-line regex searches
maxlines = 10

journalmatch = _SYSTEMD_UNIT=sshd.service + _COMM=sshd

# DEV Notes:
#
#   "Failed \S+ for .*? from <HOST>..." failregex uses non-greedy catch-all because
#   it is coming before use of <HOST> which is not hard-anchored at the end as well,
#   and later catch-all's could contain user-provided input, which need to be greedily
#   matched away first.
#
# Author: Cyril Jaquier, Yaroslav Halchenko, Petr Voralek, Daniel Black
hopimet a écrit :Et pendant qu'on y est les log de fail2ban : /var/log/fail2ban.log

Code : Tout sélectionner

sudo cat fail2ban.log                                 
2015-01-22 19:07:14,063 fail2ban.server         [14464]: INFO    Changed logging target to /var/log/fail2ban.log for Fail2ban v0.9.1
2015-01-22 19:07:14,071 fail2ban.database       [14464]: INFO    Connected to fail2ban persistent database '/var/lib/fail2ban/fail2ban.sqlite3'
2015-01-22 19:07:14,790 fail2ban.database       [14464]: WARNING New database created. Version '2'
2015-01-23 10:07:57,829 fail2ban.server         [14464]: INFO    Stopping all jails
2015-01-23 10:07:57,831 fail2ban.server         [14464]: INFO    Exiting Fail2ban
2015-01-23 10:09:07,671 fail2ban.server         [567]: INFO    Changed logging target to /var/log/fail2ban.log for Fail2ban v0.9.1
2015-01-23 10:09:07,917 fail2ban.database       [567]: INFO    Connected to fail2ban persistent database '/var/lib/fail2ban/fail2ban.sqlite3'
Je n'ai modifié aucun de ces fichiers.

Et, (mal)heureusement, personne n'est venu frapper à la porte du serveur cette nuit, donc j'ai pas de nouvelles infos. Peut-etre que le pirate a essayé depuis la même IP et que donc iptables l'a viré avant qu'il n'essaie.

Et sinon, nouvelle question. J'ai une alerte de reverse-dns sur mon IP:

Code : Tout sélectionner

Jan 24 10:51:37 mon-server sshd[20740]: reverse mapping checking getaddrinfo for 233.84-176-91.adsl-dyn.isp.belgacom.be [91.176.84.233] failed - POSSIBLE BREAK-IN ATTEMPT!
Je m'en fous, je sais que c'est moi cette IP là. Mais je peux faire quelque chose ou bien c'est mon FAI qui fait le con? (ce qui ne m'étonnerait guère)
Fanch
archer
Messages : 144
Inscription : lun. 01 déc. 2008, 21:16

Re: [LOG] Sécurité d'un serveur

Message par Fanch »

Salut,

c'est jail.local qu'il faut editer, jail.conf est fourni par le package et ne devrait pas etre changé.

Ensuite il faut s'assurer d'avoir activé le filtre:

Code : Tout sélectionner

[sshd]
enabled = true
#port    = ssh
port    = 0:65535
logpath = %(sshd_log)s
c'est le enable=true qui est important


Comme dit par hopimet, /var/log/fail2ban.log permet assez facilement de savoir si fail2ban tourne dans le vide ou pas.
Tu dois voir une ligne :

Code : Tout sélectionner

 Jail 'sshd' started

Pour finir un petit conseil, rajoute ton ip sur la ligne ignoreip = 127.0.0.1/8 ;)
"The three principal virtues of a programmer are Laziness, Impatience, and Hubris." -> man perl
hopimet
Elfe
Messages : 996
Inscription : mer. 14 mars 2012, 22:48

Re: [LOG] Sécurité d'un serveur

Message par hopimet »

@Fanch,

Tu peux modifier et adapter jail.conf ça n'a pas beaucoup d'importance. A la limite si ça peut rassurer, rien n'empêche d'en faire une copie avant.

Voici un exemple pour mon bloc ssh dans jail.conf

Code : Tout sélectionner

[ssh]
enabled  = true
port     = xx,yy
filter   = sshd
action   = iptables-multiport[name=ssh,port="xx,yy",protocol=tcp]
               mail[name=SSH,dest=tonmail@email.com]
               %(action_mwl)s 
logpath  = /var/log/auth.log
bantime = 604800
maxretry = 5
Commentaires :
  • a) xx,yy sont à remplacer par le(s) numéro(s) de ports écoutés par le serveur ssh; Perso, jécoute sur 2 ports pour des raisons spécifiques mais on peut très bien n'en mettre qu'un.
  • b) la ligne iptables-multiport[name=ssh,port="xx,yy",protocol=tcp] appelle le script correspondant pour ajouter l'IP insistante dans iptables
  • c) la ligne mail[name=SSH,dest=tonmail@email.com] sert à envoyer un mail pour prévenir qu'une IP vient d'être bannie. Ce n'est pas indispensable.
Avatar de l’utilisateur
benjarobin
Maître du Kyudo
Messages : 17187
Inscription : sam. 30 mai 2009, 15:48
Localisation : Lyon

Re: [LOG] Sécurité d'un serveur

Message par benjarobin »

Sauf que /var/log/auth.log n'existe plus depuis longtemps si on utilise que systemd...
Il faut configurer fail2ban pour utiliser systemd comme backend
Zsh | KDE | PC fixe : core i7, carte nvidia
Titre d'un sujet : [Thème] Sujet (état) / Règles du forum
hopimet
Elfe
Messages : 996
Inscription : mer. 14 mars 2012, 22:48

Re: [LOG] Sécurité d'un serveur

Message par hopimet »

@benjarobin,

Au temps pour moi. J'utilise fail2ban sur une raspberry avec raspbian. D'où ma configuration, qu'il faut effectivement adapter. Cela étant, les autres lignes ne doivent pas poser de problème.
chindit
Daikyu
Messages : 76
Inscription : dim. 07 oct. 2012, 15:56

Re: [LOG] Sécurité d'un serveur

Message par chindit »

Bon ben… j'ai rien compris (ou presque) au fichier «.conf».
Donc j'ai suivi la doc et j'ai créé le fichier «sshd-iptables» dans le dossier «jail.d»
Voici ce que j'y ai mis:

Code : Tout sélectionner

cat /etc/fail2ban/jail.d/ssh-iptables.conf 
[ssh-iptables]
enabled  = true
filter   = sshd
action   = iptables[name=SSH, port=56, protocol=tcp]                                         
           sendmail-whois[name=SSH, dest=MON@MAIL.FR, sender=fail2ban@mail.com]                                                                  
maxretry = 5
J'ai relancé le service et j'ai reçu un mail m'indiquant que le système était en route.
Donc je suppose que fail2ban est en route maintenant. Je vous tiendrai au courant.

Restent mes questions sur Postfix et sur le Reverse Mapping
hopimet
Elfe
Messages : 996
Inscription : mer. 14 mars 2012, 22:48

Re: [LOG] Sécurité d'un serveur

Message par hopimet »

Pour le reverse mapping je t'ai donné un lien dans mon premier message. T'as juste à suivre les indications.
Rajouter cette ligne :
^%(__prefix_line)sreverse mapping checking getaddrinfo for .* \[<HOST>\] failed - POSSIBLE BREAK-IN ATTEMPT!*\s*$
dans ton /etc/fail2ban/filter.d/sshd.conf
ZerooCool
newbie
Messages : 1
Inscription : mer. 11 mars 2015, 14:28

Re: [LOG] Sécurité d'un serveur

Message par ZerooCool »

Bonjour, je viens de m'inscrire sur le forum.
Je ne connais pas la moitié de linux à moitié autant que je le voudrais, et j'aime moins la moitié des questions que je me pose à moitié autant qu'elles ne le mériteraient.

Est ce que je peux copié coller cela, pour une Centos Release 3 OVH ?
Pour le reverse mapping je t'ai donné un lien dans mon premier message. T'as juste à suivre les indications.
Rajouter cette ligne :

Code : Tout sélectionner

^%(__prefix_line)sreverse mapping checking getaddrinfo for .* \[<HOST>\] failed - POSSIBLE BREAK-IN ATTEMPT!*\s*$
dans ton /etc/fail2ban/filter.d/sshd.conf
hopimet
Elfe
Messages : 996
Inscription : mer. 14 mars 2012, 22:48

Re: [LOG] Sécurité d'un serveur

Message par hopimet »

@ZerooCool

Oui, a priori tu peux rajouter la ligne indiquée dans ta config de fail2ban. Il n'y a pas de raison que la configuration de /etc/fail2ban/filter.d/sshd.conf soit différente sur une Centos.
Répondre