Jan 282012
 

Un server SOCKS è un particolare tipo di proxy che permette di effettuare connessioni TCP dirette (e, dalla versione 5, di veicolare traffico UDP) tra computer su due reti IP differenti nei casi in cui un instradamento diretto (routing) non sia disponibile. È l’abbreviazione di “SOCKetS”.
I punti di forza del protocollo SOCKS sono l’estrema semplicità di implementazione (sia dal lato client che dal lato server) e la completa indipendenza dal protocollo da veicolare attraverso di esso.

Visto che SOCKS (come è stato già detto in precedenza) trasferisce tutti i dati da un client a un server, senza aggiungere informazioni, dal punto di vista di un web-server, un proxy SOCKS è un client. Pertanto l’anonimato di questo tipo di proxy server è davvero sempre assoluto.

In questo articolo vedremo come utilizzare redsocks per ottenere un proxy SOCKS.


Redsocks consente di reindirizzare qualsiasi connessione TCP attraverso un proxy SOCKS o HTTPS utilizzando il vostro firewall, in modo che il reindirizzamento sia a livello di sistema.

Un altro problema correlato è il protocollo DNS su TCP. Redsocks include `dnstc’ che è un server DNS falso e davvero stupido, che restituisce” risposta troncata “ad ogni query tramite UDP. I resolver che sono RFC-compliant ripetono la stessa query tramite TCP, in questo caso – la richiesta può essere reindirizzata come al solito utilizzando la struttura di redsocks.

Perché è così utile? questi sono alcuni esempi di utilizzo:

  • si usa tor e non volete che qualche connessione TCP non lo utilizzi
  • si utilizza DVB ISP e questo ISP fornisce la connettività Internet con qualche demone speciale che può essere chiamato anche “acceleratore Internet” e questo acceleratore agisce come proxy. Globax è esempio di un acceleratore

Linux/iptables, OpenBSD/pf e FreeBSD/ipfw sono supportati. Linux/iptables è ben collaudato, altre implementazioni possono avere bug.

Installazione e configurazione di base

Per Debian/Ubuntu aprire un terminale e dare i seguenti comandi:

sudo apt-get install iptables git-core libevent libevent-dev
git clone http://github.com/darkk/redsocks.git
cd redsocks/
make
echo 'base{log_debug = on; log_info = on; log = "file:/tmp/reddi.log";
       daemon = on; redirector = iptables;}
       redsocks { local_ip = 127.0.0.1; local_port = 31338; ip = 127.0.0.1;
       port = 31337; type = socks5; }' > redsocks.conf
./redsocks -c redsocks.conf

Per Redhat/Centos/Fedora aprite un terminale ed eseguite :

yum install iptables libevent libevent-dev
wget -O redsocks --no-check-certificate https://github.com/darkk/redsocks/zipball/master
unzip redsocks
cd /usr/local/redsocks/darkk-redsocks-8839230  #the number could change in the future.
make
echo 'base{log_debug = on; log_info = on; log = "file:/tmp/reddi.log";
       daemon = on; redirector = iptables;}
       redsocks { local_ip = 127.0.0.1; local_port = 31338; ip = 127.0.0.1;
       port = 31337; type = socks5; }' > redsocks.conf
./redsocks -c redsocks.conf

Questa configurazione di base imposta un proxy socks5 su localhost porta 31337.

Configurazione di Iptables

Ora dobbiamo configurare il nostro firewall locale con le seguenti regole, suggerisco di metterle in un file e poi eseguirlo.

#!/bin/bash
# Create new chain
iptables -t nat -N REDSOCKS
 
# Ignore LANs and some other reserved addresses.
iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN
 
# Anything else should be redirected to port 31338
iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 31338
 
# Any tcp connection made by `linuxaria' should be redirected, put your username here.
iptables -t nat -A OUTPUT -p tcp -m owner --uid-owner linuxaria -j REDSOCKS


Start e Stop di redsocks

Per far partire redsocks e iptables:

/path/tothe/bin/redsocks -c redsocks.conf
/path/tothe/bin/iptables-redsocks.sh

Per fermare redsocks e iptables:

sudo iptables -F
sudo iptables -X 
sudo iptables -Z
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t nat -Z
killall redsocks

Conclusioni

Ora – tutto il traffico in uscita passerà in maniera trasparente attraverso redsocks al nostro proxy socks5 .
E grazie ad iptables non è necessario modificare le configurazioni delle applicazioni!

Popular Posts:

Flattr this!

  7 Responses to “Riderizionare tutto il traffico (TCP) attraverso un Proxy socks5 in Linux”

  1. In the “Installation e basic configuration” section, your blogging software has converted “>” (greater-than) into “& gt ;” (without spaces – ampersand, “g”, “t”, semi-colon).

  2. You just made my life easier friend. Thanks! Now it won’t take long for me to figure everything. It’s all here. Just good.

  3. needed to do one more thing to work
    adduser -m redsocks

  4. i’ve got this when make

    Dans le fichier inclus à partir de parser.c:29:
    utils.h:6:19: erreur: event.h : Aucun fichier ou dossier de ce type
    In file included from parser.c:29:
    utils.h:43: attention : ‘struct evbuffer’ declared inside parameter list
    utils.h:44: erreur: expected declaration specifiers or ‘…’ before ‘evbuffercb’
    utils.h:44: erreur: expected declaration specifiers or ‘…’ before ‘everrorcb’
    make: *** [parser.o] Erreur 1

  5. hi
    thanks for the howto. i have one problem though:
    i cannot make connections from the host that runs the iptables and redsocks. i guess there are some iptables entries missing but i cant figure out which

    when i test with wget i get the following:

    wget -O - http://google.de/
    --2013-12-04 20:35:23-- http://google.de/
    Resolving google.de (google.de)... 173.194.113.159, 173.194.113.151, 173.194.113.152, ...
    Connecting to google.de (google.de)|173.194.113.159|:80... connected.
    HTTP request sent, awaiting response... No data received.
    Retrying.

    --2013-12-04 20:35:24-- (try: 2) http://google.de/
    Connecting to google.de (google.de)|173.194.113.159|:80... connected.
    HTTP request sent, awaiting response... No data received.
    Retrying.
    ...

    and so on

    any ideas?

    thanks
    smoe

    • Hey Guys
      i need to use it on centos …it it possible ?? im not sure if there is a package for that

      2nd thing ….i need help with config such as i redirect to remote socks based on source ip

      can anyone help me ???

      thankx

  6. smoe,

    I have the same errors as yours. Do you get any progress?

Leave a Reply to alex Cancel reply

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=""> <s> <strike> <strong>

(required)

(required)

*