Redirect/Block outgoing HTTP traffic for a specific URL in Ubuntu

6,576

Good thing, that HTTP and its headers are sent in cleartext! We can search for the URL in the HTTP Header with the -m string filter.

Example

We want to block: http://www.example.com/I/am/some/distinguishable/URL

iptables -A OUTPUT -p tcp -m string --string "/I/am/some/distinguishable/URL" --algo kmp -j REJECT --reject-with tcp-reset

Thanks to Dennis for his tip on --reject-with tcp-reset.

Share:
6,576

Related videos on Youtube

buschtoens
Author by

buschtoens

Updated on September 18, 2022

Comments

  • buschtoens
    buschtoens over 1 year

    On my Ubuntu server I have some custom software running, that connects to its vendor server to search for updates. While this is useful in general, the software is not supposed to update itself for security reasons. I found out that, if there's no internet connection, the software is unable to update, but will still start. But I obviously can't close the connection. The hosts file is not an alternative either, as the software needs to connect to the vendor for license checks.

    So my question is: How can I redirct or block outgoing HTTP traffic for a specific URL.

    tl;dr: http://www.vendor.com/license should be allowed, but http://www.vendor.com/update should be blocked for outgoing traffic.

    • buschtoens
      buschtoens about 11 years
      I know, that I can put up some custom proxy, but I want to be the most efficient as possible and looking for other possibilities. Maybe iptables is what I'm looking for?
    • mnmnc
      mnmnc about 11 years
      nope. Definitely not IPtables unless you want to compile with additional module that perform analysis on a top layer of OSI/ISO. I guess the easiest would be a setting on a router - some security policy. I think Linksys routers have such option. Linksys WAG320n has such option: i.imgur.com/3d6UmEw.jpg
    • mnmnc
      mnmnc about 11 years
      additionally - if the software updates itself I think there might be a config setting that says to do it. Maybe you are able to change the config ?
    • Dennis
      Dennis about 11 years
      Try REJECT instead of DROP.
    • buschtoens
      buschtoens about 11 years
      Doesn't work either... wget says "HTTP request sent, awaiting response..."
    • Dennis
      Dennis about 11 years
      Right, the problem is that you're "rejecting" the connection after it has already been established. Use -j REJECT --reject-with tcp-reset. This will alert the application that the connection has been reset.
    • buschtoens
      buschtoens about 11 years
      You rock! It works. :)
  • Wayne Tun
    Wayne Tun over 4 years
    it also stopped your own access to your own server . He wants to limit outgoing, I guess.