Your message dated Mon, 13 Aug 2007 21:02:04 +0000
with message-id <[EMAIL PROTECTED]>
and subject line Bug#240054: fixed in ngrep 1.45.ds1-2
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--- Begin Message ---
Package: ngrep
Version: 1.40.1-3
Severity: wishlist
Tags: patch

The patch below adds tcpkill support to ngrep.  Use the new -K option
to kill matching TCP connections.

This approach is rather crude, but it seems quite effective.

diff -u --recursive --new-file original/ngrep-1.40.1/COPYRIGHT 
hacks/ngrep-1.40.1/COPYRIGHT
--- original/ngrep-1.40.1/COPYRIGHT     2001-04-24 07:14:30.000000000 +0200
+++ hacks/ngrep-1.40.1/COPYRIGHT        2004-03-25 14:58:36.000000000 +0100
@@ -35,3 +35,32 @@
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Portions were copied from tcpkill (part of dsniff), which has the
+following copyright:
+
+  Copyright (c) 1999, 2000 Dug Song <[EMAIL PROTECTED]>
+  All rights reserved, all wrongs reversed.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. The name of author may not be used to endorse or promote products
+     derived from this software without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+  THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff -u --recursive --new-file original/ngrep-1.40.1/Makefile.in 
hacks/ngrep-1.40.1/Makefile.in
--- original/ngrep-1.40.1/Makefile.in   2004-03-25 16:19:25.000000000 +0100
+++ hacks/ngrep-1.40.1/Makefile.in      2004-03-25 15:17:39.000000000 +0100
@@ -9,15 +9,17 @@
 [EMAIL PROTECTED]@
 
 [EMAIL PROTECTED]@ @PCAP_INCLUDE@
[EMAIL PROTECTED]@ @DEFS@
+CFLAGS_LIBNET := $(shell libnet-config --defines ; libnet-config --cflags)
[EMAIL PROTECTED]@ @DEFS@ $(CFLAGS_LIBNET)
 [EMAIL PROTECTED]@ @PCAP_LINK@
 # Modified for Debian --NES
 #LIBS=-lpcap @EXTRA_LIBS@
-LIBS=-lpcap -lpcre @EXTRA_LIBS@
+LIBNET := $(shell libnet-config --libs)
+LIBS=-lpcap -lpcre @EXTRA_LIBS@ $(LIBNET)
 [EMAIL PROTECTED]@
 
-SRC=ngrep.c 
-OBJS=ngrep.o 
+SRC=ngrep.c tcpkill.c
+OBJS=ngrep.o tcpkill.o
 TARGET=ngrep
 MANPAGE=ngrep.8
 
diff -u --recursive --new-file original/ngrep-1.40.1/debian/control 
hacks/ngrep-1.40.1/debian/control
--- original/ngrep-1.40.1/debian/control        2004-03-25 16:19:25.000000000 
+0100
+++ hacks/ngrep-1.40.1/debian/control   2004-03-25 15:10:34.000000000 +0100
@@ -2,7 +2,7 @@
 Section: net
 Priority: optional
 Maintainer: Nathan Sandver <[EMAIL PROTECTED]>
-Build-Depends: debhelper (>> 3.0.0), libpcap-dev, libpcre3-dev
+Build-Depends: debhelper (>> 3.0.0), libpcap-dev, libpcre3-dev, libnet0-dev
 Standards-Version: 3.5.8
 
 Package: ngrep
diff -u --recursive --new-file original/ngrep-1.40.1/ngrep.8 
hacks/ngrep-1.40.1/ngrep.8
--- original/ngrep-1.40.1/ngrep.8       2001-12-31 23:07:02.000000000 +0100
+++ hacks/ngrep-1.40.1/ngrep.8  2004-03-25 16:11:25.000000000 +0100
@@ -118,6 +118,10 @@
 .IP "-A num"
 Dump \fInum\fP packets of trailing context after matching a packet. 
 
+.IP "-K num"
+Kill TCP matching tcp connections (like tcpkill).  The numeric
+argument controls how many RST segments are sent.
+
 .IP "\fI match expression\fP"
 A match expression is either an extended regular expression, or if the
 \fI-X\fP option is specified, a string signifying a hexadecimal value.
diff -u --recursive --new-file original/ngrep-1.40.1/ngrep.c 
hacks/ngrep-1.40.1/ngrep.c
--- original/ngrep-1.40.1/ngrep.c       2004-03-25 16:19:25.000000000 +0100
+++ hacks/ngrep-1.40.1/ngrep.c  2004-03-25 16:05:34.000000000 +0100
@@ -72,6 +72,8 @@
 int matches = 0, max_matches = 0;
 int live_read = 1, want_delay = 0;
 
+int tcpkill_active = 0;
+
 char pc_err[PCAP_ERRBUF_SIZE];
 #ifdef USE_PCRE
 int err_offset;
@@ -117,7 +119,7 @@
   signal(SIGPIPE, clean_exit);
   signal(SIGWINCH, update_windowsize);
 
-  while ((c = getopt(argc, argv, "hXViwqpevxlDtTs:n:d:A:I:O:")) != EOF) {
+  while ((c = getopt(argc, argv, "hXViwqpevxlDtTK:s:n:d:A:I:O:")) != EOF) {
     switch (c) {
     case 'I':  
       read_file = optarg;
@@ -175,6 +177,9 @@
     case 'X':
       bin_match++;
       break;
+    case 'K':
+      tcpkill_active = atoi(optarg);
+      break;
     case 'h':
       usage(0);
     default:
@@ -207,6 +212,10 @@
       clean_exit(-1);
     }
 
+    if (tcpkill_active) {
+      tcpkill_init();
+    }
+
     if (pcap_lookupnet(dev, &net.s_addr, &mask.s_addr, pc_err) == -1) {
       perror(pc_err);
       memset(&net, 0, sizeof(net));
@@ -482,6 +491,10 @@
        pcap_dump((u_char*)pd_dump, h, p);
        if (!quiet) dump(data, len);
       } else dump(data, len);
+
+      if (tcpkill_active) {
+        tcpkill_kill(h, p, link_offset, tcpkill_active);
+      }
     }
   }
   break;
diff -u --recursive --new-file original/ngrep-1.40.1/tcpkill.c 
hacks/ngrep-1.40.1/tcpkill.c
--- original/ngrep-1.40.1/tcpkill.c     1970-01-01 01:00:00.000000000 +0100
+++ hacks/ngrep-1.40.1/tcpkill.c        2004-03-25 16:05:14.000000000 +0100
@@ -0,0 +1,87 @@
+/*
+ * tcpkill.c
+ *
+ * Kill TCP connections already in progress.
+ *
+ * Copyright (c) 2000 Dug Song <[EMAIL PROTECTED]>
+ *
+ * $Id: tcpkill.c,v 1.17 2001/03/17 08:10:43 dugsong Exp $
+ */
+
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <libnet.h>
+#include <pcap.h>
+
+#include "tcpkill.h"
+
+// #include "pcaputil.h"
+// #include "version.h"
+
+static int sock;
+
+void
+tcpkill_kill(const struct pcap_pkthdr *pcap, const u_char *pkt, unsigned 
pcap_off, unsigned kill_count)
+{
+       struct libnet_ip_hdr *ip;
+       struct libnet_tcp_hdr *tcp;
+       u_char ctext[64], buf[IP_H + TCP_H];
+       u_int32_t seq, win;
+       int i, len;
+
+       pkt += pcap_off;
+       len = pcap->caplen - pcap_off;
+
+       ip = (struct libnet_ip_hdr *)pkt;
+       if (ip->ip_p != IPPROTO_TCP)
+               return;
+       
+       tcp = (struct libnet_tcp_hdr *)(pkt + (ip->ip_hl << 2));
+       if (tcp->th_flags & (TH_SYN|TH_FIN|TH_RST))
+               return;
+
+       libnet_build_ip(TCP_H, 0, 0, 0, 64, IPPROTO_TCP,
+                       ip->ip_dst.s_addr, ip->ip_src.s_addr,
+                       NULL, 0, buf);
+
+       libnet_build_tcp(ntohs(tcp->th_dport), ntohs(tcp->th_sport),
+                        0, 0, TH_RST, 0, 0, NULL, 0, buf + IP_H);
+       
+       seq = ntohl(tcp->th_ack);
+       win = ntohs(tcp->th_win);
+       
+       snprintf(ctext, sizeof(ctext), "%s:%d > %s:%d:",
+                libnet_host_lookup(ip->ip_src.s_addr, 0),
+                ntohs(tcp->th_sport),
+                libnet_host_lookup(ip->ip_dst.s_addr, 0),
+                ntohs(tcp->th_dport));
+       
+       ip = (struct libnet_ip_hdr *)buf;
+       tcp = (struct libnet_tcp_hdr *)(ip + 1);
+       
+       for (i = 0; i < kill_count; i++) {
+               ip->ip_id = libnet_get_prand(PRu16);
+               seq += (i * win);
+               tcp->th_seq = htonl(seq);
+               
+               libnet_do_checksum(buf, IPPROTO_TCP, TCP_H);
+               
+               if (libnet_write_ip(sock, buf, sizeof(buf)) < 0)
+                       warn("write_ip");
+               
+               fprintf(stderr, "%s R %lu:%lu(0) win 0\n", ctext, seq, seq);
+       }
+}
+
+void
+tcpkill_init(void)
+{
+       if ((sock = libnet_open_raw_sock(IPPROTO_RAW)) == -1)
+               errx(1, "couldn't initialize sending");
+       
+       libnet_seed_prand();
+}      
diff -u --recursive --new-file original/ngrep-1.40.1/tcpkill.h 
hacks/ngrep-1.40.1/tcpkill.h
--- original/ngrep-1.40.1/tcpkill.h     1970-01-01 01:00:00.000000000 +0100
+++ hacks/ngrep-1.40.1/tcpkill.h        2004-03-25 16:04:44.000000000 +0100
@@ -0,0 +1,7 @@
+#ifndef TCPKILL_H
+#define TCPKILL_H
+
+void tcpkill_init(void);
+void tcpkill_kill(const struct pcap_pkthdr *pcap, const u_char *pkt, unsigned 
pcap_off, unsigned kill_count);
+
+#endif


--- End Message ---
--- Begin Message ---
Source: ngrep
Source-Version: 1.45.ds1-2

We believe that the bug you reported is fixed in the latest version of
ngrep, which is due to be installed in the Debian FTP archive:

ngrep_1.45.ds1-2.diff.gz
  to pool/main/n/ngrep/ngrep_1.45.ds1-2.diff.gz
ngrep_1.45.ds1-2.dsc
  to pool/main/n/ngrep/ngrep_1.45.ds1-2.dsc
ngrep_1.45.ds1-2_amd64.deb
  to pool/main/n/ngrep/ngrep_1.45.ds1-2_amd64.deb



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to [EMAIL PROTECTED],
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Romain Francoise <[EMAIL PROTECTED]> (supplier of updated ngrep package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing [EMAIL PROTECTED])


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.7
Date: Mon, 13 Aug 2007 22:35:24 +0200
Source: ngrep
Binary: ngrep
Architecture: source amd64
Version: 1.45.ds1-2
Distribution: unstable
Urgency: low
Maintainer: Romain Francoise <[EMAIL PROTECTED]>
Changed-By: Romain Francoise <[EMAIL PROTECTED]>
Description: 
 ngrep      - grep for network traffic
Closes: 240054 437633
Changes: 
 ngrep (1.45.ds1-2) unstable; urgency=low
 .
   * debian/patches/10_debian-build.diff: Don't strip the binary by default
     at link time, let dh_strip do it (closes: #437633).
 .
   * debian/patches/30_tcpkill.diff: New patch adding the ability to kill
     matching TCP connections.  Based on a patch by Florian Weimer, ported
     to libnet 1.1 (closes: #240054).
   * debian/patches/series: Update.
 .
   * debian/repack.sh: Include this script in the package, just in case.
Files: 
 a52ad3b59e203ecd1116009df27dac6e 643 net optional ngrep_1.45.ds1-2.dsc
 41258e454d78d7f52f4f3cb161f974e6 9096 net optional ngrep_1.45.ds1-2.diff.gz
 0ed450cda22efe04dee71e9178760d12 33360 net optional ngrep_1.45.ds1-2_amd64.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGwMMRogN2vsA8Vt8RAifpAJ4thgi3fqQqhB8ji6/CbqPozUxHewCgjFDh
h86vriHakpge5mFOTS47C0c=
=pLqN
-----END PGP SIGNATURE-----


--- End Message ---

Reply via email to