patch-tcpkill_c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. --- dsniff-2.4.orig/tcpkill.c 2001-03-17 09:10:43.000000000 +0100
  2. +++ dsniff-2.4/tcpkill.c 2009-12-11 12:59:42.000000000 +0100
  3. @@ -39,17 +39,18 @@ usage(void)
  4. static void
  5. tcp_kill_cb(u_char *user, const struct pcap_pkthdr *pcap, const u_char *pkt)
  6. {
  7. - struct libnet_ip_hdr *ip;
  8. + struct libnet_ipv4_hdr *ip;
  9. struct libnet_tcp_hdr *tcp;
  10. - u_char ctext[64], buf[IP_H + TCP_H];
  11. + u_char ctext[64];
  12. u_int32_t seq, win;
  13. - int i, *sock, len;
  14. + int i, len;
  15. + libnet_t *l;
  16. - sock = (int *)user;
  17. + l = (libnet_t *)user;
  18. pkt += pcap_off;
  19. len = pcap->caplen - pcap_off;
  20. - ip = (struct libnet_ip_hdr *)pkt;
  21. + ip = (struct libnet_ipv4_hdr *)pkt;
  22. if (ip->ip_p != IPPROTO_TCP)
  23. return;
  24. @@ -57,34 +58,31 @@ tcp_kill_cb(u_char *user, const struct p
  25. if (tcp->th_flags & (TH_SYN|TH_FIN|TH_RST))
  26. return;
  27. - libnet_build_ip(TCP_H, 0, 0, 0, 64, IPPROTO_TCP,
  28. - ip->ip_dst.s_addr, ip->ip_src.s_addr,
  29. - NULL, 0, buf);
  30. -
  31. - libnet_build_tcp(ntohs(tcp->th_dport), ntohs(tcp->th_sport),
  32. - 0, 0, TH_RST, 0, 0, NULL, 0, buf + IP_H);
  33. -
  34. seq = ntohl(tcp->th_ack);
  35. win = ntohs(tcp->th_win);
  36. snprintf(ctext, sizeof(ctext), "%s:%d > %s:%d:",
  37. - libnet_host_lookup(ip->ip_src.s_addr, 0),
  38. + libnet_addr2name4(ip->ip_src.s_addr, LIBNET_DONT_RESOLVE),
  39. ntohs(tcp->th_sport),
  40. - libnet_host_lookup(ip->ip_dst.s_addr, 0),
  41. + libnet_addr2name4(ip->ip_dst.s_addr, LIBNET_DONT_RESOLVE),
  42. ntohs(tcp->th_dport));
  43. - ip = (struct libnet_ip_hdr *)buf;
  44. - tcp = (struct libnet_tcp_hdr *)(ip + 1);
  45. -
  46. for (i = 0; i < Opt_severity; i++) {
  47. - ip->ip_id = libnet_get_prand(PRu16);
  48. seq += (i * win);
  49. - tcp->th_seq = htonl(seq);
  50. - libnet_do_checksum(buf, IPPROTO_TCP, TCP_H);
  51. + libnet_clear_packet(l);
  52. - if (libnet_write_ip(*sock, buf, sizeof(buf)) < 0)
  53. - warn("write_ip");
  54. + libnet_build_tcp(ntohs(tcp->th_dport), ntohs(tcp->th_sport),
  55. + seq, 0, TH_RST, 0, 0, 0, LIBNET_TCP_H,
  56. + NULL, 0, l, 0);
  57. +
  58. + libnet_build_ipv4(LIBNET_IPV4_H + LIBNET_TCP_H, 0,
  59. + libnet_get_prand(LIBNET_PRu16), 0, 64,
  60. + IPPROTO_TCP, 0, ip->ip_dst.s_addr,
  61. + ip->ip_src.s_addr, NULL, 0, l, 0);
  62. +
  63. + if (libnet_write(l) < 0)
  64. + warn("write");
  65. fprintf(stderr, "%s R %lu:%lu(0) win 0\n", ctext, seq, seq);
  66. }
  67. @@ -95,8 +93,10 @@ main(int argc, char *argv[])
  68. {
  69. extern char *optarg;
  70. extern int optind;
  71. - int c, sock;
  72. + int c;
  73. char *p, *intf, *filter, ebuf[PCAP_ERRBUF_SIZE];
  74. + char libnet_ebuf[LIBNET_ERRBUF_SIZE];
  75. + libnet_t *l;
  76. pcap_t *pd;
  77. intf = NULL;
  78. @@ -136,14 +136,14 @@ main(int argc, char *argv[])
  79. if ((pcap_off = pcap_dloff(pd)) < 0)
  80. errx(1, "couldn't determine link layer offset");
  81. - if ((sock = libnet_open_raw_sock(IPPROTO_RAW)) == -1)
  82. + if ((l = libnet_init(LIBNET_RAW4, intf, libnet_ebuf)) == NULL)
  83. errx(1, "couldn't initialize sending");
  84. - libnet_seed_prand();
  85. + libnet_seed_prand(l);
  86. warnx("listening on %s [%s]", intf, filter);
  87. - pcap_loop(pd, -1, tcp_kill_cb, (u_char *)&sock);
  88. + pcap_loop(pd, -1, tcp_kill_cb, (u_char *)l);
  89. /* NOTREACHED */