Howdy, On Wed, Nov 12, 1997 at 12:57:47PM +1100, Andrew Snare wrote: > You can expect to see it ported sometime during the next weekend when I > have time -- other committments have kept me busy for the last few > months. I've got no idea how much work will be required, but it should > be fairly straight-forward. Hmm. Perhaps you wanna test the attached port? :) Seems to work. No major change had to be made. Regards, Eumel -- +----------------------------------------------------------------------------+ | Michael 'Eumel' Neumayer <Michael.Neumayer@xxxxxxxxxxxxxxxxxxxx> | | Eumel@IRC ! LinuX inside ! pgp-key available | +----------------------------------------------------------------------------+
diff -urN irc2.9.4/common/numeric_def.h irc2.9.4+nospoof/common/numeric_def.h --- irc2.9.4/common/numeric_def.h Wed Sep 3 19:45:15 1997 +++ irc2.9.4+nospoof/common/numeric_def.h Wed Nov 12 04:29:43 1997 @@ -196,6 +196,9 @@ #define ERR_UMODEUNKNOWNFLAG 501 #define ERR_USERSDONTMATCH 502 +/* This is compatible with the Undernet error code returned */ +#define ERR_BADPING 513 + /* * Numberic replies from server commands. * These are currently in the range 200-399. diff -urN irc2.9.4/common/parse.c irc2.9.4+nospoof/common/parse.c --- irc2.9.4/common/parse.c Fri Sep 19 22:47:12 1997 +++ irc2.9.4+nospoof/common/parse.c Wed Nov 12 04:05:34 1997 @@ -49,7 +49,7 @@ { MSG_KICK, m_kick, MAXPARA, MSG_LAG|MSG_REGU, 0, 0, 0L}, { MSG_WALLOPS, m_wallops, MAXPARA, MSG_LAG|MSG_REG|MSG_NOU, 0, 0, 0L}, { MSG_PING, m_ping, MAXPARA, MSG_LAG|MSG_REG, 0, 0, 0L}, - { MSG_PONG, m_pong, MAXPARA, MSG_LAG|MSG_REG, 0, 0, 0L}, + { MSG_PONG, m_pong, MAXPARA, MSG_LAG, 0, 0, 0L}, { MSG_ERROR, m_error, MAXPARA, MSG_LAG|MSG_REG|MSG_NOU, 0, 0, 0L}, #ifdef OPER_KILL { MSG_KILL, m_kill, MAXPARA, MSG_LAG|MSG_REG|MSG_OP|MSG_LOP, 0,0, 0L}, diff -urN irc2.9.4/common/send.c irc2.9.4+nospoof/common/send.c --- irc2.9.4/common/send.c Wed Sep 3 22:33:20 1997 +++ irc2.9.4+nospoof/common/send.c Wed Nov 12 03:30:46 1997 @@ -467,7 +467,7 @@ # ifdef ZIP_LINKS NULL, # endif - 0, {0, 0, NULL }, {0, 0, NULL }, + 0, {0, 0, NULL }, {0, 0, NULL }, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, NULL, 0, 0, 0 # if defined(__STDC__) /* hack around union{} initialization -Vesa */ diff -urN irc2.9.4/common/struct_def.h irc2.9.4+nospoof/common/struct_def.h --- irc2.9.4/common/struct_def.h Fri Sep 12 20:00:09 1997 +++ irc2.9.4+nospoof/common/struct_def.h Wed Nov 12 04:31:37 1997 @@ -419,6 +419,7 @@ short lastsq; /* # of 2k blocks when sendqueued called last*/ dbuf sendQ; /* Outgoing message queue--if socket full */ dbuf recvQ; /* Hold for data incoming yet to be parsed */ + u_long cookie; /* Random number the user must PONG */ long sendM; /* Statistics: protocol messages send */ long sendK; /* Statistics: total k-bytes send */ long receiveM; /* Statistics: protocol messages received */ diff -urN irc2.9.4/common/support.c irc2.9.4+nospoof/common/support.c --- irc2.9.4/common/support.c Tue Sep 23 17:36:20 1997 +++ irc2.9.4+nospoof/common/support.c Wed Nov 12 03:40:47 1997 @@ -708,7 +708,7 @@ char *make_version() { int ve, re, mi, dv, pl; - char ver[15]; + char ver[30]; sscanf(PATCHLEVEL, "%2d%2d%2d%2d%2d", &ve, &re, &mi, &dv, &pl); sprintf(ver, "%d.%d", ve, re); /* version & revision */ @@ -718,6 +718,7 @@ sprintf(ver + strlen(ver), "%c%d", DEVLEVEL, dv); if (pl) /* patchlevel */ sprintf(ver + strlen(ver), "p%d", pl); + strcat(ver, "+nospoof"); return mystrdup(ver); } diff -urN irc2.9.4/doc/nospoof-notes irc2.9.4+nospoof/doc/nospoof-notes --- irc2.9.4/doc/nospoof-notes Thu Jan 1 01:00:00 1970 +++ irc2.9.4+nospoof/doc/nospoof-notes Sun Jul 27 10:42:30 1997 @@ -0,0 +1,36 @@ +The nospoof patch was adapted from the nospoof5 patch in use on Undernet +servers. + +When a client connects to the server, they are sent a PING with a random +number (please do not confuse this with a CTCP PING -- they're very +different things). Until the client responds with a PONG and the correct +random number, it is not registered with the server and cannot do +anything. + +Please not that this _does_ break the RFC. However, it has been tested +with most popular clients. The only client that appears to have problems +is Homer. + +To cater for possibly broken clients, a message is also sent to clients +on connect of the form: + +*** If your client freezes here, type /QUOTE PONG 12345678 or /PONG 12345678 + +To cater for this, it is a good idea to increase the allowed timeout on +connections since the user might have to manually PONG the server with +the ugly number. + +If the client PONGs with the wrong number, another message is sent to +the client directing the user what to type. In addition, if the +connection does end up timing out due to no PONG, a message is sent to +the user explainging the client may not be compatible, and lists where +compatible clients for all the major platforms can be found. + +The random number sequence is based on an md5 series. I didn't write it. +Someone else did. It's included because many have a dud random() in their +libc (this applies to more people than you think). It is seeded on a +#define value in config.h - YOU MUST CHANGE THIS FROM THE DEFAULT OR YOU +CAN STILL BE SPOOFED. If you still find that you get spoofed, try +changing this value again and recompiling. + + - Andrew (earthpig@xxxxxxxxxxxxxxxxxxxxx) diff -urN irc2.9.4/ircd/ircd.c irc2.9.4+nospoof/ircd/ircd.c --- irc2.9.4/ircd/ircd.c Mon Sep 22 14:18:39 1997 +++ irc2.9.4+nospoof/ircd/ircd.c Wed Nov 12 04:47:29 1997 @@ -432,6 +432,17 @@ else { cptr->exitc = EXITC_PING; + if((!IsRegistered(cptr)) && (cptr->name) && + (cptr->user->username)) + { + sendto_one(cptr, + ":%s %d %s :Your client may not be compatible with this server.", + me.name, ERR_BADPING, cptr->name ); + sendto_one(cptr, + ":%s %d %s :Compatible clients are available at " + "ftp://yoyo.cc.monash.edu.au/pub/irc/clients", + me.name, ERR_BADPING, cptr->name ); + } (void)exit_client(cptr, cptr, &me, "Ping timeout"); } diff -urN irc2.9.4/ircd/list.c irc2.9.4+nospoof/ircd/list.c --- irc2.9.4/ircd/list.c Wed Sep 3 19:45:51 1997 +++ irc2.9.4+nospoof/ircd/list.c Wed Nov 12 04:49:29 1997 @@ -143,6 +143,7 @@ if (size == CLIENT_LOCAL_SIZE) { cptr->since = cptr->lasttime = cptr->firsttime = timeofday; + cptr->cookie = 0; cptr->confs = NULL; cptr->sockhost[0] = '\0'; cptr->buffer[0] = '\0'; diff -urN irc2.9.4/ircd/random.c irc2.9.4+nospoof/ircd/random.c --- irc2.9.4/ircd/random.c Thu Jan 1 01:00:00 1970 +++ irc2.9.4+nospoof/ircd/random.c Sun Jul 27 10:42:31 1997 @@ -0,0 +1,157 @@ +/************************************************************************ + * IRC - Internet Relay Chat, ircd/random.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sys/time.h> +#include "config.h" + +char localkey[8] = RANDOM_SEED; + +/* + * MD5 transform algorithm, taken from code written by Colin Plumb, + * and put into the public domain + * + * Kev: Taken from Ted T'so's /dev/random random.c code and modified to + * be slightly simpler. That code is released under a BSD-style copyright + * OR under the terms of the GNU Public License, which should be included + * at the top of this source file. + * + * record: Cleaned up to work with ircd. RANDOM_TOKEN is defined in + * setup.h by the make script; if people start to "guess" your cookies, + * consider recompiling your server with a different random token. + */ + +/* The four core functions - F1 is optimized somewhat */ + +#define F1(x, y, z) (z ^ (x & (y ^ z))) +#define F2(x, y, z) F1(z, x, y) +#define F3(x, y, z) (x ^ y ^ z) +#define F4(x, y, z) (y ^ (x | ~z)) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP(f, w, x, y, z, data, s) \ + ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) + +/* + * The core of the MD5 algorithm, this alters an existing MD5 hash to + * reflect the addition of 16 longwords of new data. MD5Update blocks + * the data and converts bytes into longwords for this routine. + * + * original comment left in; this used to be called MD5Transform and took + * two arguments; I've internalized those arguments, creating the character + * array "localkey," which should contain 8 bytes of data. The function also + * originally returned nothing; now it returns an unsigned long that is the + * random number. It appears to be reallyrandom, so... -Kev + * + * I don't really know what this does. I tried to figure it out and got + * a headache. If you know what's good for you, you'll leave this stuff + * for the smart people and do something else. -record + */ +unsigned long ircrandom(void) +{ + unsigned long a, b, c, d; + unsigned char in[16]; + struct timeval tv; + + (void)gettimeofday(&tv, NULL); + + (void)memcpy((void *)in, (void *)localkey, 8); + (void)memcpy((void *)(in+8), (void *)&tv.tv_sec, 4); + (void)memcpy((void *)(in+12), (void *)&tv.tv_usec, 4); + + a = 0x67452301; + b = 0xefcdab89; + c = 0x98badcfe; + d = 0x10325476; + + MD5STEP(F1, a, b, c, d, (long)in[ 0]+0xd76aa478, 7); + MD5STEP(F1, d, a, b, c, (long)in[ 1]+0xe8c7b756, 12); + MD5STEP(F1, c, d, a, b, (long)in[ 2]+0x242070db, 17); + MD5STEP(F1, b, c, d, a, (long)in[ 3]+0xc1bdceee, 22); + MD5STEP(F1, a, b, c, d, (long)in[ 4]+0xf57c0faf, 7); + MD5STEP(F1, d, a, b, c, (long)in[ 5]+0x4787c62a, 12); + MD5STEP(F1, c, d, a, b, (long)in[ 6]+0xa8304613, 17); + MD5STEP(F1, b, c, d, a, (long)in[ 7]+0xfd469501, 22); + MD5STEP(F1, a, b, c, d, (long)in[ 8]+0x698098d8, 7); + MD5STEP(F1, d, a, b, c, (long)in[ 9]+0x8b44f7af, 12); + MD5STEP(F1, c, d, a, b, (long)in[10]+0xffff5bb1, 17); + MD5STEP(F1, b, c, d, a, (long)in[11]+0x895cd7be, 22); + MD5STEP(F1, a, b, c, d, (long)in[12]+0x6b901122, 7); + MD5STEP(F1, d, a, b, c, (long)in[13]+0xfd987193, 12); + MD5STEP(F1, c, d, a, b, (long)in[14]+0xa679438e, 17); + MD5STEP(F1, b, c, d, a, (long)in[15]+0x49b40821, 22); + + MD5STEP(F2, a, b, c, d, (long)in[ 1]+0xf61e2562, 5); + MD5STEP(F2, d, a, b, c, (long)in[ 6]+0xc040b340, 9); + MD5STEP(F2, c, d, a, b, (long)in[11]+0x265e5a51, 14); + MD5STEP(F2, b, c, d, a, (long)in[ 0]+0xe9b6c7aa, 20); + MD5STEP(F2, a, b, c, d, (long)in[ 5]+0xd62f105d, 5); + MD5STEP(F2, d, a, b, c, (long)in[10]+0x02441453, 9); + MD5STEP(F2, c, d, a, b, (long)in[15]+0xd8a1e681, 14); + MD5STEP(F2, b, c, d, a, (long)in[ 4]+0xe7d3fbc8, 20); + MD5STEP(F2, a, b, c, d, (long)in[ 9]+0x21e1cde6, 5); + MD5STEP(F2, d, a, b, c, (long)in[14]+0xc33707d6, 9); + MD5STEP(F2, c, d, a, b, (long)in[ 3]+0xf4d50d87, 14); + MD5STEP(F2, b, c, d, a, (long)in[ 8]+0x455a14ed, 20); + MD5STEP(F2, a, b, c, d, (long)in[13]+0xa9e3e905, 5); + MD5STEP(F2, d, a, b, c, (long)in[ 2]+0xfcefa3f8, 9); + MD5STEP(F2, c, d, a, b, (long)in[ 7]+0x676f02d9, 14); + MD5STEP(F2, b, c, d, a, (long)in[12]+0x8d2a4c8a, 20); + + MD5STEP(F3, a, b, c, d, (long)in[ 5]+0xfffa3942, 4); + MD5STEP(F3, d, a, b, c, (long)in[ 8]+0x8771f681, 11); + MD5STEP(F3, c, d, a, b, (long)in[11]+0x6d9d6122, 16); + MD5STEP(F3, b, c, d, a, (long)in[14]+0xfde5380c, 23); + MD5STEP(F3, a, b, c, d, (long)in[ 1]+0xa4beea44, 4); + MD5STEP(F3, d, a, b, c, (long)in[ 4]+0x4bdecfa9, 11); + MD5STEP(F3, c, d, a, b, (long)in[ 7]+0xf6bb4b60, 16); + MD5STEP(F3, b, c, d, a, (long)in[10]+0xbebfbc70, 23); + MD5STEP(F3, a, b, c, d, (long)in[13]+0x289b7ec6, 4); + MD5STEP(F3, d, a, b, c, (long)in[ 0]+0xeaa127fa, 11); + MD5STEP(F3, c, d, a, b, (long)in[ 3]+0xd4ef3085, 16); + MD5STEP(F3, b, c, d, a, (long)in[ 6]+0x04881d05, 23); + MD5STEP(F3, a, b, c, d, (long)in[ 9]+0xd9d4d039, 4); + MD5STEP(F3, d, a, b, c, (long)in[12]+0xe6db99e5, 11); + MD5STEP(F3, c, d, a, b, (long)in[15]+0x1fa27cf8, 16); + MD5STEP(F3, b, c, d, a, (long)in[ 2]+0xc4ac5665, 23); + + MD5STEP(F4, a, b, c, d, (long)in[ 0]+0xf4292244, 6); + MD5STEP(F4, d, a, b, c, (long)in[ 7]+0x432aff97, 10); + MD5STEP(F4, c, d, a, b, (long)in[14]+0xab9423a7, 15); + MD5STEP(F4, b, c, d, a, (long)in[ 5]+0xfc93a039, 21); + MD5STEP(F4, a, b, c, d, (long)in[12]+0x655b59c3, 6); + MD5STEP(F4, d, a, b, c, (long)in[ 3]+0x8f0ccc92, 10); + MD5STEP(F4, c, d, a, b, (long)in[10]+0xffeff47d, 15); + MD5STEP(F4, b, c, d, a, (long)in[ 1]+0x85845dd1, 21); + MD5STEP(F4, a, b, c, d, (long)in[ 8]+0x6fa87e4f, 6); + MD5STEP(F4, d, a, b, c, (long)in[15]+0xfe2ce6e0, 10); + MD5STEP(F4, c, d, a, b, (long)in[ 6]+0xa3014314, 15); + MD5STEP(F4, b, c, d, a, (long)in[13]+0x4e0811a1, 21); + MD5STEP(F4, a, b, c, d, (long)in[ 4]+0xf7537e82, 6); + MD5STEP(F4, d, a, b, c, (long)in[11]+0xbd3af235, 10); + MD5STEP(F4, c, d, a, b, (long)in[ 2]+0x2ad7d2bb, 15); + MD5STEP(F4, b, c, d, a, (long)in[ 9]+0xeb86d391, 21); + + /* + * we have 4 unsigned longs generated by the above sequence; this scrambles + * them together so that if there is any pattern, it will be obscured. + */ + return (a ^ b ^ c ^ d); +} diff -urN irc2.9.4/ircd/s_err.c irc2.9.4+nospoof/ircd/s_err.c --- irc2.9.4/ircd/s_err.c Tue Sep 23 22:47:57 1997 +++ irc2.9.4+nospoof/ircd/s_err.c Wed Nov 12 08:24:00 1997 @@ -161,6 +161,17 @@ { 0, (char *)NULL }, /* 501 */ { ERR_UMODEUNKNOWNFLAG, ":Unknown MODE flag" }, /* 502 */ { ERR_USERSDONTMATCH, ":Cant change mode for other users" }, + { 0, (char *)NULL }, + { 0, (char *)NULL }, + { 0, (char *)NULL }, + { 0, (char *)NULL }, + { 0, (char *)NULL }, + { 0, (char *)NULL }, + { 0, (char *)NULL }, + { 0, (char *)NULL }, + { 0, (char *)NULL }, + { 0, (char *)NULL }, +/* 513 */ { ERR_BADPING, (char *)NULL }, { 0, (char *)NULL } }; diff -urN irc2.9.4/ircd/s_user.c irc2.9.4+nospoof/ircd/s_user.c --- irc2.9.4/ircd/s_user.c Sat Oct 11 06:21:22 1997 +++ irc2.9.4+nospoof/ircd/s_user.c Wed Nov 12 08:22:19 1997 @@ -915,9 +915,25 @@ /* This had to be copied here to avoid problems.. */ (void)strcpy(sptr->name, nick); - if (sptr->user) + + /* If the client hasn't gotten a cookie-ping yet, + choose a cookie and send it. -record!jegelhof@xxxxxxxxxx */ + + if (!sptr->cookie) + { + while((!sptr->cookie) || (sptr->cookie==-1)) + sptr->cookie=(ircrandom()); + sendto_one(cptr, "PING :%lu", sptr->cookie); + sendto_one(sptr, + ":%s %d %s :If your client freezes here, type /QUOTE PONG %lu or /PONG %lu", + me.name, ERR_BADPING, sptr->name, + sptr->cookie, sptr->cookie); + } + + if ((sptr->user) && (sptr->cookie==-1)) + { /* - ** USER already received, now we have NICK. + ** USER and PONG already received, now we have NICK. ** *NOTE* For servers "NICK" *must* precede the ** user message (giving USER before NICK is possible ** only for local client connection!). register_user @@ -928,6 +944,7 @@ sptr->user->username) == FLUSH_BUFFER) return FLUSH_BUFFER; + } } /* ** Finally set new nick name. @@ -1723,7 +1740,8 @@ user->servp->userlist = user; strncpyzt(sptr->info, realname, sizeof(sptr->info)); - if (sptr->name[0]) /* NICK already received, now we have USER... */ + if ((sptr->name[0]) && (!MyConnect(sptr) || (sptr->cookie==-1))) + /* NICK already received, now we have USER... */ { if ((parc == 6) && IsServer(cptr)) /* internal m_user() */ { @@ -2086,6 +2104,29 @@ { aClient *acptr; char *origin, *destination; + + /* Check to see if this is a PONG :cookie reply from an + unregistered user. If so, process it. -record */ + + if((!IsRegistered(sptr)) && (sptr->cookie!=0) && + (sptr->cookie!=-1) && (parc>1)) + { + if(strtoul(parv[parc-1],NULL,10)==sptr->cookie) + { + sptr->cookie=-1; + if((sptr->user) && (sptr->name[0])) + /* NICK and USER OK */ + return register_user(cptr, sptr, sptr->name, + sptr->user->username); + } + else + sendto_one(sptr, + ":%s %d %s :To connect, type /QUOTE PONG %lu or /PONG %lu", + me.name, ERR_BADPING, sptr->name, + sptr->cookie, sptr->cookie); + + return 0; + } if (parc < 2 || *parv[1] == '\0') { diff -urN irc2.9.4/support/Makefile.in irc2.9.4+nospoof/support/Makefile.in --- irc2.9.4/support/Makefile.in Wed Sep 24 20:38:08 1997 +++ irc2.9.4+nospoof/support/Makefile.in Wed Nov 12 05:57:55 1997 @@ -80,7 +80,7 @@ SERVER_OBJS = channel.o class.o hash.o ircd.o list.o res.o s_auth.o \ s_bsd.o s_conf.o s_debug.o s_err.o s_misc.o s_numeric.o \ s_serv.o s_service.o s_user.o s_zip.o whowas.o \ - res_init.o res_comp.o res_mkquery.o + res_init.o res_comp.o res_mkquery.o random.o SERVER = ircd CHKCONF_COMMON_OBJS = match.o @@ -279,6 +279,9 @@ whowas.o: ../ircd/whowas.c setup.h config.h $(CC) $(S_CFLAGS) -c -o $@ ../ircd/whowas.c + +random.o: ../ircd/random.c config.h + $(CC) $(S_CFLAGS) -c -o $@ ../ircd/random.c res_init.o: ../ircd/res_init.c setup.h config.h $(CC) $(S_CFLAGS) -c -o $@ ../ircd/res_init.c diff -urN irc2.9.4/support/config.h.dist irc2.9.4+nospoof/support/config.h.dist --- irc2.9.4/support/config.h.dist Fri Sep 26 17:23:55 1997 +++ irc2.9.4+nospoof/support/config.h.dist Wed Nov 12 03:58:17 1997 @@ -395,6 +395,16 @@ */ #undef MIRC_KLUDGE +/* Random number generator seed. + * + * Set this to an 8 character random text string. + * Do _NOT_ use the default text. + * If people are able to defeat the IP-spoofing protection on your + * server, please consider changing this value and recompiling. + */ + +#define RANDOM_SEED "12345678" + /* STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP */ /* STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP */ /* STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP STOP */ @@ -463,8 +473,12 @@ * NOTE: this must be at *LEAST* 10. When a client connects, it has * CONNECTTIMEOUT - 10 seconds for its host to respond to an ident lookup * query and for a DNS answer to be retrieved. - */ -#define CONNECTTIMEOUT 30 /* Recommended value: 30 */ + * + * This value should consider the fact that users whose clients do not + * support NOSPOOF will have to type /QUOTE PING <bignumber> before + * registration. +*/ +#define CONNECTTIMEOUT 90 /* Recommended value: 30 */ /* * Max time from the nickname change that still causes KILL
Attachment:
pgp00001.pgp
Description: PGP signature