Gentoo Archives: gentoo-user

From: Meino.Cramer@×××.de
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Blocking a domain instead of an IP with ufw
Date: Sat, 01 Aug 2015 12:17:04
Message-Id: 20150801121650.GE4402@solfire
In Reply to: Re: [gentoo-user] Blocking a domain instead of an IP with ufw by Mick
1 Mick <michaelkintzios@×××××.com> [15-08-01 13:20]:
2 > On Saturday 01 Aug 2015 11:35:14 Meino.Cramer@×××.de wrote:
3 > > Mick <michaelkintzios@×××××.com> [15-08-01 12:20]:
4 > > > On Saturday 01 Aug 2015 10:48:15 Alan McKinnon wrote:
5 > > > > On 01/08/2015 11:21, Meino.Cramer@×××.de wrote:
6 > > > > > Hi,
7 > > > > >
8 > > > > > With ufw I want temporary block any access from my Gentoo PC to
9 > > > > > certain domains. Since domain names change IP addresses I dont want
10 > > > > > to block on base of the IP only.
11 > > > > >
12 > > > > > Is this possible with ufw?
13 > > > >
14 > > > > That is really not a good idea, which is why packet filtering firewalls
15 > > > > seldom attempt it.
16 > > > >
17 > > > > It means that *every*single*packet* involves a reverse DNS lookup to
18 > > > > get the (unreliable) DNS name (which might not even be listed at all),
19 > > > > do a string comparison and make a block decision based on that. All of
20 > > > > which is probably an order of magnitude more resource use that simply
21 > > > > sending the packet out. There are optimizations of course, such as
22 > > > > caching the results of previous lookups, but there's still a
23 > > > > considerable overhead.
24 > > > >
25 > > > > There's a few ways around it:
26 > > > >
27 > > > > 1. Rethink your firewalling policy. Maybe you really don't need to
28 > > > > block stuff and just think you do.
29 > > > >
30 > > > > 2. Do a DNS lookup and check the TTL. If it's high, say 86400 then it
31 > > > > cannot change more than once a day. So you only need to do a lookup
32 > > > > once a day. Write or get a script that looks up your banned domains
33 > > > > every so often, gets the new IP if it changed and reload a new
34 > > > > netfilter rule set.
35 > > > >
36 > > > > #2 is the correct approach for large firewalls with many users but does
37 > > > > involves a quite sophisticated codebase, probably way more than you
38 > > > > need for your 1 pc. Which brings us back to #1
39 > > >
40 > > > There's also the option to set in /etc/hosts:
41 > > >
42 > > > 127.0.0.1 safebrowsing.clients.google.com
43 > > >
44 > > > (Replace the google domain above with whatever you want to stop access
45 > > > to).
46 > >
47 > > Hi Mick,
48 > >
49 > > yes this comes close to what I want, but it is not that easy to switch
50 > > on/off.
51 > >
52 > > Background:
53 > > I have a Android tablet which I connected via Wifi to my PC and
54 > > started wireshark before the connection was etablished.
55 > >
56 > > As soon the connection was there, the tablet starts to phone home.
57 > > I want to stop that for the case, when the tablet accesses those
58 > > domains, since in that case an tablet ID or whatever this
59 > > "anonymous identification" is called is transmitted.
60 > >
61 > > Next came iptables into my mind since it is a configuration
62 > > item and not a phyical thing like a file.
63 > >
64 > > Is there a way (for example via something below /proc or /sys) to
65 > > feed the contents of /etc/hosts into the kernel instead of using
66 > > the physical file?
67 > >
68 > > Best regards
69 > > Meino
70 >
71 > If I recall right you are using dnsmasq on the PC you connect the tablet to?
72 >
73 > In this case you can add in dnsmasq.conf:
74 >
75 > address=/some-adnroid-site.com/127.0.0.1
76 >
77 > This will cause any dns queries to this address from the tablet to fail, but
78 > it will NOT block connections to relevant IP addresses. Not sure if this is
79 > any easier than altering /etc/hosts on the tablet.
80 >
81 > --
82 > Regards,
83 > Mick
84
85 Hi Mick,
86
87 I am using create_ap on my PC to build a temporary Access Point for a
88 Wifi connection with my tablet. I think, create_ap uses dnsmasq on the
89 fly...not sure.
90 I will try not to touch any Android system owned files on the tablet
91 until a Custom ROM is made public for this tablet. With this Custom
92 ROMS there is a tool bundled called "TWPR" or "CWM" which makes it
93 easy to replay a so called nandroid backup (an image copy of the whole
94 system internal flash) right after the bootloader is run and the
95 system is still not booted. May sound a little paranoid, but changing
96 things below /etc the wrong way especially on a system I dont
97 understand in full currently has the ability to create "Just another
98 brick in the wall"..."There is a difference in knowing the path and
99 walking the path, Neo"..."Do you think you are booting, Neo? In _this
100 room....?"
101 Ok...back to the topic.
102
103 I added the suspicious accesses to the /etc/hosts on my PC, which
104 I hope has the same effect, since everything is routed to the same
105 DNS.
106
107 What do you think?
108
109 Best regards,
110 Meino