From: Jonathan W. <jw...@at...> - 2016-12-20 05:09:24
|
On Tue, Oct 25, 2016 at 11:04:42AM -0700, Kevin Zheng wrote: > On 10/24/2016 17:05, Jonathan Woithe wrote: > > In this case, sshguard evidently blocked 91.224.160.131 after 4 of the > > "Failed password" messages, as I would expect. What I can't work out is why > > 91.224.160.131 was blocked while 212.129.60.203 was not, even though they > > generated the same messages. The only difference is that 91.224.160.131 had > > the single failure around 6 hours before the main block, but this should not > > make a difference. > > It appears that SSHGuard is not recognizing any of the messages with > "port NNNN" at the end. > > > [1] For example, the "Invalid user inexu from 6.6.6.0" rule would not detect > > the "Invalid user guest from 212.129.60.203 port 52019" entries because our > > ssh logs the port number on the end of the rule. This rule might require > > "arbitrary text" to be added to the end to allow for this. > > I think this is the solution. Has such a solution been implemented yet? If not, an initial patch is included at the end of this email. Please do check it for correctness: I'm still getting my head around the .l/.y syntax. Regards jonathan This patch against sshguard 1.7.0 adds arbitrary text to the end of "invalid user" ssh messages. This covers the cases where additional text is appended to this message (most commonly the incoming port number). --- sshguard-1.7.0-new/src/parser/attack_parser.y 2016-10-26 09:28:32.071665939 +1030 +++ sshguard-1.7.0-new2/src/parser/attack_parser.y 2016-10-26 09:22:42.997004608 +1030 @@ -69,7 +69,7 @@ /* flat tokens */ %token SYSLOG_BANNER TIMESTAMP_SYSLOG TIMESTAMP_ISO8601 TIMESTAMP_TAI64 AT_TIMESTAMP_TAI64 METALOG_BANNER SOCKLOG_BANNER /* ssh */ -%token SSH_INVALUSERPREF SSH_NOTALLOWEDPREF SSH_NOTALLOWEDSUFF +%token SSH_INVALUSERPREF SSH_INVALDUSERSUFF SSH_NOTALLOWEDPREF SSH_NOTALLOWEDSUFF %token SSH_LOGINERR_PREF SSH_LOGINERR_SUFF SSH_LOGINERR_PAM %token SSH_VIA %token SSH_NOIDENTIFSTR SSH_BADPROTOCOLIDENTIF SSH_BADPROTOCOLIDENTIF_SUFF @@ -219,7 +219,7 @@ ssh_illegaluser: /* nonexistent user */ - SSH_INVALUSERPREF addr + SSH_INVALUSERPREF addr SSH_INVALDUSERSUFF /* existent, unallowed user */ | SSH_NOTALLOWEDPREF addr SSH_NOTALLOWEDSUFF ; --- sshguard-1.7.0-new/src/parser/attack_scanner.l 2016-10-26 09:28:16.783513172 +1030 +++ sshguard-1.7.0-new2/src/parser/attack_scanner.l 2016-10-26 09:24:22.852473989 +1030 @@ -38,7 +38,7 @@ /* Start Conditions */ /* for Login services */ -%s ssh_notallowed ssh_loginerr ssh_reversemap ssh_disconnect ssh_badproto ssh_badkex +%s ssh_invaliduser ssh_notallowed ssh_loginerr ssh_reversemap ssh_disconnect ssh_badproto ssh_badkex /* for Mail services */ %s dovecot_loginerr cyrusimap_loginerr exim_esmtp_autherr sendmail_relaydenied sendmail_authfailure sendmail_noissue postfix_loginerr /* for FTP services */ @@ -123,7 +123,8 @@ /* SSH: invalid or rejected user (cross platform [generated by openssh]) */ -[Ii]"nvalid user ".+" from " { return SSH_INVALUSERPREF; } +[Ii]"nvalid user ".+" from " { BEGIN(ssh_invaliduser); return SSH_INVALUSERPREF; } +<ssh_invaliduser>.* { BEGIN(INITIAL); return SSH_INVALDUSERSUFF; } /* match disallowed user (not in AllowUsers/AllowGroups or in DenyUsers/DenyGroups) on Linux Ubuntu/FreeBSD */ /* "User tinydns from 1.2.3.4 not allowed because not listed in AllowUsers" */ "User ".+" from " { BEGIN(ssh_notallowed); return SSH_NOTALLOWEDPREF; } |