Protocollo ICMP - Politecnico di Milano
Transcript
Protocollo ICMP - Politecnico di Milano
Protocollo ICMP Introduzione The Internet Control Message Protocol (ICMP) is part of the Internet protocol suite as defined in RFC 792. ICMP messages are typically generated in response to errors in IP datagrams (as specified in RFC 1122) or for diagnostic or routing purposes. The version of ICMP for Internet Protocol version 4 is also known as ICMPv4, as it is part of IPv4. IPv6 has an equivalent protocol, ICMPv6. ICMP messages are constructed at the IP layer, usually from a normal IP datagram that has generated an ICMP response. IP encapsulates the appropriate ICMP message with a new IP header (to get the ICMP message back to the original sending host) and transmits the resulting datagram in the usual manner. For example, every machine (such as intermediate routers) that forwards an IP datagram has to decrement the time to live (TTL) field of the IP header by one; if the TTL reaches 0, an ICMP Time to live exceeded in transit message is sent to the source of the datagram. Each ICMP message is encapsulated directly within a single IP datagram, and thus, like UDP, ICMP does not guarantee delivery. Although ICMP messages are contained within standard IP datagrams, ICMP messages are usually processed as a special case, distinguished from normal IP processing, rather than processed as a normal sub-protocol of IP. In many cases, it is necessary to inspect the contents of the ICMP message and deliver the appropriate error message to the application that generated the original IP packet, the one that prompted the sending of the ICMP message. Many commonly-used network utilities are based on ICMP messages. The traceroute command is implemented by transmitting UDP datagrams with specially set IP TTL header fields, and looking for ICMP Time to live exceeded in transit (above) and "Destination unreachable" messages generated in response. The related ping utility is implemented using the ICMP "Echo" and "Echo reply" messages. List of permitted control messages (incomplete list): 0 - Echo Reply 1 - Reserved 2 - Reserved 3 - Destination Unreachable 4 - Source Quench 5 - Redirect Message 6 - Alternate Host Address 7 - Reserved 8 - Echo Request 9 - Router Advertisement 10 - Router Solicitation 11 - Time Exceeded 12 - Parameter Problem 13 - Timestamp 14 - Timestamp Reply 15 - Information Request 16 - Information Reply 17 - Address Mask Request 18 - Address Mask Reply 19 - Reserved for security 20-29 - Reserved for robustness experiment 30 - Traceroute 31 - Datagram Conversion Error Carlo Todeschini – [email protected] Reti di Comunicazione e Internet – Politecnico di Milano sede di Cremona – A.A. 2010-2011 – v. 1.5 1 32 - Mobile Host Redirect 33 - IPv6 Where-Are-You 34 - IPv6 Here-I-Am 35 - Mobile Registration Request 36 - Mobile Registration Reply 37 - Domain Name Request 38 - Domain Name Reply 39 - SKIP Algorithm Discovery Protocol 40 - Photuris, Security failures 41 - ICMP for experimental mobility protocols such as Seamoby [RFC4065] 42-255 - Reserved Fonte: Wikipedia Utilizzo Esistono in GNU/Linux due comandi che possono essere utilizzati per interagire tramite protocollo ICMP: ping e traceroute. Entrambi hanno lo scopo di facilitare le operazioni di diagnostica della rete. Il comando ping invia pacchetti di tipo ICMP con una richiesta di “Echo Request” e rimane in attesa della relativa risposta “Echo Reply”. Tipicamente viene utilizzato per verificare se un dato host è al momento raggiungibile in rete (non sempre però, per motivi di sicurezza, lo stack di rete dell'host da analizzare è configurato per rispondere al ping...). Ping is a computer network tool used to test whether a particular host is reachable across an IP network; it is also used to self test the network interface card of the computer, or as a speed test. It works by sending ICMP “echo request” packets to the target host and listening for ICMP “echo response” replies. Ping measures the round-trip time[1] and records any packet loss, and prints when finished a statistical summary of the echo response packets received, the minimum, mean, max and in some versions the standard deviation of the round trip time. Fonte: Wikipedia - http://en.wikipedia.org/wiki/Ping Il comando traceroute permette di capire il tragitto che un pacchetto esegue per arrivare a un host di destinazione; anche questo comando non dà sempre informazioni sicure al 100%.... traceroute is a computer network tool used to determine the route taken by packets across an IP network. An IPv6 variant, traceroute6, is also widely available. The traceroute tool is available on practically all Unix-like operating systems. Variants with similar functionality are also available, such as tracepath on modern Linux installations and tracert on Microsoft Windows operating systems. Windows NT-based operating systems also provide PathPing, which provides similar functionality. Fonte: Wikipedia - http://en.wikipedia.org/wiki/Traceroute Il comando traceroute funziona inviando, ad ogni step, tre pacchetti; al primo invio i tre pacchetti hanno un valore di “time-to-live” (TTL) pari a 1 e quindi non superano il primo router che incontrano (non vengono forwardati al next-hop). Il router che riceve il pacchetti con TTL pari 1 li distrugge e invia al mittente un pacchetto ICMP del tipo “ICMP time exceeded”. Al secondo invio il TTL vale 2 e quindi i tre pacchetti, vedendo il TTL decrementato dal primo router incontrato, Carlo Todeschini – [email protected] Reti di Comunicazione e Internet – Politecnico di Milano sede di Cremona – A.A. 2010-2011 – v. 1.5 2 provocheranno al secondo router una risposta di tipo “ICMP time exceeded” e così via. Esercizio 1 Verificare il funzionamento del comando ping. Lanciare il seguente comando che esegue 3 ping verso il sito individuato: ping -c 3 www.gnu.org Verificare la corrispondenza della cattura con lo schema riportato: Type (8 o 0) Code (0) identificatore Checksum Numero di sequenza dati opzionali Nota: il comando ping potrebbe non dare nessun risultato; questo non significa che l'host remoto non esista o sia spento/in avaria, ma potrebbe essere “protetto” (ciò configurato per non rispondere al comando ping) per motivi di sicurezza. Per esercizio provare a lanciare un ping verso indirizzi host conosciuti. Esempio di output: ping -c 3 www.gnu.org PING gnu.org (199.232.41.10) 56(84) bytes of data. 64 bytes from www.gnu.org (199.232.41.10): icmp_seq=1 ttl=45 time=183 ms 64 bytes from www.gnu.org (199.232.41.10): icmp_seq=2 ttl=45 time=182 ms 64 bytes from www.gnu.org (199.232.41.10): icmp_seq=3 ttl=45 time=182 ms --- gnu.org ping statistics --3 packets transmitted, 3 received, 0% packet loss, time 2007ms rtt min/avg/max/mdev = 182.336/182.863/183.681/0.766 ms E' possibile variare il valore di TTL contenuto nei pacchetti generati dal ping con il parametro “-t <VALORE DI TTL>”. Esiste anche un metodo che permette di impostare il valore di TTL per l'intero stack IP (attenzione: il cambiamento impatta sull'intero sistema); il valore attuale di TTL per i pacchetti generati dalla macchina viene visualizzato tramite il comando, da lanciare come utente root, cat /proc/sys/net/ipv4/ip_default_ttl Per impostare un valore differente utilizzare il seguente comando: echo <NUOVO_TTL> > /proc/sys/net/ipv4/ip_default_ttl Carlo Todeschini – [email protected] Reti di Comunicazione e Internet – Politecnico di Milano sede di Cremona – A.A. 2010-2011 – v. 1.5 3 (notare il simbolo “>” di redirezione). In questo modo si possono costruire dei pacchetti che daranno errore dopo un certo numero di host incontrati sul loro cammino. Esercizio 2 Per esercizio si conteggi la “lontananza” misurata in “numero di host da attraversare” tra la macchina in uso e un server sulla rete variando di volta in volta il valore di TTL partendo dal valore 1 e incrementandolo di volta in volta fino a che non si genera più errore. Esercizio 3 Eseguire il comando traceroute verso l'host utilizzato nell'esempio precedente: traceroute www.gnu.org e sniffare il traffico. ➢ ➢ Che protocollo viene utilizzato? Quanti pacchetti vengono inviati ad ogni iterazione? Esercizio 4 – Importante... Eseguire il comando traceroute con una modalità diversa verso l'host utilizzato nell'esempio precedente: traceroute -In www.gnu.org e sniffare il traffico. ➢ ➢ ➢ Che protocollo viene utilizzato rispetto all'esercizio precedente? Riportano entrami gli stessi risultati? Quale dei due è più efficiente/efficace? Hint... [...] On modern Unix and Linux-based operating systems, the traceroute utility by default uses UDP datagrams with destination ports number from 33434 to 33534. The traceroute utility usually has an option to specify use of ICMP echo request (type 8) instead, as used by the Windows tracert utility. If you have a firewall and if you want traceroute to work from both machines (Unix/Linux and Windows) you will need to allow both protocols inbound through your firewall (UDP with ports from 33434 to 33534 and ICMP type 8). There are also traceroute implementations that use TCP packets, such as tcptraceroute or layer four traceroute. PathPing is a utility introduced with Windows NT that combines ping and traceroute functionality. mtr (my traceroute) is an enhanced version of ICMP traceroute which is available for Unix and Windows systems. All implementations of traceroute rely on ICMP (type 11) packets being sent to the originator. Fonte: Wikipedia - http://en.wikipedia.org/wiki/Traceroute Carlo Todeschini – [email protected] Reti di Comunicazione e Internet – Politecnico di Milano sede di Cremona – A.A. 2010-2011 – v. 1.5 4