Adblock with bfilter

Bfilter is a proxy server used to block advertisements. It is available under the GPL, cross platform (Windows, Linux, OSX), can be used with any browser, and can be run from a flash drive (think portable). In addition you can import the Adblock Plus (Firefox extension) “blacklist” via a pearl script.

BFilter is a filtering web proxy. It was originally intended for removing banner ads only, but since then its capabilities have been greatly extended. Unlike most of the similar tools, it doesn’t rely on blacklists (although it does support them). The problem with blacklists is that advertisers are always one step ahead. You see an ad slip through, you update your blacklist, and in case it didn’t help, you add a new entry yourself. Once I got tired of that, I decided to write a proxy that would detect ads heuristically, much like modern anti-virus software manages to detect many viruses unknown to it.

Install Bfilter

Bfilter can be run in two ways, as a service (started in /etc/init.d/bfilter) or as a GUI (graphical user interface).

  • Ubuntu – bfilter is in the repositories – install either bfilter (service, no gui) or bfilter-gui (gui) but NOT Both !!!
  • Other distros (Fedora) you will need to either compile bfilter or use the bfilter-gui which is available as an “Autopackage” (See the Bfilter Downloads page). Run the Autopackage on the command line (does not work when launched from a gui).
  • Windows – Obtain it from the Bfilter Downloads page. To run portable, download from here.

Using bfilter

Start bfilter

  • As a service (bfilter) – bfilter starts on boot. You can start or stop it manually with

    # Ubuntu
    sudo /etc/init.d/bfilter start|stop|restart

    # Fedora
    su -c ‘service bfilter start|stop|restart’

  • As a gui -
    1. Windows – run (double click) the bfilter.exe .
    2. Linux – You will find it easier to write a (short) script to autostart bfilter-gui when you log in. Save this script in ~/bin/bfilter-gui :

      #!/bin/bash
      sleep 10
      nohup /usr/bin/bfilter-gui > /dev/null &

      Make it executable:

      chmod a+x ~/bin/bfilter-gui

      Now add to your autolauncher, go to Settings -> Sessions and Startup
      Add an entry:
      name: bfilter-gui
      command: /home/you/bin/bfilter-gui
      Auto start

Configure your browser

One advantage of bfilter, it will work with any browser. The menus will vary with your browser, and on Windows you may need to edit your network configuration.

  1. Friefox –

    • Open your options, navigate to the Advanced tab
    • Select the “network” tab and hit the settings button.
      Firefox Config 1
    • In the dialog box, set your proxy to 127.0.0.1 port 8080
      Firefox Config 2
  2. Windows users –
    • In your control panel, open your “Internet Options” , select the “connections” tab.
      Windows Config 1
    • Hit the “LAN Settings” button and insert your proxy settings 127.0.0.1 port 8080
      Windows Config 2

That is all there is to it, no need to re-boot or re-start your browser.

Power Tweaks

Import the Adblock Plus (Firefox extension) “blacklist”

This is not necessary as bfilter does just fine on it’s own. If you find there are some ads not blocked, you can try to add the Adblock Plus filter list.

See This Link for the original scripts. I modified them (fixed the paths and files, fixed the perl script with dos2unix) and re-posted them below.

Save this first one in /usr/local/bin/adblock2bfilter.pl

And the second one in /usr/local/bin/bfilterUpdateLists.sh

Make them executable :

sudo chmod a+x /usr/local/bin/*

Note: On the origional page there is a link to a windows script, but I used the above scripts on Linux, converted with tofrodos, and saved the urls.local to my flash drive. If you wish here is a link to a urls.local you may use on Windows (Note: the list in that link is unmaintained).

To use the script simply:

sudo /usr/local/bin/bfilterUpdateLists.sh

This will update your list in /etc/bfilter/urls.local
To use the list with the service, simply restart bfilter.
To use the list with bfilter-gui, copy

sudo cp /etc/bfilter/urls.local /home/your_user/.bfilter/urls.local
sudo chown you:you /home/your_user/.bfilter/urls.local

Then quit and restart the bfilter-gui

Use a cache for bfilter

  • bfilter-gui uses a cache automatically.
    • Linux it is located in ~/.bfilter/cache .
    • Windows it is in Program Files\BFilter\Cache
  • If you are using bfilter as a service you will need to make a (small) edit to /etc/init.d/bfilter. Using any editor, add “-C /tmp/bfilter” to /etc/init.d/bfilter on the “DAEMON_OPTS” line. It looks like this:

    # All one line:
    DAEMON_OPTS=”-u nobody -g nogroup -p /var/run/bfilter.pid -C /tmp/bfilter $DAEMON_OPTS”

Use bfilter as a proxy server on your LAN

This is easy to do if you are running bfilter as a service.

Using any editor, open /etc/bfilter/config

Under the [global] section, at the top of the page, edit the “listen_address” line, use your ip address rather then 127.0.0.1

listen_address = 192.168.0.10:8080

You may wish to change the default port and firewall the connection.

Additional options are explained in the configuration file.

The advantage of running bfilter this way is that you then only need to maintain one set of config files for all clients on your LAN.

Assuming your LAN is 192.168.0.0/24 any your bfilter server is 192.168.0.10 , you can firewall the connection with ufw

sudo ufw enable
sudo ufw default deny
sudo ufw allow from 192.168.0.0/24 to 192.168.0.10 port 8080

This entry was posted in Linux and tagged . Bookmark the permalink.

6 Responses to Adblock with bfilter

  1. jdong says:

    Haha ok now all you need is an AppArmor profile for the daemon and the fetcher scripts ;-)

    But I’m serious! This is a good candidate for confinement.

  2. Chascon says:

    The following command is not necessary.
    sudo chown you:you /home/your_user/.bfilter/urls.local

    Because if you copy the urls.local as a regular user, you’ll get a copy under the ownership of the user that issues the cp
    cp /etc/bfilter/urls.local /home/your_user/.bfilter/urls.local

    You can then write the cp and also add in kill and invoke bfilter-gui commands into one script.

    Thanks for your scripts.

  3. bodhi.zazen says:

    No, but it is necessary if you are setting up multiple users (which is why I included the information).

  4. remus says:

    sadly this project seems to be down

    cant install it with ubuntu lucid, not in repo and debian packages failed to install due to conflicts with libboost-program, even launchpad branch is outdated

  5. bodhi.zazen says:

    remus: Sad but true, bfilter was removed from the Ubuntu (Lucid) repository.

    The bfilter home page is here :

    http://bfilter.sourceforge.net/

    Use the “autopackage”

    http://prdownloads.sourceforge.net/bfilter/bfilter-gui-1.1.4.x86.package?download

    The autopackage is gui only.

    wget http://prdownloads.sourceforge.net/bfilter/bfilter-gui-1.1.4.x86.package?download

    chmod a+x bfilter-gui-1.1.4.x86.package
    sudo ./bfilter-gui-1.1.4.x86.package

    Answer Y to downloading and installing.

    Your other option would be to convert to an alternate proxy, I suggest you consider Privoxy.

    Privoxy is in the Ubuntu repos and includes adblocking.

Add Comment Register



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>