Ver Fonte

* Added new link encryption method to fix nat/proxy linking bugs

svn: 1690
Bryan Drewery há 21 anos atrás
pai
commit
3d68da5549
3 ficheiros alterados com 66 adições e 0 exclusões
  1. 1 0
      doc/UPDATES
  2. 64 0
      src/enclink.c
  3. 1 0
      src/enclink.h

+ 1 - 0
doc/UPDATES

@@ -45,6 +45,7 @@ This is a summary of ChangeLog basically.
 * Added hijacked invite detection based on server invite notices.
 * Added hijacked invite detection based on server invite notices.
 * Added an action when a bot performs an invite, including username and full address.
 * Added an action when a bot performs an invite, including username and full address.
 * No longer making the bot fatal() if it cannot open a new socket.
 * No longer making the bot fatal() if it cannot open a new socket.
+* Fixed NAT bug for botlinks.
 
 
 1.2
 1.2
 * No longer displaying SALTS on ./bin -v
 * No longer displaying SALTS on ./bin -v

+ 64 - 0
src/enclink.c

@@ -10,6 +10,69 @@
 
 
 #include <stdarg.h>
 #include <stdarg.h>
 
 
+static void ghost_link_nat(int idx, direction_t direction)
+{
+  int snum = findanysnum(dcc[idx].sock);
+
+  if (snum >= 0) {
+    char initkey[33] = "", *tmp2 = NULL;
+    char tmp[256] = "";
+    char *keyp = NULL, *nick1 = NULL, *nick2 = NULL;
+    size_t key_len = 0;
+    port_t port = 0;
+
+    if (direction == TO) {
+      keyp = socklist[snum].ikey;
+      key_len = sizeof(socklist[snum].ikey);
+      nick1 = dcc[idx].nick;
+      nick2 = conf.bot->nick;
+      port = htons(dcc[idx].port);
+    } else if (direction == FROM) {
+      keyp = socklist[snum].okey;
+      key_len = sizeof(socklist[snum].okey);
+      nick1 = conf.bot->nick;
+      nick2 = dcc[idx].nick;
+
+      struct sockaddr_in sa;
+      socklen_t socklen = sizeof(sa);
+
+      egg_bzero(&sa, socklen);
+      getsockname(socklist[snum].sock, (struct sockaddr *) &sa, &socklen);
+      port = sa.sin_port;
+    }
+
+    /* initkey-gen */
+    /* bdhash port mynick conf.bot->nick */
+    sprintf(tmp, "%s@%4x@%s@%s", settings.bdhash, port, nick1, nick2);
+    strncpyz(keyp, SHA1(tmp), key_len);
+    putlog(LOG_DEBUG, "@", "Link hash for %s: %s", dcc[idx].nick, tmp);
+    putlog(LOG_DEBUG, "@", "outkey (%d): %s", strlen(keyp), keyp);
+
+    if (direction == FROM) {
+      make_rand_str(initkey, 32);       /* set the initial out/in link key to random chars. */
+      socklist[snum].oseed = random();
+      socklist[snum].iseed = socklist[snum].oseed;
+      tmp2 = encrypt_string(settings.salt2, initkey);
+      putlog(LOG_BOTS, "*", "Sending encrypted link handshake to %s...", dcc[idx].nick);
+
+      socklist[snum].encstatus = 1;
+      socklist[snum].gz = 1;
+
+      link_send(idx, "elink %s %d\n", tmp2, socklist[snum].oseed);
+      free(tmp2);
+      strcpy(socklist[snum].okey, initkey);
+      strcpy(socklist[snum].ikey, initkey);
+    } else {
+      socklist[snum].encstatus = 1;
+      socklist[snum].gz = 1;
+    }
+  } else {
+    putlog(LOG_MISC, "*", "Couldn't find socket for %s connection?? Shouldn't happen :/", dcc[idx].nick);
+    killsock(dcc[idx].sock);
+    lostdcc(idx);
+  }
+}
+
 static void ghost_link(int idx, direction_t direction)
 static void ghost_link(int idx, direction_t direction)
 {
 {
   int snum = findanysnum(dcc[idx].sock);
   int snum = findanysnum(dcc[idx].sock);
@@ -267,6 +330,7 @@ void link_parse(int idx, char *buf)
 }
 }
 
 
 struct enc_link enclink[] = {
 struct enc_link enclink[] = {
+  { "ghost+nat", LINK_GHOSTNAT, ghost_linknat, ghost_write, ghost_read, ghost_parse },
   { "ghost", LINK_GHOST, ghost_link, ghost_write, ghost_read, ghost_parse },
   { "ghost", LINK_GHOST, ghost_link, ghost_write, ghost_read, ghost_parse },
   { "cleartext", LINK_CLEARTEXT, NULL, NULL, NULL, NULL },
   { "cleartext", LINK_CLEARTEXT, NULL, NULL, NULL, NULL },
   { NULL, 0, NULL, NULL, NULL, NULL }
   { NULL, 0, NULL, NULL, NULL, NULL }

+ 1 - 0
src/enclink.h

@@ -9,6 +9,7 @@
 
 
 enum {
 enum {
         LINK_GHOST = 0,
         LINK_GHOST = 0,
+	LINK_GHOSTNAT,
         LINK_GHOSTSHA1,
         LINK_GHOSTSHA1,
         LINK_GHOSTMD5,
         LINK_GHOSTMD5,
         LINK_CLEARTEXT
         LINK_CLEARTEXT