Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Allan Beaufour
committed
Sep 27, 2012
0 parents
commit aaac8e8
Showing
7 changed files
with
549 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* config.h. Generated automatically by configure. */ | ||
/* config.h.in. Generated automatically from configure.in by autoheader. */ | ||
|
||
/* Define to empty if the keyword does not work. */ | ||
/* #undef const */ | ||
|
||
/* Define if you have the strftime function. */ | ||
#define HAVE_STRFTIME 1 | ||
|
||
/* Define as the return type of signal handlers (int or void). */ | ||
#define RETSIGTYPE void | ||
|
||
/* Define to `unsigned' if <sys/types.h> doesn't define. */ | ||
/* #undef size_t */ | ||
|
||
/* Define if you have the ANSI C header files. */ | ||
#define STDC_HEADERS 1 | ||
|
||
/* Define if your <sys/time.h> declares struct tm. */ | ||
/* #undef TM_IN_SYS_TIME */ | ||
|
||
/* Define if the X Window System is missing or not being used. */ | ||
#define X_DISPLAY_MISSING 1 | ||
|
||
/* Define to 'uint32_t' if <sys/types.h> doesn't define. */ | ||
/* #undef u_int32_t */ | ||
|
||
/* Define to 'uint64_t' if <sys/types.h> doesn't define. */ | ||
/* #undef u_int64_t */ | ||
|
||
/* Define to 'u_int32_t' if <sys/types.h> doesn't define. */ | ||
#define in_addr_t u_int32_t | ||
|
||
/* Define if you have the <db.h> header file. */ | ||
/* #undef HAVE_DB_H */ | ||
|
||
/* Define if you have the <db_185.h> header file. */ | ||
#define HAVE_DB_185_H 1 | ||
|
||
/* Should be in <sys/param.h>, *sigh* */ | ||
#define HAVE_MINMAX 1 | ||
#ifndef HAVE_MINMAX | ||
#define MIN(a,b) (((a)<(b))?(a):(b)) | ||
#define MAX(a,b) (((a)>(b))?(a):(b)) | ||
#endif | ||
|
||
/* Define if you have the MD5Update function. */ | ||
/* #undef HAVE_MD5UPDATE */ | ||
|
||
/* Define if you have the dirname function. */ | ||
#define HAVE_DIRNAME 1 | ||
|
||
/* Define if you have the ether_ntoa function. */ | ||
#define HAVE_ETHER_NTOA 1 | ||
|
||
/* Define if you have the gethostname function. */ | ||
#define HAVE_GETHOSTNAME 1 | ||
|
||
/* Define if you have the socket function. */ | ||
#define HAVE_SOCKET 1 | ||
|
||
/* Define if you have the strdup function. */ | ||
#define HAVE_STRDUP 1 | ||
|
||
/* Define if you have the strlcat function. */ | ||
/* #undef HAVE_STRLCAT */ | ||
|
||
/* Define if you have the strlcpy function. */ | ||
/* #undef HAVE_STRLCPY */ | ||
|
||
/* Define if you have the strsep function. */ | ||
#define HAVE_STRSEP 1 | ||
|
||
/* Define if you have the strstr function. */ | ||
#define HAVE_STRSTR 1 | ||
|
||
/* Define if you have the warnx function. */ | ||
#define HAVE_WARNX 1 | ||
|
||
/* Define if you have the <err.h> header file. */ | ||
#define HAVE_ERR_H 1 | ||
|
||
/* Define if you have the <fcntl.h> header file. */ | ||
#define HAVE_FCNTL_H 1 | ||
|
||
/* Define if you have the <libgen.h> header file. */ | ||
#define HAVE_LIBGEN_H 1 | ||
|
||
/* Define if you have the <net/if_tun.h> header file. */ | ||
/* #undef HAVE_NET_IF_TUN_H */ | ||
|
||
/* Define if you have the <sys/ioctl.h> header file. */ | ||
#define HAVE_SYS_IOCTL_H 1 | ||
|
||
/* Define if you have the <sys/queue.h> header file. */ | ||
#define HAVE_SYS_QUEUE_H 1 | ||
|
||
/* Define if you have the <unistd.h> header file. */ | ||
#define HAVE_UNISTD_H 1 | ||
|
||
/* Define if you have the nsl library (-lnsl). */ | ||
#define HAVE_LIBNSL 1 | ||
|
||
/* Define if you have the resolv library (-lresolv). */ | ||
/* #undef HAVE_LIBRESOLV */ | ||
|
||
/* Define if you have the rpcsvc library (-lrpcsvc). */ | ||
#define HAVE_LIBRPCSVC 1 | ||
|
||
/* Define if you have the socket library (-lsocket). */ | ||
/* #undef HAVE_LIBSOCKET */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
--- tcpkill.c.orig 2009-09-08 23:51:15.000000000 +0200 | ||
+++ tcpkill.c 2009-09-09 00:02:18.000000000 +0200 | ||
@@ -39,17 +39,18 @@ | ||
static void | ||
tcp_kill_cb(u_char *user, const struct pcap_pkthdr *pcap, const u_char *pkt) | ||
{ | ||
- struct libnet_ip_hdr *ip; | ||
+ struct libnet_ipv4_hdr *ip; | ||
struct libnet_tcp_hdr *tcp; | ||
- u_char ctext[64], buf[IP_H + TCP_H]; | ||
+ u_char ctext[64]; | ||
u_int32_t seq, win; | ||
- int i, *sock, len; | ||
+ int i, len; | ||
+ libnet_t *l; | ||
|
||
- sock = (int *)user; | ||
+ l = (libnet_t *)user; | ||
pkt += pcap_off; | ||
len = pcap->caplen - pcap_off; | ||
|
||
- ip = (struct libnet_ip_hdr *)pkt; | ||
+ ip = (struct libnet_ipv4_hdr *)pkt; | ||
if (ip->ip_p != IPPROTO_TCP) | ||
return; | ||
|
||
@@ -57,34 +58,31 @@ | ||
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), | ||
+ libnet_addr2name4(ip->ip_src.s_addr, LIBNET_DONT_RESOLVE), | ||
ntohs(tcp->th_sport), | ||
- libnet_host_lookup(ip->ip_dst.s_addr, 0), | ||
+ libnet_addr2name4(ip->ip_dst.s_addr, LIBNET_DONT_RESOLVE), | ||
ntohs(tcp->th_dport)); | ||
|
||
- ip = (struct libnet_ip_hdr *)buf; | ||
- tcp = (struct libnet_tcp_hdr *)(ip + 1); | ||
- | ||
for (i = 0; i < Opt_severity; i++) { | ||
- ip->ip_id = libnet_get_prand(PRu16); | ||
seq += (i * win); | ||
- tcp->th_seq = htonl(seq); | ||
|
||
- libnet_do_checksum(buf, IPPROTO_TCP, TCP_H); | ||
+ libnet_clear_packet(l); | ||
+ | ||
+ libnet_build_tcp(ntohs(tcp->th_dport), ntohs(tcp->th_sport), | ||
+ seq, 0, TH_RST, 0, 0, 0, LIBNET_TCP_H, | ||
+ NULL, 0, l, 0); | ||
+ | ||
+ libnet_build_ipv4(LIBNET_IPV4_H + LIBNET_TCP_H, 0, | ||
+ libnet_get_prand(LIBNET_PRu16), 0, 64, | ||
+ IPPROTO_TCP, 0, ip->ip_dst.s_addr, | ||
+ ip->ip_src.s_addr, NULL, 0, l, 0); | ||
|
||
- if (libnet_write_ip(*sock, buf, sizeof(buf)) < 0) | ||
- warn("write_ip"); | ||
+ if (libnet_write(l) < 0) | ||
+ warn("write"); | ||
|
||
fprintf(stderr, "%s R %lu:%lu(0) win 0\n", ctext, seq, seq); | ||
} | ||
@@ -95,8 +93,10 @@ | ||
{ | ||
extern char *optarg; | ||
extern int optind; | ||
- int c, sock; | ||
+ int c; | ||
char *p, *intf, *filter, ebuf[PCAP_ERRBUF_SIZE]; | ||
+ char libnet_ebuf[LIBNET_ERRBUF_SIZE]; | ||
+ libnet_t *l; | ||
pcap_t *pd; | ||
|
||
intf = NULL; | ||
@@ -136,14 +136,14 @@ | ||
if ((pcap_off = pcap_dloff(pd)) < 0) | ||
errx(1, "couldn't determine link layer offset"); | ||
|
||
- if ((sock = libnet_open_raw_sock(IPPROTO_RAW)) == -1) | ||
+ if ((l = libnet_init(LIBNET_RAW4, intf, libnet_ebuf)) == NULL) | ||
errx(1, "couldn't initialize sending"); | ||
|
||
- libnet_seed_prand(); | ||
+ libnet_seed_prand(l); | ||
|
||
warnx("listening on %s [%s]", intf, filter); | ||
|
||
- pcap_loop(pd, -1, tcp_kill_cb, (u_char *)&sock); | ||
+ pcap_loop(pd, -1, tcp_kill_cb, (u_char *)l); | ||
|
||
/* NOTREACHED */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* pcaputil.c | ||
* | ||
* Copyright (c) 2000 Dug Song <dugsong@monkey.org> | ||
* | ||
* $Id: pcaputil.c,v 1.2 2001/03/15 08:33:04 dugsong Exp $ | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include <sys/param.h> | ||
#include <sys/types.h> | ||
#include <sys/ioctl.h> | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <err.h> | ||
#include <pcap.h> | ||
#ifdef BSD | ||
#include <pcap-int.h> | ||
#endif | ||
|
||
#include "pcaputil.h" | ||
|
||
#ifdef BSD | ||
static int | ||
bpf_immediate(int fd, int on) | ||
{ | ||
return (ioctl(fd, BIOCIMMEDIATE, &on)); | ||
} | ||
#endif | ||
|
||
int | ||
pcap_dloff(pcap_t *pd) | ||
{ | ||
int offset = -1; | ||
|
||
switch (pcap_datalink(pd)) { | ||
case DLT_EN10MB: | ||
offset = 14; | ||
break; | ||
case DLT_IEEE802: | ||
offset = 22; | ||
break; | ||
case DLT_FDDI: | ||
offset = 21; | ||
break; | ||
#ifdef DLT_LOOP | ||
case DLT_LOOP: | ||
#endif | ||
case DLT_NULL: | ||
offset = 4; | ||
break; | ||
default: | ||
warnx("unsupported datalink type"); | ||
break; | ||
} | ||
return (offset); | ||
} | ||
|
||
pcap_t * | ||
pcap_init(char *intf, char *filter, int snaplen) | ||
{ | ||
pcap_t *pd; | ||
u_int net, mask; | ||
struct bpf_program fcode; | ||
char ebuf[PCAP_ERRBUF_SIZE]; | ||
|
||
if (intf == NULL && (intf = pcap_lookupdev(ebuf)) == NULL) { | ||
warnx("%s", ebuf); | ||
return (NULL); | ||
} | ||
if ((pd = pcap_open_live(intf, snaplen, 1, 512, ebuf)) == NULL) { | ||
warnx("%s", ebuf); | ||
return (NULL); | ||
} | ||
if (pcap_lookupnet(intf, &net, &mask, ebuf) == -1) { | ||
warnx("%s", ebuf); | ||
return (NULL); | ||
} | ||
if (pcap_compile(pd, &fcode, filter, 1, mask) < 0) { | ||
pcap_perror(pd, "pcap_compile"); | ||
return (NULL); | ||
} | ||
if (pcap_setfilter(pd, &fcode) == -1) { | ||
pcap_perror(pd, "pcap_compile"); | ||
return (NULL); | ||
} | ||
#ifdef BSD | ||
if (bpf_immediate(pd->fd, 1) < 0) { | ||
perror("ioctl"); | ||
return (NULL); | ||
} | ||
#endif | ||
return (pd); | ||
} | ||
|
||
/* from tcpdump util.c. */ | ||
char * | ||
copy_argv(char **argv) | ||
{ | ||
char **p, *buf, *src, *dst; | ||
u_int len = 0; | ||
|
||
p = argv; | ||
if (*p == 0) | ||
return (0); | ||
|
||
while (*p) | ||
len += strlen(*p++) + 1; | ||
|
||
if ((buf = (char *)malloc(len)) == NULL) | ||
err(1, "copy_argv: malloc"); | ||
|
||
p = argv; | ||
dst = buf; | ||
|
||
while ((src = *p++) != NULL) { | ||
while ((*dst++ = *src++) != '\0') | ||
; | ||
dst[-1] = ' '; | ||
} | ||
dst[-1] = '\0'; | ||
|
||
return (buf); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* pcaputil.h | ||
* | ||
* pcap utility routines. | ||
* | ||
* Copyright (c) 2000 Dug Song <dugsong@monkey.org> | ||
* | ||
* $Id: pcaputil.h,v 1.2 2001/03/15 08:33:06 dugsong Exp $ | ||
*/ | ||
|
||
#ifndef PCAPUTIL_H | ||
#define PCAPUTIL_H | ||
|
||
pcap_t *pcap_init(char *intf, char *filter, int snaplen); | ||
|
||
int pcap_dloff(pcap_t *pd); | ||
|
||
char *copy_argv(char **argv); | ||
|
||
#endif /* PCAPUTIL_H */ |
Oops, something went wrong.