Anda di halaman 1dari 33

INSTITUTO POLITCNICO NACIONAL

ESCUELA SUPERIOR DE CMPUTO

REDES DE COMPUTADORAS
ANALIZADOR DE TRAMAS

By:
Robles Jimnez Mauricio Alejandro

Professor:
M. en C. NIDIA ASUNCIN CORTEZ DUARTE
JUNIO 2016
ndex
Contenido

Problem:......................................................................................................................2
Hypothesis:..................................................................................................................2
Software (libraries, packages, tools):..............................................................................2
Procedure:................................................................................................................2-8
Results (Data):........................................................................................................8-12

Conclusions:..............................................................................................................12
References:..............................................................................................................30
Code....................................................................................................................12-30

Problema:
Realizar un analizador de tramas, que identifique cada uno de los protocolos
vistos en clase y imprima la informacin necesaria de cada cabecera.
Hipotesis:
La programacin ser usada con base en el anterior programa que fue el
analizador LLC, analizando correctamente cada capa de la trama como vimos
en clase, nicamente editando cada cabecera para sacar correctamente la
informacin de la trama .
Software y herramientas a utlizar:
DevC++
Cabeceras de los protocolos
Procedimiento:

Protocolo IP
CABECERA

MAC header

IP header

Data :::

0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3
31
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
Version

IHL

Differentiated
Services

Identification
TTL

Total length
Flags

Protocol

Fragment offset
Header checksum

Source IP address
Destination IP address
Options and padding :::
Para sacar la versin del protocolo se hace la siguiente operacin:

T[14]>>4&15

Despues sacamos el valor de la cabecera:


1

T[14]&15)*4

Luego checamos el tipo de servicio que tiene la trama

T[15]&16 = Minimize delay


T[15]&8 = Maximize througthout
T[15]&4 = Maximize reliability
T[15]&2 = MInimize cost

Sacamos el identificador de la cabecera

T[18]*256+T[19]

Luego checamos las banderas que estn prendidas:

T[20]&64 = sin fragmentar


T[20]&32 = mas de un fragmento

Calculamos el Offset:

T[20]&31*256+T[21]

Imprimimos el tipo de protocolo con un switch:

switch(T[23]){

Valor
1
6
17
Otros

Protocolo
ICMP
TCP
UDP
No soportado

Imprimimos el Checksum:

T[24]*256+T[25]

Imprimimos la direccin de origen y la destino

for(i=26;i<29;i++)
printf("%i:",T[i]);
printf("%i\n",T[29]);
for(i=30;i<33;i++)
printf("%i:",T[i]);
printf("%i\n",T[33]);

Checamos si existen datos adicionales a la cabecera ip y de ser as los


imprimimos:

if(tope>34)
while(i<=tope){
printf("%x ",T[i]);
i++;

Protocolo IP-ICMP
CABECERA
MAC header

IP header

ICMP header

Data :::

0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
Type

Code

ICMP header checksum


Data :::

Checamos el bit 23 para saber el protocolo si es igual a 1 entraremos al


protocolo ICMP y entraremos a un switch para saber que tipo de mensaje es:

Tipo
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

if(T[23]==1)
switch(T[i])

Descripcin
Echo reply.

Referencias
RFC 792

Destination unreachable.
Source quench.
Redirect.
Alternate host address.

RFC 792
RFC 792
RFC 792

Echo request.
Router advertisement.
Router solicitation.
Time exceeded.
Parameter problem.
Timestamp request.
Timestamp reply.
Information request. Obsolete.

RFC 792
RFC 1256
RFC 1256
RFC 792
RFC 792
RFC 792
RFC 792
RFC 792
3

16
17
18
19
20
29
30
31
32
33
34
35
36
37
38
39
40
41
42
255

Information reply. Obsolete.


Address mask request.
Address mask reply.
reserved (for security).
reserved (for robustness experiment).

RFC 792
RFC 950
RFC 950

Traceroute.
Conversion error.
Mobile Host Redirect.
IPv6 Where-Are-You.
IPv6 I-Am-Here.
Mobile Registration Request.
Mobile Registration Reply.
Domain Name request.
Domain Name reply.
SKIP Algorithm Discovery Protocol.
Photuris, Security failures.
Experimental mobility protocols.
Reserved.

RFC 1393
RFC 1475

Subtipo (Cambio de ruta)


0
1
2
3
Subtipo (Tiempo excedido)
0
1
Subtipo (Problemas de parametros)
0
1
2

RFC 1788
RFC 1788
RFC 2521
RFC 4065

Descripcion
Redirect Datagram for the Network
Redirect Datagram for the Host
Redirect Datagram for the TOS & Network
Redirect Datagram for the TOS & Host
Descripcion
Time to Live exceeded in Transit
Fragment Reassembly Time Exceeded
Descripcion
Pointer indicates the error
Missing a Required Option
Bad Length

CABECERA
.::Protocolo envio::.
01

000101
Dir.Orig
en
T[13]

0001
10
0
Dir.
Tipo
Desti
tram
no
a
T[13]-T[14]

00
Enrutamie
nto
T[14]

Protocolo IP-TCP
CABECERA
MAC header

IP header

TCP header

Data :::

0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
Source Port

Destination Port
Sequence Number
Acknowledgment Number

Data
Offset

reserv
ed

ECN

Control Bits

Checksum

Window
Urgent Pointer

Options and padding :::


Data :::

En caso de que el bit del protocolo sea igual a 6 entonces entramos al


protocolo TCP y imprimimos los puertos de origen y destino:

T[24]+T[25]
T[26]+T[29]

Despues sacamos el numero de secuencia y el numero de reconocimiento, asi


como el offset, los bits de control , la ventana, checksum, el apuntador de
urgencia, y las opciones en caso de tener:

Numero de secuencia
T[28]+T[29]+T[30]+T[31]
Numero de reconocimiento T[32]+T[33]+T[34]+T[35]
Offset
T[36]<<4
Bit de control
cb[T[37]]
Ventana
T[38]+T[39]
Checksum
T[40]+T[41]
Apuntador de urgencia
T[42]+T[43]
Opciones
opcitcp[T[44]]

Protocolo IP-UDP
CABECERA
MAC header

IP header

UDP header

Data :::

0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
Source Port

Destination Port

Length

Checksum
Data :::

En el caso de que no entre en ninguno de los otros 2 casos entonces ser una
trama de tipo UDP entonces solamente imprimimos el puerto origen, el destino
la longitud de la tramam y el checksum:

Puerto origen
T[24]+T[25]
Puerto destino
T[26]+T[27]
Longitud de la trama
T[28]+T[29]
Checksum
T[30]+T[31]

Protocolo ARP
CABECERA
MAC header

ARP header

Data :::

ARP header:
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
Hardware type
Hardware address
length

Protocol type

Protocol address
length

Opcode

Source hardware address :::


Source protocol address :::
Destination hardware address :::
Destination protocol address :::
Data :::

Primero checamos si los bits 12 y 13 sean igual a 2054, de ser asi entra al
protocolo ARP y imprimimos el tipo de direccin de hardware:

if((T[12]<<8)+(T[13])==2054)
TH[((T[14])+T[15])])

Despues imprimimos la direccin de protocolo, el tamao de direccin de


hardware y el tamao de direccin de protocolo:

if(((T[16]>>3)+T[17])==2048)
if(((T[18]))==6)
if(((T[19]))==4)

Luego imprimimos la operacin que se est realizando, la direccin de


Hardware origen, la direccin de protocolo origen, la direccin de hardware
destino y la direccin de protocolo destino:

Operacin OP[T[20]+T[21]]
Direccion HO
T[22],T[23],T[24],T[25],T[26],T[27]
Direccion PO
T[28],T[29],T[30],T[31]
Direccion HD
T[32],T[33],T[34],T[35],T[36],T[37]
Direccion PD
T[38],T[39],T[40],T[41]

Capturas de pantalla:

10

11

Concluciones:
En este semestre aprendimos como codificar diferentes tipos de analizadores,
para los diferentes tipos de protocolos que existen en las redes todo ello para
comprender ms a fondo como es que se mandan las tramas y la informacin a
travs de las redes, y la programacin a nivel de bit que es cmo se maneja
una trama, tambin aprendimos los diferentes tipos de protocolos y sus
variantes.

Codigo
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int analizartrama(unsigned char*T, unsigned char*cadena);
int crc(unsigned char *T, short int tam);

12

int main(){
unsigned char trama[20][125]={
/* TRAMA 1 */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x23, /* .......# */
0x8b, 0x46, 0xe9, 0xad, 0x08, 0x06, 0x00, 0x01, /* .F...... */
0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x23, /* .......# */
0x8b, 0x46, 0xe9, 0xad, 0x94, 0xcc, 0x39, 0xcb, /* .F....9. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0xcc, /* ........ */
0x39, 0xfe

/* 9. */

},
/*TRAMA 2 */
{
0x00, 0x23, 0x8b, 0x46, 0xe9, 0xad, 0x00, 0x1f, /* .#.F.... */
0x45, 0x9d, 0x1e, 0xa2, 0x08, 0x06, 0x00, 0x01, /* E....... */
0x08, 0x00, 0x06, 0x04, 0x00, 0x02, 0x00, 0x1f, /* ........ */
0x45, 0x9d, 0x1e, 0xa2, 0x94, 0xcc, 0x39, 0xfe, /* E.....9. */
0x00, 0x23, 0x8b, 0x46, 0xe9, 0xad, 0x94, 0xcc, /* .#.F.... */
0x39, 0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9....... */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00

/* .... */

},
/* TRAMA 3 */
{
0x00, 0x1f, 0x45, 0x9d, 0x1e, 0xa2, 0x00, 0x23, /* ..E....# */
0x8b, 0x46, 0xe9, 0xad, 0x08, 0x00, 0x46, 0x00, /* .F....F. */

13

0x80, 0x42, 0x04, 0x55, 0x34, 0x11, 0x80, 0x11, /* .B.U4... */


0x6b, 0xf0, 0x94, 0xcc, 0x39, 0xcb, 0x94, 0xcc, /* k...9... */
0x67, 0x02, 0xaa, 0xbb, 0xcc, 0xdd, 0x04, 0x0c, /* g....... */
0x00, 0x35, 0x00, 0x2e, 0x85, 0x7c, 0xe2, 0x1a, /* .5...|.. */
0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x03, 0x77, 0x77, 0x77, 0x03, 0x69, /* ...www.i */
0x73, 0x63, 0x05, 0x65, 0x73, 0x63, 0x6f, 0x6d, /* sc.escom */
0x03, 0x69, 0x70, 0x6e, 0x02, 0x6d, 0x78, 0x00, /* .ipn.mx. */
0x00, 0x1c, 0x00, 0x01

/* .... */

},
/* TRAMA 4 */
{
0x00, 0x02, 0xb3, 0x9c, 0xdf, 0x1b, 0x00, 0x02, /* ........ */
0xb3, 0x9c, 0xae, 0xba, 0x00, 0x04, 0xf0, 0xf0, /* ........ */
0x01/*aqui es el de control
0x00, /* ........ */

*/, 0xc9, 0x00, 0x00, 0x00, 0x00, 0x00,

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x9b, 0x6d /* .....|.m */
},
/* TRAMA 5 */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x23, /* .......# */
0x8b, 0x46, 0xe9, 0xad, 0x08, 0x06, 0x00, 0x01, /* .F...... */
0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x23, /* .......# */
14

0x8b, 0x46, 0xe9, 0xad, 0x94, 0xcc, 0x39, 0xcb, /* .F....9. */


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0xcc, /* ........ */
0x3a, 0xe1

/* :. */

},
/* TRAMA 6*/
{
0x00, 0x23, 0x8b, 0x46, 0xe9, 0xad, 0x00, 0x1f, /* .#.F.... */
0x45, 0x9d, 0x1e, 0xa2, 0x08, 0x06, 0x00, 0x01, /* E....... */
0x08, 0x00, 0x06, 0x04, 0x00, 0x02, 0x00, 0x1f, /* ........ */
0x45, 0x9d, 0x1e, 0xa2, 0x94, 0xcc, 0x3a, 0xe1, /* E.....:. */
0x00, 0x23, 0x8b, 0x46, 0xe9, 0xad, 0x94, 0xcc, /* .#.F.... */
0x39, 0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9....... */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00

/* .... */

},
/* TRAMA 7 */
{
0x00, 0x23, 0x8b, 0x46, 0xe9, 0xad, 0x00, 0x1f, /* .#.F.... */
0x45, 0x9d, 0x1e, 0xa2, 0x08, 0x00, 0x45, 0x00, /* E.....E. */
0x00, 0x6f, 0x90, 0x30, 0x40, 0x00, 0xfb, 0x11, /* .o.0@... */
0x24, 0xe7, 0x94, 0xcc, 0x67, 0x02, 0x94, 0xcc, /* $...g... */
0x39, 0xcb, 0x00, 0x35, 0x04, 0x0c, 0x00, 0x5b, /* 9..5...[ */
0xe8, 0x60, 0xe2, 0x1a, 0x85, 0x80, 0x00, 0x01, /* .`...... */
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03, 0x77, /* .......w */
0x77, 0x77, 0x03, 0x69, 0x73, 0x63, 0x05, 0x65, /* ww.isc.e */
0x73, 0x63, 0x6f, 0x6d, 0x03, 0x69, 0x70, 0x6e, /* scom.ipn */

15

0x02, 0x6d, 0x78, 0x00, 0x00, 0x1c, 0x00, 0x01, /* .mx..... */


0xc0, 0x14, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, /* ........ */
0x0e, 0x10, 0x00, 0x21, 0x04, 0x64, 0x6e, 0x73, /* ...!.dns */
0x31, 0xc0, 0x1a, 0x03, 0x74, 0x69, 0x63, 0xc0, /* 1...tic. */
0x1a, 0x77, 0xec, 0xdf, 0x29, 0x00, 0x00, 0x2a, /* .w..)..* */
0x30, 0x00, 0x00, 0x0e, 0x10, 0x00, 0x12, 0x75, /* 0......u */
0x00, 0x00, 0x00, 0x2a, 0x30

/* ...*0 */

},
/* TRAMA 8 */
{
0x00, 0x1f, 0x45, 0x9d, 0x1e, 0xa2, 0x00, 0x23, /* ..E....# */
0x02, 0x03, 0x04, 0x05, 0x08, 0x00, 0x45, 0x00, /* .F....E. */
0x00, 0x42, 0x04, 0x56, 0x00, 0x00, 0x80, 0x11, /* .B.V.... */
0x6b, 0xef, 0x94, 0xcc, 0x39, 0xcb, 0x94, 0xcc, /* k...9... */
0x67, 0x02, 0x04, 0x0c, 0x00, 0x35, 0x00, 0x2e, /* g....5.. */
0xff, 0x87, 0x68, 0x2a, 0x01, 0x00, 0x00, 0x01, /* ..h*.... */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, /* .......w */
0x77, 0x77, 0x03, 0x69, 0x73, 0x63, 0x05, 0x65, /* ww.isc.e */
0x73, 0x63, 0x6f, 0x6d, 0x03, 0x69, 0x70, 0x6e, /* scom.ipn */
0x02, 0x6d, 0x78, 0x00, 0x00, 0x01, 0x00, 0x01 /* .mx..... */
},
/* TRAMA 9 */
{
0x00, 0x1f, 0x45, 0x9d, 0x1e, 0xa2, 0x00, 0x23, /* ..E....# */
0x8b, 0x46, 0xe9, 0xad, 0x08, 0x00, 0x45, 0x00, /* .F....E. */
0x00, 0x3c, 0x04, 0x57, 0x00, 0x00, 0x80, 0x01, /* .<.W.... */

16

0x98, 0x25, 0x94, 0xcc, 0x39, 0xcb, 0x94, 0xcc, /* .%..9... */


0x3a, 0xe1, 0x08, 0x00, 0x49, 0x5c, 0x03, 0x00, /* :...I\.. */
0x01, 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
0x68, 0x69

/* hi */

},
/* TRAMA 10 */
{
0x00, 0x02, 0xb3, 0x9c, 0xdf, 0x1b, 0x00, 0x02, /* ........ */
0x02, 0x03, 0x04, 0x05, 0x00, 0x04, 0xf0, 0xf0, /* ........ */
0x0c,/*control*/ 0xc7,/*extendida*/ 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x9b, 0x6d /* .....|.m */
},
/* trama 11 */
{
0x00, 0x02, 0xb3, 0x9c, 0xae, 0xba, 0x11, 0x11, /* ........ */
0x11, 0x11, 0x11, 0x11, 0x00, 0x03, 0xf0, 0xf0, /* ........ */
0x63, /*control*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
17

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x43, 0x05, 0x90, 0x6d /* ....C..m */
},
/* trama 12 */
{
0x00, 0x23, 0x8b, 0x46, 0xe9, 0xad, 0x00, 0x1f, /* .#.F.... */
0x02, 0x03, 0x04, 0x05, 0x08, 0x00, 0x45, 0x00, /* E.....E. */
0x00, 0x3c, 0x01, 0xb5, 0x00, 0x00, 0x3f, 0x01, /* .<....?. */
0xdb, 0xc7, 0x94, 0xcc, 0x3a, 0xe1, 0x94, 0xcc, /* ....:... */
0x39, 0xcb, 0x00, 0x00, 0x51, 0x5c, 0x03, 0x00, /* 9...Q\.. */
0x01, 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
0x68, 0x69

/* hi */

},
/* trama 13 */
{
0x00, 0x02, 0xb3, 0x9c, 0xae, 0xba, 0x00, 0x01, /* ........ */
0x02, 0x03, 0x04, 0x05, 0x00, 0x03, 0xf0, 0xf1, /* ........ */
0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */

18

0x00, 0x00, 0x00, 0x00, 0x43, 0x05, 0x90, 0x6d /* ....C..m */


},
/* trama 14 */
{
0x00, 0x1f, 0x45, 0x9d, 0x1e, 0xa2, 0x00, 0x1c, /* ..E..... */
0xc0, 0x7b, 0x35, 0xa1, 0x08, 0x00, 0x48, 0x00, /* .{5...H. */
0x00, 0x48, 0x5c, 0x7d, 0x00, 0x00, 0x80, 0x01, /* .H\}.... */
0x6c, 0x88, 0x94, 0xcc, 0x39, 0xc3, 0x94, 0xcc, /* l...9... */
0x00, 0x49, 0x07, 0x0b, 0x04, 0x00, 0x00, 0x00, /* .I...... */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, /* ........ */
0x3b, 0x5c, 0x02, 0x00, 0x10, 0x00, 0x61, 0x62, /* ;\....ab */
0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, /* cdefghij */
0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, /* klmnopqr */
0x73, 0x74, 0x75, 0x76, 0x77, 0x61, 0x62, 0x63, /* stuvwabc */
0x64, 0x65, 0x66, 0x67, 0x68, 0x69

/* defghi */

},
/* trama 15*/
{
0x00, 0x23, 0x8b, 0x46, 0xe9, 0xad, 0x00, 0x1f, /* .#.F.... */
0x45, 0x9d, 0x1e, 0xa2, 0x08, 0x00, 0x00, 0x01, /* E....5.. */
0x08, 0x00, 0x06, 0x04, 0x00, 0x03, 0x00, 0x1f, /* ........ */
0x45, 0x9d, 0x1e, 0xa2, 0x94, 0xcc, 0x3a, 0xe1, /* E.....:. */
0x00, 0x23, 0x8b, 0x46, 0xe9, 0xad, 0x94, 0xcc, /* .#.F.... */
0x39, 0xcb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9....... */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0xd8, 0xee, 0xdf, 0xb0 /* ........ */

19

},
/* trama 16 */
{
0x00, 0x02, 0xb3, 0x9c, 0xae, 0xba, 0x22, 0x22, /* ........ */
0x22, 0x22, 0x22, 0x22, 0x00, 0x03, 0xf0, 0xf0, /* ........ */
0x73,/*control*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x43, 0x05, 0x90, 0x6d /* ....C..m */
},
/*trama 17 */
{
0x00, 0x02, 0xb3, 0x9c, 0xae, 0xba, 0x00, 0x02, /* ........ */
0xb3, 0x9c, 0xdf, 0x1b, 0x00, 0x03, 0xf0, 0xf0, /* ........ */
0x53,/*control*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x43, 0x05, 0x90, 0x6d /* ....C..m */
},
/* trama 18 */
{
0x02, 0xff, 0x53, 0xc3, 0xe9, 0xab, 0x00, 0xff, /* ..S..... */

20

0x66, 0x7f, 0xd4, 0x3c, 0x08, 0x00, 0x45, 0x00, /* f..<..E. */


0x00, 0x30, 0x2c, 0x00, 0x40, 0x00, 0x80, 0x06, /* .0,.@... */
0x4b, 0x74, 0xc0, 0xa8, 0x01, 0x02, 0xc0, 0xa8, /* Kt...... */
0x01, 0x01, 0x04, 0x03, 0x00, 0x15, 0x00, 0x3b, /* .......; */
0xcf, 0x44, 0x00, 0x00, 0x00, 0x00, 0x70, 0x20, /* .D....p */
0x20, 0x00, 0x0c, 0x34, 0x00, 0x00, 0x02, 0x04, /* ..4.... */
0x05, 0xb4, 0x01, 0x01, 0x04, 0x02

/* ...... */

},
/*trama 19 */
{
0x00, 0x02, 0xb3, 0x9c, 0xae, 0xba, 0x00, 0x02, /* ........ */
0xb3, 0x9c, 0xdf, 0x1b, 0x00, 0x03, 0xf0, 0xf1, /* ........ */
0x53, 0x0b, 0x0e, 0x00, 0xff, 0xef, 0x14, 0x00, /* ........ */
0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x7f, 0x23, /* ..(....# */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
0x00, 0x00, 0x00, 0x00, 0x01, 0x99, 0x98, 0x6d /* .......m */
},
/* trama 20 */
{
0x00, 0xff, 0x66, 0x7f, 0xd4, 0x3c,/*mD*/ 0x02, 0xff, /* ..f..<.. */
0x53, 0xc3, 0xe9, 0xab,/*mO*/ 0x08, 0x00,/*tot*/ 0x45,/*V*/ 0x00/*ToS*/,
/* S.....E. */
0x00, 0x30,/*Total Lenght*/ 0x05, 0xc4, /*Identification*/0x40, 0x00,
/*FLags and FO*/0x80,/*TtL*/ 0x06/*Protocol*/, /* .0..@... */
0x71, 0xb0,/*checksum*/ 0xc0, 0xa8, 0x01, 0x01, 0xc0, 0xa8, /* q....... */
21

0x01, 0x02, 0x00, 0x15, 0x04, 0x03, 0x21, 0x5d, /* ......!] */


0x3a, 0x44, 0x00, 0x3b, 0xcf, 0x45, 0x70, 0x12, /* :D.;.Ep. */
0x44, 0x70, 0x8c, 0x11, 0x00, 0x00, 0x02, 0x04, /* Dp...... */
0x05, 0xb4, 0x01, 0x01, 0x04, 0x02

/* ...... */

}};

//desde aqui va la funcion


short int i=0;
unsigned char cadena[50];
for(i=0;i<20;i++){
strcpy(cadena,"");
printf("Trama %d:\n", i+1);
if(analizartrama(trama[i],cadena))
printf("%s\n", cadena);
}
return 0;
}

int analizartrama(unsigned char*T, unsigned char*cadena){


unsigned char TH[][13]={"","Ethernet","","","","","IEEE 802",""};
unsigned char TP[]={"IPv4 (0x0800)"};
unsigned char OP[][10]={"","Solicitud","Respuesta",""};
unsigned char flag_1[][4]={"OFF","ON"};
int i=0;
".::Capa fisica::.";

22

printf("MAC destino: ");


for(i=0;i<=5;i++)
printf("%.2x:",T[i]);
printf("\nMAC origen: ");
for(i=6;i<=11;i++)
printf("%.2x:",T[i]);
printf("\n");
if((T[12]<<8)+(T[13])==2054){
printf("ARP:\n");
printf("Tipo de direccion de hardware: %s\n",TH[((T[14])
+T[15])]);
if(((T[16]>>3)+T[17])==2048)
printf("Tipo de direccion de protocolo: %s\n",TP);
if(((T[18]))==6)
printf("Tamao de direccion de hardware: 6\n");
if(((T[19]))==4)
printf("Tamao de direccion de protocolo: 4\n");
printf("Operacion: %s\n",OP[T[20]+T[21]]);
printf("Direccion Hardware Origen: %.2x:%.2x:%.2x:%.2x:%.2x:
%.2x\n",T[22],T[23],T[24],T[25],T[26],T[27]);
printf("Direccion Protocolo Origen: %d.%d.%d.
%d\n",T[28],T[29],T[30],T[31]);
printf("Direccion Hardware Destino: %.2x:%.2x:%.2x:%.2x:%.2x:
%.2x\n",T[32],T[33],T[34],T[35],T[36],T[37]);
printf("Direccion Protocolo Destino: %d.%d.%d.
%d\n",T[38],T[39],T[40],T[41]);
return 1;
}

23

else
if(((T[12]<<8)+(T[13]))==2048){//Protocolo IP
printf("\n.::Protocolo IP::.\n");
printf("Version: %i\n",T[14]>>4&15);
printf("IP Header Length: %i\n",(T[14]&15)*4);
unsigned char tope=((T[14]&15)*4)+13;//Limite de la cabecera IP
printf("Servicios:\n");
if(T[15]&16)
printf("\tMinimize delay\n");
if(T[15]&8)
printf("\tMaximize througthout\n");
if(T[15]&4)
printf("\tMaximize reliability\n");
if(T[15]&2)
printf("\tMinimize cost\n");
printf("Total: %i\n",T[16]);
printf("Identification: %i\n",(T[18]*256+T[19]));
printf("banderas: ");
if(T[20]&64)
printf("Sin fragmentar\n");
else if(T[20]&32)
printf("Mas de un fragmento\n");
else printf("\n");
printf("Offset: %i\n",(T[20]&31)*256+T[21]);
printf("TTL: %i\n",T[22]);
printf("Protocolo: ");

24

switch(T[23]){
case 1: printf("ICMP\n");
break;
case 6: printf("TCP\n");
break;
case 17:printf("UDP\n");
break;
default:printf("No soportado\n");
break;
}
printf("Header Checksum: %i\n",(T[24]*256)+T[25]);
printf("Direccion origen: ");
for(i=26;i<29;i++)
printf("%i:",T[i]);
printf("%i\n",T[29]);
printf("Direccion destino: ");
for(i=30;i<33;i++)
printf("%i:",T[i]);
printf("%i\n",T[33]);
if(tope>34){//Imprime lo que se encuentre en el campo de opciones
adicionales
i=34;
printf("Opciones: ");
while(i<=tope){
printf("%x ",T[i]);
i++;
}
25

printf("\n");
}
if(T[23]==1){//Codigo para ICMP
i++;//Se incrementa una unidad para salir de IP
printf("\n.::Cabecera ICMP::.\n");
printf("Tipo de mensaje ICMP: ");
switch(T[i]){
case 0: printf("Echo Reply\n");
break;
case 3: printf("Destino inalcanzable: ");
switch(T[i+1]){
case 0: printf("Red inalcanzable\n");
break;
case 1: printf("Host inalcanzable\n");
break;
case 2: printf("Protocolo inalcanzable\n");
break;
case 3: printf("Puerto inalcanzable\n");
break;
case 4: printf("Paquete demasiado grande, no es posible
fragmentarlo\n");
break;
case 5: printf("Error de router origen\n");
break;
case 6: printf("Error desconocido en la red destino\n");
break;
case 7: printf("Error desconocido en el host de destino\n");
26

break;
case 8: printf("Host de origen aislado\n");
break;
case 9: printf("Acceso a la red destino denegado\n");
break;
case 10:printf("Acceso no autorizado al host destino\n");
break;
case 11:printf("Red inalcanzable para este servicio\n");
break;
case 12:printf("Host inalcanzable para este servicio\n");
break;
case 13:printf("Comunicacion no autorizada\n");
break;
}
break;
case 4: printf("Disminucion del trafico desde el origen (source
quench)\n");
break;
case 5: printf("Cambio de ruta: ");
switch(T[i+1]){
case 0: printf("Redireccionar todos los datagramas para una
red\n");
break;
case 1: printf("Redireccionar todos los datagramas para un
host\n");
break;
case 2: printf("Redireccionar todos los datagramas de un servicio
para una red\n");
27

break;
case 3: printf("Redireccionar todos los datagramas de un servicio
para un host\n");
break;
}
break;
case 8: printf("Echo request\n");
break;
case 9: printf("Anuncio de router\n");
break;
case 10:printf("Seleccion de router\n");
break;
case 11:printf("Tiempo excedido: ");
switch(T[i+1]){
case 0: printf("Tiempo de vida en transito excedido\n");
break;
case 1: printf("Tiempo de reensamble de fragmentos excedido\n");
break;
}
break;
case 12:printf("Problema de parametros ");
switch(T[i+1]){
case 0: printf("Error indicado en el puntero\n");
break;
case 1: printf("Se perdio una opcion requerida\n");
break;
case 2: printf("Mala longitud\n");
28

break;
}
break;
case 13:printf("Marca temporal\n");
break;
case 14:printf("Respuesta de marca temporal\n");
break;
case 15:printf("Solicitud de informacion\n");
break;
case 16:printf("Respuesta de informacion\n");
break;
case 17:printf("Solicitud de mascara de direccion\n");
break;
case 18:printf("Respuesta de mascara de direccion\n");
break;
case 30:printf("Traceroute\n");
break;
}
}//Termina ICMP

else if(T[23]== 6){ // Protocolo TCP


unsigned char cb[][5]={"urg","ack","psh","rst","syn","fin"};
unsigned char opcitcp[][5]={"End of option list.","No
operation","Maximum Segment Size.","Window scale factor.","SACK
permitted.","SACK."};
printf("protocolo TCP\n");
i++;
29

printf("Puerto origen %d\n",(T[24]+T[25]));


printf("Puerto destino %d\n",(T[26]+T[27]));
printf("sequence number %d\n",(T[28]+T[29]+T[30]+T[31]));
printf("Acknowledgment Number %d",(T[32]+T[33]+T[34]+T[35]));
printf("Data offset %d\n",T[36]<<4);
printf("Control bits %d\n",cb[T[37]]);
printf("window %d\n ",T[38]+T[39]);
printf("checksum : %d \n",T[40]+T[41]);
printf("URGENT POINTER : %d \n",(T[42]+T[43]));
printf("Options: %d\n",opcitcp[T[44]]);
}

else if(T[23==17]){
printf("protocolo udp\n");
i++;
printf("Puerto origen %d\n",(T[24]+T[25]));
printf("Puerto destino %d\n",(T[26]+T[27]));
printf("lenght %d\n ",(T[28]+T[29]));
printf("Checksum %d\n ",(T[30]+T[31]));
}
}//Termina IP
return -1;
}
Referencias:
http://www.networksorcery.com/enp/protocol/802/ethertypes.htm
http://www.comunidad.escom.ipn.mx/ealdana/redesnp/tcp_ip/tcpip%5b1%5d.pdf

30

31

Anda mungkin juga menyukai