/* * trojanscan.c * (C) Peter Salanki 2002 * This program is copyright, and covered by the Gnu Public License. * The Natasha Trojan Scan bot. * sorcer@linux.se */ #include #include #include #include "globals.h" void loadchannels (void) { cchannel = 0; dbquery("SELECT `id`, `name` FROM `channels` LIMIT " TSC_STARTCHAN ", " TSC_NUMOFCHANS); while((row = mysql_fetch_row(res))) { clist[cchannel].id = atoi(row[0]); strncpy(clist[cchannel].name, row[1], CHANNELLEN); ++cchannel; } mysql_free_result(res); maxchannel = cchannel; printf("Loaded %i channels.\n", cchannel); cchannel = 0; } void loopaction (void) { if(strcasecmp(clist[cchannel].name, REPORTCHAN) != 0) partchannel(clist[cchannel].name, PARTMSG); if(cchannel+1 == maxchannel) { printf("Round complete, let's restart.\n"); privmsg(REPORTCHAN, "Round complete."); loadchannels(); } else ++cchannel; printf("Channel: %s, %i/%i\n", clist[cchannel].name, cchannel, maxchannel); if(strcasecmp(clist[cchannel].name, REPORTCHAN) != 0) joinchannel(clist[cchannel].name); } void privscan (char *text) { char query[MAX_QUERY+512]; snprintf(query, MAX_QUERY+512, "SELECT `id`, `severity` FROM `tscan_msgs` WHERE '%s' REGEXP `regex`", escapequery(text)); dbquery(query); if((row = mysql_fetch_row(res))) { /* Haha found lamer */ foundinfected(atoi(row[0]), atoi(row[1])); } else foundnew(text); mysql_free_result(res); } void foundinfected (int id, int severity) { char query[MAX_QUERY]; FILE *pFile; int time = 0; snprintf(query, MAX_QUERY, "INSERT INTO `tscan_cases` (`nickname`, `username`, `hostname`, `timestamp`, `tid`) VALUES ('%s', '%s', '%s', UNIX_TIMESTAMP(), '%i')", escapequery(sender), escapequery(username), escapequery(host), id); dbquery(query); snprintf(query, MAX_QUERY, "Infected user found: %c%s%c with trojan type: %c%i%c.", BOLD, sender, BOLD, BOLD, id, BOLD); privmsg(REPORTCHAN, query); printf("Infected: %s found with type: %i\n", sender, id); pFile = fopen (COMFILE, "a"); if(pFile == NULL) { printf("Could not open: " COMFILE ".\n"); return; } if(severity == 4) time = 1800; else if(severity == 3) time = 3600; else if(severity == 2) time = 3600*5; snprintf(query, MAX_QUERY, "%s %i " INFOSITE "%i\n", sender, time, id); fputs (query, pFile); fclose (pFile); } void foundnew (char *text) { FILE *pFile; char msg[1024]; pFile = fopen ("newtrojans", "a"); if(pFile == NULL) { printf("Could not open: newtrojans.\n"); return; } snprintf(msg, 1024, "From: %s!%s@%s Text: %s\n", sender, username, host, text); fputs (msg, pFile); fclose (pFile); }