From nobody Thu Aug 25 10:20:23 2022 X-Original-To: freebsd-net@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MCzWJ1qCMz4ZB6N; Thu, 25 Aug 2022 10:20:44 +0000 (UTC) (envelope-from grembo@freebsd.org) Received: from mail.evolve.de (mail.evolve.de [213.239.217.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA512 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mail.evolve.de", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MCzWH0Hflz3qVx; Thu, 25 Aug 2022 10:20:42 +0000 (UTC) (envelope-from grembo@freebsd.org) Received: by mail.evolve.de (OpenSMTPD) with ESMTP id 0609d67d; Thu, 25 Aug 2022 10:20:35 +0000 (UTC) Received: by mail.evolve.de (OpenSMTPD) with ESMTPSA id f58d69d0 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Thu, 25 Aug 2022 10:20:35 +0000 (UTC) Date: Thu, 25 Aug 2022 12:20:23 +0200 From: Michael Gmelin To: Carlos =?UTF-8?B?TMOzcGV6IE1hcnTDrW5leg==?= Cc: questions@freebsd.org, freebsd-net@FreeBSD.org Subject: Re: How to apply brute force rate limitings with rdr and pass rules under FreeBSD 13? Message-ID: <20220825122023.08491369.grembo@freebsd.org> In-Reply-To: References: X-Face: $wrgCtfdVw_H9WAY?S&9+/F"!41z'L$uo*WzT8miX?kZ~W~Lr5W7v?j0Sde\mwB&/ypo^}> +a'4xMc^^KroE~+v^&^#[B">soBo1y6(TW6#UZiC]o>C6`ej+i Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWJBwe5BQDl LASZU0/LTEWEfHbyj0Txi32+sKrp1Mv944X8/fm1rS+cAAAACXBIWXMAAAsTAAAL EwEAmpwYAAAAB3RJTUUH3wESCxwC7OBhbgAAACFpVFh0Q29tbWVudAAAAAAAQ3Jl YXRlZCB3aXRoIFRoZSBHSU1QbbCXAAAAAghJREFUOMu11DFvEzEUAGCfEhBVFzuq AKkLd0O6VrIQsLXVSZXoWE5N1K3DobBBA9fQpRWc8OkWouaIjedWKiyREOKs+3PY fvalCNjgLVHeF7/3bMtBzV8C/VsQ8tecEgCcDgrzjekwKZ7TwsJZd/ywEKwwP+ZM 8P3drTsAwWn2mpWuDDuYiK1bFs6De0KUUFw0tWxm+D4AIhuuvZqtyWYeO7jQ4Aea 7jUqI+ixhQoHex4WshEvSXdood7stlv4oSuFOC4tqGcr0NjEqXgV4mMJO38nld4+ xKNxRDon7khyKVqY7YR4d+Cg0OMrkWXZOM7YDkEfKiilCn1qYv4mighZiynuHHOA Wq9QJq+BIES7lMFUtcikMnkDGHUoncA+uHgrP0ctIEqfwLHzeSo+eUA66AqzwN6n 2ZHJhw6Qh/PoyC/QENyEyC/AyNjq74Bs+3UH0xYwzDUC4B97HgLocg1QLYgDDO1v f3UX9Y307Ew4AHh67YAFFsxEpkXwpXY3eIgMhAAE3R19L919nNnuD2wlPcDE3UeT L2ytEICQib9BXgS2fU8PrD82ToYO1OEmMSnYTjSqSv9wdC0tPYC+rQRQD9ESnldF CyqfmiYW+tlALt8gH2xrMdC/youbjzPXEun+/ReXsMCDyve3dZc09fn2Oas8oXGc Jj6/fOeK5UmSMPmf/jL+GD8BEj0k/Fn6IO4AAAAASUVORK5CYII= List-Id: Networking and TCP/IP with FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-net List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-net@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4MCzWH0Hflz3qVx X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=softfail (mx1.freebsd.org: 213.239.217.29 is neither permitted nor denied by domain of grembo@freebsd.org) smtp.mailfrom=grembo@freebsd.org X-Spamd-Result: default: False [-1.10 / 15.00]; SUBJECT_ENDS_QUESTION(1.00)[]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MLMMJ_DEST(0.00)[freebsd-net@FreeBSD.org,questions@freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_TO(0.00)[outlook.com]; MIME_TRACE(0.00)[0:+]; R_DKIM_NA(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; R_SPF_SOFTFAIL(0.00)[~all]; FROM_HAS_DN(0.00)[]; FREEFALL_USER(0.00)[grembo]; RCVD_VIA_SMTP_AUTH(0.00)[]; ASN(0.00)[asn:24940, ipnet:213.239.192.0/18, country:DE]; RCPT_COUNT_THREE(0.00)[3]; DMARC_NA(0.00)[freebsd.org]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; RCVD_TLS_LAST(0.00)[] X-ThisMailContainsUnwantedMimeParts: N On Thu, 25 Aug 2022 10:48:45 +0200 Carlos L=C3=B3pez Mart=C3=ADnez wrote: > Hi all, >=20 > I am tryping to rate limit public connections for certain services to=20 > avoid brutforce attacks under a FreeBSD 13.1 firewall. Under OpenBSD > is "pretty simple" with a rule like: >=20 > table persist > block quick from > pass inet proto tcp from ! to (egress:0) port=20 > $tcp_services \ > flags S/SA keep state \ > (max-src-conn 100, max-src-conn-rate 15/5, \ > overload flush global) rdr-to $internal_server >=20 > But under Freebsd when I try to combine "pass" with "rdr" rules, it=20 > doesn't works. For example: >=20 > rdr on egress inet proto tcp from ! to egress port=20 > $tcp_services -> $internal_server >=20 > pass in on egress inet proto tcp from ! to > (egress:0) port $tcp_services flags S/SA keep state (max-src-conn > 100, max-src-conn-rate 15/5, overload flush global) >=20 > Any idea about what am I doing wrong? Your pass rule won't match the rdr rule, as it is matched *after* rdr was applied. So at this point the target address is not egress:0, anymore, but $internal_server. If your traffic passes anyway, it's probably matched by some other more general rule. You could simplify your config by using tags, which could look like this: rdr on egress inet proto tcp from ! to \ egress port $tcp_services tag pass_rate_limit -> $internal_server pass in quick flags S/SA keep state (max-src-conn 100, \ max-src-conn-rate 15/5, overload flush global) \ tagged pass_rate_limit Using the "pass quick" rule early in your pf.conf will make sure it is applied instead of other matching rules. Cheers Michael --=20 Michael Gmelin