From 9b5142a14d7acadd2b71047898dbefb95af8cf57 Mon Sep 17 00:00:00 2001 From: stskeeps Date: Wed, 11 Apr 2001 01:52:12 +0000 Subject: [PATCH] +- Found a way to do +x IPv4 cloaking right. +- Added set::cloak-keys { longvalue; longvalue; longvalue; }; for the cipher --- Changes | 3 +++ include/dynconf.h | 10 ++++++++++ src/cloak.c | 31 ++++++++++++++++++++++--------- src/s_conf.c | 43 ++++++++++++++++++++++++++++++++++++++++++- src/s_serv.c | 23 ++++++++++++++++------- src/version.c.SH | 3 +++ 6 files changed, 96 insertions(+), 17 deletions(-) diff --git a/Changes b/Changes index be1865ca1..55d21c078 100644 --- a/Changes +++ b/Changes @@ -387,3 +387,6 @@ - Readded timestamp to log, accidentily got removed - Made it so /stats C doesn't show the user@host of servers to non-opers - Possibly fixed the vhost crashing bug, with much help from IpAddress +- Found a way to do +x IPv4 cloaking right. +- Added set::cloak-keys { longvalue; longvalue; longvalue; }; for the cipher + \ No newline at end of file diff --git a/include/dynconf.h b/include/dynconf.h index 2d38a2d16..fc428feb1 100644 --- a/include/dynconf.h +++ b/include/dynconf.h @@ -28,6 +28,10 @@ typedef struct zNetwork aNetwork; struct zNetwork { + long key; + long key2; + long key3; + long keycrc; unsigned x_inah:1; char *x_ircnetwork; char *x_defserv; @@ -130,3 +134,9 @@ extern aConfiguration iConf; #define iNAH iConf.network.x_inah #define prefix_quit iConf.network.x_prefix_quit #define STOPSE iConf.network.x_se + + +#define CLOAK_KEY1 iConf.network.key +#define CLOAK_KEY2 iConf.network.key2 +#define CLOAK_KEY3 iConf.network.key3 +#define CLOAK_KEYCRC iConf.network.keycrc \ No newline at end of file diff --git a/src/cloak.c b/src/cloak.c index ad800f3b8..2d6da7a36 100644 --- a/src/cloak.c +++ b/src/cloak.c @@ -34,7 +34,17 @@ static char sccxid[] = "@(#)cloak.c 9.00 7/12/99 UnrealIRCd"; #include #include "h.h" -#define CLOAK_KEY "()%289259248924924" +#undef KEY +#undef KEY2 +#undef KEY3 +#define KEY CLOAK_KEY1 +#define KEY2 CLOAK_KEY2 +#define KEY3 CLOAK_KEY3 + +#define POW_8 256L +#define POW_16 65536L +#define POW_32 4294967296L + /* The implementation here was originally done by Gary S. Brown. I have borrowed the tables directly, and made some minor changes to the @@ -157,7 +167,8 @@ char *hidehost(char *host) static char cloaked[512]; static char h1[512]; static char h2[4][4]; - long l[5]; + static char h3[300]; + unsigned long l[5]; int i; char *p; @@ -170,7 +181,7 @@ char *hidehost(char *host) break; if (!isdigit(*p) && !(*p == '.')) { - break; + break; } } if (!(*p)) @@ -182,13 +193,15 @@ char *hidehost(char *host) { strncpy(h2[i], p, 4); } + ircsprintf(h3, "%s.%s", h2[0], h2[1]); + l[0] = ((crc32(h3, strlen(h3)) + KEY2) ^ KEY) ^ KEY3; + ircsprintf(h3, "%s.%s.%s", h2[0], h2[1], h2[2]); + l[1] = ((KEY2 + crc32(h3, strlen(h3))) ^ KEY) ^ KEY3; l[4] = crc32(host, strlen(host)); - for (i = 0; i <= 3; i++) - { - l[i] = crc32(h2[i], strlen(h2[i])); - } - l[3] += l[4]; - ircsprintf(cloaked, "%X-%X-%X.%X", l[0], l[1], l[2], l[3]); + l[2] = ((l[4] + KEY2) ^ KEY)^ KEY3; + l[2] << 2; l[2] >> 2; + l[0] >> 1; l[0] << 1; + ircsprintf(cloaked, "%X.%X.%X.IP", l[2], l[1], l[0]); return cloaked; } else if (*p == ':') diff --git a/src/s_conf.c b/src/s_conf.c index 7ba852bb8..6a4b7fc5f 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -1906,6 +1906,9 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) { ConfigEntry *cep; ConfigEntry *cepp; + char temp[512]; + int i; + for (cep = ce->ce_entries; cep; cep = cep->ce_next) { @@ -2047,6 +2050,31 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) } } } + else if (!strcmp(cep->ce_varname, "cloak-keys")) + { + /* Count number of numbers there .. */ + for (cepp = cep->ce_entries, i = 0; cepp; cepp = cepp->ce_next, i++) { } + if (i != 3) + { + config_error("%s:%i: set::cloak-keys: we want 3 values, not %i!", + cep->ce_fileptr->cf_filename, cep->ce_varlinenum, + i); + return 0; + } + /* i == 3 SHOULD make this true .. */ + CLOAK_KEY1 = atol(cep->ce_entries->ce_varname); + CLOAK_KEY2 = atol(cep->ce_entries->ce_next->ce_varname); + CLOAK_KEY3 = atol(cep->ce_entries->ce_next->ce_next->ce_varname); + ircsprintf(temp, "%li.%li.%li", CLOAK_KEY1, + CLOAK_KEY2, CLOAK_KEY3); + CLOAK_KEYCRC = (long) crc32(temp, strlen(temp)); + } + else + { + config_status("%s:%i: unknown directive set::%s", + cep->ce_fileptr->cf_filename, cep->ce_varlinenum, + cep->ce_varname); + } } } #ifdef STRIPBADWORDS @@ -2691,7 +2719,18 @@ void validate_configuration(void) Warning("set::socks::quit-message is missing. Using default of \"Insecure SOCKS server\""); ircstrdup(iConf.socksquitmessage, "Insecure SOCKS server"); } - + + if ((CLOAK_KEY1 < 10000) || (CLOAK_KEY2 < 10000) || (CLOAK_KEY3 < 10000)) + { + if (!CLOAK_KEY1 || !CLOAK_KEY2 || !CLOAK_KEY3) + { + Error("set::cloak-keys are missing or is 0."); + Error("Add this in your config file:"); + Error("set { cloak-keys { ; ; ; };"); + Error("The numbers must be purely random, and the same on every server you link to"); + } + Error("set::cloak-keys are too easy to guess. Please select three other more absurd and crazy numbers - will increase security a lot"); + } /* Now for the real config */ if (conf_me) { @@ -3546,5 +3585,7 @@ void report_network(aClient *sptr) sptr->name, STATS_SERVER); sendto_one(sptr, ":%s %i %s :INAH: %i", me.name, RPL_TEXT, sptr->name, iNAH); + sendto_one(sptr, ":%s %i %s :KEYCRC: %X", me.name, RPL_TEXT, sptr->name, + CLOAK_KEYCRC); } diff --git a/src/s_serv.c b/src/s_serv.c index 6e25b08f2..2a70d9782 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -1289,9 +1289,11 @@ int m_server_synch(aClient *cptr, long numeric, ConfigItem_link *aconf) } } - sendto_one(cptr, "%s %li %li %li 0 0 0 0 :%s", + sendto_one(cptr, "%s %li %li %li %X 0 0 0 :%s", (IsToken(cptr) ? TOK_NETINFO : MSG_NETINFO), - IRCstats.global_max, TStime(), UnrealProtocol, ircnetwork); + IRCstats.global_max, TStime(), UnrealProtocol, + CLOAK_KEYCRC, + ircnetwork); return 0; } @@ -1811,7 +1813,7 @@ int m_links(cptr, sptr, parc, parv) ** parv[1] = max global count ** parv[2] = time of end sync ** parv[3] = unreal protocol using (numeric) -** parv[4] = free(for unrealprotocol > 2100) +** parv[4] = cloak-crc (> u2302) ** parv[5] = free(**) ** parv[6] = free(**) ** parv[7] = free(**) @@ -1823,9 +1825,10 @@ int m_netinfo(cptr, sptr, parc, parv) int parc; char *parv[]; { - long lmax; - time_t xx; - long endsync, protocol; + long lmax; + time_t xx; + long endsync, protocol; + char buf[512]; if (IsPerson(sptr)) return 0; @@ -1913,7 +1916,13 @@ int m_netinfo(cptr, sptr, parc, parv) me.name, cptr->name, protocol, me.name, UnrealProtocol); } - + ircsprintf(buf, "%X", CLOAK_KEYCRC); + if (strcmp(buf, parv[4])) + { + sendto_realops + ("Link %s is having a different cloak key - %s != %s", + parv[4], buf); + } SetNetInfo(cptr); } diff --git a/src/version.c.SH b/src/version.c.SH index e70a27659..0dcd5a323 100644 --- a/src/version.c.SH +++ b/src/version.c.SH @@ -187,6 +187,9 @@ char *unrealcredits[] = "[FBI] Corey Lang fbi@dal.net", " - Being a good IRC friend and getting me started with", " IRC through our old little wIRCd net :)", + "The +x 2.0 team: RaYmAn, NiQuiL, narf, Griever (great thinking)", + " eternal, bball, JK. Thanks for makin a", + " drop dead gorgeous algoritm.", "", " \2\37Also thanks to:\2\37", "Enforcer, Andy Church, Mick, Sp^, ShadowMastr, Almaris",