elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Mensajes
Páginas: 1 2 3 4 5 6 7 8 9 10 11 12 13 [14] 15 16 17 18 19 20 21 22
131  Programación / Programación C/C++ / Re: Ayuda con conversión de tipo de variable [c++] en: 6 Abril 2012, 14:34 pm
¡Buenas xkiz!

Prueba con lo siguiente....
Código
  1. string cadena1 = sample;
  2. char * cadena2 = (char *) cadena1;
  3.  

Para hacer una conversion de tipos en C/C++ solo tienes que poner el tipo al que lo quieres convertir entre parentesis y precedido de la variable a convertir.

Un saludo.
132  Seguridad Informática / Hacking / Re: Teardrop II en: 4 Abril 2012, 05:37 am
¡Buenas!

Por lo que tengo entendido....TEADROP aprovecha una vulnerabilidad en la fragmentacion/reensamblado de TCP.

Mira este enlace a ver si te dice algo:
http://www2.udec.cl/~crmendoz/18.htm

Un saludo.
133  Programación / Programación C/C++ / Sock_Raw recv(), recvfrom()..... en: 4 Abril 2012, 05:16 am
¡Buenas a todos!

Esto programando un sniffer y tengo un problema con estas funciones. Necesito una funcion del estilo de recv() pero que no necesite que el socket este conectado.

El sniffer en si mismo me funciona muy bien, pero cuando hago un MITM el sniffer no me captura datos pero el wireshark si. Y creo que el problema esta en el recv() que necesista que haya se ejecutado la funcion connect() para que recv() capture los datos.

Asi que mi pregunta es:¿Conoceis alguna funcion equivalente a recv() pero que no sea dependiente de la funcion connect()?

Gracias, un saludo.
134  Programación / Programación C/C++ / Re: Warnings en gcc -Wall en: 4 Abril 2012, 02:24 am
¡Buenas CrisQC!

Muchas gracias por tu ayuda. Tenias razon, mi problema estaban en las librerias. En el main.c necesitaba añadir la libreria stdlib.h. Lo del char *, le he declarado como me dijiste (array char) y me ha funcionado tambien, y lo del ether_aton() y el close() solo tuve que añadir la libreria que contenian esas funciones y me ha funcionado tambien! jeje

Lo que no entiendo es como las funciones ether_aton() y close() me funcionaban si tener incluidas las librerias que las contiene....deberia haberme dado errores de compilacion del tipo: "no esta declarada la funcion close()..." Pero imagino que esto se debe a que otras librerias que tengo incluidas acceden de manera indirecta a estas funciones y por eso me compilaba pero con warnings.

Muchas gracias.
135  Programación / Programación C/C++ / Warnings en gcc -Wall en: 4 Abril 2012, 00:34 am
¡Buenas a todos!

Tengo los siguientes warnings en gcc y no se porque:

Warning 1:
Citar
sendPacket3.c: In function ‘CreateEthernetHeader’:
sendPacket3.c:120: warning: implicit declaration of function ‘ether_aton’

Código
  1. void * sourceMAC;
  2.        sourceMAC =(void *) ether_aton(src_mac);  //linea 120
  3.  
  4.  

Warning 2-3
Citar
sendPacket3.c: In function ‘sendPacket’:
sendPacket3.c:309: warning: pointer targets in assignment differ in signedness
sendPacket3.c:383: warning: implicit declaration of function ‘close’

Código
  1.        unsigned char *data;
  2.        int pkt_len;
  3.  
  4.        //data = CreateData(DATA_SIZE);
  5.        data="<html>HOLA</html>";  //linea 309
  6.        int DATA_SIZE=0;
  7.        DATA_SIZE=17;//strlen((const char *)data);
  8.  
  9.        /**************************************************/
  10.  
  11.        int raw;
  12.                 // por aqui sigen varias lineas de codigo....
  13.        close(raw);  //linea 383
  14.  

Warning 4
Citar
main.c: In function ‘main’:
main.c:16: warning: implicit declaration of function ‘atoi’

Código
  1.    int srcPort,destPort, seqnum, acknum, urg,ack,psh,rst,syn,fin;
  2.                srcPort=atoi(argv[3]); //esta es la linea 16...
  3.                destPort=atoi(argv[5]);
  4.                seqnum=atoi(argv[6]);
  5.                acknum=atoi(argv[7]);
  6.                urg=atoi(argv[8]);
  7.                ack=atoi(argv[9]);
  8.                psh=atoi(argv[10]);
  9.                rst=atoi(argv[11]);
  10.                syn=atoi(argv[12]);
  11.                fin=atoi(argv[13]);
  12.  
  13.  

¿Alguna idea de como solucionar estos warnings?
136  Programación / Programación C/C++ / CheckSum TCP en C en: 30 Marzo 2012, 15:46 pm
¡Buenas!

¿Podriais decirme porque no me crea bien el checksum?
Código
  1. /* Tama~o del paquete TCP */
  2. unsigned int buffer_size = sizeof(struct iphdr) + sizeof(struct tcphdr);
  3.  
  4. /* Buffer de tama~o suficiente para un paquete TCP */
  5. unsigned char buffer[buffer_size];
  6. memset (buffer,0,buffer_size);
  7.  
  8. /* Cabecera IP */
  9. struct iphdr *ip = (struct iphdr *)buffer;
  10.  
  11. /* Cabecera TCP */
  12. struct tcphdr *tcp = (struct tcphdr *)(buffer + sizeof(struct iphdr));
  13. /*
  14.    Aqui relleno la cabecera TCP y la de IP
  15. */
  16. unsigned short CheckSum(unsigned short *buffer, int size)
  17. {
  18.    unsigned long cksum=0;
  19.    while(size >1)
  20.    {
  21.        cksum+=*buffer++;
  22.        size -=sizeof(unsigned short);
  23.    }
  24.    if(size)
  25.        cksum += *(unsigned char*)buffer;
  26.  
  27.    cksum = (cksum >> 16) + (cksum & 0xffff);
  28.    cksum += (cksum >>16);
  29.    return (unsigned short)(~cksum);
  30. }
  31.  
  32. tcp->check=CheckSum((unsigned short int*)buffer,buffer_size);
  33.  
  34.  

Gracias, un saludo.
137  Programación / Programación C/C++ / Re: Enviar paquetes TCP/IP en: 29 Marzo 2012, 17:16 pm
¡Buenas a todos!

Bueno, dado mi nivel de mediocridad para el lenguaje C al final no he sabido solucionar el problema....pero he encontrado un enlace espectacular donde esta el codigo que necesitaba bien programado. La verdad es que la info de este blog es buenisima y muy recomendable para la gente que quiera programar socket y aprender sobre estos.

http://dlerch.blogspot.com.es/2007/05/raw-sockets.html

Un saludo.
138  Programación / Programación C/C++ / Re: Enviar paquetes TCP/IP en: 28 Marzo 2012, 17:45 pm
Muchas gracias!

Eso es precisamente lo que necesitaba.

Bueno por ahora tengo este codigo....y ando un poco atascado.
No se como especificar mi ip de origen, y tampoco se porque me manda los FLAGS: FYN SYN PSH y NS, cuando en realidad solo deberia mandar el SYN....
Código
  1. #include <sys/types.h>
  2. #define __FAVOR_BSD
  3. #include <sys/socket.h>
  4. #include <stdio.h>
  5. #include <netdb.h>
  6. #include <netinet/ip.h>
  7. #include <netinet/tcp.h>
  8. #include <arpa/inet.h>
  9. #include <string.h>
  10. char data[1024] = "";
  11.  
  12.  
  13.  
  14. unsigned short csum(unsigned short *buf,int nwords)
  15. {
  16. //this function returns the checksum of a buffer
  17. unsigned long sum;
  18. for (sum = 0; nwords > 0; nwords--){sum += *buf++;}
  19. sum = (sum >> 16) + (sum & 0xffff);
  20. sum += (sum >> 16);
  21. return (unsigned short) (~sum);
  22. }
  23.  
  24. int createRaw(int protocol_to_sniff)
  25. {
  26. int raw_fd = socket(AF_INET, SOCK_RAW, protocol_to_sniff);
  27. if (raw_fd < 0)
  28. {
  29. printf("ERROR creating raw socket\n");
  30. return(1);
  31. }else{
  32. printf( "Raw Socket Created! :-D\n");
  33. return raw_fd;
  34. }
  35. }
  36. int bindRaw(int socketToBind,struct sockaddr_in *sin)
  37. {
  38. int err = bind(socketToBind,(struct sockaddr *)sin,sizeof(*sin));
  39. if (err < 0)
  40. {
  41. printf("ERROR binding socket.\n");
  42. return(1);
  43. }else{
  44. printf("Bound socket! :-D\n");
  45. return 0;
  46. }
  47. }
  48.  
  49. int main(int argc,char* argv[])
  50. {
  51. //create raw socket for binding
  52. int bindSocket = createRaw(6);
  53.  
  54. //create structures
  55. struct sockaddr_in sin;
  56. unsigned char packetBuf[4096];
  57.  
  58. //specify port to bind to
  59. bzero((char *)&sin,sizeof(sin));
  60. sin.sin_port = htons(55000);
  61.  
  62. //bind socket
  63. bindRaw(bindSocket,&sin);
  64.  
  65. //inform os of recieving raw ip packet
  66. {
  67. int tmp = 1;
  68. setsockopt(bindSocket, 0, IP_HDRINCL,&tmp,sizeof(tmp));
  69. }
  70.  
  71. //re-use socket structure
  72. //Details about where this custom packet is going:
  73. bzero((char *)& sin, sizeof(sin));
  74. sin.sin_family = AF_INET;
  75. sin.sin_port = htons(55000); //port to send packet to
  76. sin.sin_addr.s_addr = inet_addr("173.194.34.215"); //IP to send packet to
  77.  
  78.  
  79. unsigned short buffer_size = sizeof(struct ip) + sizeof(struct tcphdr);//+ sizeof(data);
  80. //cout << "Buffer size: " << buffer_size << endl;
  81.  
  82. struct ip *IPheader = (struct ip *) packetBuf;
  83. struct tcphdr *TCPheader = (struct tcphdr *) (packetBuf + sizeof (struct ip));
  84.  
  85. //Fill out IP Header information:
  86. IPheader->ip_hl = 5;
  87. IPheader->ip_v = 4; //IPv4
  88. IPheader->ip_tos = 0; //type of service
  89. IPheader->ip_len = htons(buffer_size); //length
  90. IPheader->ip_id = htonl(54321);
  91. IPheader->ip_off = 0;
  92. IPheader->ip_ttl = 255; //max routers to pass through
  93. IPheader->ip_p = 6; //tcp
  94. IPheader->ip_sum = 0; //Set to 0 before calulating later
  95. IPheader->ip_src.s_addr = inet_addr("11.11.11.11"); //source IP address
  96. IPheader->ip_dst.s_addr = inet_addr("173.194.34.215"); //destination IP address
  97.  
  98. //Fill out TCP Header information:
  99. TCPheader->th_sport = htons(55000); //source port
  100. TCPheader->th_dport = htons(55000); //destination port
  101. TCPheader->th_seq = 0;
  102. TCPheader->th_ack = 0; //Only 0 on initial SYN
  103. TCPheader->th_off = 0;
  104. TCPheader->th_flags = TH_SYN; //SYN flag set
  105. TCPheader->th_win = htonl(65535); //used for segmentation
  106. TCPheader->th_sum = 0; //Kernel fill this out
  107. TCPheader->th_urp = 0;
  108.  
  109. //Now fill out the checksum for the IPheader
  110. IPheader->ip_sum = csum((unsigned short *) packetBuf, IPheader->ip_len >> 1);
  111. //cout << "IP Checksum: " << IPheader->ip_sum << endl;
  112. //create raw socket for sending ip packet
  113. int sendRaw = createRaw(6);
  114. if (sendRaw < 0)
  115. {
  116. printf( "ERROR creating raw socket for sending.\n");
  117. return(1);
  118. }else{
  119. printf( "Raw socket created for sending! :-D\n");
  120. }
  121. int sendErr = sendto(sendRaw,packetBuf,
  122. sizeof(packetBuf),0,(struct sockaddr *)&sin,sizeof(sin));
  123.  
  124. if (sendErr < sizeof(packetBuf))
  125. {
  126. //cout << sendErr << " out of " << sizeof(packetBuf) << " were sent.\n";
  127. return(1);
  128. }else{
  129. //cout << "<" << sendErr << "> Sent message!!! :-D\n";
  130. }
  131.  
  132. printf( "Sleeping for 2 seconds");
  133. sleep(1);
  134. printf(".");
  135. sleep(1);
  136. printf(".\n");
  137. char recvPacket[4096] = "";
  138. int newData = recv(bindSocket,recvPacket,sizeof(recvPacket),0);
  139. if (newData <=0)
  140. {
  141. //cout << newData << " returned by recv! :(\n";
  142. return(1);
  143. }else{
  144. //cout << "<" << newData << "> RECIEVE SUCCESSFULL!! :-D\n";
  145. }
  146.  
  147. return 0;
  148. }
  149.  
  150.  

¿alguna idea?

Gracias.
139  Programación / Programación C/C++ / Re: Iniciar un programa al arrancar el PC. en: 27 Marzo 2012, 21:03 pm
Eternal_Idol tiene razon. Los autorun.inf son ficheros que windows detecta como fichero de arranque. Estos solo te sirven cuando tienes un windows instalado. Pero si lo que quieres es que tu aplicacion se arranque sin el sistema operativo tienes que hacer que tu aplicacion guarde en el sector de arranque de la memoria (ya sea un CD, un DVD, un pendrive, etc).

Un saludo.
140  Programación / Programación C/C++ / Re: Enviar paquetes TCP/IP en: 27 Marzo 2012, 20:59 pm
Gracias por la ayuda.

Yo mas que un libro sobre redes lo que necesito es saber mas de C. La teoria de redes me la se bastante bien, mi problema viene al implementarlo.

Lo que pretendo es hacer un programa tipo hping3. Este es un programa que te permite mandar paquetes TCP (y de mas tipo) dejandote elegir la ip de origen, la ip de destino, el nº de secuencia, el nº de ACK, y los FLAGS de TCP.

Entonces solo necesito (mas o menos) sabes cual es la instruccion de C para enviar un paquete TCP pasandole por parametro los campos de la cabecera de un paquete TCP.

Un saludo.
Páginas: 1 2 3 4 5 6 7 8 9 10 11 12 13 [14] 15 16 17 18 19 20 21 22
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines