[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: IPtables localhost redirect



2010/7/9 Emanuele Santoro <santoro@autistici.org>:
> Potrebbe essere un workaround un po' brutale, ma secondo me se ci
> giochi un po' riesci a creare un semplice proxy con nc.
>
> Adesso, giocando con il webserver che ho qui sul portatile, sono
> arrivato a questo comando:
>
>         manu@joker:~$ nc -l -p 5000  > nc 127.0.0.1 80
>
> Che però non funziona completamente perchè la pagina web mi viene
> renderizzata come codice html nel terminale e non dentro
> firefox... comunque l'idea è questa, fanne ciò che preferisci :-)

Grazie Emanuele,
come mi hanno suggerito sul canale freenode.#Netfilter e #debian,
un plausibile workaround consiste nel'eseguire il portforwarding
mediante tunneling come dici tu.

Queste le soluzioni a cui siamo giunti:

# Apre un tunnel ssh, autenticandosi localmente
ssh localhost -L ${local_port}:${remote_host}:${remote_port}

# Apre un tunnel ssh, autenticandosi in remoto
ssh ${user}@${remote_host} -L ${local_port}:localhost:${remote_port}

# Stesso di prima, ma crea una connessione che si chiude automaticamente
# quando termina ${local_command_using_tunnel}
ssh localhost -L ${local_port}:${remote_host}:${remote_port} sleep 10;
${local_command_using_tunnel}

# Oppure, il più semplice e versatile socat
# (netcat soffre di problemi di concorrenza e persistenza)
socat TCP4-LISTEN:${local_port} TCP4:${remote_host}:${remote_port}

Come workaround sono giunto a questo script:

{code}
#!/bin/sh

. "$(dirname $0)/_lib_.sh"

PID=/tmp/socat.pid

case "$1" in
        create)
                [ -f $PID ] && echo "socat already running on port
5432." && exit 1

                options=",fork,reuseaddr"
                [ "$2" = "--one" ] &&  options=""

                log_action_begin "Creating tunnel..."
                socat TCP4-LISTEN:5432${options} TCP4:192.168.1.113:5432 &
                echo $! > $PID
                log_action_end
                exit $?
                ;;
        destroy)
                log_action_begin "Destroing tunnel..."
                set +e
                /sbin/start-stop-daemon --stop --pid $PID 2> /dev/null
                rm $PID
                log_action_end
                exit $?
                ;;
        *)
                usage $0 "help | create [ --one ] | destroy"
                ;;
esac

exit 1
{/code}

Ti terrò aggiornato se escono soluzioni iptables native.

Ciao e grazie.

Daniele


Reply to: