/*************************************************************************** * nipper - The network infrastructure parser * * Copyright (C) 2006 - 2007 by Ian Ventura-Whiting (Fizz) * * fizz@titania.co.uk * * * * 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 3 of the License, 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, see . * ***************************************************************************/ #define adminfmt_default 0 #define adminfmt_dos 1 #define adminfmt_unix 2 #define adminpriv_default 0 #define adminpriv_rw 1 #define adminpriv_ext 2 #define adminpriv_all 3 #define adminpriv_read 4 #define trustee_none 0 #define trustee_modem 1 #define trustee_inter 2 struct adminUsersSOS { char username[32]; char password[32]; int trustee; int privilege; struct adminUsersSOS *next; }; struct adminSOS // NetScreenOS Admin Configuration { int accessAttempts; // Login attempts allowed int mailAlert; // Mail admin alerts int authTimeout; // Connection timeout char authServer[64]; // Authentication server int adminFormat; // Format of config file (default, dos or unix) int httpRedirect; // Redirect Admin HTTP traffic to HTTPS char email[64]; // Admin email address char email1[64]; // Admin additional email address char email2[64]; // Admin additional email address char emailServer[32]; // Email Server Name char name[32]; // Admin username char password[32]; // Admin password int restrictLength; // Restrict Minimum Password Length (Between 1 and 31) int privilege; // Admin privilege (default, read-write or get external) char adminIP[16]; // Administration IP address (default 0.0.0.0) char adminNetMask[16]; // Administration Netmask (default 255.255.255.255) int consoleOnly; // Restrict admin access to only the console struct adminUsersSOS *users; // Administrative users }; // Process admin lines void processSOSAdmin(char *line, struct nipperConfig *nipper) { // Variables struct ciscoCommand command; struct adminUsersSOS *userSOSPointer = 0; if (nipper->debugMode == true) printf("Admin Line: %s\n", line); // Has Admin structure been created? if (nipper->sos->admin == 0) { // Create nipper->sos->admin = malloc(sizeof(struct adminSOS)); // Init memset(nipper->sos->admin, 0 , sizeof(struct adminSOS)); nipper->sos->admin->accessAttempts = 3; nipper->sos->admin->mailAlert = false; nipper->sos->admin->adminFormat = adminfmt_default; nipper->sos->admin->httpRedirect = unconfigured; nipper->sos->admin->privilege = adminpriv_default; strcpy(nipper->sos->admin->adminIP, "0.0.0.0"); strcpy(nipper->sos->admin->adminNetMask, "0.0.0.0"); nipper->sos->admin->consoleOnly = false; } // Init command = splitLine(line); // Access Attempts if ((strcmp(command.part[2], "access") == 0) && (strcmp(command.part[3], "attempts") == 0)) { if (strcmp(command.part[1], "unset") == 0) nipper->sos->admin->accessAttempts = 3; else nipper->sos->admin->accessAttempts = atoi(command.part[4]); } // Users else if ((strcmp(command.part[0], "set") == 0) && (strcmp(command.part[2], "user") == 0)) { // Is this the first user? if (nipper->sos->admin->users == 0) { // Create nipper->sos->admin->users = malloc(sizeof(struct adminSOS)); // Init memset(nipper->sos->admin->users, 0 , sizeof(struct adminUsersSOS)); userSOSPointer = nipper->sos->admin->users; userSOSPointer->trustee = trustee_none; userSOSPointer->privilege = adminpriv_default; } // Find users else { userSOSPointer = nipper->sos->admin->users; while ((userSOSPointer->next != 0) && (strcmp(userSOSPointer->username, command.part[3]) != 0)) userSOSPointer = userSOSPointer->next; // If not found if (strcmp(userSOSPointer->username, command.part[3]) != 0) { // Create userSOSPointer->next = malloc(sizeof(struct adminSOS)); // Init memset(userSOSPointer->next, 0 , sizeof(struct adminUsersSOS)); userSOSPointer = userSOSPointer->next; userSOSPointer->trustee = trustee_none; userSOSPointer->privilege = adminpriv_default; } } // Set username strncpy(userSOSPointer->username, command.part[3], sizeof(userSOSPointer->username) - 1); // Is it a password? if (strcmp(command.part[4], "password") == 0) { stripQuotes(command.part[5], userSOSPointer->password, sizeof(userSOSPointer->password)); addJohnPassword(nipper, userSOSPointer->username, userSOSPointer->password); // Is there a privilege set? if (command.parts > 7) { if ((strcmp(command.part[6], "privilege") == 0) && (strcmp(command.part[7], "all") == 0)) userSOSPointer->privilege = adminpriv_all; else if ((strcmp(command.part[6], "privilege") == 0) && (strcmp(command.part[7], "read-only") == 0)) userSOSPointer->privilege = adminpriv_read; } } // Is it a trustee? else if (strcmp(command.part[4], "trustee") == 0) { if (command.parts > 5) { if (strcmp(command.part[5], "interface") == 0) userSOSPointer->trustee = trustee_inter; else if (strcmp(command.part[5], "modem") == 0) userSOSPointer->trustee = trustee_modem; } else userSOSPointer->trustee = trustee_none; } } // Auth Timeout else if ((strcmp(command.part[2], "auth") == 0) && (strcmp(command.part[3], "timeout") == 0)) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->authTimeout = 0; else nipper->sos->admin->authTimeout = atoi(command.part[4]); } // Auth Server else if ((strcmp(command.part[2], "auth") == 0) && (strcmp(command.part[3], "server") == 0)) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->authServer[0] = 0; else stripQuotes(command.part[4], nipper->sos->admin->authServer, sizeof(nipper->sos->admin->authServer)); } // Name else if (strcmp(command.part[2], "name") == 0) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->name[0] = 0; else { stripQuotes(command.part[3], nipper->sos->admin->name, sizeof(nipper->sos->admin->name)); if (nipper->sos->admin->password[0] != 0) addJohnPassword(nipper, nipper->sos->admin->name, nipper->sos->admin->password); } } // Password Length else if ((strcmp(command.part[2], "password") == 0) && (strcmp(command.part[3], "restrict") == 0) && (strcmp(command.part[4], "length") == 0)) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->restrictLength = 0; else nipper->sos->admin->restrictLength = atoi(command.part[5]); } // Password else if (strcmp(command.part[2], "password") == 0) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->password[0] = 0; else { stripQuotes(command.part[3], nipper->sos->admin->password, sizeof(nipper->sos->admin->password)); if (nipper->sos->admin->name[0] != 0) addJohnPassword(nipper, nipper->sos->admin->name, nipper->sos->admin->password); } } // Admin Privilege else if (strcmp(command.part[2], "privilege") == 0) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->privilege = adminpriv_default; else if (strcmp(command.part[3], "read-write") == 0) nipper->sos->admin->privilege = adminpriv_rw; else if (strcmp(command.part[3], "get-external") == 0) nipper->sos->admin->privilege = adminpriv_ext; } // Management IP else if (strcmp(command.part[2], "manager-ip") == 0) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->name[0] = 0; else { stripQuotes(command.part[3], nipper->sos->admin->adminIP, sizeof(nipper->sos->admin->adminIP)); if (command.parts > 4) stripQuotes(command.part[4], nipper->sos->admin->adminNetMask, sizeof(nipper->sos->admin->adminNetMask)); } } // Admin Format else if (strcmp(command.part[2], "format") == 0) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->adminFormat = adminfmt_default; else if (strcmp(command.part[3], "dos") == 0) nipper->sos->admin->adminFormat = adminfmt_dos; else if (strcmp(command.part[3], "unix") == 0) nipper->sos->admin->adminFormat = adminfmt_unix; } // Admin HTTP Redirect else if ((strcmp(command.part[2], "http") == 0) && (strcmp(command.part[3], "redirect") == 0)) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->httpRedirect = false; else nipper->sos->admin->httpRedirect = true; } // Console only access else if ((strcmp(command.part[2], "root") == 0) && (strcmp(command.part[3], "access") == 0) && (strcmp(command.part[4], "console") == 0)) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->consoleOnly = false; else nipper->sos->admin->consoleOnly = true; } // Mail Alerts else if ((strcmp(command.part[2], "mail") == 0) && (strcmp(command.part[3], "alert") == 0)) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->mailAlert = false; else nipper->sos->admin->mailAlert = true; } // Mail Server Name / IP else if ((strcmp(command.part[2], "mail") == 0) && (strcmp(command.part[3], "server-name") == 0)) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->emailServer[0] = 0; else stripQuotes(command.part[4], nipper->sos->admin->emailServer, sizeof(nipper->sos->admin->emailServer)); } // Mail email address - additional 1 else if ((strcmp(command.part[2], "mail") == 0) && (strcmp(command.part[3], "mail-addr1") == 0)) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->email1[0] = 0; else stripQuotes(command.part[4], nipper->sos->admin->email1, sizeof(nipper->sos->admin->email1)); } // Mail email address - additional 2 else if ((strcmp(command.part[2], "mail") == 0) && (strcmp(command.part[3], "mail-addr2") == 0)) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->email2[0] = 0; else stripQuotes(command.part[4], nipper->sos->admin->email2, sizeof(nipper->sos->admin->email2)); } // Admin email address (this should be the last mail entry!) else if ((strcmp(command.part[2], "mail") == 0) && (strcmp(command.part[3], "traffic-log") == 0)) { if (strcmp(command.part[0], "unset") == 0) nipper->sos->admin->email[0] = 0; else stripQuotes(command.part[3], nipper->sos->admin->email, sizeof(nipper->sos->admin->email)); } }