+ Responder ao Tópico



  1. #1

    Post Dificuldade em liberar firewall para acessar FTP.

    E ai galera, tudo em cima? o/
    Não sei se já passaram por esse problema, mas... ^^''

    A parada é o seguinte. XD
    Eu estou mantendo um firewall em FreeBSD utilizando o IPFilter e talz e por padrão todas as conexões de saída estão dropadas (negadas).

    Toda vez que desjo liberar uma conexão, eu informo a porta de saída e a interface, por exemplo:

    Se destino for porta 80 saindo pela interface externa (nfe0) permitir em statefull (ida e volta).

    Até ai tudo bem, funciona, mas não consigo de jeito nenhum colocar conexões FTP pra funcionar. Li em alguns sites e fóruns que conexões FTP usam a porta 21 para estabelecer a conexão e 20 em alguns casos para transferir dados. Liberei as portas, mas mesmo assim não estou conseguindo sanar o problema. Existe mais alguma coisa que eu possa fazer?

    Estou listando as regras abaixo:

    ipf.conf (referente as regras de tráfego)
    Código :
    [SIZE=2]# Sem restrições na interface interna para tráfego da rede interna. [Saída][/SIZE]
    [SIZE=2]pass out quick on rl1 all[/SIZE]
    [SIZE=2]# Sem restrições na interface interna para tráfego da rede interna. [Entrada][/SIZE]
    [SIZE=2]pass in quick on rl1 all[/SIZE]
    [SIZE=2]# Sem restrições na Loopback [Entrada][/SIZE]
    [SIZE=2]pass in quick on lo0 all[/SIZE]
    [SIZE=2]# Sem restrições na Loopback [Saída][/SIZE]
    [SIZE=2]pass out quick on lo0 all[/SIZE]
    [SIZE=2]# Se origem for rede externa tentando acessar o DNS, permitir.[/SIZE]
    [SIZE=2]pass in quick proto udp from any to any port = 53 keep state[/SIZE]
    [SIZE=2]# Se destino for sistema de Imposto de Renda na porta 3456, permitir.[/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 3456 keep state[/SIZE]
    [SIZE=2]# Permitir acesso ao DNS externo para resolver nomes. [UDP][/SIZE]
    [SIZE=2]pass out quick proto udp from any to any port = 53 keep state[/SIZE]
    [SIZE=2]# Permitir acesso a sites WWW [Saída][/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 80 flags S keep state[/SIZE]
    [SIZE=2]# Permitir conexão segura https SSL [Saída][/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 443 flags S keep state[/SIZE]
    [SIZE=2]# Permitir receber e enviar mensagens [pop3][/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 110 flags S keep state[/SIZE]
    [SIZE=2]# Permitir receber e enviar mensagens [pop3] GMail[/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 995 keep state[/SIZE]
    [SIZE=2]# Permitir receber e enviar mensagens [smtp][/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 25 flags S keep state[/SIZE]
    [SIZE=2]# Permitir receber e enviar mensagens [smtp] no GMail[/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 587 keep state[/SIZE]
    [SIZE=2]# Permitir saida de tempo.[/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 37 flags S keep state[/SIZE]
    [SIZE=2]# Permitir que a rede interna e o gateway consigam usar FTP[/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 21 flags S keep state[/SIZE]
    [SIZE=2]# Permitir FTP, Telnet e SCP seguro[/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 22 flags S keep state[/SIZE]
    [SIZE=2]# Permitir Telnet não-seguro[/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 23 flags S keep state[/SIZE]
    [SIZE=2]#Permitir função FBSD CVSUP[/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 5999 flags S keep state[/SIZE]
    [SIZE=2]# Permitir pingar para a internet pública[/SIZE]
    [SIZE=2]pass out quick on nfe0 proto icmp from any to any icmp-type 8 keep state[/SIZE]
    [SIZE=2]# Permitir whois da LAN para a internet [/SIZE]
    [SIZE=2]pass out quick on nfe0 proto tcp from any to any port = 43 flags S keep state[/SIZE]
    [SIZE=2]# Bloquear e gravar a primeira ocorrencia de tudo que esta tentando sair. A regra reforça o "negar tudo" por padrão.[/SIZE]
    [SIZE=2]block out log first quick on nfe0 all[/SIZE]
    [SIZE=2]# Barrar RFC 1918 IP Privado[/SIZE]
    [SIZE=2]block in quick on nfe0 from 192.168.0.0/16 to any[/SIZE]
    [SIZE=2]# Barrar RFC 1918 IP Privado[/SIZE]
    [SIZE=2]block in quick on nfe0 from 172.16.0.0/12 to any[/SIZE]
    [SIZE=2]# Barrar RFC 1918 IP Privado[/SIZE]
    [SIZE=2]block in quick on nfe0 from 10.0.0.0/8 to any[/SIZE]
    [SIZE=2]# Barrar loopback[/SIZE]
    [SIZE=2]block in quick on nfe0 from 127.0.0.0/8 to any[/SIZE]
    [SIZE=2]# Barrar loopback[/SIZE]
    [SIZE=2]block in quick on nfe0 from 0.0.0.0/8 to any[/SIZE]
    [SIZE=2]# Configurção automática de DHCP[/SIZE]
    [SIZE=2]block in quick on nfe0 from 169.254.0.0/16 to any[/SIZE]
    [SIZE=2]# Reservado para documentos[/SIZE]
    [SIZE=2]block in quick on nfe0 from 192.0.2.0/24 to any[/SIZE]
    [SIZE=2]# Interconexão de cluster Sun[/SIZE]
    [SIZE=2]block in quick on nfe0 from 204.152.64.0/23 to any[/SIZE]
    [SIZE=2]# Multicast Classe D e E[/SIZE]
    [SIZE=2]block in quick on nfe0 from 224.0.0.0/3 to any[/SIZE]
    [SIZE=2]# Bloquear frags[/SIZE]
    [SIZE=2]block in quick on nfe0 all with frags[/SIZE]
    [SIZE=2]# Bloquear pacotes curtos de TCP[/SIZE]
    [SIZE=2]block in quick on nfe0 proto tcp all with short[/SIZE]
    [SIZE=2]# Bloquear pacotes com fonte roteada[/SIZE]
    [SIZE=2]block in quick on nfe0 all with opt lsrr[/SIZE]
    [SIZE=2]# Bloqueia PING externo.[/SIZE]
    [SIZE=2]block in quick on nfe0 proto icmp all icmp-type 8[/SIZE]
    [SIZE=2]# Bloqueia tentativa de acesso NetBios (por nome)[/SIZE]
    [SIZE=2]block in log first quick on nfe0 proto tcp/udp from any to any port = 137[/SIZE]
    [SIZE=2]# Bloqueia tentativa de acesso NetBios (por datagrama)[/SIZE]
    [SIZE=2]block in log first quick on nfe0 proto tcp/udp from any to any port = 138[/SIZE]
    [SIZE=2]# Permitir acesso a servidor www pela rede internet (Apache)[/SIZE]
    [SIZE=2]pass in quick on nfe0 proto tcp from any to any port = 80 flags S keep state[/SIZE]
    [SIZE=2]# Se origem for firewall com proxy, tentando acessar a DMZ onde se encontra o servidor web, permitir.[/SIZE]
    [SIZE=2]pass out quick from 200.200.200.200 mask 255.255.255.255 to 192.168.255.1 mask 255.255.255.255 port = 80 keep state[/SIZE]
    [SIZE=2]# Se destino for o servidor Web na DMZ, permitir acesso na porta 80.[/SIZE]
    [SIZE=2]pass out quick from any to 192.168.255.1 mask 255.255.255.255 port = 80 keep state[/SIZE]
    [SIZE=2]# Se destino for servidor web na DMZ, sendo a porta 21 (FTP) permitir.[/SIZE]
    [SIZE=2]pass out quick from any to 192.168.255.1 mask 255.255.255.255 port = 21 keep state[/SIZE]
    [SIZE=2]# Se destino for rede da DMZ, barrar tráfego.[/SIZE]
    [SIZE=2]block out quick from any to 192.168.255.0 mask 255.255.255.0 keep state[/SIZE]
    [SIZE=2]# Bloquear qualquer entrada pela rede externa.[/SIZE]
    [SIZE=2]block in log first quick on nfe0 all[/SIZE]

    ipnat.conf (referente as regras de NAT)
    Código :
    [SIZE=2]# Mascaramento da rede interna.[/SIZE]
    [SIZE=2]map nfe0 from any to any -> 0.0.0.0/32[/SIZE]
    [SIZE=2]# Se origem for rede externa tentando acessar a porta 80, jogar na DMZ via porta 80[/SIZE]
    [SIZE=2]rdr nfe0 200.200.200.200/32 port 80 -> 192.168.255.1 port 80[/SIZE]

    Detalhando:
    nfe0 = interface externa, conectada direto a internet.
    rl0 = interface da DMZ.
    rl1 = interface da rede interna.

    Obs.: A regra da porta 20 não está ai em cima mesmo na lista, não esqueci de colocar. :P

    Nota: Quando eu libero a conexão completa pela interface de saída (nfe0) com statefull, funciona normalmente. Por padrão, eu quero fechar a saída por esta interface e abrir apenas o que desejar.
    Última edição por Bit; 02-07-2008 às 10:09.

  2. #2

    Padrão

    Você chega a conseguir estabelecer a conexão ao servidor externo ou nem isso?

    Se consegue conectar, usando ftp passivo, consegue fazer transferência?

    Liberando a porta 20, faz alguma diferença?

  3. #3

    Padrão

    Sim, consigo. Chega a ocorrer uma conexão, ele se autentica e tudo beleza. Quando o software tenta listar o conteúdo do diretório, eu recebo a mensagem: 425 Can't open data connection.

    Mesmo com a porta 20 liberada o problema persiste, seja com FTP passivo ou ativo (o browser por padrão usa o passivo).

    Obrigado pela força. /o

  4. #4

    Padrão Nat...

    As maquinas q sao acessadas ou acessam estao atras de nat? No linux isso acontece qdo nao se carrega o mudulo ip_conntrack_ftp!

  5. #5

    Padrão

    Tirado do handbook do FreeBSD, talvez possa te ajudar:
    Código :
    28.5.21 FTP and NAT
     
      FTP is a dinosaur left over from the time before the Internet as it is known today, when research universities were leased lined together and FTP was used to share files among research Scientists. This was a time when data security was not a consideration. Over the years the FTP protocol became buried into the backbone of the emerging Internet and its username and password being sent in clear text was never changed to address new security concerns. FTP has two flavors, it can run in active mode or passive mode. The difference is in how the data channel is acquired. Passive mode is more secure as the data channel is acquired be the ordinal ftp session requester. For a real good explanation of FTP and the different modes see [URL]http://www.slacksite.com/other/ftp.html[/URL].
       28.5.21.1 IPNAT Rules
     
      IPNAT has a special built in FTP proxy option which can be specified on the NAT map rule. It can monitor all outbound packet traffic for FTP active or passive start session requests and dynamically create temporary filter rules containing only the port number really in use for the data channel. This eliminates the security risk FTP normally exposes the firewall to from having large ranges of high order port numbers open.
      This rule will handle all the traffic for the internal LAN:
      map dc0 10.0.10.0/29 -> 0/32 proxy port 21 ftp/tcp
     This rule handles the FTP traffic from the gateway:
      map dc0 0.0.0.0/0 -> 0/32 proxy port 21 ftp/tcp
     This rule handles all non-FTP traffic from the internal LAN:
      map dc0 10.0.10.0/29 -> 0/32
     The FTP map rule goes before our regular map rule. All packets are tested against the first rule from the top. Matches on interface name, then private LAN source IP address, and then is it a FTP packet. If all that matches then the special FTP proxy creates temp filter rules to let the FTP session packets pass in and out, in addition to also NATing the FTP packets. All LAN packets that are not FTP do not match the first rule and fall through to the third rule and are tested, matching on interface and source IP, then are NATed.
     
       28.5.21.2 IPNAT FTP Filter Rules
     
      Only one filter rule is needed for FTP if the NAT FTP proxy is used.
      Without the FTP Proxy you will need the following three rules:
      # Allow out LAN PC client FTP to public Internet
    # Active and passive modes
    pass out quick on rl0 proto tcp from any to any port = 21 flags S keep state
     
    # Allow out passive mode data channel high order port numbers
    pass out quick on rl0 proto tcp from any to any port > 1024 flags S keep state
     
    # Active mode let data channel in from FTP server
    pass in quick on rl0 proto tcp from any to any port = 20 flags S keep state

  6. #6

    Padrão

    Opa terencerocha tudo em cima? o/
    No caso, quando qualquer máquina da rede interna tenta sair para acessar algum servidor FTP através de NAT, ocorre o problema. No Linux eu já sabia que tinha essa questão do módulo, mas no FreeBSD não sei. Lembrando que quando eu abro todas as conexões de saída na interface externa, funciona normalmente.

    galahad, eu vou fazer um teste aqui, obrigado pela força. o/
    Última edição por Bit; 03-07-2008 às 12:35.

  7. #7

    Padrão

    Opa galera, beleza?
    Só passando pra informar que a dica funcionou, mas... isso me gerou outro problema. ^^''

    Bom, qualquer pessoa consegue acessar o eMule ou outros programas externos. Alguém sabe se tem como permitir apenas o FTP?

    Coloquei a seguinte regra:
    Se destino for interface externa e porta de saída for acima de 1024, permitir.
    pass out quick on nfe0 proto tcp from any to any port > 1024 flags S keep state

  8. #8

    Padrão

    Bit,

    essa regra que você adicionou liberou todas as portas acima de 1024. O problema maior é que eu não tenho nenhum FreeBSD pra fazer o teste pra você. Faz o seguinte, volta a tua regra da forma que estava e faz uma captura de pacotes usando o tcpdump:

    tcpdump -n -vvv -w problema_ftp.pcap -i any host <IP DA MAQUINA QUE VOCE USA PRA TESTE>

    Rodando o tcpdump, abra a conexão ftp e tente executar alguns comandos. Vamos ver o que que está sendo bloqueado.

    Depois posta aqui o arquivo com o dump, ou me manda uma PM que eu te passo meu e-mail, por conta dos ips públicos/senhas.