Fail2ban nem ismeri fel a proftpd-t

Fórumok

Sziasztok!

A fail2ban nem ismeri fel a proftp-t.
A megoldás ott lesz, hogy jól kell bekonfigutálni a /etc/fail2ban/filter.d/proftpd.conf fájlt (de valahogy nekem nem jön össze).
Ezen belül is a failregex-et.
proftpd.conf eredeti tartalma:

failregex =
\(\S+\[\]\)[: -]+ USER \S+: no such user found from \S+ \[\S+\] to \S+:\S+ *$
\(\S+\[\]\)[: -]+ USER \S+ \(Login failed\): .*$
\(\S+\[\]\)[: -]+ SECURITY VIOLATION: \S+ login attempted\. *$
\(\S+\[\]\)[: -]+ Maximum login attempts \(\d+\) exceeded *$

A proftpd log tartalma sikertelen belépésnél a következő:

jún 16 01:07:45 kkk proftpd[11673] 127.0.1.1 (xxx.xxx.xxx.xxx[xxx.xxx.xxx.xxx]): USER valami.hu (Login failed): No such user found.
jún 16 01:33:46 kkk proftpd[12053] 127.0.1.1 (xxx.xxx.xxx.xxx[xxx.xxx.xxx.xxx]): USER valami: no such user found from xxx.xxx.xxx.xxx [xxx.xxx.xxx.xxx] to yyy.yyy.yyy.yyy:21

Előre is köszönöm a segítséget!

Hozzászólások

Triviális kérdés, de azért tisztázzuk a legelején. Ugye a fail2ban konfigjában beállítottad a ProFTPD logjának figyelését? Mert alapesetben - a csomag telepítésével - csak az SSH van engedélyezve. Ha engedélyezettre állítottad, működnie kell (a regexpet nem kell módosítani hozzá, mert valóban illeszkedik). Ha ennek ellenére mégsem működik, akkor a szokásos minimum információkat írd le, légy szíves: milyen release, milyen fail2ban verzió, releváns konfigok, logok, hány próbát tettél stb.

Igen természetesen beállítottam:
Verzió: Fail2ban v0.8.4

[proftpd]

enabled = true
port = ftp,ftp-data,ftps,ftps-data
filter = proftpd
logpath = /var/log/proftpd/proftpd.log
#logpath = /var/log/auth.log
maxretry = 3

Volt egy olyan kísérletem is, hogy egy alternatív logot hozok lére a Proftpd-vel:

ExtendedLog /var/log/proftpd/auth.log AUTH auth
LogFormat auth "%v %t \"%r\" [%h] %s"

És a /etc/fail2ban/filter.d/proftpd.conf failregex-t átírom a következőre:

failregex = \[\]\s+530$

A fail2ban logjában látom a proftpd-t:

2013-06-16 06:25:10,167 fail2ban.filter : INFO Log rotation detected for /var/log/proftpd/proftpd.log

Próbák száma végtelen:D

u.i.: SSH tiltása jól működik.

Tehát még Squeeze. Feltettem egy Squeeze-re, és hogy teljesen megegyezzen a konfig a tiéddel, a fail2ban konfigjában a tiedéhez hasonlóan átírtam a default 6-ról 3-ra a maxretry értékét. Ezután kipróbáltam, és megfelelőeen működik:


  a# /etc/init.d/fail2ban start

A fail2ban logban látszik, hogy követi a proftpd logját:


  2013-06-16 09:39:52,451 fail2ban.server : INFO   Changed logging target to /var/log/fail2ban.log for Fail2ban v0.8.4-SVN
  ...
  2013-06-16 09:39:52,618 fail2ban.jail   : INFO   Creating new jail 'proftpd'
  2013-06-16 09:39:52,618 fail2ban.jail   : INFO   Jail 'proftpd' uses poller
  2013-06-16 09:39:52,619 fail2ban.filter : INFO   Added logfile = /var/log/proftpd/proftpd.log
  2013-06-16 09:39:52,619 fail2ban.filter : INFO   Set maxRetry = 3
  2013-06-16 09:39:52,620 fail2ban.filter : INFO   Set findtime = 600
  2013-06-16 09:39:52,620 fail2ban.actions: INFO   Set banTime = 600
  2013-06-16 09:39:52,629 fail2ban.jail   : INFO   Jail 'ssh' started
  2013-06-16 09:39:52,630 fail2ban.jail   : INFO   Jail 'proftpd' started

Egy távoli gépről:

  b# ftp 198.51.100.1
  Connected to 198.51.100.1.
  220 ProFTPD 1.3.3a Server (Debian) [::ffff:198.51.100.1]
  Name (198.51.100.1:root): asdf
  500 AUTH not understood
  500 AUTH not understood
  SSL not available
  331 Password required for asdf
  Password:
  530 Login incorrect.
  Login failed.
  Remote system type is UNIX.
  Using binary mode to transfer files.
  ftp> quit
  221 Goodbye.
  b#

és még kétszer, a maxretry-nak megfelelően.

/var/log/proftpd/proftpd.log:


  Jun 16 09:43:13 a proftpd[12378] a (b[::ffff:198.51.100.2]): FTP session opened.
  Jun 16 09:43:17 a proftpd[12378] a (b[::ffff:198.51.100.2]): USER asdf: no such user found from b [::ffff:198.51.100.2] to ::ffff:198.51.100.1:21
  Jun 16 09:43:26 a proftpd[12378] a (b[::ffff:198.51.100.2]): FTP session closed.
  Jun 16 09:43:29 a proftpd[13029] a (b[::ffff:198.51.100.2]): FTP session opened.
  Jun 16 09:43:32 a proftpd[13029] a (b[::ffff:198.51.100.2]): USER asdf: no such user found from b [::ffff:198.51.100.2] to ::ffff:198.51.100.1:21
  Jun 16 09:43:34 a proftpd[13029] a (b[::ffff:198.51.100.2]): FTP session closed.
  Jun 16 09:43:36 a proftpd[13324] a (b[::ffff:198.51.100.2]): FTP session opened.
  Jun 16 09:43:38 a proftpd[13324] a (b[::ffff:198.51.100.2]): USER asdf: no such user found from b [::ffff:198.51.100.2] to ::ffff:198.51.100.1:21
  Jun 16 09:43:40 a proftpd[13324] a (b[::ffff:198.51.100.2]): FTP session closed.

/var/log/fail2ban.log:


  2013-06-16 09:43:40,678 fail2ban.actions: WARNING [proftpd] Ban 198.51.100.2

A tiltás is életbe lépett:

  a# iptables -nvL fail2ban-proftpd
  Chain fail2ban-proftpd (1 references)
   pkts bytes target     prot opt in     out     source               destination
      7   406 DROP       all  --  *      *       198.51.100.2         0.0.0.0/0
  a#

Viszont nem jó az a kísérleted, amikor azt írtad, hogy: "És a /etc/fail2ban/filter.d/proftpd.conf failregex-t átírom a következőre: failregex = \[\]\s+530$". Mert a log sorvége nem teljesen az általad felírt mintának megfelelő, ami: "[]" + egy vagy több whitespace + "530". Kimaradt belőle a kliens neve. Helyette a '\[\S+\]\s+530$' már jó lehetne.

Még egy kérdés: ugye nem 127.0.0.1-ről (pontosabban "ignoreip"-s címről) jövő kérésekkel nézed?

Nem a 127.0.0.1 címről nézem, hanem külső IP-ről.

SSH, postfix, couriersmtp simán tilt!
De az FTP-t nem veszi figyelembe.

/var/log/fail2ban.log

2013-06-16 13:11:51,447 fail2ban.jail : INFO Creating new jail 'proftpd'
2013-06-16 13:11:51,447 fail2ban.jail : INFO Jail 'proftpd' uses poller
2013-06-16 13:11:51,447 fail2ban.filter : INFO Added logfile = /var/log/proftpd/proftpd.log
2013-06-16 13:11:51,447 fail2ban.filter : INFO Set maxRetry = 3
2013-06-16 13:11:51,448 fail2ban.filter : INFO Set findtime = 600
2013-06-16 13:11:51,448 fail2ban.actions: INFO Set banTime = 6000
2013-06-16 13:11:51,464 fail2ban.jail : INFO Jail 'proftpd' started

Log készítése proftpd-ben
/etc/proftpd/proftpd.conf

SystemLog /var/log/proftpd/proftpd.log

Iptables:

Chain fail2ban-proftpd (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere

Megemeltem debugra.

Nem látja a próbálkozásokat a fail2ban pedig a log-ban benne van:(
fail2ban-client status proftpd

Status for the jail: proftpd
|- filter
| |- File list: /var/log/proftpd/proftpd.log
| |- Currently failed: 0
| `- Total failed: 0
`- action
|- Currently banned: 0
| `- IP list:
`- Total banned: 0

De a log módosulását sem veszi észre? Így néz ki normál esetben, benne a "DEBUG  /var/log/proftpd/proftpd.log has been modified" sorokkal (ill. az auth.log-ra hasonlóan), a végén pedig ban, és az iptables parancsok, valamint azok sikeressége.


  2013-06-16 14:29:12,422 fail2ban.filter : DEBUG  /var/log/auth.log has been modified
  2013-06-16 14:29:12,423 fail2ban.filter.datedetector: DEBUG  Sorting the template list
  2013-06-16 14:29:28,426 fail2ban.filter : DEBUG  /var/log/proftpd/proftpd.log has been modified
  2013-06-16 14:29:28,426 fail2ban.filter.datedetector: DEBUG  Sorting the template list
  2013-06-16 14:29:43,426 fail2ban.filter : DEBUG  /var/log/proftpd/proftpd.log has been modified
  2013-06-16 14:29:43,432 fail2ban.filter : DEBUG  Found 198.51.100.2
  2013-06-16 14:29:43,432 fail2ban.filter.datedetector: DEBUG  Sorting the template list
  2013-06-16 14:29:51,430 fail2ban.filter : DEBUG  /var/log/proftpd/proftpd.log has been modified
  2013-06-16 14:29:51,430 fail2ban.filter.datedetector: DEBUG  Sorting the template list
  2013-06-16 14:30:00,430 fail2ban.filter : DEBUG  /var/log/proftpd/proftpd.log has been modified
  2013-06-16 14:30:00,430 fail2ban.filter.datedetector: DEBUG  Sorting the template list
  2013-06-16 14:30:01,422 fail2ban.filter : DEBUG  /var/log/auth.log has been modified
  2013-06-16 14:30:01,423 fail2ban.filter.datedetector: DEBUG  Sorting the template list
  2013-06-16 14:30:03,430 fail2ban.filter : DEBUG  /var/log/proftpd/proftpd.log has been modified
  2013-06-16 14:30:03,430 fail2ban.filter : DEBUG  Found 198.51.100.2
  2013-06-16 14:30:03,430 fail2ban.filter.datedetector: DEBUG  Sorting the template list
  2013-06-16 14:30:05,430 fail2ban.filter : DEBUG  /var/log/proftpd/proftpd.log has been modified
  2013-06-16 14:30:05,430 fail2ban.filter.datedetector: DEBUG  Sorting the template list
  2013-06-16 14:30:09,430 fail2ban.filter : DEBUG  /var/log/proftpd/proftpd.log has been modified
  2013-06-16 14:30:09,430 fail2ban.filter.datedetector: DEBUG  Sorting the template list
  2013-06-16 14:30:12,430 fail2ban.filter : DEBUG  /var/log/proftpd/proftpd.log has been modified
  2013-06-16 14:30:12,430 fail2ban.filter : DEBUG  Found 198.51.100.2
  2013-06-16 14:30:12,431 fail2ban.filter.datedetector: DEBUG  Sorting the template list
  2013-06-16 14:30:12,450 fail2ban.actions: WARNING [proftpd] Ban 198.51.100.2
  2013-06-16 14:30:12,450 fail2ban.actions.action: DEBUG  iptables -n -L INPUT | grep -q fail2ban-proftpd
  2013-06-16 14:30:12,457 fail2ban.actions.action: DEBUG  iptables -n -L INPUT | grep -q fail2ban-proftpd returned successfully
  2013-06-16 14:30:12,458 fail2ban.actions.action: DEBUG  iptables -I fail2ban-proftpd 1 -s 198.51.100.2 -j DROP
  2013-06-16 14:30:12,460 fail2ban.actions.action: DEBUG  iptables -I fail2ban-proftpd 1 -s 198.51.100.2 -j DROP returned successfully
  2013-06-16 14:30:15,422 fail2ban.filter : DEBUG  /var/log/auth.log has been modified
  2013-06-16 14:30:15,423 fail2ban.filter.datedetector: DEBUG  Sorting the template list

Konfigmódosítás után szokott lenni restart vagy reload? Most csomaggal szállított regexp van beállítva filterként?

Mert annak illeszkednie kell:


a# grep -oE "$(sed 's/<HOST>/xxx.xxx.xxx.xxx/' <<<'\(\S+\[<HOST>\]\)[: -]+ USER \S+: no such user found from \S+ \[\S+\] to \S+:\S+ *$')" <<<'jún 16 01:33:46 kkk proftpd[12053] 127.0.1.1 (xxx.xxx.xxx.xxx[xxx.xxx.xxx.xxx]): USER valami: no such user found from xxx.xxx.xxx.xxx [xxx.xxx.xxx.xxx] to yyy.yyy.yyy.yyy:21'
(xxx.xxx.xxx.xxx[xxx.xxx.xxx.xxx]): USER valami: no such user found from xxx.xxx.xxx.xxx [xxx.xxx.xxx.xxx] to yyy.yyy.yyy.yyy:21
a#

Lehet dátum formátum miatt van? Hogy lehet orvosolni?

fail2ban.log


2013-06-16 15:25:29,247 fail2ban.filter : DEBUG Found a match for ' aaa proftpd[24406] 127.0.1.1 (xxx.xxx.xxx.xxx[xxx.xxx.xxx.xxx]): USER valami.hu (Login failed): No such user found.
' but no valid date/time found for 'jún 16 15:25:28'. Please contact the author in order to get support for this format
2013-06-16 15:25:29,247 fail2ban.filter : DEBUG Found a match for ' aaa proftpd[24406] 127.0.1.1 (xxx.xxx.xxx.xxx[xxx.xxx.xxx.xxx]): USER valami.hu (Login failed): No such user found.
' but no valid date/time found for 'jún 16 15:25:28'. Please contact the author in order to get support for this format

Úgy tűnik, a Squeeze-ben lévő fail2ban nincs felkészítve a más locale szerinti dátum mező értelmezésére. Van is róla jegy: #648324. A 0.8.6-1 verzióban javították, azaz a Wheezy-ben már menni fog rendesen. Ha valamiért még nem akarsz upgrade-elni, akkor a proftpd-re, vagy akár a teljes rendszerre állítsd vissza locale-t pl. C-re. Vagy - mivel az SSH megy -, meg lehet nézni a syslogon keresztüli logolást is.