Re: Blocking packets from suspicious ports

Christian Huitema <huitema@huitema.net> Wed, 04 May 2022 00:44 UTC

Return-Path: <huitema@huitema.net>
X-Original-To: quic@ietfa.amsl.com
Delivered-To: quic@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 98534C15E6D3 for <quic@ietfa.amsl.com>; Tue, 3 May 2022 17:44:41 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -3.746
X-Spam-Level:
X-Spam-Status: No, score=-3.746 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, NICE_REPLY_A=-1.857, SPF_HELO_NONE=0.001, T_SPF_PERMERROR=0.01] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4A9FGU-VbW56 for <quic@ietfa.amsl.com>; Tue, 3 May 2022 17:44:40 -0700 (PDT)
Received: from mx36-out21.antispamcloud.com (mx36-out21.antispamcloud.com [209.126.121.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id A59ABC159A21 for <quic@ietf.org>; Tue, 3 May 2022 17:44:40 -0700 (PDT)
Received: from xse440.mail2web.com ([66.113.197.186] helo=xse.mail2web.com) by mx257.antispamcloud.com with esmtp (Exim 4.92) (envelope-from <huitema@huitema.net>) id 1nm387-0009rE-Tr for quic@ietf.org; Wed, 04 May 2022 02:44:38 +0200
Received: from xsmtp21.mail2web.com (unknown [10.100.68.60]) by xse.mail2web.com (Postfix) with ESMTPS id 4KtJ2p63K0z9tv for <quic@ietf.org>; Tue, 3 May 2022 17:42:58 -0700 (PDT)
Received: from [10.5.2.17] (helo=xmail07.myhosting.com) by xsmtp21.mail2web.com with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from <huitema@huitema.net>) id 1nm36Y-0001Tm-N2 for quic@ietf.org; Tue, 03 May 2022 17:42:58 -0700
Received: (qmail 21903 invoked from network); 4 May 2022 00:42:57 -0000
Received: from unknown (HELO [192.168.1.107]) (Authenticated-user:_huitema@huitema.net@[172.58.43.164]) (envelope-sender <huitema@huitema.net>) by xmail07.myhosting.com (qmail-ldap-1.03) with ESMTPA for <w@1wt.eu>; 4 May 2022 00:42:56 -0000
Message-ID: <e8c90e2b-e0f1-82ca-8243-2b41412de513@huitema.net>
Date: Tue, 03 May 2022 17:42:56 -0700
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1
Content-Language: en-US
To: Willy Tarreau <w@1wt.eu>, Paul Vixie <paul=40redbarn.org@dmarc.ietf.org>
Cc: IETF QUIC WG <quic@ietf.org>
References: <6830cf87-e1b6-14bb-7b10-9341fdb6d941@huitema.net> <1b686f1e-912d-5c02-cf5f-a8afbdd924bb@redbarn.org> <20220503032335.GB20878@1wt.eu>
From: Christian Huitema <huitema@huitema.net>
Subject: Re: Blocking packets from suspicious ports
In-Reply-To: <20220503032335.GB20878@1wt.eu>
Content-Type: text/plain; charset="UTF-8"; format="flowed"
Content-Transfer-Encoding: 7bit
X-Originating-IP: 66.113.197.186
X-Spampanel-Domain: xsmtpout.mail2web.com
X-Spampanel-Username: 66.113.197.0/24
Authentication-Results: antispamcloud.com; auth=pass smtp.auth=66.113.197.0/24@xsmtpout.mail2web.com
X-Spampanel-Outgoing-Class: unsure
X-Spampanel-Outgoing-Evidence: Combined (0.15)
X-Recommended-Action: accept
X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT9WLQux0N3HQm8ltz8rnu+BPUtbdvnXkggZ 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5x6h2yQpzTslcOqazQkKtAFKj/EwzSHE5FGYwwjsNRPCKi/ Fo7Y3tjvaPao5NOVhCjmD6wdmZPcItWbGe10hXJtXL4FsauCVkDjmcYJdU3yWp7KuHNaaKdg7iBE ZefdsNUFWKwa/wzJUjmazeC7ImcaNOiP8tKCLoTs73rCt+paKRQ6V51u76v35b1wNe/MvdKgXtf/ I8Zg+7J5IC/SF7EL2+J9PgaoF8SQHto3le4zsHTaeQtlKubP6iUTjj6yPARK6buALVaA782LKxg6 vRmng8N1aLhXqdc+jC1RcnVud53D5caUhbVtvqItBqoizkEt9O20UjkwI0v+LOlw05G4BS+iyyNq bT8dUMXMJ4tUCMj6G37ZfAMLceP5aNHPt26RBupu5v1nytoNnc138GfEJRQ2qC7jjynPIHPNqSn4 QTXUjLjYWQt1/5xnQymMoPsgr/U0flMcy2Vi/IcBgY4arPaiJ1W6hAyiRC61jekdwIcXNugoOEbH RyFULpSjm7hMIABpqqRGKyDs8xujM3cqz2icAXJ44pwgKRmsUjw7TKW9i9p8yS80MpEAWYigrd9a n6rKLQX8oKVGyq8/et/KEnFzsC48bTEFY06/YbB87Ww8G0LoS8V3Mt1pta8qAcLtCB3G1CwpaI3Z 4ESkMWDVJEenxBoIht3V0nekAoxXAnv0r1AGVmvAw1lDkrW7iTeyuLfHqAnAj7rgKH7+eCmms+9P yJSv1nkF8sLJDMOF01ShcA6Xvva2QAVEjpqzANbJ1UfXmet2cbFKoyT/OdZLxeZFPaxJ3xa5cPxJ RrHTzG0AuXq0T17woJo3avKeADIsy647Mn0zwmGzAi3Zn+YdthRNgs7Ig4l/XErpYn3glZTKFuaT l19W3ISq9+1KiLsESGU+y+fjdgjudZxiTPi+MG1QP35nsYfP84c+RFK3KiZuZ5OAUoGBziSYFLZu u6zX3xxsmqT8l9ARlsTalAaf
X-Report-Abuse-To: spam@quarantine11.antispamcloud.com
Archived-At: <https://mailarchive.ietf.org/arch/msg/quic/3z3JcduAZYoLpCx3a71hQlBsxSI>
X-BeenThere: quic@ietf.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: Main mailing list of the IETF QUIC working group <quic.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/quic>, <mailto:quic-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/quic/>
List-Post: <mailto:quic@ietf.org>
List-Help: <mailto:quic-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/quic>, <mailto:quic-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 04 May 2022 00:44:41 -0000

Thanks, Willy. That's exactly the kind of analysis I was trying to elicit.

Comments in line.

On 5/2/2022 8:23 PM, Willy Tarreau wrote:
> On Mon, May 02, 2022 at 02:27:15PM -0700, Paul Vixie wrote:
>> a partially managed (not fully transparent) network (public or private) can
>> be expected to implement port-based inbound UDP blocking of the kind you
>> describe. the set of ports will be dynamic, updated during attacks. not
>> something to be hardcoded or "set and forget".
> I think that's the most important aspect, and for having participated many
> times to fightng DDoS I agree with this. There are obvious common sanity
> rules that are often applied based on what is possible/available:
>    - have a (set of) local DNS and NTP server(s) that are the only ones
>      susceptible of receiving UDP from privilege ports (< 1024) and have
>      all other servers use DNS and NTP from there
>    - have the edge components (routers, L3 switches) block all inbound
>      UDP from privileged and well-known source ports to regular servers;
>      this list may evolve during attacks
>    - have all servers locally refine their blocking list at the kernel
>      level (netfilter, BPF, PF and so on etc) preventing cross-protocol
>      communication (53->123, 123->53 etc).
>    - when possible, refine filtering by source/destination ports based
>      on the expected protocol (e.g. verify that traffic to port 53 looks
>      like a DNS request, from port 53 looks like a DNS response, from
>      123 looks like an NTP response, with special cases for 53->53 or
>      123->123)
>
> If the wrong packet is delivered to the userspace application, you lose
> anyway as most of the harm caused by network stack traversal by a packet
> was already done. Worse once a packet passes through, it's often trivial
> for the attacker to repeat it and flood the application. A good rule of
> thumb is to count on 1 million packets per second delivered to the
> application, per CPU core. Of course it will vary a lot between systems
> and the filtering in place, but the order of magnitude is there. This
> means that a 100G NIC can keep 148 cores busy just delivering bad
> packets to be dropped by the application.

As I said, there appear to be two concerns. One is to protect the local 
server from floods, and, as you say, this is much better done by 
blocking the suspicious traffic ahead of the server. The other is, 
provide at least a modicum of defense against attacks that use the QUIC 
server as a reflector. For example:

* attacker sends a "carefully crafted" UDP packet to QUIC server, 
spoofing the source address and port of a target,

* QUIC server processes the packet and produces the expected "response"

* target attempts to process the packet and something bad happens.

The concern here is not so much volumetric attacks, which can be 
mitigated with a combination of not amplifying traffic and carefully 
using retry. We are also concerned about "Request Forgery" attacks, in 
which the "response" activates a bug in the target. For example, QUIC 
sends a long packet to a poorly written game server, and the game server 
crashes when trying to process that packet. There may also be variants 
of that attack in which an attacking server bounces packets through a 
QUIC client.

Clearly, servers that can be crashed by a few magic packets have no 
business being reachable from the Internet. But the concern here is that 
by spoofing the source address, an attacker located outside of the 
server network can reflect and attack towards a vulnerable server inside 
that network, even if firewalls isolate that vulnerable server from the 
Internet.

> I would suggest that port filtering at the application layer is only
> used to decide whether to respond or not (i.e. should I send a retry
> for a packet that parses correctly). For example it could be suggested
> that packets coming from suspicious but valid source ports ought to
> be double-checked with a retry to preserve local resources. But that
> will not be used to save CPU anyway.

Yes. Makes sense. But there are four ways by which QUIC can bounce packets:

* Initial packets from the client will cause the server to send a flight 
of up to 3 Handshake packets. The Retry mechanism could be used there.

* Initial packets from the client with an unsupported version number 
cause the server to send a Version Negotiation packet. These are short 
packets, but up to 256 bytes of the VN packet content can be 
predetermined by the attacker.

* 1RTT packets sent to a server with a unknown Connection ID may cause 
the server to send a Stateless Reset packet. The Stateless Reset packet 
must be shorter than the incoming packet, so there is no amplification. 
The content is hard to predict, but who knows.

* After a connection has been established and verified, either party can 
send a "path validation" packet from a "new" address and port. Clients 
or servers will respond with a path validation packet of their own, 
trying to reach the new address. The validation attempt could be 
repeated multiple time, typically 3 times. At least 20 bytes at the 
beginning of the packet can be controlled by the attacker, and possibly 
many more.

If an application just drops packets from a suspicious port, it 
mitigates all 4 avenues of attack. If it want precision instead, it has 
to write specific code at four locations. RFC 9000 details these 
attacks, but mostly says "protect using ingress filtering, per BCP38".

>
> Maintaining a public list of well-known suspicious ports can be both
> helpful and dangerous. It's helpful in that it shows implementers that
> some ranges should never appear as they're normally reserved for
> listening services, that some numbers are well known and widely
> deployed, and that some are less common but appear anywhere, indicating
> that a range is not sufficient. This should help design a flexible
> filtering mechanism. But it can also be dangerous if applied as-is:
> this list cannot remain static as new entries may have to be added
> within a few minutes to hours hours and each addition will cause extra
> breakage, thus some previous ones will likely be dropped after a
> previous service stopped being widely attacked. I.e. the list in
> question likely needs to be accessible by configuration in field and
> not be hard-coded.
AFAIK, such lists are hard coded in quite a few implementations. Even if 
they are provided in a configuration file, changing the file requires 
restarting the server. So "within a few minutes" may be problematic.
> Other approaches could work fairly well, such as keeping a rate counter
> of incoming packets per source port (e.g. unparsable or initial packets)
> which, above a moderate value, would serve to send retry, and above a
> critical value, can be used to decide to block the port (possibly earlier
> in the chain). This remains reasonably cheap to implement, though it may
> end up causing some flapping as the rate will fall after the port is
> blocked upstream, which may lead to it being reopened before the attack
> is finished.
Yes. Should that really be "per source port" or "per source IP + port"?
>
> I think we'll discover new fun things over time and will learn new
> attacks and workarounds as deployments grow.

I have not heard of actual attacks "in the wild", but who knows...

-- Christian Huitema