From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Tremer To: development@lists.ipfire.org Subject: Re: ASN support for iptables Date: Tue, 05 Dec 2017 17:29:56 +0000 Message-ID: <1512494996.1472.41.camel@ipfire.org> In-Reply-To: <20171204174706.36a23d09.peter.mueller@link38.eu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3746357525891460936==" List-Id: --===============3746357525891460936== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Mon, 2017-12-04 at 17:47 +0100, Peter M=C3=BCller wrote: > Hello, >=20 > > On Fri, 2017-11-24 at 19:31 +0100, Peter M=C3=BCller wrote: > > > Hello, > > > =20 > > > > Hi, > > > >=20 > > > > On Mon, 2017-11-20 at 20:03 +0100, Peter M=C3=BCller wrote: =20 > > > > > Hello Michael, > > > > > =20 > > > > > > Hi, > > > > > >=20 > > > > > > On Sun, 2017-11-19 at 15:52 +0100, Peter M=C3=BCller wrote: =20 > > > > > > > Hello development list, > > > > > > >=20 > > > > > > > today, I'd like to discuss whether a new feature in > > > > > > > the firewall engine of IPFire makes sense or not. > > > > > > >=20 > > > > > > > Since Core Update 90, IPFire supports GeoIP based firewall > > > > > > > rules, which goes beyond simple IP addresses or CIDR blocks > > > > > > > and makes firewalling easier. > > > > > > >=20 > > > > > > > The idea I had in mind is to add ASN (Autonomous System > > > > > > > Number) support for firewall rules, too. > > > > > > >=20 > > > > > > > An AS (Autonomous System) can be described as an administrative > > > > > > > instance on top of IP: For example, several IP blocks belong > > > > > > > to an AS, i.e. to the same company, university or whatever. > > > > > > > Although these blocks may be used for completely different > > > > > > > purposes > > > > > > > in completely different countries, they share the same owner. > > > > > > >=20 > > > > > > > Every AS has a number (ASN) and a description (sometimes > > > > > > > abbreviated to ASDescr), while the number is unique. =20 > > > > > >=20 > > > > > > I think this makes sense and I would welcome that as a new feature > > > > > > in > > > > > > IPFire. It > > > > > > will in the end have some similar problems like the GeoIP blocker, > > > > > > but > > > > > > that > > > > > > is > > > > > > not too bad. =20 > > > > >=20 > > > > > Just for curiosity: Which ones are they? =20 > > > >=20 > > > > Apologies for nothing into depths of that. I just thought of the usual > > > > ones > > > > like > > > > not actually blocking what the user intends to block. Rules changing > > > > because > > > > prefixes might be moved around, etc. =20 > > >=20 > > > Ah, yes, the usual suspects. :-) =20 > > > >=20 > > > > It is just not 100% determinable. But indeed it is better than GeoIP.= =20 > > >=20 > > > True. =20 > > > > =20 > > > > > I only see the (potential) problem of _another_ incomplete database > > > > > here > > > > > (see > > > > > below). > > > > > Since all necessary data for this AS stuff are more or less public, > > > > > inaccurate > > > > > data and extensive manual research are not necessary. > > > > >=20 > > > > > All we need is to write some scripts that convert the RIPE, ... > > > > > databases > > > > > to a suitable format. =20 > > > >=20 > > > > Does such a public database of the RIRs exist? I don't know of one. = > > >=20 > > > Yes, they do exist, but mostly without the connection between an IP ran= ge > > > and > > > the ASN (see below). At least for RIPE, I have not checked the others in > > > detail. =20 > > > >=20 > > > > For IPv4 handing out address space has slowed down a lot. And we shou= ld > > > > not > > > > use > > > > the BGP feed and parse that because then we might miss prefixes that = are > > > > currently not announced - either deliberately or because of a downtim= e. > > > >=20 > > > > I know this: > > > > http://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-extended-la= tes > > > > t > > > >=20 > > > > But it doesn't connect the prefixes to an ASN AFAIK. > > > > =20 > > > > > Second, in contrast to the GeoIP database, false-positives are > > > > > extremely > > > > > rare > > > > > when dealing with AS information since they have to be technically > > > > > correct. As > > > > > always, there are some "good" and "bad" ASNs, and a lot "grey" ones, > > > > > which > > > > > stays > > > > > the same. =20 > > > >=20 > > > > We wouldn't really care about that, would we? That is up to the user = to > > > > decide > > > > what they want to block/whitelist. > > > > =20 > > > > > > =20 > > > > > > > There are some scenarios in which AS based firewall rules > > > > > > > make sense, since AS information change less seldom than > > > > > > > IP ranges: > > > > > > >=20 > > > > > > > (a) One wants to block malicious traffic, but blocking entire > > > > > > > countries is too much since there are some legitimate partners, > > > > > > > customers, ... out there. With AS support, it is possible to > > > > > > > grant them access by simply permitting their AS. The rest of > > > > > > > the country may now safely be blocked. =20 > > > > > >=20 > > > > > > True. This might work well in some situations, but is probably qu= ite > > > > > > useless > > > > > > when fighting against a botnet. =20 > > > > >=20 > > > > > I am not sure about this. In some cases, blocking access to some > > > > > bullet > > > > > proof/ > > > > > rogue ISPs where many C&C servers are hosted improves the situation. > > > > > Of > > > > > course, > > > > > if there is a simple DDoS attack from many different IPs, this will > > > > > not > > > > > help > > > > > very much. =20 > > > > > >=20 > > > > > > What would also be good is to open a port forwarding only from a > > > > > > certain > > > > > > AS. > > > > > > Let's call that whitelisting. =20 > > > > >=20 > > > > > Yes, that is a very good use case. :-) > > > > >=20 > > > > > And the combination of GeoIP and AS filtering (inbound and outbound) > > > > > opens up fare more possibilities... =20 > > > >=20 > > > > How would we combine this? =20 > > >=20 > > > I meant that it opens up new possibilities for creating firewall rules > > > (allowing > > > one AS and block/throttle the rest of a country, ...). =20 > >=20 > > LOL > >=20 > > > > =20 > > > > > > > (b) In some cases, IP ranges change very often, making firewall > > > > > > > rules very complex and hard to maintain, or the exact IP address > > > > > > > of a machine cannot be determined (dial-up connections). In > > > > > > > both cases, the AS (mostly) stays the same and allows firewall > > > > > > > rules without permitting access to a whole country. =20 > > > > > >=20 > > > > > > That will be the biggest challenge here. The database will need to > > > > > > be > > > > > > complete > > > > > > and needs regular updates. We don't really care if someone is > > > > > > actually > > > > > > announcing their prefix, but if they have one assigned, we should > > > > > > block/permit > > > > > > access. =20 > > > > >=20 > > > > > I agree with you. > > > > >=20 > > > > > We could simply ship an updated version with every Core Update (I > > > > > had that in mind for the CA list, too, so we don't get too big > > > > > deltas). =20 > > > >=20 > > > > If we don't convert this into some nice binary format this will indeed > > > > become a > > > > huge database of probably ~10MB?! That would be too much to be includ= ed > > > > in > > > > every > > > > Core Update. =20 > > >=20 > > > Is shipping database deltas an option? An maybe every 20th Core Update = the > > > complete one so we do not have too much trouble with incremental > > > updates. =20 > >=20 > > I don't think that this is worth it since we have to have a format that is > > possible to being delta-ed or we have to create a delta format and a tool > > which > > applies the delta. Way too much work for a different problem. >=20 > Hm, I thought about that a little bit. It surprises me that shipping lager > files (even bzipped or something) is a problem. >=20 > In fact, MaxMinds GeoIP database is just a .tar.gz-file containing an > aggregated > CSV. So if the machines are able to handle such a download once a month, I > thought > they would also handle updates which are a few MBytes lager. The problem we have is a maximum size for the core update. With some other big things like the kernel being shipped we get quite close to that limit. Therefore it would be nice to avoid a certain amount of that size being used = up by those databases. > >=20 > > In that case, text probably won't be the worst format and just applying a > > diff. >=20 > Yes, that's what I had in mind. > >=20 > > > If there is a nice small binary format, we should use it indeed. I am n= ot > > > very > > > deep into this subject. :-| =20 > >=20 > > Not that I know of. > >=20 > > > Shipping the database with every update avoids fetching them by the > > > systems > > > itself, in which I see a set of issues: > > >=20 > > > (a) A download server for the database must be reachable. In some netwo= rks > > > with restrictive policies, this might be a problem. On the other hand, = if > > > people install a Core Update, everybody understands that IPFire needs to > > > connect to some mirror servers. So why not shipping the databases via t= his > > > way. > > >=20 > > > (The idea behind this is that every network connection can go wrong. A = bit > > > ancient, I know. :-) ) =20 > >=20 > > We will have to find out if we are free to redistribute this data. > >=20 > > I wouldn't really like if we would distribute this through our mirrors. W= hat > > could be an option is only to put this into a package that is always > > installed > > and just regularly updated - but that would be a manual process again and > > not > > possible to update the package without installing all recent Core Updates. >=20 > Again, I thought that data amount would be fine. Glad you are mentioning it= is > not. > >=20 > > > (b) Error handling for database servers is problematic. In the given > > > scenario: > > > What if downloading the AS database fails? Simply using the old version > > > without > > > notifying is not an option. On the other hand, a notification (i.e. a > > > warning > > > in the WebUI) needs to be noticed by the administrator. If they install > > > an update, they will see errors instantly. =20 > >=20 > > Yes, continue to use the old version. >=20 > Not very nice, is it? I saw some of the download servers being out of sync = for > ~ two months, which is also very difficult to handle since there is no DNS > entry > showing the current version, similar to what ClamAV does. I quite like the ClamAV approach. However, that information needs to be signed (either by DNSSEC or something else). And another downside is that it brings another protocol in which can cause mo= re problems when being blocked behind another firewall or when there are other problems. Want to say: It makes the solution more complex. > I would prefer a notification in the WebUI here, too, so the admins know th= at > their machine is using probably outdated information. I never considered the database to be important to be up to date. We don't kn= ow how good and recent the information inside it is and assume it is rather old sometime. Therefore it is very often the case that the information is not of good quality. What ever the reason for that is. > >=20 > > > (c) A download server is an unnecessary information leak. Since all > > > systems > > > fetch their databases from a - hopefully redundant - server, this server > > > sees > > > all IP addresses (and wget user agents, ...) belonging to firewall > > > systems. > > > Although it may not be obvious at the first glance that IP x.y.z is an > > > IPFire > > > machine, > > > it is a good point for hacking tools to start from. =20 > >=20 > > We do have that already for the GeoIP database which I do not like either, > > but I > > think the license doesn't allow us to do anything else. > >=20 > > Some systems are being blocked Internet access by a proxy and probably ca= n't > > download anything at all. We need a contingency plan for that. > >=20 > > > This problem becomes more important when talking about third party sites > > > (MaxMind!) since nobody knows what they are actually doing with the log= s. > > > Even worse, if "geolite.maxmind.com" is going offline permanently, there > > > is no fallback server where the data can be fetched from. =20 > >=20 > > We would update the URL then... > >=20 > > > I do not consider the IPFire mirrors as problematic here, since there is > > > redundancy, and the traffic is split up to more than one system. > > >=20 > > > (d) Integrity checking for downloaded databases is problematic. In most > > > cases, they are just .tar.gz-files. No HTTPS, no DNSSEC/DANE, no checks= um > > > file, no GPG signature. Great. =20 > >=20 > > Certainly is a must if you want to go that way... The timestamp also has = to > > be > > signed so that an older database cannot be used to replace a newer one. >=20 > Indeed. > >=20 > > But we don't do any of this for GeoIP because we can only download this f= rom > > the > > third-party servers. > >=20 > > > And a firewall system is _relying_ on these data??? =20 > >=20 > > Yes. If you want features like this you have no other option. >=20 > Except building and shipping the databases (ASN and GeoIP) by ourselves. Let's do that then! > >=20 > > > Of course, this problem needs to be fixed by mirror operators in first > > > place. > > > But it is also a question of design: If one assumes that the internet in > > > general and the mirror servers in particular cannot be trusted, he/she/= it > > > will provide signed (and GPG encrypted) data, as IPFire does. Again, why > > > not using this way? =20 > >=20 > > We don't trust the mirrors. They are operated by third parties and I have= no > > idea if and how well they are secured against hacks, etc. > >=20 > > They are also constantly out of sync and slow and just integrity of the > > files > > because of disk corruption isn't guaranteed. > >=20 > > And most people who are operating the servers or have databases like MaxM= ind > > don't seem to know or care about these problems. > >=20 > > > > > > > (c) Rogue ISPs (networks which are controlled/operated by > > > > > > > professional > > > > > > > spammers or worse, such as the "Russian Business Network" (RBN), > > > > > > > which died in end-2007) sometimes run networks located in "good" > > > > > > > countries such as US or NL. Blocking them by GeoIP is not an > > > > > > > option because of many false-positives. AS based rules may help > > > > > > > here. =20 > > > > > >=20 > > > > > > The US is practically unblockable on the GeoIP filter, because too > > > > > > much > > > > > > is > > > > > > hosted in the US (at least according to the database by businesses > > > > > > that > > > > > > have > > > > > > their HQ there). =20 > > > > >=20 > > > > > Indeed, and there are several ASs over there the internet would be a > > > > > better > > > > > place without. But I guess that applies to most other countries, > > > > > too. =20 > > > > > >=20 > > > > > > So this would be a good extension to blocking more granular. > > > > > > =20 > > > > > > > Since the data behind this can be extracted from BGP feeds, > > > > > > > no external databases (such as MaxMind) are required. =20 > > > > > >=20 > > > > > > If we would use a BGP feed, we will only have the networks in the > > > > > > database > > > > > > that > > > > > > are currently announced. Wouldn't scraping the WHOIS database be > > > > > > better? =20 > > > > >=20 > > > > > Good idea. For example, RIPE has one here: > > > > > http://ftp.ripe.net/ripe/dbase/split/inet(6)num.gz=C2=A0=C2=A0=C2= =A0=20 > > > >=20 > > > > And where is the link to the ASN? =20 > > >=20 > > > Sorry, I used the wrong link while researching for the GeoIP stuff. Here > > > is > > > the correct one: https://ftp.ripe.net/ripe/dbase/ripe.db.gz > > >=20 > > > As far as I know, the link between "as-block" and an IP range can be do= ne > > > via the "mnt-by" or the "origin" tags. =20 > >=20 > > Okay. > >=20 > > > > =20 > > > > > >=20 > > > > > > Why not MaxMind? Not that I am in favour of that, but I am > > > > > > interested > > > > > > why it > > > > > > is > > > > > > not an option. =20 > > > > >=20 > > > > > Well, technically, it is an option. But since there is some trouble > > > > > with > > > > > their GeoIP database, as mentioned somewhere else some time before, > > > > > I'd > > > > > like to move away from them. =20 > > > >=20 > > > > What trouble? =20 > > >=20 > > > Well, some of them are mentioned above already. Here are some more: > > >=20 > > > (i) There is no changelog or release note. Once in a month, the GeoIP > > > database > > > is updated - and there is no (simple) way of telling which changes were > > > made. > > >=20 > > > For example, the IP ranges belonging to Cloudflare were recently deleted > > > from > > > this database. As a result, some websites became unreachable from today= to > > > tomorrow (see bug #11482 for details) since the iptables module permits > > > access > > > in case an IP is not listed (which is the correct behaviour). > > >=20 > > > Not sure how much went wrong here in productive networks, but it certai= nly > > > is an issue only MaxMind can fix. =20 > >=20 > > That is a problem that every blacklist has. Same goes for the proxy URL > > blacklists. > >=20 > > It is hard to track what is on there and probably most people don't really > > care > > much. But in case of disputing if something should be on it or not it is > > never > > good to have a commercial company to make that decision for you. > >=20 > > I suppose we can be much more "objective" about this here with the AS > > because we > > just export information from the RIRs. >=20 > I agree. > >=20 > > > (ii) The database update is performed silently. In case of troubles, th= is > > > procedure might not be obvious. On the other hand, if people install a > > > Core > > > Update, they are in maintenance mode, scheduled downtime, or whatever a= nd > > > are somewhat prepared for trouble. =20 > >=20 > > Yes. Saying what? >=20 > Saying that people are aware that updating might cause problems, so they are > prepared to test and fix something afterwards. In case a new database versi= on > causes network trouble because some firewall rules do not apply anymore, th= ey > can react to this instantly without fixing a productive system. >=20 > If the database is updated silently at a random time, trouble occur out of > nowhere and might break things since the firewall is actively used. >=20 > Because of that, I like updating the AS database via a Core Update better. > >=20 > > > (iii) The quality of the GeoIP database by MaxMind we use is poor. > > > For example, allocations to countries are incorrect (especially in case= of > > > "A1 - Anonymous Proxies") even if the correct data is known. Much worse, > > > sometimes the allocations are incorrect without being obvious (anycast > > > networks > > > are assigned to "US", or simply dropped in case of Cloudflare). It seems > > > like they are only scraping WHOIS, too. =20 > >=20 > > I don't have much resources to verify the quality of it too much. I was > > hoping > > they would do a better job at this. >=20 > Not sure what they are doing with their commercial database editions, but t= he > free one is not that good indeed. For example, all AOL IP ranges are listed= in > US, even if they are used in Brazil or other countries. > >=20 > > If they just get this from the RIRs databases, we can do this ourselves. >=20 > I think so but currently doing some research how to build this thing. > >=20 > > > There should be an "A3 - Anycast Networks" section for companies like > > > Google, > > > similar to "EU" or "AP" which also only indicate a continent without go= ing > > > down > > > to the country level. A3 would be a step further. =20 > >=20 > > I don't really appreciate the A* categories because they are just a random > > collection of what didn't fit anywhere else... >=20 > But they are actually needed since proxies, satellite and anycast network _= do_ > not fit into anything else. We also have EU for networks somewhere in Europ= e, > and there is AP for locations in Asia/Pacific. I did not really get your po= int > here. :-) My point is that blocking those categories is a very very vage guess. Like a = box of chocolates. You never know what you are gonna get. > >=20 > > > Note that I am not talking about their chargeable products or the city > > > databases here. =20 > > > Because of these issues, I'd like to build our own GeoIP database, but > > > that > > > is off-topic here, and will be mentioned in another mail. ;-) =20 > >=20 > > Oooookay... > >=20 > > > > =20 > > > > > And since we can build our own database here, I do not see why we > > > > > should > > > > > rely on 3rd party data. =20 > > > > > > =20 > > > > > > > Unfortunately, my programming skills are too low for implementi= ng > > > > > > > this feature. Thereof, if it is decided to do this, I will need > > > > > > > some help here. :-) =20 > > > > > >=20 > > > > > > *raises hand* =20 > > > > >=20 > > > > > Thank you very much. :-) =20 > > > > > > =20 > > > > > > > Technically, this is similar to the GeoIP firewall stuff (just > > > > > > > another database), so I assume most of the work done there can > > > > > > > just be copied. =20 > > > > > >=20 > > > > > > The GeoIP block uses an iptables extension which parses the > > > > > > database. We > > > > > > wouldn't use that here but would either build something with ipset > > > > > > or > > > > > > similar. =20 > > > > >=20 > > > > > Hmmm, not sure how well this performs: If there is only a small AS > > > > > with > > > > > few IP ranges to parse, ipset would be sufficient. > > > > >=20 > > > > > However, if we have large networks (Level 3, Hurricane Electric, DT= AG, > > > > > ...), > > > > > ipset might become slow and cause many iptables rules. And if we > > > > > update > > > > > the database (whomever created it), we need to reload the firewall > > > > > rules. > > > > > Using a database lookup module similar to GeoIP avoids that issues > > > > > here, > > > > > as > > > > > far as I am concerned. =20 > > > >=20 > > > > I mean it is an option to build an iptables extension, but I am not s= ure > > > > if > > > > that > > > > is the best thing. > > > >=20 > > > > ipset is O(1) for each lookup. So it doesn't matter how large the AS = is. > > > > iptables rules would be O(n) which is not very nice for larger ASNs, = but > > > > we > > > > should have a look since I do not expect ASNs to announce hundreds of > > > > prefixes. > > > > The average might be way less and I have no idea what to expect as the > > > > worst- > > > > case performance. That needs investigation. =20 > > >=20 > > > All right. > > >=20 > > > @Everybody else: Comments? > > >=20 > > > Best regards, > > > Peter M=C3=BCller =20 > > > >=20 > > > > Best, > > > > -Michael > > > > =20 > > > > >=20 > > > > > Best regards, > > > > > Peter M=C3=BCller =20 > > > > > > =20 > > > > > > > Any thoughts on this idea? > > > > > > >=20 > > > > > > > Best regards, > > > > > > > Peter M=C3=BCller =20 > > > > > >=20 > > > > > > -Michael =20 > > > > >=20 > > > > > =20 > > >=20 > > > =20 >=20 > Best regards, > Peter M=C3=BCller --===============3746357525891460936== Content-Type: application/pgp-signature Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="signature.asc" MIME-Version: 1.0 LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCmlRSXpCQUFCQ2dBZEZpRUU1L3JXNWwzR0dl Mnlwa3R4Z0hudy8yK1FDUWNGQWxvbTE1UUFDZ2tRZ0hudy8yK1EKQ1FlQjBSQUFxWi80Smdoam5V QWsrU25lREkxZ1hYRWpwVWZmVDFEVEZIZXAyV2xvT1pVTHNxWlRGSjVNQlQwNApOUHlCUlBXRFV5 Sk55aGVINUFUSzc5WmlYYUhuRVRuV3BlYTJma284NFpxTURtd3V6QTN1blc4SUgydDZaZkFjCmZF NGk3QVU1bDhIaFVaQTUxZEliNSttYzJSS08zb2o4QUVaalhFYUlRT0tVMFhubDZDYnFOVGZnbyts TGJqa1MKVjJkTnZsa1Z3NFRsUVk3VnVHb1ZWcUhEZ3YyVTB1cjIwSWc2ekdnQjlTcFAxWmFEdldR Tm00SVFXeGljWUNmRAo3bERnYUV0MCs3WmpnY2NncEpmOGMwZGJDcmJnSDRzYmwxVE5HSEtQQmNv ZjQwZlh6SFdBVkNNcW9nWXR6RER2Ckdwb2FacC82ZGw5WjRPTEIyRzd5ZVNBMFNSbHFMZWdiSk51 ZlNWcUF3SmcyZTZIRDZrWU90QkVHZGxQZDJGMkMKcUc1VnlzZVU5MUJxdlJhSHNZQU5aQm1RL01U NXUzeDZTREt0a0pXQnJXY3diMktOcDl5aGtKaXMrSDFYWEpmRApMZlJLQy9INWFuSkRmblIvVFFF MmtTS3VYcXJZdU1aM0dsYzk3bDdJN0psV3pkY3d1TlprUkhkM3A3dlhDTzhECmRKYXRNR1JNNHpl SVVjMHUwdzFOU0YzNjIwUTJlZFUyeXgzZWhzaW1wN004cnB2amsvNWU3MFZlMEY4eGlaTzUKRzFj bVVJOS9KbWR2elZkSklxZnpsVi9ydnlWUVE0WHI2WkxiRXNJa2pnTEs2SjZ6ZmFkWTB2RTFmd0hL Yk9xaAo4RWlQTjRteFowL1U2aFVMMExKK1F5OTQvUFFGd1gzcEdlY0pSQTNlUmNBbHBmRTJ0c0U9 Cj1nZ1JaCi0tLS0tRU5EIFBHUCBTSUdOQVRVUkUtLS0tLQo= --===============3746357525891460936==--