Debian 7, fail2ban met ssh key authentication

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • PyBo
  • Registratie: April 2013
  • Niet online
Beste tweakers,

Ik heb mijn VPS server bij OVH al een tijdje draaien stabiel. Hier heb ik extra beveiliging op toegevoegd, zoals geen root logins, andere poort en als laatste key authentication en geen wachtwoorden meer.

Dit alles heb ik stap voor stap uitgevoerd, inclusief het testen van fail2ban tussendoor. Echter heb ik sinds de key authentication geen actieve fail2ban meer. Ik heb al een aantal pogingen gedaan en gezocht op internet, maar hij reageert totaal niet meer.

Hieronder nog een aantal dingen ter informatie.

Weet iemand/ kan iemand mij hier helpen, ik ben eigenlijk even klaar met uitzoeken.

Groet,

Patrick



Mijn fail2ban logfile komt iedere keer netjes zo uit.
code:
1
2
3
4
5
6
7
8
9
10
11
12
2015-01-24 10:53:54,340 fail2ban.jail   : INFO   Creating new jail 'ssh'
2015-01-24 10:53:54,363 fail2ban.jail   : INFO   Jail 'ssh' uses Gamin
2015-01-24 10:53:54,577 fail2ban.filter : INFO   Added logfile = /var/log/auth.log
2015-01-24 10:53:54,579 fail2ban.filter : INFO   Set maxRetry = 3
2015-01-24 10:53:54,581 fail2ban.filter : INFO   Set findtime = 600
2015-01-24 10:53:54,582 fail2ban.actions: INFO   Set banTime = 86400
2015-01-24 10:53:54,681 fail2ban.jail   : INFO   Jail 'ssh' started
2015-01-24 10:56:49,873 fail2ban.filter : INFO   Log rotation detected for /var/log/auth.log
2015-01-24 11:04:42,884 fail2ban.server : INFO   Stopping all jails
2015-01-24 11:04:44,259 fail2ban.jail   : INFO   Jail 'ssh' stopped
2015-01-24 11:04:44,261 fail2ban.server : INFO   Exiting Fail2ban
2015-01-24 11:04:44,838 fail2ban.server : INFO   Changed logging target to /var/log/fail2ban.log for Fail2ban v0.8.6


Een deel van de auth.log logfile, ontstaan door foutieve connecties opgevoerd door mijzelf vanaf een tijdelijke VPS server
code:
1
2
3
4
5
6
7
8
Jan 24 11:06:19 vps64484 sshd[2519]: Connection closed by --ip-- [preauth]
Jan 24 11:06:21 vps64484 sshd[2521]: Connection closed by --ip-- [preauth]
Jan 24 11:06:22 vps64484 sshd[2523]: Connection closed by --ip-- [preauth]
Jan 24 11:06:23 vps64484 sshd[2525]: Connection closed by --ip-- [preauth]
Jan 24 11:06:25 vps64484 sshd[2527]: Connection closed by --ip-- [preauth]
Jan 24 11:06:26 vps64484 sshd[2529]: Connection closed by --ip-- [preauth]
Jan 24 11:06:28 vps64484 sshd[2531]: Connection closed by --ip-- [preauth]
Jan 24 11:06:29 vps64484 sshd[2533]: Connection closed by --ip-- [preauth]


Een test uitgevoerd op de log file
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d/sshd.conf 

Running tests
=============

Use regex file : /etc/fail2ban/filter.d/sshd.conf
Use log file   : /var/log/auth.log


Results
=======

Failregex
|- Regular expressions:
|  [1] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*(?:error: PAM: )?Authentication failure for .* from <HOST>\s*$
|  [2] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*(?:error: PAM: )?User not known to the underlying authentication module for .* from <HOST>\s*$
|  [3] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*Failed (?:password|publickey) for .* from <HOST>(?: port \d*)?(?: ssh\d*)?$
|  [4] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*ROOT LOGIN REFUSED.* FROM <HOST>\s*$
|  [5] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*[iI](?:llegal|nvalid) user .* from <HOST>\s*$
|  [6] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*User .+ from <HOST> not allowed because not listed in AllowUsers$
|  [7] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*authentication failure; logname=\S* uid=\S* euid=\S* tty=\S* ruser=\S* rhost=<HOST>(?:\s+user=.*)?\s*$
|  [8] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*refused connect from \S+ \(<HOST>\)\s*$
|  [9] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*Address <HOST> .* POSSIBLE BREAK-IN ATTEMPT!*\s*$
|  [10] ^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*User .+ from <HOST> not allowed because none of user's groups are listed in AllowGroups\s*$
|
`- Number of matches:
   [1] 0 match(es)
   [2] 0 match(es)
   [3] 4 match(es)
   [4] 0 match(es)
   [5] 2 match(es)
   [6] 0 match(es)
   [7] 0 match(es)
   [8] 0 match(es)
   [9] 0 match(es)
   [10] 0 match(es)

Ignoreregex
|- Regular expressions:
|
`- Number of matches:

Summary
=======

Addresses found:
[1]
[2]
[3]
    92.110.106.172 (Mon Jan 19 22:15:37 2015)
    92.110.106.172 (Mon Jan 19 22:15:49 2015)
    92.110.106.172 (Tue Jan 20 10:11:34 2015)
    92.110.106.172 (Tue Jan 20 10:11:39 2015)
[4]
[5]
    145.24.189.113 (Mon Jan 19 15:20:16 2015)
    145.24.178.93 (Wed Jan 21 16:16:10 2015)
[6]
[7]
[8]
[9]
[10]

Date template hits:
15036 hit(s): MONTH Day Hour:Minute:Second
0 hit(s): WEEKDAY MONTH Day Hour:Minute:Second Year
0 hit(s): WEEKDAY MONTH Day Hour:Minute:Second
0 hit(s): Year/Month/Day Hour:Minute:Second
0 hit(s): Day/Month/Year Hour:Minute:Second
0 hit(s): Day/Month/Year Hour:Minute:Second
0 hit(s): Day/MONTH/Year:Hour:Minute:Second
0 hit(s): Month/Day/Year:Hour:Minute:Second
0 hit(s): Year-Month-Day Hour:Minute:Second
0 hit(s): Year.Month.Day Hour:Minute:Second
0 hit(s): Day-MONTH-Year Hour:Minute:Second[.Millisecond]
0 hit(s): Day-Month-Year Hour:Minute:Second
0 hit(s): TAI64N
0 hit(s): Epoch
0 hit(s): ISO 8601
0 hit(s): Hour:Minute:Second
0 hit(s): <Month/Day/Year@Hour:Minute:Second>

Success, the total number of match is 6

However, look at the above section 'Running tests' which could contain important
information.

Acties:
  • 0 Henk 'm!

  • Thralas
  • Registratie: December 2002
  • Laatst online: 30-09 08:10
Je probleem is dat je teveel security probeert te stapelen.

Als je password authentication uitzet (heel goed!) is de enige mogelijkheid tot authenticatie een geldig RSA/DSA/EC keypair. Zodra je verbinding maakt stuurt de server welke authentication methods hij support, de client kiest er een en probeert te authenticeren:

code:
1
2
3
4
5
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: Authentication succeeded (publickey).


Nu zijn alle ssh bruteforcing bots afhankelijk van het raden van een wachtwoord, maar je server ondersteunt geen password authentication. Pubkey auth proberen ze niet, want de security van een key is zoveel bits dat dit niet te 'raden' valt.

Wat zie je in je logs als een (nette) ssh client connect maar nooit een authenticatiepoging doet? Connection closed [preauth[. En je fail2ban config matched alleen daadwerkelijk gefaalde authenticatiepogingen.

Is het dan zinnig om fail2ban te gebruiken? In mijn ogen niet, met enkel pubkey auth enabled hoef je niet bang te zijn voor bots die 'aan de poort rammelen', ze komen er toch niet in. Met bannen schiet je verder ook niets op, ze connecten toch maar een keer. Als je je ergert aan de log entries zou ik je firewall strakker afstellen.

Zelfde geldt voor disabled root login en non-default ports, die maatregelen voegen weinig tot niets toe als je de meest belangrijke (PasswordAuthentication no) al hebt toegepast.