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

 

 


Tema destacado: Arreglado, de nuevo, el registro del warzone (wargame) de EHN


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Cual seria la mejor forma de enviar una foto? en: 1 Enero 2016, 20:44 pm
Hace unos dias estuve trabajando en una troyano , acabe casi todo pero lo que me queda es enviar unos archivos de texto y unas imagenes.Si alquien me podria ayudar,con los archivos de text tengo alguna idea , pero no se como enviar las imagenes.Estoy buscando informacion en C/C++.
2  Programación / Programación C/C++ / Re: Como podria la URL actual del browser? en: 29 Agosto 2015, 16:32 pm
Gracias,al final fue la interfaz.Muchas gracias por la ayuda :D!
3  Programación / Programación C/C++ / Re: Como podria la URL actual del browser? en: 28 Agosto 2015, 15:52 pm
El subforo esta bien.
Muestra el código y prueba con una página que no sea https

Código
  1. #include "stdio.h"
  2. #include "winsock2.h"
  3.  
  4.  
  5. #define SIO_RCVALL _WSAIOW(IOC_VENDOR,1) //this removes the need of mstcpip.h
  6.  
  7. void StartSniffing (SOCKET Sock); //This will sniff here and there
  8.  
  9. void ProcessPacket (char* , int); //This will show they type of the sniffed packets
  10. void PrintIpHeader (char*);
  11. void PrintIcmpPacket (char* , int);
  12. void PrintUdpPacket (char* , int);
  13. void PrintTcpPacket (char* , int);
  14. void ConvertToHex (char* , unsigned int);
  15. void PrintData (char* , int);
  16.  
  17. typedef struct ip_hdr
  18. {
  19. unsigned char ip_header_len:4; // 4-bit header length (in 32-bit words) normally=5 (Means 20 Bytes may be 24 also)
  20. unsigned char ip_version :4; // 4-bit IPv4 version
  21. unsigned char ip_tos; // IP type of service
  22. unsigned short ip_total_length; // Total length
  23. unsigned short ip_id; // Unique identifier
  24.  
  25. unsigned char ip_frag_offset :5; // Fragment offset field
  26.  
  27. unsigned char ip_more_fragment :1;
  28. unsigned char ip_dont_fragment :1;
  29. unsigned char ip_reserved_zero :1;
  30.  
  31. unsigned char ip_frag_offset1; //fragment offset
  32.  
  33. unsigned char ip_ttl; // Time to live
  34. unsigned char ip_protocol; // Protocol(TCP,UDP etc)
  35. unsigned short ip_checksum; // IP checksum
  36. unsigned int ip_srcaddr; // Source address
  37. unsigned int ip_destaddr; // Source address
  38. } IPV4_HDR;
  39.  
  40. typedef struct udp_hdr
  41. {
  42. unsigned short source_port; // Source port no.
  43. unsigned short dest_port; // Dest. port no.
  44. unsigned short udp_length; // Udp packet length
  45. unsigned short udp_checksum; // Udp checksum (optional)
  46. } UDP_HDR;
  47.  
  48. // TCP header
  49. typedef struct tcp_header
  50. {
  51. unsigned short source_port; // source port
  52. unsigned short dest_port; // destination port
  53. unsigned int sequence; // sequence number - 32 bits
  54. unsigned int acknowledge; // acknowledgement number - 32 bits
  55.  
  56. unsigned char ns :1; //Nonce Sum Flag Added in RFC 3540.
  57. unsigned char reserved_part1:3; //according to rfc
  58. unsigned char data_offset:4; /*The number of 32-bit words in the TCP header.
  59. This indicates where the data begins.
  60. The length of the TCP header is always a multiple
  61. of 32 bits.*/
  62.  
  63. unsigned char fin :1; //Finish Flag
  64. unsigned char syn :1; //Synchronise Flag
  65. unsigned char rst :1; //Reset Flag
  66. unsigned char psh :1; //Push Flag
  67. unsigned char ack :1; //Acknowledgement Flag
  68. unsigned char urg :1; //Urgent Flag
  69.  
  70. unsigned char ecn :1; //ECN-Echo Flag
  71. unsigned char cwr :1; //Congestion Window Reduced Flag
  72.  
  73. ////////////////////////////////
  74.  
  75. unsigned short window; // window
  76. unsigned short checksum; // checksum
  77. unsigned short urgent_pointer; // urgent pointer
  78. } TCP_HDR;
  79.  
  80. typedef struct icmp_hdr
  81. {
  82. BYTE type; // ICMP Error type
  83. BYTE code; // Type sub code
  84. USHORT checksum;
  85. USHORT id;
  86. USHORT seq;
  87. } ICMP_HDR;
  88.  
  89. FILE *logfile;
  90. int tcp=0,udp=0,icmp=0,others=0,igmp=0,total=0,i,j;
  91. struct sockaddr_in source,dest;
  92. char hex[2];
  93.  
  94. //Its free!
  95. IPV4_HDR *iphdr;
  96. TCP_HDR *tcpheader;
  97. UDP_HDR *udpheader;
  98. ICMP_HDR *icmpheader;
  99.  
  100. int main()
  101. {
  102. SOCKET sniffer;
  103. struct in_addr addr;
  104. int in;
  105.  
  106. char hostname[100];
  107. struct hostent *local;
  108. WSADATA wsa;
  109.  
  110. logfile=fopen("log.txt","w");
  111. if(logfile == NULL)
  112. {
  113. printf("Unable to create file.");
  114. }
  115.  
  116. //Initialise Winsock
  117. printf("\nInitialising Winsock...");
  118. if (WSAStartup(MAKEWORD(2,2), &wsa) != 0)
  119. {
  120. printf("WSAStartup() failed.\n");
  121. return 1;
  122. }
  123. printf("Initialised");
  124.  
  125. //Create a RAW Socket
  126. printf("\nCreating RAW Socket...");
  127. sniffer = socket(AF_INET, SOCK_RAW, IPPROTO_IP);
  128. if (sniffer == INVALID_SOCKET)
  129. {
  130. printf("Failed to create raw socket.\n");
  131. return 1;
  132. }
  133. printf("Created.");
  134.  
  135. //Retrive the local hostname
  136. if (gethostname(hostname, sizeof(hostname)) == SOCKET_ERROR)
  137. {
  138. printf("Error : %d",WSAGetLastError());
  139. return 1;
  140. }
  141. printf("\nHost name : %s \n",hostname);
  142.  
  143. //Retrive the available IPs of the local host
  144. local = gethostbyname(hostname);
  145. printf("\nAvailable Network Interfaces : \n");
  146. if (local == NULL)
  147. {
  148. printf("Error : %d.\n",WSAGetLastError());
  149. return 1;
  150. }
  151.  
  152. //Sniffing on all of the interfaces
  153. for (i = 0; local->h_addr_list[i] != 0; ++i)
  154. {
  155. memcpy(&addr, local->h_addr_list[i], sizeof(struct in_addr));
  156. memset(&dest, 0, sizeof(dest));
  157.    memcpy(&dest.sin_addr.s_addr,local->h_addr_list[1],sizeof(dest.sin_addr.s_addr));
  158.    dest.sin_family = AF_INET;
  159.    dest.sin_port = 0;
  160. }
  161.  
  162. /*printf("Enter the interface number you would like to sniff : ");
  163. scanf("%d",&in);*/
  164.  
  165.  
  166.  
  167. printf("\nBinding socket to local system and port 0 ...");
  168. if (bind(sniffer,(struct sockaddr *)&dest,sizeof(dest)) == SOCKET_ERROR)
  169. {
  170. printf("bind(%s) failed.\n", inet_ntoa(addr));
  171. return 1;
  172. }
  173. printf("Binding successful");
  174.  
  175. //Enable this socket with the power to sniff : SIO_RCVALL is the key Receive ALL ;)
  176.  
  177. j=1;
  178. printf("\nSetting socket to sniff...");
  179. if (WSAIoctl(sniffer, SIO_RCVALL, &j, sizeof(j), 0, 0, (LPDWORD) &in , 0 , 0) == SOCKET_ERROR)
  180. {
  181. printf("WSAIoctl() failed.\n");
  182. return 1;
  183. }
  184. printf("Socket set.");
  185.  
  186. //Begin
  187. printf("\nStarted Sniffing\n");
  188. printf("Packet Capture Statistics...\n");
  189. StartSniffing(sniffer);
  190.  
  191. //End
  192. closesocket(sniffer);
  193. WSACleanup();
  194.  
  195. return 0;
  196. }
  197.  
  198. void StartSniffing(SOCKET sniffer)
  199. {
  200. char *Buffer = (char *)malloc(65536);
  201. int mangobyte;
  202.  
  203. if (Buffer == NULL)
  204. {
  205. printf("malloc() failed.\n");
  206. return;
  207. }
  208.  
  209. do
  210. {
  211. mangobyte = recvfrom(sniffer , Buffer , 65536 , 0 , 0 , 0);
  212.  
  213. if(mangobyte > 0)
  214. {
  215. ProcessPacket(Buffer, mangobyte);
  216. }
  217. else
  218. {
  219. printf( "recvfrom() failed.\n");
  220. }
  221. }
  222. while (mangobyte > 0);
  223.  
  224. free(Buffer);
  225. }
  226.  
  227. void ProcessPacket(char* Buffer, int Size)
  228. {
  229. iphdr = (IPV4_HDR *)Buffer;
  230. ++total;
  231.  
  232. switch (iphdr->ip_protocol) //Check the Protocol and do accordingly...
  233. {
  234. case 1: //ICMP Protocol
  235. ++icmp;
  236. PrintIcmpPacket(Buffer,Size);
  237. break;
  238.  
  239. case 2: //IGMP Protocol
  240. ++igmp;
  241. break;
  242.  
  243. case 6: //TCP Protocol
  244. ++tcp;
  245. PrintTcpPacket(Buffer,Size);
  246. break;
  247.  
  248. case 17: //UDP Protocol
  249. ++udp;
  250. PrintUdpPacket(Buffer,Size);
  251. break;
  252.  
  253. default: //Some Other Protocol like ARP etc.
  254. ++others;
  255. break;
  256. }
  257. printf("TCP : %d UDP : %d ICMP : %d IGMP : %d Others : %d Total : %d\r",tcp,udp,icmp,igmp,others,total);
  258. }
  259.  
  260.  
  261. void PrintIpHeader (char* Buffer )
  262. {
  263. unsigned short iphdrlen;
  264.  
  265. iphdr = (IPV4_HDR *)Buffer;
  266. iphdrlen = iphdr->ip_header_len*4;
  267.  
  268. memset(&source, 0, sizeof(source));
  269. source.sin_addr.s_addr = iphdr->ip_srcaddr;
  270.  
  271. memset(&dest, 0, sizeof(dest));
  272. dest.sin_addr.s_addr = iphdr->ip_destaddr;
  273.  
  274. fprintf(logfile,"\n");
  275. fprintf(logfile,"IP Header\n");
  276. fprintf(logfile," |-IP Version : %d\n",(unsigned int)iphdr->ip_version);
  277. fprintf(logfile," |-IP Header Length : %d DWORDS or %d Bytes\n",(unsigned int)iphdr->ip_header_len,((unsigned int)(iphdr->ip_header_len))*4);
  278. fprintf(logfile," |-Type Of Service : %d\n",(unsigned int)iphdr->ip_tos);
  279. fprintf(logfile," |-IP Total Length : %d Bytes(Size of Packet)\n",ntohs(iphdr->ip_total_length));
  280. fprintf(logfile," |-Identification : %d\n",ntohs(iphdr->ip_id));
  281. fprintf(logfile," |-Reserved ZERO Field : %d\n",(unsigned int)iphdr->ip_reserved_zero);
  282. fprintf(logfile," |-Dont Fragment Field : %d\n",(unsigned int)iphdr->ip_dont_fragment);
  283. fprintf(logfile," |-More Fragment Field : %d\n",(unsigned int)iphdr->ip_more_fragment);
  284. fprintf(logfile," |-TTL : %d\n",(unsigned int)iphdr->ip_ttl);
  285. fprintf(logfile," |-Protocol : %d\n",(unsigned int)iphdr->ip_protocol);
  286. fprintf(logfile," |-Checksum : %d\n",ntohs(iphdr->ip_checksum));
  287. fprintf(logfile," |-Source IP : %s\n",inet_ntoa(source.sin_addr));
  288. fprintf(logfile," |-Destination IP : %s\n",inet_ntoa(dest.sin_addr));
  289. }
  290.  
  291. //Prints all the sniffed DATA(TCP,UDP,ICMP)
  292.  
  293. void PrintTcpPacket(char* Buffer, int Size)
  294. {
  295. unsigned short iphdrlen;
  296.  
  297. iphdr = (IPV4_HDR *)Buffer;
  298. iphdrlen = iphdr->ip_header_len*4;
  299.  
  300. tcpheader=(TCP_HDR*)(Buffer+iphdrlen);
  301.  
  302. fprintf(logfile,"\n\n***********************TCP Packet*************************\n");
  303.  
  304. PrintIpHeader( Buffer );
  305.  
  306. fprintf(logfile,"\n");
  307. fprintf(logfile,"TCP Header\n");
  308. fprintf(logfile," |-Source Port : %u\n",ntohs(tcpheader->source_port));
  309. fprintf(logfile," |-Destination Port : %u\n",ntohs(tcpheader->dest_port));
  310. fprintf(logfile," |-Sequence Number : %u\n",ntohl(tcpheader->sequence));
  311. fprintf(logfile," |-Acknowledge Number : %u\n",ntohl(tcpheader->acknowledge));
  312. fprintf(logfile," |-Header Length : %d DWORDS or %d BYTES\n"
  313. ,(unsigned int)tcpheader->data_offset,(unsigned int)tcpheader->data_offset*4);
  314. fprintf(logfile," |-CWR Flag : %d\n",(unsigned int)tcpheader->cwr);
  315. fprintf(logfile," |-ECN Flag : %d\n",(unsigned int)tcpheader->ecn);
  316. fprintf(logfile," |-Urgent Flag : %d\n",(unsigned int)tcpheader->urg);
  317. fprintf(logfile," |-Acknowledgement Flag : %d\n",(unsigned int)tcpheader->ack);
  318. fprintf(logfile," |-Push Flag : %d\n",(unsigned int)tcpheader->psh);
  319. fprintf(logfile," |-Reset Flag : %d\n",(unsigned int)tcpheader->rst);
  320. fprintf(logfile," |-Synchronise Flag : %d\n",(unsigned int)tcpheader->syn);
  321. fprintf(logfile," |-Finish Flag : %d\n",(unsigned int)tcpheader->fin);
  322. fprintf(logfile," |-Window : %d\n",ntohs(tcpheader->window));
  323. fprintf(logfile," |-Checksum : %d\n",ntohs(tcpheader->checksum));
  324. fprintf(logfile," |-Urgent Pointer : %d\n",tcpheader->urgent_pointer);
  325. fprintf(logfile,"\n");
  326. fprintf(logfile," DATA Dump ");
  327. fprintf(logfile,"\n");
  328.  
  329. fprintf(logfile,"IP Header\n");
  330. PrintData(Buffer,iphdrlen);
  331.  
  332. fprintf(logfile,"TCP Header\n");
  333. PrintData(Buffer+iphdrlen,tcpheader->data_offset*4);
  334.  
  335. fprintf(logfile,"Data Payload\n");
  336. PrintData(Buffer+iphdrlen+tcpheader->data_offset*4
  337. ,(Size-tcpheader->data_offset*4-iphdr->ip_header_len*4));
  338.  
  339. fprintf(logfile,"\n###########################################################");
  340. }
  341.  
  342. void PrintUdpPacket(char *Buffer,int Size)
  343. {
  344. unsigned short iphdrlen;
  345.  
  346. iphdr = (IPV4_HDR *)Buffer;
  347. iphdrlen = iphdr->ip_header_len*4;
  348.  
  349. udpheader = (UDP_HDR *)(Buffer + iphdrlen);
  350.  
  351. fprintf(logfile,"\n\n***********************UDP Packet*************************\n");
  352.  
  353. PrintIpHeader(Buffer);
  354.  
  355. fprintf(logfile,"\nUDP Header\n");
  356. fprintf(logfile," |-Source Port : %d\n",ntohs(udpheader->source_port));
  357. fprintf(logfile," |-Destination Port : %d\n",ntohs(udpheader->dest_port));
  358. fprintf(logfile," |-UDP Length : %d\n",ntohs(udpheader->udp_length));
  359. fprintf(logfile," |-UDP Checksum : %d\n",ntohs(udpheader->udp_checksum));
  360.  
  361. fprintf(logfile,"\n");
  362. fprintf(logfile,"IP Header\n");
  363.  
  364. PrintData(Buffer,iphdrlen);
  365.  
  366. fprintf(logfile,"UDP Header\n");
  367.  
  368. PrintData(Buffer+iphdrlen,sizeof(UDP_HDR));
  369.  
  370. fprintf(logfile,"Data Payload\n");
  371.  
  372. PrintData(Buffer+iphdrlen+sizeof(UDP_HDR) ,(Size - sizeof(UDP_HDR) - iphdr->ip_header_len*4));
  373.  
  374. fprintf(logfile,"\n###########################################################");
  375. }
  376.  
  377. void PrintIcmpPacket(char* Buffer , int Size)
  378. {
  379. unsigned short iphdrlen;
  380.  
  381. iphdr = (IPV4_HDR *)Buffer;
  382. iphdrlen = iphdr->ip_header_len*4;
  383.  
  384. icmpheader=(ICMP_HDR*)(Buffer+iphdrlen);
  385.  
  386. fprintf(logfile,"\n\n***********************ICMP Packet*************************\n");
  387. PrintIpHeader(Buffer);
  388.  
  389. fprintf(logfile,"\n");
  390.  
  391. fprintf(logfile,"ICMP Header\n");
  392. fprintf(logfile," |-Type : %d",(unsigned int)(icmpheader->type));
  393.  
  394. if((unsigned int)(icmpheader->type)==11)
  395. {
  396. fprintf(logfile," (TTL Expired)\n");
  397. }
  398. else if((unsigned int)(icmpheader->type)==0)
  399. {
  400. fprintf(logfile," (ICMP Echo Reply)\n");
  401. }
  402.  
  403. fprintf(logfile," |-Code : %d\n",(unsigned int)(icmpheader->code));
  404. fprintf(logfile," |-Checksum : %d\n",ntohs(icmpheader->checksum));
  405. fprintf(logfile," |-ID : %d\n",ntohs(icmpheader->id));
  406. fprintf(logfile," |-Sequence : %d\n",ntohs(icmpheader->seq));
  407. fprintf(logfile,"\n");
  408.  
  409. fprintf(logfile,"IP Header\n");
  410. PrintData(Buffer,iphdrlen);
  411.  
  412. fprintf(logfile,"UDP Header\n");
  413. PrintData(Buffer+iphdrlen,sizeof(ICMP_HDR));
  414.  
  415. fprintf(logfile,"Data Payload\n");
  416. PrintData(Buffer+iphdrlen+sizeof(ICMP_HDR) , (Size - sizeof(ICMP_HDR) - iphdr->ip_header_len*4));
  417.  
  418. fprintf(logfile,"\n###########################################################");
  419. }
  420.  
  421. /*
  422. Print the hex values of the data
  423. */
  424. void PrintData (char* data , int Size)
  425. {
  426. char a , line[17] , c;
  427. int j;
  428.  
  429. //loop over each character and print
  430. for(i=0 ; i < Size ; i++)
  431. {
  432. c = data[i];
  433.  
  434. //Print the hex value for every character , with a space. Important to make unsigned
  435. fprintf(logfile," %.2x", (unsigned char) c);
  436.  
  437. //Add the character to data line. Important to make unsigned
  438. a = ( c >=32 && c <=128) ? (unsigned char) c : '.';
  439.  
  440. line[i%16] = a;
  441.  
  442. //if last character of a line , then print the line - 16 characters in 1 line
  443. if( (i!=0 && (i+1)%16==0) || i == Size - 1)
  444. {
  445. line[i%16 + 1] = '\0';
  446.  
  447. //print a big gap of 10 characters between hex and characters
  448. fprintf(logfile ,"          ");
  449.  
  450. //Print additional spaces for last lines which might be less than 16 characters in length
  451. for( j = strlen(line) ; j < 16; j++)
  452. {
  453. fprintf(logfile , "   ");
  454. }
  455.  
  456. fprintf(logfile , "%s \n" , line);
  457. }
  458. }
  459.  
  460. fprintf(logfile , "\n");
  461. }
  462.  

Aqui esta todo el programa,intente sniffear pero no funciono nada de nada solo recibia UDP.
4  Programación / Programación C/C++ / Re: Como podria la URL actual del browser? en: 27 Agosto 2015, 18:03 pm
Como el subforo es de C/C++ busco hacerlo en C o C++,no encontre casi nada buscandolo en ingles :/,bueno a lo mejor no busque bien, por lo que entendi los metodos de extraer la URL de un browser varian segun el tipo del browser.Intente hacer sniffing con raw sockets para monotorizar el ordenador,tenia tambien un algoritmo de busqueda de URLs "google.com" o "msdn.com" pero cuando ejecute el programa de sniffing e intentaba conectarme a google.com recibia datos criptados o basura.Lo de la consola lo dije porque no pienso hacer algo como el wireshark con interfaz.



subforo equivocado amigo
Estas seguro "amigo" ?
5  Programación / Programación C/C++ / Como podria la URL actual del browser? en: 27 Agosto 2015, 16:17 pm
Como podria ver la URL del browser por ejemplo yo abro firefox y voy a google.com como podria ver esto en la consola?
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines