Skip to content

Commit

Permalink
modified tor blocking to use iptables
Browse files Browse the repository at this point in the history
  • Loading branch information
OP committed Jan 31, 2014
1 parent 82a90a9 commit d7731d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
32 changes: 32 additions & 0 deletions block_tor
@@ -0,0 +1,32 @@
#!/bin/bash

IPTABLES_TARGET="DROP"
IPTABLES_CHAINNAME="TOR"

WORKING_DIR="/tmp/"

# get IP address of eth0 network interface
IP_ADDRESS=$(ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}')

if ! iptables -L "$IPTABLES_CHAINNAME" -n >/dev/null 2>&1 ; then #If chain doesn't exist
iptables -N "$IPTABLES_CHAINNAME" >/dev/null 2>&1 #Create it
fi

cd $WORKING_DIR

wget -q -O - "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$IP_ADDRESS&port=80" -U NoSuchBrowser/1.0 > temp_tor_list
wget -q -O - "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$IP_ADDRESS&port=9998" -U NoSuchBrowser/1.0 >> temp_tor_list
sed -i 's|^#.*$||g' temp_tor_list

iptables -F "$IPTABLES_CHAINNAME"

CMD=$(cat temp_tor_list | uniq | sort)

for IP in $CMD; do
let COUNT=COUNT+1
iptables -A "$IPTABLES_CHAINNAME" -s $IP -j $IPTABLES_TARGET
done

iptables -A "$IPTABLES_CHAINNAME" -j RETURN

rm temp_tor*
10 changes: 0 additions & 10 deletions lib/index.js
Expand Up @@ -25,7 +25,6 @@ var path = require('path');

var captcha = require('captcha');
var express = require('express');
var ipfilter = require('ipfilter');
var logfmt = require('logfmt');
var mongoose = require('mongoose');
var socketio = require('socket.io');
Expand Down Expand Up @@ -92,15 +91,6 @@ app.use(express.bodyParser({
keepExtensions: true
}));

/* blocked nodes. this file can include more */
fs.readFile('tor_list.txt', 'utf8', function(err, data) {
if (err) return;

// One IP per line
var tor_list = data.split('\n');
app.use(ipfilter(tor_list));
});

/* logging only during development */
if (port !== 80)
app.use(logfmt.requestLogger());
Expand Down

0 comments on commit d7731d5

Please sign in to comment.