Linux Redes

  • Upload
    nicolas

  • View
    256

  • Download
    0

Embed Size (px)

Citation preview

  • 8/3/2019 Linux Redes

    1/78

    Portantier Information Security Introducci

    n a GNU/Linux

    Redes TCP/IP con GNU/Linux2011-08-20 (v1.0)

  • 8/3/2019 Linux Redes

    2/78

    Portantier Information Security Introducci

    n a GNU/Linux

    Fabian Portantier

    Consultor en Seguridad Informtica

    Fantico de GNU/Linux (Debian)

    Mail: [email protected]

    Web: www.portantier.com

    mailto:[email protected]://www.portantier.com/http://www.portantier.com/mailto:[email protected]
  • 8/3/2019 Linux Redes

    3/78

    Portantier Information Security Introducci

    n a GNU/Linux

    TCP/IP

    Familia de protocolos de internet

    Los dos ms importantes son TCP e IP

    M

    s de 100 protocolos diferentes Desarrollado en 1972 por el US DOD

    Actualmente se utiliza la versin 4 (IPv4)

    Suele ser descrito en base al modelo OSI

  • 8/3/2019 Linux Redes

    4/78

    Portantier Information Security Introducci

    n a GNU/Linux

    Modelo OSI

    Creado en 1984

    Dividido en siete capas

    http://web.frm.utn.edu.ar/comunicaciones/modelo_osi.html

    http://web.frm.utn.edu.ar/comunicaciones/modelo_osi.htmlhttp://web.frm.utn.edu.ar/comunicaciones/modelo_osi.html
  • 8/3/2019 Linux Redes

    5/78

    Portantier Information Security Introduccin a GNU/Linux

    Modelo OSI

    APLICACIN

    PRESENTACIN

    SESIN

    TRANSPORTE

    RED

    ENLACE DE DATOS

    FSICA

  • 8/3/2019 Linux Redes

    6/78

    Portantier Information Security Introduccin a GNU/Linux

    Capa 1: Fsica

    Define el medio (cable, aire, fibra ptica, etc)

    Define las caractersticas de los materiales

    Transmite el flujo de bits a travs del medio

    Maneja las seales elctricas

  • 8/3/2019 Linux Redes

    7/78

    Portantier Information Security Introduccin a GNU/Linux

    Capa 2: Enlace de Datos

    Direccionamiento fsico (MAC Address)

    Topologa de la red (Estrella, Bus, Mesh, etc)

    Acceso al medio y deteccin de errores

    Transforma las seales en datos (tramas)

    Ethernet, ISDN, PPP, DSL, FDDI

  • 8/3/2019 Linux Redes

    8/78

    Portantier Information Security Introduccin a GNU/Linux

    Capa 3: Red

    Protocolos enrutables (IP, ICMP, IPX, Appletalk)

    Protocolos de enrutamiento (RIP, OSPF, BGP)

    Que los datos lleguen del origen al destino

    Trabaja con paquetes

  • 8/3/2019 Linux Redes

    9/78

    Portantier Information Security Introduccin a GNU/Linux

    Capa 4: Transporte

    Transporte de un dispositivo a otro

    TCP (orientado a conexin)

    UDP (no-orientado a conexin)

    Sockets (IP:PUERTO | 192.168.0.100:80)

  • 8/3/2019 Linux Redes

    10/78

    Portantier Information Security Introduccin a GNU/Linux

    Capa 5: Sesin

    Sesiones entre dos extremos

    Puede ser prescindible

    Control de dilogo (Half-Duplex, Full-Duplex)

  • 8/3/2019 Linux Redes

    11/78

    Portantier Information Security Introduccin a GNU/Linux

    Capa 6: Presentacin

    Formateo de datos (ASCII, UTF-8, etc)

    Cifrado de datos

    Compresin de datos

  • 8/3/2019 Linux Redes

    12/78

    Portantier Information Security Introduccin a GNU/Linux

    Capa 7: Aplicacin

    Define protocolos a utilizar por aplicaciones

    Suele ser utilizado por las aplicaciones

    HTTP, FTP, IMAP, SMTP, SSH, etc

  • 8/3/2019 Linux Redes

    13/78

    Portantier Information Security Introduccin a GNU/Linux

  • 8/3/2019 Linux Redes

    14/78

    Portantier Information Security Introduccin a GNU/Linux

    Puertos TCP y UDP

    Asocian puertos con aplicaciones

    Tanto para salida como para entrada

    Ej: Apache HTTPD TCP/80

  • 8/3/2019 Linux Redes

    15/78

    Portantier Information Security Introduccin a GNU/Linux

    Direcciones IP

    Un nmero binario de 32bits

    Permite 4.294.967.296 direcciones (232)

    Expresables en 4 grupos de 0 a 254

    Ejemplo: 192.168.0.100

  • 8/3/2019 Linux Redes

    16/78

    Portantier Information Security Introduccin a GNU/Linux

    Direcciones IP - Clases

    Clase A: 0.0.0.0 127.255.255.255

    Clase B: 128.0.0.0 191.255.255.255

    Clase C: 192.0.0.0 223.255.255.255 Clase D: 224.0.0.0 239.255.255.255

    Clase E: 240.0.0.0 255.255.255.255

  • 8/3/2019 Linux Redes

    17/78

    Portantier Information Security Introduccin a GNU/Linux

    Direcciones IP Privadas

    Clase A:

    10.0.0.0 a 10.255.255.255

    (8 bits red, 24 bits hosts)

    Clase B:172.16.0.0 a 172.31.255.255

    (16 bits red, 16 bits hosts)

    Clase C:192.168.0.0 a 192.168.255.255

    (24 bits red, 8 bits hosts)

  • 8/3/2019 Linux Redes

    18/78

    Portantier Information Security Introduccin a GNU/Linux

    Mscara de Subred

    Permiten dividir las direcciones en red/host

    Para organizar las redes

    Se crean en base a los bits

    Se le restan a las direcciones

  • 8/3/2019 Linux Redes

    19/78

    Portantier Information Security Introduccin a GNU/Linux

    Mscara de subred (ejemplos)

    IP: 192.168.000.001

    Mscara: 255.255.255.000

    ----red-----host-

    IP: 192.168.000.001

    Mscara: 255.255.000.000

    --red----host--

  • 8/3/2019 Linux Redes

    20/78

    Portantier Information Security Introduccin a GNU/Linux

    Rutas

    Definen las puertas de enlace a las redes

    Podemos tener varias rutas

    Siempre existe una por default

    Pueden ser estticas o dinmicas

  • 8/3/2019 Linux Redes

    21/78

    Portantier Information Security Introduccin a GNU/Linux

    Rutas estticas

    Se definen con el comando 'route':

    route add default gw 192.168.0.1

    route del default

    route add -net 10.0.0.0 netmask 255.0.0.0 dev

    eth0

    route del -net 10.0.0.0 netmask 255.0.0.0

  • 8/3/2019 Linux Redes

    22/78

    Portantier Information Security Introduccin a GNU/Linux

    Switches

    Operan en la capa de enlace (Capa 2)

    Interconectan dispositivos en una misma red

    Se basan en las direcciones MAC

    Pueden ser gestionables o no

  • 8/3/2019 Linux Redes

    23/78

    Portantier Information Security Introduccin a GNU/Linux

    Routers

    Operan en la capa de red (Capa 3)

    Interconectan diferentes redes

    Pueden elegir la mejor ruta hacia un dispositivo

  • 8/3/2019 Linux Redes

    24/78

    Portantier Information Security Introduccin a GNU/Linux

    ifconfig

    Nos permite ver / configurar interfaces de red

    Ejemplos:ifconfig

    ifconfig eth0 10.0.0.1 netmask 255.0.0.0

    ifconfig eth0 upifconfig eth0 down

  • 8/3/2019 Linux Redes

    25/78

    Portantier Information Security Introduccin a GNU/Linux

    ping

    Consulta si un dispositivo de red responde

    (Utiliza ICMP Echo Request)

    Ejemplo:

    ping www.google.com.ar

    http://www.google.com.ar/http://www.google.com.ar/
  • 8/3/2019 Linux Redes

    26/78

    Portantier Information Security Introduccin a GNU/Linux

    ping

    Opciones comunes:

    c Cantidad de paquetes a enviar

    i Intervalo de tiempo entre cada paquete

    s Define el tamao de los paquetes a enviar

    t Define el valor del campo TimeToLive (ttl)

  • 8/3/2019 Linux Redes

    27/78

    Portantier Information Security Introduccin a GNU/Linux

    traceroute

    Permite seguir el camino hacia un dispositivo

    Ejemplo:

    traceroute www.google.com.ar

    http://www.google.com.ar/http://www.google.com.ar/
  • 8/3/2019 Linux Redes

    28/78

    Portantier Information Security Introduccin a GNU/Linux

    /etc/protocols

    Define los protocolos y sus nmeros asignados

  • 8/3/2019 Linux Redes

    29/78

    Portantier Information Security Introduccin a GNU/Linux

    Puertos bien conocidos

    Puertos TCP y UDP asignados a aplicaciones

    Definidos por el IANA

    http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_p

    http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbershttp://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
  • 8/3/2019 Linux Redes

    30/78

    Portantier Information Security Introduccin a GNU/Linux

    /etc/services

    Definiciones de puertos y aplicaciones conocidos

  • 8/3/2019 Linux Redes

    31/78

    Portantier Information Security Introduccin a GNU/Linux

    telnet

    Permite conectarnos a puertos TCP

    Ejemplos:

    telnet www.google.com.ar 80

    telnet smtp.gmail.com 25

    http://www.google.com.ar/http://www.google.com.ar/
  • 8/3/2019 Linux Redes

    32/78

    Portantier Information Security Introduccin a GNU/Linux

    Configuraciones de Red

  • 8/3/2019 Linux Redes

    33/78

    Portantier Information Security Introduccin a GNU/Linux

    ifconfig

    ifconfig(Muestra las interfaces activas)

    ifconfig -a

    (Muestra todas las interfaces)

    ifconfig eth0 10.0.0.1 netmask 255.255.255.0

    (Define la direcci

    n 10.0.0.1/24)

    ifconfig eth0 down

    (Deshabilita la interfaz)

  • 8/3/2019 Linux Redes

    34/78

    Portantier Information Security Introduccin a GNU/Linux

    /etc/network/interfacesConfiguracin de las interfaces (Debian)

    auto lo eth0 eth1

    iface eth0 inet

    address 192.168.14.10netmask 255.255.0.0

    gateway 192.168.1.1

    up route add default gw 192.168.2.1down route del default gw 192.168.2.1

    iface eth1 inet dhcp

  • 8/3/2019 Linux Redes

    35/78

    Portantier Information Security Introduccin a GNU/Linux

    ifup / ifdown

    Subir / Bajar interfaces (/etc/network/interfaces)

    ifup -a, ifdown -a

    (Subir / Bajar todas las interfaces)

    ifup IF, ifdown IF

    (Subir / Bajar una interfaz)

    Ejemplo:

    ifup eth0

  • 8/3/2019 Linux Redes

    36/78

    Portantier Information Security Introduccin a GNU/Linux

    /etc/hostname

    Configura el nombre de host

    Es utilizado por /etc/init.d/hostname.sh

    Para cambios no-permanentes podemos usar:

    hostname o /proc/sys/kernel/hostname

  • 8/3/2019 Linux Redes

    37/78

    Portantier Information Security Introduccin a GNU/Linux

    /etc/resolv.conf

    Lista los servidores de nombres (DNS) a utilizar

    nameserver 192.168.0.1

    nameserver 192.168.0.2

    Si utilizamos DHCP se actualiza automticamente

  • 8/3/2019 Linux Redes

    38/78

    Portantier Information Security Introduccin a GNU/Linux

    netstat

    Muestra conexiones y puertos en escucha

    netstat -lnpt

    (puertos TCP en escucha)

    netstat -s

    (estadsticas de conexin)

    netstat -c

    (actualiza la info cada 2 segundos)

  • 8/3/2019 Linux Redes

    39/78

    Portantier Information Security Introduccin a GNU/Linux

    Resoluci

    n de Nombres (DNS)

    J d N b

  • 8/3/2019 Linux Redes

    40/78

    Portantier Information Security Introduccin a GNU/Linux

    Jerarqua de Nombres

    Ti d R i t DNS

  • 8/3/2019 Linux Redes

    41/78

    Portantier Information Security Introduccin a GNU/Linux

    Tipos de Registros DNS

    A Mapea nombres a direcciones IPv4

    AAAA Mapea nombres a direcciones IPv6CNAME Alias de un nombre a otro

    MX Servidores de correo del dominio

    NS Servidores de nombre del dominio

    SOA Informacin de la zona DNS

    di

  • 8/3/2019 Linux Redes

    42/78

    Portantier Information Security Introduccin a GNU/Linux

    dig

    Permite consultar los registros DNS

    di

  • 8/3/2019 Linux Redes

    43/78

    Portantier Information Security Introduccin a GNU/Linux

    dig

    $ dig +short portantier.com NSns13.zoneedit.com.

    ns8.zoneedit.com.

    di

  • 8/3/2019 Linux Redes

    44/78

    Portantier Information Security Introduccin a GNU/Linux

    dig

    $ dig +short portantier.com MX

    5 ALT1.ASPMX.L.GOOGLE.com.

    10 ALT2.ASPMX.L.GOOGLE.com.

    0 ASPMX.L.GOOGLE.com.

    15 ASPMX2.GOOGLEMAIL.com.

    20 ASPMX3.GOOGLEMAIL.com.

    dig

  • 8/3/2019 Linux Redes

    45/78

    Portantier Information Security Introduccin a GNU/Linux

    dig

    $ dig +short portantier.com A

    174.122.105.94

    $ dig +short portantier.com SOA

    ns8.zoneedit.com. soacontact.zoneedit.com.

    2011323541 2400 360 1209600 300

    host

  • 8/3/2019 Linux Redes

    46/78

    Portantier Information Security Introduccin a GNU/Linux

    host

    $ host www.portantier.com

    www.portantier.com has address 174.122.105.94

    nslookup

  • 8/3/2019 Linux Redes

    47/78

    Portantier Information Security Introduccin a GNU/Linux

    nslookup

    $ nslookup www.portantier.com

    Server: 192.168.0.1

    Address: 192.168.0.1#53

    Non-authoritative answer:

    Name: www.portantier.com

    Address: 174.122.105.94

    tcpdump

  • 8/3/2019 Linux Redes

    48/78

    Portantier Information Security Introduccin a GNU/Linux

    tcpdump

    Permite capturar paquetes de red

    tcpdump

  • 8/3/2019 Linux Redes

    49/78

    Portantier Information Security Introduccin a GNU/Linux

    tcpdump

    # tcpdump -i eth0

    (Escucha paquetes en la interfaz eth0)

    # tcpdump -i eth0 -A

    (Mostrar el contenido de los paquetes en ASCII)

    # tcpdump -i eth0 tcp port 80

    (Capturar los paquetes TCP puerto 80)

    # tcpdump -i eth0 host 192.168.0.10

    (Capturar los paquetes de la ip 192.168.0.10)

    nmap

  • 8/3/2019 Linux Redes

    50/78

    Portantier Information Security Introduccin a GNU/Linux

    nmap

    Escanea puertos

    Puede reconocer sistemas operativos

    Puede reconocer versiones de software

    nmap

  • 8/3/2019 Linux Redes

    51/78

    Portantier Information Security Introduccin a GNU/Linux

    nmaproot@debian:~# nmap 127.0.0.1

    Starting Nmap 5.00Interesting ports on localhost(127.0.0.1):

    PORT STATE SERVICE22/tcp open ssh53/tcp open domain80/tcp open http143/tcp open imap3306/tcp open mysql

    nmap

  • 8/3/2019 Linux Redes

    52/78

    Portantier Information Security Introduccin a GNU/Linux

    nmap

    nmap -p T:80,U:53 127.0.0.1

    (Escanear puertos TCP/80 y UDP/53)

    nmap -sV 127.0.0.1

    (Reconocer versiones de software)

    nmap -O 127.0.0.1(Reconocer versin del sistema operativo)

    Nombres de Dominio

  • 8/3/2019 Linux Redes

    53/78

    Portantier Information Security Introduccin a GNU/Linux

    Nombres de Dominio

    Asignados a una direccin IP

    Requieren una direccin IP fija (paga)

    Necesarios para dar servicios (web, mail, etc)

    DNS Dinmicos

  • 8/3/2019 Linux Redes

    54/78

    Portantier Information Security Introduccin a GNU/Linux

    DNS Dinmicos

    Se actualizan a pedido del cliente

    Permiten dar servicios con IP dinmica

    Requieren clientes de actualizacin

    DNS Dinmicos (proveedores)

  • 8/3/2019 Linux Redes

    55/78

    Portantier Information Security Introduccin a GNU/Linux

    DNS Dinmicos (proveedores)

    http://dyn.com

    http://www.no-ip.com

    http://www.zoneedit.com

    Muchos otros

    http://dyn.com/http://www.no-ip.com/http://www.zoneedit.com/http://www.zoneedit.com/http://www.no-ip.com/http://dyn.com/
  • 8/3/2019 Linux Redes

    56/78

    Portantier Information Security Introduccin a GNU/Linux

    apt-cache search dyndns

    Protocolos de Enrutamiento

  • 8/3/2019 Linux Redes

    57/78

    Portantier Information Security Introduccin a GNU/Linux

    Protocolos de Enrutamiento

    Permiten definir rutas para los paquetes IP

    Evitan el enrutamiento esttico

    Se actualizan automticamente

    Eligen la mejor ruta disponible

    Sistemas Autnomos (AS)

  • 8/3/2019 Linux Redes

    58/78

    Portantier Information Security Introduccin a GNU/Linux

    Sistemas Autnomos (AS)

    Autonomous Systems

    Redes IP administradas por una misma entidad

    Se les asigna un nmero de AS

    Comunmente utilizados por los ISP

    www.team-cymru.org/Services/ip-to-asn.html

    Sistemas Autnomos (AS)

    http://www.team-cymru.org/Services/ip-to-asn.htmlhttp://www.team-cymru.org/Services/ip-to-asn.html
  • 8/3/2019 Linux Redes

    59/78

    Portantier Information Security Introduccin a GNU/Linux

    Sistemas Autnomos (AS)

    Utilizar el servicio de consulta de cymru:

    whois -h whois.cymru.com " -v 74.125.159.147"

    whois -h whois.cymru.com " -v AS15169"

    Enrutamiento Interior

  • 8/3/2019 Linux Redes

    60/78

    Portantier Information Security Introduccin a GNU/Linux

    Enrutamiento Interior

    (Dentro de un mismo AS)

    IGRP (Interior Gateway Routing Protocol)

    EIGRP (Enhanced IGRP)

    OSPF (Open Shortest Path First)

    RIP (Routing Information Protocol)

    IS-IS (Intermediate System to Intermediate

    System)

    Enrutamiento Exterior

  • 8/3/2019 Linux Redes

    61/78

    Portantier Information Security Introduccin a GNU/Linux

    uta e to te o

    (Entre distintos AS)

    BGP v4 (Border Gateway Protocol)

    Netcat

  • 8/3/2019 Linux Redes

    62/78

    Portantier Information Security Introduccin a GNU/Linux

    Permite realizar varias funciones de red

    Conectarnos a un puerto

    Poner un puerto en escucha

    Y muchas funciones ms.

    http://es.wikipedia.org/wiki/Netcat

    Netcat (mini chat)

    http://es.wikipedia.org/wiki/Netcathttp://es.wikipedia.org/wiki/Netcat
  • 8/3/2019 Linux Redes

    63/78

    Portantier Information Security Introduccin a GNU/Linux

    ( )

    Servidor

    netcat -l -p 2000

    Cliente

    netcat ip-del-servidor 2000

    Netcat (copia de archivos remota)

  • 8/3/2019 Linux Redes

    64/78

    Portantier Information Security Introduccin a GNU/Linux

    ( p )

    Receptor

    netcat -l -p 2000 > archivo.recibido

    Emisor

    netcat ip-del-receptor 2000 < archivo

    lsof

  • 8/3/2019 Linux Redes

    65/78

    Portantier Information Security Introduccin a GNU/Linux

    Lista los archivos abiertos

    lsof -i -n -P

    Samba

  • 8/3/2019 Linux Redes

    66/78

    Portantier Information Security Introduccin a GNU/Linux

    Permite compartir archivos y carpetas

    Protocolo CIFS (Windows Shares)

    Multiplataforma (Windows, Linux, Mac)

  • 8/3/2019 Linux Redes

    67/78

    Portantier Information Security Introduccin a GNU/Linux

    apt-get install samba

    /etc/samba/smb.conf

  • 8/3/2019 Linux Redes

    68/78

    Portantier Information Security Introduccin a GNU/Linux

    [global]workgroup = midominio

    server string = %h server

    security = share

    [shared]

    path = /home/fabian/shared

    browseable = yesread only = yes

    guest ok = yes

    Administracin grfica

  • 8/3/2019 Linux Redes

    69/78

    Portantier Information Security Introduccin a GNU/Linux

    apt-get install gadmin-samba

    webmin

  • 8/3/2019 Linux Redes

    70/78

    Portantier Information Security Introduccin a GNU/Linux

    Permite administrar linux a travs de la web

    Permite conexiones seguras (HTTPS)

    Cuenta con una alta cantidad de mdulos

    Altamente probado

    www.webmin.com

    http://www.webmin.com/http://www.webmin.com/
  • 8/3/2019 Linux Redes

    71/78

    Portantier Information Security Introduccin a GNU/Linux

    NAT

    Network Address Translation

  • 8/3/2019 Linux Redes

    72/78

    Portantier Information Security Introduccin a GNU/Linux

    Habilitar enrutamiento

  • 8/3/2019 Linux Redes

    73/78

    Portantier Information Security Introduccin a GNU/Linux

    echo 1 > /proc/sys/net/ipv4/ip_forward

    Source NAT Esttico

  • 8/3/2019 Linux Redes

    74/78

    Portantier Information Security Introduccin a GNU/Linux

    iptables -t nat -A POSTROUTING -s

    192.168.3.0/24 -o eth0 -j SNAT --to 80.58.1.14

    -A POSTROUTING: Aade a POSTROUTING

    -s 192.168.3.0/24: Direccin origen

    -o eth0: Interfaz de salida

    -j SNAT --to 80.58.1.14: Cambia a esta direccin

    Source NAT Dinmico

  • 8/3/2019 Linux Redes

    75/78

    Portantier Information Security Introduccin a GNU/Linux

    iptables -t nat -A POSTROUTING -s192.168.3.0/24 -o eth0 -j MASQUERADE

    Destination NAT

  • 8/3/2019 Linux Redes

    76/78

    Portantier Information Security Introduccin a GNU/Linux

    iptables -A PREROUTING -p tcp --dport -8080 -i

    eth0 -j DNAT --to 192.168.3.3:80

    -A PREROUTING: Aade a PREROUTING-p tcp: Protocolo TCP

    --dport 8080: Puerto de destino

    -i eth0: Interfaz de entrada-j DNAT --to 192.168.3.2:80: Cambia a IP:Puerto

    iwconfig

  • 8/3/2019 Linux Redes

    77/78

    Portantier Information Security Introduccin a GNU/Linux

    # iwconfigwlan0 IEEE 802.11bg ESSID:"bomberman"

    Mode:Managed Freq:2.4 GHz AP: 00:1E:58:C6:73:C7Bit Rate=48 Mb/s Tx-Power=27 dBm

    Retry long limit:7 RTS thr:off Fragment thr:offEncryption key:offPower Management:offLink Quality=56/70 Signal level=-54 dBm

    Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0Tx excessive retries:0 Invalid misc:0 Missed beacon:0

    wpa_supplicant

  • 8/3/2019 Linux Redes

    78/78

    Portantier Information Security Introduccin a GNU/Linux

    network={ssid="ssi-de-la-red"

    scan_ssid=1

    proto=WPA2key_mgmt=WPA-PSK

    psk="contrasena"

    }

    wpa_supplicant -d -Dwext -i wlan0