summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/ipsend
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1998-03-21 10:04:55 +0000
committerpeter <peter@FreeBSD.org>1998-03-21 10:04:55 +0000
commit58e3555d887b6a5b1f460d8ee84ca4e97c0a8217 (patch)
treeb9974c621ce6d3d5054fe5cc47ebdcbc84178204 /contrib/ipfilter/ipsend
parent594e73c3109178aa1c5317785aaa284a0c135ff4 (diff)
downloadFreeBSD-src-58e3555d887b6a5b1f460d8ee84ca4e97c0a8217.zip
FreeBSD-src-58e3555d887b6a5b1f460d8ee84ca4e97c0a8217.tar.gz
Import ipfilter 3.2.3
Diffstat (limited to 'contrib/ipfilter/ipsend')
-rw-r--r--contrib/ipfilter/ipsend/ip.c54
-rw-r--r--contrib/ipfilter/ipsend/iptest.c11
-rw-r--r--contrib/ipfilter/ipsend/iptests.c63
-rw-r--r--contrib/ipfilter/ipsend/sock.c4
4 files changed, 87 insertions, 45 deletions
diff --git a/contrib/ipfilter/ipsend/ip.c b/contrib/ipfilter/ipsend/ip.c
index 0f8d19b..459c09b 100644
--- a/contrib/ipfilter/ipsend/ip.c
+++ b/contrib/ipfilter/ipsend/ip.c
@@ -7,7 +7,7 @@
*/
#if !defined(lint)
static const char sccsid[] = "%W% %G% (C)1995";
-static const char rcsid[] = "@(#)$Id: ip.c,v 2.0.2.11 1997/10/23 11:42:44 darrenr Exp $";
+static const char rcsid[] = "@(#)$Id: ip.c,v 2.0.2.11.2.2 1997/11/28 03:36:47 darrenr Exp $";
#endif
#include <errno.h>
#include <stdio.h>
@@ -96,7 +96,7 @@ int frag;
static u_short id = 0;
ether_header_t *eh;
ip_t ipsv;
- int err;
+ int err, iplen;
if (!ipbuf)
ipbuf = (char *)malloc(65536);
@@ -115,7 +115,8 @@ int frag;
bcopy((char *)ip, (char *)&ipsv, sizeof(*ip));
last_gw.s_addr = gwip.s_addr;
- ip->ip_len = htons(ip->ip_len);
+ iplen = ip->ip_len;
+ ip->ip_len = htons(iplen);
ip->ip_off = htons(ip->ip_off);
if (!(frag & 2)) {
if (!ip->ip_v)
@@ -126,13 +127,13 @@ int frag;
ip->ip_ttl = 60;
}
- if (!frag || (sizeof(*eh) + ntohs(ip->ip_len) < mtu))
+ if (!frag || (sizeof(*eh) + iplen < mtu))
{
ip->ip_sum = 0;
ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
- bcopy((char *)ip, ipbuf + sizeof(*eh), ntohs(ip->ip_len));
- err = sendip(nfd, ipbuf, sizeof(*eh) + ntohs(ip->ip_len));
+ bcopy((char *)ip, ipbuf + sizeof(*eh), iplen);
+ err = sendip(nfd, ipbuf, sizeof(*eh) + iplen);
}
else
{
@@ -144,7 +145,7 @@ int frag;
ether_header_t eth;
char optcpy[48], ol;
char *s;
- int i, iplen, sent = 0, ts, hlen, olen;
+ int i, sent = 0, ts, hlen, olen;
hlen = ip->ip_hl << 2;
if (mtu < (hlen + 8)) {
@@ -235,43 +236,44 @@ struct in_addr gwip;
{
static tcp_seq iss = 2;
struct tcpiphdr *ti;
- int thlen, i;
- u_long lbuf[20];
+ tcphdr_t *t;
+ int thlen, i, iplen, hlen;
+ u_32_t lbuf[20];
+ iplen = ip->ip_len;
+ hlen = ip->ip_hl << 2;
+ t = (tcphdr_t *)((char *)ip + hlen);
ti = (struct tcpiphdr *)lbuf;
+ thlen = t->th_off << 2;
+ if (!thlen)
+ thlen = sizeof(tcphdr_t);
bzero((char *)ti, sizeof(*ti));
- thlen = sizeof(tcphdr_t);
ip->ip_p = IPPROTO_TCP;
ti->ti_pr = ip->ip_p;
ti->ti_src = ip->ip_src;
ti->ti_dst = ip->ip_dst;
- bcopy((char *)ip + (ip->ip_hl << 2),
- (char *)&ti->ti_sport, sizeof(tcphdr_t));
+ bcopy((char *)ip + hlen, (char *)&ti->ti_sport, thlen);
if (!ti->ti_win)
ti->ti_win = htons(4096);
- if (!ti->ti_seq)
- ti->ti_seq = htonl(iss);
- iss += 64;
+ iss += 63;
- if ((ti->ti_flags == TH_SYN) && !ip->ip_off)
- {
- ip = (ip_t *)realloc((char *)ip, ntohs(ip->ip_len) + 4);
- i = sizeof(struct tcpiphdr) / sizeof(long);
+ i = sizeof(struct tcpiphdr) / sizeof(long);
+
+ if ((ti->ti_flags == TH_SYN) && !ip->ip_off &&
+ (lbuf[i] != htonl(0x020405b4))) {
lbuf[i] = htonl(0x020405b4);
- bcopy((char *)(lbuf + i), (char*)ip + ntohs(ip->ip_len),
- sizeof(u_long));
+ bcopy((char *)ip + hlen + thlen, (char *)ip + hlen + thlen + 4,
+ iplen - thlen - hlen);
thlen += 4;
}
- if (!ti->ti_off)
- ti->ti_off = thlen >> 2;
+ ti->ti_off = thlen >> 2;
ti->ti_len = htons(thlen);
- ip->ip_len = (ip->ip_hl << 2) + thlen;
+ ip->ip_len = hlen + thlen;
ti->ti_sum = 0;
ti->ti_sum = chksum((u_short *)ti, thlen + sizeof(ip_t));
- bcopy((char *)&ti->ti_sport,
- (char *)ip + (ip->ip_hl << 2), thlen);
+ bcopy((char *)&ti->ti_sport, (char *)ip + hlen, thlen);
return send_ip(nfd, mtu, ip, gwip, 1);
}
diff --git a/contrib/ipfilter/ipsend/iptest.c b/contrib/ipfilter/ipsend/iptest.c
index 6b3cf23..415e4fc 100644
--- a/contrib/ipfilter/ipsend/iptest.c
+++ b/contrib/ipfilter/ipsend/iptest.c
@@ -12,7 +12,7 @@
*/
#if !defined(lint)
static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
-static const char rcsid[] = "@(#)$Id: iptest.c,v 2.0.2.8 1997/10/12 09:48:39 darrenr Exp $";
+static const char rcsid[] = "@(#)$Id: iptest.c,v 2.0.2.8.2.1 1997/11/28 03:36:18 darrenr Exp $";
#endif
#include <stdio.h>
#include <netdb.h>
@@ -146,7 +146,7 @@ char **argv;
usage(name);
}
- if (argc - optind < 2 && !tests)
+ if ((argc <= optind) || !argv[optind])
usage(name);
dst = argv[optind++];
@@ -209,6 +209,13 @@ char **argv;
ip_test7(dev, mtu, (ip_t *)ti, gwip, pointtest);
break;
default :
+ ip_test1(dev, mtu, (ip_t *)ti, gwip, pointtest);
+ ip_test2(dev, mtu, (ip_t *)ti, gwip, pointtest);
+ ip_test3(dev, mtu, (ip_t *)ti, gwip, pointtest);
+ ip_test4(dev, mtu, (ip_t *)ti, gwip, pointtest);
+ ip_test5(dev, mtu, (ip_t *)ti, gwip, pointtest);
+ ip_test6(dev, mtu, (ip_t *)ti, gwip, pointtest);
+ ip_test7(dev, mtu, (ip_t *)ti, gwip, pointtest);
break;
}
return 0;
diff --git a/contrib/ipfilter/ipsend/iptests.c b/contrib/ipfilter/ipsend/iptests.c
index f938272..f12dbad 100644
--- a/contrib/ipfilter/ipsend/iptests.c
+++ b/contrib/ipfilter/ipsend/iptests.c
@@ -7,7 +7,7 @@
*/
#if !defined(lint)
static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
-static const char rcsid[] = "@(#)$Id: iptests.c,v 2.0.2.13 1997/10/23 11:42:45 darrenr Exp $";
+static const char rcsid[] = "@(#)$Id: iptests.c,v 2.0.2.13.2.1 1997/11/28 03:37:10 darrenr Exp $";
#endif
#include <stdio.h>
#include <unistd.h>
@@ -892,6 +892,7 @@ int ptest;
t->th_sum = 0;
t->th_seq = 1;
t->th_ack = 0;
+ ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t);
nfd = initdevice(dev, t->th_sport, 1);
if (!ptest || (ptest == 1)) {
@@ -1021,9 +1022,10 @@ int ptest;
PAUSE();
}
-#if !defined(linux) && !defined(__SVR4) && !defined(__svr4__) && !defined(__sgi)
+#if !defined(linux) && !defined(__SVR4) && !defined(__svr4__) && \
+ !defined(__sgi)
{
- struct tcpcb *t, tcb;
+ struct tcpcb *tcbp, tcb;
struct tcpiphdr ti;
struct sockaddr_in sin;
int fd, slen;
@@ -1032,10 +1034,13 @@ int ptest;
for (i = 1; i < 63; i++) {
fd = socket(AF_INET, SOCK_STREAM, 0);
+ bzero((char *)&sin, sizeof(sin));
sin.sin_addr.s_addr = ip->ip_dst.s_addr;
sin.sin_port = htons(i);
+ sin.sin_family = AF_INET;
if (!connect(fd, (struct sockaddr *)&sin, sizeof(sin)))
break;
+ close(fd);
}
if (i == 63) {
@@ -1046,15 +1051,15 @@ int ptest;
}
bcopy((char *)ip, (char *)&ti, sizeof(*ip));
- ti.ti_dport = i;
+ t->th_dport = htons(i);
slen = sizeof(sin);
if (!getsockname(fd, (struct sockaddr *)&sin, &slen))
- ti.ti_sport = sin.sin_port;
- if (!(t = find_tcp(fd, &ti))) {
+ t->th_sport = sin.sin_port;
+ if (!(tcbp = find_tcp(fd, &ti))) {
printf("Can't find PCB\n");
goto skip_five_and_six;
}
- KMCPY(&tcb, t, sizeof(tcb));
+ KMCPY(&tcb, tcbp, sizeof(tcb));
ti.ti_win = tcb.rcv_adv;
ti.ti_seq = tcb.snd_nxt - 1;
ti.ti_ack = tcb.rcv_nxt;
@@ -1063,27 +1068,36 @@ int ptest;
/*
* Test 5: urp
*/
- printf("5.1 TCP Urgent pointer\n");
- ti.ti_urp = 1;
+ t->th_flags = TH_ACK|TH_URG;
+ printf("5.5.1 TCP Urgent pointer, sport %hu dport %hu\n",
+ ntohs(t->th_sport), ntohs(t->th_dport));
+ t->th_urp = htons(1);
(void) send_tcp(nfd, mtu, ip, gwip);
PAUSE();
- ti.ti_urp = 0x7fff;
+
+ t->th_seq = tcb.snd_nxt;
+ ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t) + 1;
+ t->th_urp = htons(0x7fff);
(void) send_tcp(nfd, mtu, ip, gwip);
PAUSE();
- ti.ti_urp = 0x8000;
+ t->th_urp = htons(0x8000);
(void) send_tcp(nfd, mtu, ip, gwip);
PAUSE();
- ti.ti_urp = 0xffff;
+ t->th_urp = htons(0xffff);
(void) send_tcp(nfd, mtu, ip, gwip);
PAUSE();
+ t->th_urp = htons(0);
+ t->th_flags &= ~TH_URG;
+ ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t);
}
if (!ptest || (ptest == 6)) {
/*
* Test 6: data offset, off = 0, off is inside, off is outside
*/
- printf("6.1 TCP off = 0-15, len = 40\n");
- for (i = 0; i < 16; i++) {
+ t->th_flags = TH_ACK;
+ printf("5.6.1 TCP off = 1-15, len = 40\n");
+ for (i = 1; i < 16; i++) {
ti.ti_off = ntohs(i);
(void) send_tcp(nfd, mtu, ip, gwip);
printf("%d\r", i);
@@ -1091,6 +1105,7 @@ int ptest;
PAUSE();
}
putchar('\n');
+ ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t);
}
(void) close(fd);
@@ -1099,9 +1114,9 @@ skip_five_and_six:
#endif
t->th_seq = 1;
t->th_ack = 1;
+ t->th_off = 0;
if (!ptest || (ptest == 7)) {
- t->th_off = 0;
t->th_flags = TH_SYN;
/*
* Test 7: sport = 0, sport = 1, sport = 32767
@@ -1140,6 +1155,7 @@ skip_five_and_six:
if (!ptest || (ptest == 8)) {
t->th_sport = 1;
+ t->th_flags = TH_SYN;
/*
* Test 8: dport = 0, dport = 1, dport = 32767
* dport = 32768, dport = 65535
@@ -1174,6 +1190,20 @@ skip_five_and_six:
fflush(stdout);
PAUSE();
}
+
+ /* LAND attack - self connect, so make src & dst ip/port the same */
+ if (!ptest || (ptest == 9)) {
+ printf("5.9 TCP LAND attack. sport = 25, dport = 25\n");
+ /* chose SMTP port 25 */
+ t->th_sport = htons(25);
+ t->th_dport = htons(25);
+ t->th_flags = TH_SYN;
+ ip->ip_src = ip->ip_dst;
+ (void) send_tcp(nfd, mtu, ip, gwip);
+ fflush(stdout);
+ PAUSE();
+ }
+
/* TCP options header checking */
/* 0 length options, etc */
}
@@ -1208,6 +1238,9 @@ int ptest;
u->uh_dport = htons(u->uh_dport);
u->uh_ulen = 7168;
+ printf("6. Exhaustive mbuf test.\n");
+ printf(" Send 7k packet in 768 & 128 byte fragments, 128 times.\n");
+ printf(" Total of around 8,900 packets\n");
for (i = 0; i < 128; i++) {
/*
* First send the entire packet in 768 byte chunks.
diff --git a/contrib/ipfilter/ipsend/sock.c b/contrib/ipfilter/ipsend/sock.c
index 92e4a24..fc4e866 100644
--- a/contrib/ipfilter/ipsend/sock.c
+++ b/contrib/ipfilter/ipsend/sock.c
@@ -7,7 +7,7 @@
*/
#if !defined(lint)
static const char sccsid[] = "@(#)sock.c 1.2 1/11/96 (C)1995 Darren Reed";
-static const char rcsid[] = "@(#)$Id: sock.c,v 2.0.2.9 1997/09/28 07:13:37 darrenr Exp $";
+static const char rcsid[] = "@(#)$Id: sock.c,v 2.0.2.9.2.1 1997/11/28 03:36:01 darrenr Exp $";
#endif
#include <stdio.h>
#include <unistd.h>
@@ -253,7 +253,7 @@ static struct kinfo_proc *getproc()
mib[2] = KERN_PROC_PID;
mib[3] = pid;
- n = 1;
+ n = sizeof(kp);
if (sysctl(mib, 4, &kp, &n, NULL, 0) == -1)
{
perror("sysctl");
OpenPOWER on IntegriCloud