Galera,
Preciso muito de uma ajuda:
Tenho a seguinte situação, tenho um firewall e preciso me conectar a este servidor de fora pelo ssh criando um tunel e startando um terminal server no localhost:3389 e o mesmo utilizar o ts do xinetd para redirecionar para o meu servidor de TS que é um 2008, a conexão ssh e a conexão ao localhost:3389 está funcionando, mas não consigo redirecionar para o meu outro servidor, alguém pode me ajudar, pois ja criei umas 300 regras no iptabes e nenhuma resolveu,
Grato desde já
#!bin/bash
#firewall
### VARIAVEIS GLOBAIS
ipt="/sbin/iptables"
mod="/sbin/modprobe"
### VARIAVEIS DO SISTEMA
LO_IP="127.0.0.1"
LAN_IF="eth1"
LAN_IP="172.16.16.1"
LAN_NET="172.16.16.0/24"
WAN_IF="eth0"
DNS="201.10.1.2"
### PORTAS DE SAIDA
FW_TCPOUT="443,1049,1364,2500,3007,3456,5017,5024,7080,8017"
### HABILITA ROTEAMENTO DE PACOTES
echo 1 > /proc/sys/net/ipv4/ip_forward
### DESABILITA RESPOSTA DE PING DE BROADCAST
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
### DESABILITA TCP SYNCOOKIES
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
## PROTECAO CONTRA IP SPOOFING
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
## IMPEDIR QUE ATAQUES REDIRECIONEM ROTAS
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
## IMPEDIR QUE ATAQUES DETERMINEM O CAMINHO DA ROTA
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
## PROTECAO CONTRA RESPONSES BOGUS
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
### CARREGANDO MODULOS
$mod ip_tables
$mod ip_conntrack
$mod iptable_filter
$mod iptable_mangle
$mod ipt_LOG
$mod ipt_limit
$mod ipt_state
$mod ipt_MASQUERADE
$mod ip_nat_ftp
$mod ip_conntrack_ftp
### APAGANDO AS REGRAS
$ipt -F
$ipt -X
$ipt -t nat -F
$ipt -t nat -X
$ipt -t mangle -F
$ipt -t mangle -X
### SETANDO AS POLITICAS
$ipt -P INPUT DROP
$ipt -P FORWARD DROP
$ipt -P OUTPUT ACCEPT
$ipt -t nat -P OUTPUT ACCEPT
$ipt -t nat -P PREROUTING ACCEPT
$ipt -t nat -P POSTROUTING ACCEPT
$ipt -t mangle -P PREROUTING ACCEPT
$ipt -t mangle -P POSTROUTING ACCEPT
### TABELAS ADICIONAIS
# $ipt -N SYN_FLOOD
# $ipt -N UNCLEAN
# $ipt -N PING_DEATH
$ipt -N PORT_SCANNER
$ipt -N INVALID_SOURCE
$ipt -N INVALID_CONNECTION
#$ipt -N TRANS_PROXY -t nat
$ipt -N SSH
### CONFIGURA AS TABELAS
$ipt -A PORT_SCANNER -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j RETURN
$ipt -A PORT_SCANNER -j LOG --log-prefix "[IPTables PortScan] : " --log-level info
$ipt -A PORT_SCANNER -j DROP
$ipt -A INVALID_SOURCE -j LOG --log-prefix "[IPTables Drop_Source] : " --log-level info
$ipt -A INVALID_SOURCE -j DROP
$ipt -A INVALID_CONNECTION -j LOG --log-prefix "[IPTables Drop_Port] : " --log-level info
$ipt -A INVALID_CONNECTION -j DROP
$ipt -A SSH -j LOG --log-prefix "[IPTables SSH] : " --log-level info
$ipt -A SSH -j DROP
#########################################################################################
#################### TABELA NAT
#########################################################################################
## SQUID3 / PROXY TRANSPARENTE
$ipt -t nat -A PREROUTING -s $LAN_NET -p tcp --dport 80 -j REDIRECT --to-port 3128
## ROTEAMENTO TS MICROS DA REDE
$ipt -t nat -A PREROUTING -i $WAN_IF -p tcp --dport 3310 -j DNAT --to-destination 172.16.16.10:3389 ##
$ipt -t nat -A PREROUTING -i $WAN_IF -p tcp --dport 3311 -j DNAT --to-destination 172.16.16.11:3389 ##
$ipt -t nat -A PREROUTING -i $WAN_IF -p tcp --dport 3312 -j DNAT --to-destination 172.16.16.12:3389 ##
$ipt -t nat -A PREROUTING -i $WAN_IF -p tcp -m tcp --dport 443 -j DNAT --to-destination 172.16.16.1:22 ##
$ipt -t nat -A PREROUTING -i $WAN_IF -p udp -m udp --dport 443 -j DNAT --to-destination 172.16.16.1:22 ##
$ipt -t nat -A PREROUTING -i $WAN_IF -p tcp -m tcp --dport 8443 -j DNAT --to-destination 172.16.16.220:443 ##
$ipt -t nat -A PREROUTING -i $WAN_IF -p udp -m udp --dport 8443 -j DNAT --to-destination 172.16.16.220:443 ##
#$ipt -t nat -A PREROUTING -i $LO_IP -p tcp -m tcp --dport 3389 -j DNAT --to-destination 172.16.16.220
$ipt -t nat -A POSTROUTING -s $LO_IP -p tcp -m tcp --dport 3389 -j SNAT --to 172.16.16.220
## MASCARANDO CONEXAO DO COMPARTILHAMENTO DE INTERNET
$ipt -t nat -F POSTROUTING
$ipt -A POSTROUTING -t nat -s $LAN_NET -o $WAN_IF -j MASQUERADE
#########################################################################################
##################### TABELA OUTPUT
#########################################################################################
## DESTINOS CONFIAVEIS
$ipt -A OUTPUT -d $LAN_NET -j ACCEPT
$ipt -A OUTPUT -d $LO_IP -j ACCEPT
$ipt -A OUTPUT -o $LO_IP -j ACCEPT
$ipt -A OUTPUT -s 172.16.50.0/32 -j ACCEPT
$ipt -A OUTPUT -d 172.16.50.0/32 -j ACCEPT
## ORIGENS / DESTINOS NAO CONFIAVEIS
#$ipt -A OUTPUT -s 10.0.0.0/8 -j DROP
$ipt -A OUTPUT -s 192.168.0.0/16 -j DROP
$ipt -A OUTPUT -s 224.0.0.0/4 -j DROP
$ipt -A OUTPUT -s 240.0.0.0/5 -j DROP
$ipt -A OUTPUT -s 127.0.0.0/8 -j DROP
$ipt -A OUTPUT -s 0.0.0.0/8 -j DROP
$ipt -A OUTPUT -d 255.255.255.255 -j DROP
$ipt -A OUTPUT -d 224.0.0.0/4 -j DROP
#########################################################################################
###################### TABELA INPUT
#########################################################################################
## SSH - LIBERA CONEXOES DA REDE INTERNA
$ipt -A INPUT -s $LAN_NET -p tcp --dport 22 -j ACCEPT
$ipt -A FORWARD -d $LAN_NET -p tcp --dport 22 -j ACCEPT
$ipt -A FORWARD -s $LAN_NET -p tcp --dport 22 -j ACCEPT
$ipt -A OUTPUT -s $LAN_NET -p tcp --dport 22 -j ACCEPT
## SSH - LOGA QUANQUER OUTRA TENTATIVA
$ipt -A INPUT -p tcp --dport 22 -j ACCEPT
$ipt -A FORWARD -p tcp --dport 22 -j ACCEPT
$ipt -A OUTPUT -p tcp --dport 22 -j ACCEPT
## ORIGENS CONFIAVEIS
$ipt -A INPUT -i $LO_IP -j ACCEPT
$ipt -A INPUT -i $LAN_NET -j ACCEPT
$ipt -A INPUT -s 172.16.50.0/32 -j ACCEPT
$ipt -A INPUT -d 172.16.50.0/32 -j ACCEPT
## ORIGENS NAO CONFIAVEIS
#$ipt -A INPUT -s 10.0.0.0/8 -j DROP
$ipt -A INPUT -s 192.168.0.0/16 -j INVALID_SOURCE
$ipt -A INPUT -s 224.0.0.0/4 -j INVALID_SOURCE
$ipt -A INPUT -s 240.0.0.0/4 -j INVALID_SOURCE
$ipt -A INPUT -s 127.0.0.0/8 -j INVALID_SOURCE
$ipt -A INPUT -s 0.0.0.0/8 -j INVALID_SOURCE
$ipt -A INPUT -d 255.255.255.255 -j INVALID_SOURCE
$ipt -A INPUT -d 224.0.0.0/4 -j INVALID_SOURCE
## PORTAS NAO CONFIAVEIS - TROJAN/TRINOO
$ipt -A INPUT -p tcp --dport 1433 -j DROP
$ipt -A INPUT -p tcp --dport 6677 -j DROP
$ipt -A INPUT -p tcp --dport 6711 -j DROP
$ipt -A INPUT -p tcp --dport 6712 -j DROP
$ipt -A INPUT -p tcp --dport 6713 -j DROP
$ipt -A INPUT -p tcp --dport 12345 -j DROP
$ipt -A INPUT -p tcp --dport 12346 -j DROP
$ipt -A INPUT -p tcp --dport 20034 -j DROP
$ipt -A INPUT -p tcp --dport 6000 -j DROP
$ipt -A INPUT -p tcp --dport 666 -j DROP
$ipt -A INPUT -p tcp --dport 4000 -j DROP
$ipt -A INPUT -p tcp --dport 6006 -j DROP
$ipt -A INPUT -p tcp --dport 16660 -j DROP
$ipt -A INPUT -p tcp --dport 27444 -j DROP
$ipt -A INPUT -p tcp --dport 27665 -j DROP
$ipt -A INPUT -p tcp --dport 31335 -j DROP
$ipt -A INPUT -p tcp --dport 34555 -j DROP
$ipt -A INPUT -p tcp --dport 35555 -j DROP
## BLOQUEIA ACESSO EXTERNO AO PROXY
#$ipt -A INPUT -i WAN_IF -m state --state !ESTABLISHED,RELATED -j LOG --log-level 6 --log-prefix "FIREWALL entrada"
#$ipt -A INPUT -i WAN_IF -m state --state !ESTABLISHED,RELATED -j DROP
#$ipt -A INPUT -i WAN_IF -p tcp --dport 3128 -j DROP
## BLOQUEIO TELNET
$ipt -A INPUT -p tcp -i WAN_IF --dport telnet -j DROP
## TRACEROUTES CAINDO
$ipt -A INPUT -p udp --dport 33434:33523 -j DROP
$ipt -A INPUT -p tcp --dport 113 -j REJECT
$ipt -A INPUT -p igmp -j REJECT
$ipt -A INPUT -p tcp --dport 80 -j DROP
#$ipt -A INPUT -p tcp --dport 443 -j REJECT
## PERMITE TRAFEGOS JA ESTABELECIDOS
$ipt -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
## LIBERANDO MENSAGENS ICMP
$ipt -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
$ipt -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT
$ipt -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT
## TERMINAL SERVICE
$ipt -A INPUT -p tcp --dport 443 -j ACCEPT
$ipt -A INPUT -p tcp --dport 3310 -j ACCEPT
$ipt -A INPUT -p tcp --dport 3311 -j ACCEPT
$ipt -A INPUT -p tcp --dport 3312 -j ACCEPT
## COMPUTADORES LIBERADOS E SEM PROXY
#for i in $(cat /etc/fw_net_free)
#do
#$ipt -A INPUT -i $WAN_IF -s $i -p tcp --sport 0:65535 --dport 0:65535 -j ACCEPT
#$ipt -A INPUT -i $WAN_IF -s $i -p udp --sport 0:65535 --dport 0:65535 -j ACCEPT
#done
## SERVIDOR WEB
$ipt -A INPUT -i $WAN_IF -p tcp --dport 80 -j ACCEPT
$ipt -A INPUT -i $LAN_IF -p tcp --dport 80 -j ACCEPT
## DNS
$ipt -A INPUT -p tcp --dport 53 -j ACCEPT
$ipt -A INPUT -p udp --dport 53 -j ACCEPT
$ipt -A INPUT -p tcp --dport 953 -j ACCEPT
$ipt -A INPUT -p udp --dport 953 -j ACCEPT
$ipt -A INPUT -p tcp --dport 80 -s $LAN_NET -j ACCEPT
$ipt -A INPUT -p tcp --dport 22 -s $LAN_NET -j ACCEPT
$ipt -A INPUT -p tcp --dport 3128 -s $LAN_NET -j ACCEPT
$ipt -A INPUT -p tcp --destination-port 80 -j ACCEPT
$ipt -A INPUT -p tcp --destination-port 22 -j ACCEPT
$ipt -A INPUT -p tcp --destination-port 443 -j ACCEPT
$ipt -A INPUT -p tcp --dport 110 -s $LAN_NET -j ACCEPT
$ipt -A INPUT -p tcp --dport 25 -s $LAN_NET -j ACCEPT
$ipt -A INPUT -p tcp --dport 143 -s $LAN_NET -j ACCEPT
$ipt -A INPUT -p tcp --dport 587 -s $LAN_NET -j ACCEPT
$ipt -A INPUT -p tcp --dport 465 -s $LAN_NET -j ACCEPT
#############################################################################################
######################### TABELA FORWARD
#############################################################################################
$ipt -A FORWARD -i $WAN_IF -j ACCEPT
## PORTA 3128 ACEITA PELA REDE INTERNA
$ipt -A FORWARD -i $LAN_NET -p tcp --dport 3128 -j ACCEPT
## PERMITE TRAFEGO JA ESTABELECIDO
$ipt -A FORWARD -i $WAN_IF -o $LAN_IF -m state --state RELATED,ESTABLISHED -j ACCEPT
$ipt -A FORWARD -i $LAN_IF -o $WAN_IF -m state --state RELATED,ESTABLISHED -j ACCEPT
## BLOQUEIA ORKUT
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d 64.233.171.0/24 -p tcp --dport 443 -j DROP
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d 72.14.209.0/24 -p tcp --dport 443 -j DROP
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d 216.239.51.0/24 -p tcp --dport 443 -j DROP
#$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d orkut.com.br -j DROP
## LIBERA CONEXOES HTTPS
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -p tcp --dport 443 -j ACCEPT
## LIBERA MSN
#for i in $(cat /etc/fw_msn_free)
#do
#$ipt -A FORWARD -i $LAN_IF -s $i -p tcp --dport 1863 -j ACCEPT
#done
## BLOQUEIA MSN
#$ipt -A FORWARD -s $LAN_NET -p tcp --dport 1863 -j REJECT
#$ipt -A FORWARD -s $LAN_NET -p tcp --dport 1864 -j REJECT
#$ipt -A FORWARD -s $LAN_NET -d loginnet.passport.com -j REJECT
#$ipt -A FORWARD -s $LAN_NET -d login.live.com -j REJECT
## PERMITE TRAFEGO DEFINIDO
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d 0/0 -p tcp -m multiport --dport $FW_TCPOUT -j ACCEPT
## PERMITIR PING PARTINDO DA REDE LOCAL
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d 0/0 -p icmp -j ACCEPT
## PERMITIR FTP
$ipt -A FORWARD -i $LAN_IF -p tcp --dport 21 -j ACCEPT
$ipt -A FORWARD -i $LAN_IF -p tcp --dport 20 -j ACCEPT
## TERMINAL SERVER
$ipt -A FORWARD -p tcp --dport 443 -j ACCEPT
$ipt -A FORWARD -i $WAN_IF -p tcp --dport 3310 -j ACCEPT
$ipt -A FORWARD -i $WAN_IF -p tcp --dport 3311 -j ACCEPT
$ipt -A FORWARD -i $WAN_IF -p tcp --dport 3312 -j ACCEPT
#$ipt -A FORWARD -s 0/0 -p tcp --dport 3389 -d 0/0 -j ACCEPT
$ipt -A FORWARD -s $LO_IP -j ACCEPT
$ipt -A FORWARD -d $LAN_NET -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
$ipt -A FORWARD -d $LAN_NET -p udp -m state --state RELATED,ESTABLISHED -j ACCEPT
## PERMITIR CLIENTES POP
$ipt -A FORWARD -p tcp -s $LAN_NET -d $DNS --dport 53 -j ACCEPT
$ipt -A FORWARD -p tcp -s $DNS --sport 53 -d $LAN_NET -j ACCEPT
$ipt -A FORWARD -p udp -s $LAN_NET -d $DNS --dport 53 -j ACCEPT
$ipt -A FORWARD -p udp -s $DNS --sport 53 -d $LAN_NET -j ACCEPT
$ipt -A FORWARD -p tcp -s $LAN_NET --dport 25 -j ACCEPT # SMTP
$ipt -A FORWARD -p tcp -s $LAN_NET --dport 587 -j ACCEPT # SMTP
$ipt -A FORWARD -p tcp -s $LAN_NET --dport 110 -j ACCEPT # POP3
$ipt -A FORWARD -p tcp -s $LAN_NET --dport 143 -j ACCEPT # POP3
$ipt -A FORWARD -p tcp -s $LAN_NET --dport 465 -j ACCEPT # POP3
## LIBERAR OPENVPN
$ipt -A FORWARD -p tcp -s $LAN_NET -d 200.195.175.230 --dport 9443 -j ACCEPT
$ipt -A FORWARD -p tcp -s 200.195.175.230 -d $LAN_NET --dport 9443 -j ACCEPT
## LIBERA COMPLETO
#for i in $(cat /etc/fw_net_free)
#do
#$ipt -A FORWARD -i $WAN_IF -d $i -j ACCEPT
#$ipt -A FORWARD -i $LAN_IF -s $i -j ACCEPT
#done
## LOG DO TRAFEGO NAO PERMITIDO
$ipt -A FORWARD -p tcp -j INVALID_CONNECTION