void EasySelectorWidget::redrawBackground(void) { Q_D(EasySelectorWidget); if (width() == 0 || height() == 0) { d->background = QPixmap(); return; } const int nX = d->maxLength - d->minLength + 1; const int nY = Password::MaxComplexity + 1; const int xs = width() / nX; const int ys = height() / nY; d->background = QPixmap(QSize(xs * nX + 1, ys * nY + 1)); QPainter p(&d->background); for (int y = 0; y < nY; ++y) for (int x = 0; x < nX; ++x) p.fillRect(QRect(x * xs, d->background.height() - y * ys - ys, xs, ys), red2yellow2green(qLn(passwordStrength(x + d->minLength, y)) / 40).darker(168)); p.setBrush(Qt::transparent); p.setPen(QPen(QBrush(QColor(0, 0, 0, 128)), 1)); for (int x = 0; x <= nX; ++x) p.drawLine(xs * x, 0, xs * x, d->background.height()); for (int y = 0; y <= nY; ++y) p.drawLine(0, ys * y, d->background.width(), ys * y); }
// Process Key Chain void processKeyChain(char *line, struct nipperConfig *nipper) { // Variables struct keyChain *keyChainPointer = 0; struct keyConfig *keyPointer = 0; struct ciscoCommand command; // Debug if (nipper->debugMode == true) { printf("Key Chain Line: %s\n", line); } // Init command = splitLine(line); // Is this the first key chain? if (nipper->ios->chain == 0) { keyChainPointer = malloc(sizeof(struct keyChain)); memset(keyChainPointer, 0, sizeof(struct keyChain)); // Pointers nipper->ios->chain = keyChainPointer; keyChainPointer->next = 0; // Init strncpy(keyChainPointer->name, command.part[2], sizeof(keyChainPointer->name)); keyChainPointer->key = 0; } // other key chains already exist else { // Find last key chain keyChainPointer = nipper->ios->chain; while (keyChainPointer->next != 0) keyChainPointer = keyChainPointer->next; // create new keyChainPointer->next = malloc(sizeof(struct keyChain)); memset(keyChainPointer->next, 0, sizeof(struct keyChain)); // Pointers keyChainPointer = keyChainPointer->next; keyChainPointer->next = 0; // Init strncpy(keyChainPointer->name, command.part[2], sizeof(keyChainPointer->name)); keyChainPointer->key = 0; } // Get keys readLine(nipper->input, line, nipper->maxSize); while ((feof(nipper->input) == 0) && (line[0] == ' ')) { // Debug if (nipper->debugMode == true) { printf("Key Chain Line: %s\n", line); } // Init command = splitLine(line); // Key if (strcmp(command.part[0], "key") == 0) { // Is it the first key? if (keyChainPointer->key == 0) { keyPointer = malloc(sizeof(struct keyConfig)); // Pointers keyChainPointer->key = keyPointer; } // Other keys exist else { keyPointer = keyChainPointer->key; while (keyPointer->next != 0) keyPointer = keyPointer->next; keyPointer->next = malloc(sizeof(struct keyConfig)); // Pointers keyPointer = keyPointer->next; } // Init memset(keyPointer, 0, sizeof(struct keyConfig)); keyPointer->keyNumber = atoi(command.part[1]); strcpy(keyPointer->key, ""); keyPointer->weak = false; keyPointer->dictionary = false; } // Key String else if (strcmp(command.part[0], "key-string") == 0) { strncpy(keyPointer->key, command.part[1], sizeof(keyPointer->key)); if (simplePassword(keyPointer->key, nipper) == true) { nipper->simplePasswords++; keyPointer->dictionary = true; } if (passwordStrength(keyPointer->key, nipper) == false) { nipper->passwordStrengths++; keyPointer->weak = true; } } // Get next line readLine(nipper->input, line, nipper->maxSize); } }
// Process FTP void processFtp(char *line, struct nipperConfig *nipper) { // Variables struct netInterface *interfacePointer = 0; // Debug if (nipper->debugMode == true) { printf("FTP Line: %s\n", line); } // Check to see if FTP already exists if (nipper->ios->ftp == 0) { // Create struct nipper->ios->ftp = malloc(sizeof(struct ftpConfig)); memset(nipper->ios->ftp, 0, sizeof(struct ftpConfig)); // Init nipper->ios->ftp->encryption = -1; nipper->ios->ftp->weak = false; nipper->ios->ftp->dictionary = false; } // Check for username if (strncmp(line, "ip ftp username ", 16) == 0) { strncpy(nipper->ios->ftp->username, line + 16, sizeof(nipper->ios->ftp->username)); } // Check for interface if (strncmp(line, "ip ftp source-interface ", 24) == 0) { // Allocate struct interfacePointer = malloc(sizeof(struct netInterface)); memset(interfacePointer, 0, sizeof(struct netInterface)); // Pointers interfacePointer->next = nipper->ios->ftp->interface; nipper->ios->ftp->interface = interfacePointer; // Copy interface strncpy(interfacePointer->interface, line + 24, sizeof(interfacePointer->interface)); } // Check for password else if (strncmp("ip ftp password ", line, 16) == 0) { switch (line[16]) { case '7': nipper->ios->ftp->encryption = encrypt_type7; if (password7(line+18, nipper->ios->ftp->password, sizeof(nipper->ios->ftp->password), nipper->debugMode) != 0) strcpy(nipper->ios->ftp->password, "<unknown>"); strncpy(nipper->ios->ftp->passwordEncrypted, line+18, sizeof(nipper->ios->ftp->passwordEncrypted)); break; case '5': nipper->ios->ftp->encryption = encrypt_md5; strcpy(nipper->ios->ftp->password, "<unknown>"); strncpy(nipper->ios->ftp->passwordEncrypted, line+18, sizeof(nipper->ios->ftp->passwordEncrypted)); addJohnPassword(nipper, nipper->ios->ftp->username, nipper->ios->ftp->passwordEncrypted); break; case '0': nipper->ios->ftp->encryption = encrypt_none; strncpy(nipper->ios->ftp->password, line+18, sizeof(nipper->ios->ftp->password)); strcpy(nipper->ios->enable->passwordEncrypted, ""); break; default: nipper->ios->ftp->encryption = encrypt_unknown; strcpy(nipper->ios->ftp->password, "<unknown>"); strncpy(nipper->ios->ftp->passwordEncrypted, line+18, sizeof(nipper->ios->ftp->passwordEncrypted)); break; } if ((strcmp(nipper->ios->ftp->password, "<unknown>") != 0) && (strlen(nipper->ios->ftp->password) != 0)) { if (simplePassword(nipper->ios->ftp->password, nipper) == true) { nipper->simplePasswords++; nipper->ios->ftp->dictionary = true; } if (passwordStrength(nipper->ios->ftp->password, nipper) == false) { nipper->passwordStrengths++; nipper->ios->ftp->weak = true; } } } }
// Process admin lines void processSOSSNMP(char *line, struct nipperConfig *nipper) { // Variables struct ciscoCommand command; struct snmpCommunitySOS *communityPointer = 0; struct snmpHostSOS *snmpHostPointer = 0; int tempInt; if (nipper->debugMode == true) printf("SNMP Line: %s\n", line); // Init command = splitLine(line); // Create SNMP Struct if required. if (nipper->sos->snmp == 0) { nipper->sos->snmp = malloc(sizeof(struct snmpSOS)); memset(nipper->sos->snmp, 0 , sizeof(struct snmpSOS)); nipper->sos->snmp->listenPort = 161; nipper->sos->snmp->trapPort = 162; nipper->sos->snmp->authTrap = false; } // SNMP Contact... if (strcasecmp(command.part[2], "contact") == 0) stripQuotes(command.part[3], nipper->sos->snmp->contact, sizeof(nipper->sos->snmp->contact)); // SNMP location... else if (strcasecmp(command.part[2], "location") == 0) stripQuotes(command.part[3], nipper->sos->snmp->location, sizeof(nipper->sos->snmp->location)); // SNMP System Name... else if (strcasecmp(command.part[2], "name") == 0) stripQuotes(command.part[3], nipper->sos->snmp->systemName, sizeof(nipper->sos->snmp->systemName)); // SNMP Listen Port... else if ((strcasecmp(command.part[2], "port") == 0) && (strcmp(command.part[3], "listen") == 0)) nipper->sos->snmp->listenPort = atoi(command.part[4]); // SNMP Trap Port... else if ((strcasecmp(command.part[2], "port") == 0) && (strcmp(command.part[3], "trap") == 0)) nipper->sos->snmp->trapPort = atoi(command.part[4]); // Authentication Traps... else if ((strcasecmp(command.part[2], "auth-trap") == 0) && (strcmp(command.part[3], "enable") == 0)) nipper->sos->snmp->authTrap = true; // Community else if ((strcasecmp(command.part[2], "community") == 0) && (strcmp(command.part[0], "set") == 0)) { // If first community... if (nipper->sos->snmp->community == 0) { nipper->sos->snmp->community = malloc(sizeof(struct snmpCommunitySOS)); memset(nipper->sos->snmp->community, 0 , sizeof(struct snmpCommunitySOS)); communityPointer = nipper->sos->snmp->community; } else { communityPointer = nipper->sos->snmp->community; while (communityPointer->next != 0) communityPointer = communityPointer->next; communityPointer->next = malloc(sizeof(struct snmpCommunitySOS)); memset(communityPointer->next, 0 , sizeof(struct snmpCommunitySOS)); communityPointer = communityPointer->next; } // Init... communityPointer->enableTraps = false; communityPointer->trafficTraps = false; communityPointer->version = snmp1_2; communityPointer->weak = false; communityPointer->dictionary = false; // Community stripQuotes(command.part[3], communityPointer->community, sizeof(communityPointer->community)); // Check strength / dictionary... if (simplePassword(communityPointer->community, nipper) == true) { nipper->simplePasswords++; communityPointer->dictionary = true; } if (passwordStrength(communityPointer->community, nipper) == false) { nipper->passwordStrengths++; communityPointer->weak = true; } // Get other parameters... tempInt = 4; while (tempInt < command.parts) { // version if (strcasecmp(command.part[tempInt], "version") == 0) { tempInt++; if (strcasecmp(command.part[tempInt], "any") == 0) communityPointer->version = snmp1_2; else if (strcasecmp(command.part[tempInt], "v1") == 0) communityPointer->version = snmp1; else if ((strcasecmp(command.part[tempInt], "v2") == 0) || (strcmp(command.part[tempInt], "v2c") == 0)) communityPointer->version = snmp2c; } // Trap On else if (strcasecmp(command.part[tempInt], "trap-on") == 0) communityPointer->enableTraps = true; // Trap Off else if (strcasecmp(command.part[tempInt], "trap-off") == 0) communityPointer->enableTraps = false; // Trap On else if (strcasecmp(command.part[tempInt], "traffic") == 0) communityPointer->trafficTraps = true; tempInt++; } } // Host else if (strcasecmp(command.part[2], "host") == 0) { // If first community... if (nipper->sos->snmp->host == 0) { nipper->sos->snmp->host = malloc(sizeof(struct snmpHostSOS)); memset(nipper->sos->snmp->host, 0 , sizeof(struct snmpHostSOS)); snmpHostPointer = nipper->sos->snmp->host; } else { snmpHostPointer = nipper->sos->snmp->host; while (snmpHostPointer->next != 0) snmpHostPointer = snmpHostPointer->next; snmpHostPointer->next = malloc(sizeof(struct snmpHostSOS)); memset(snmpHostPointer->next, 0 , sizeof(struct snmpHostSOS)); snmpHostPointer = snmpHostPointer->next; } // Init strcpy(snmpHostPointer->sourceInterface, "Any"); snmpHostPointer->weak = false; snmpHostPointer->dictionary = false; // Community stripQuotes(command.part[3], snmpHostPointer->community, sizeof(snmpHostPointer->community)); // Check strength / dictionary... if (simplePassword(snmpHostPointer->community, nipper) == true) { nipper->simplePasswords++; snmpHostPointer->dictionary = true; } if (passwordStrength(snmpHostPointer->community, nipper) == false) { nipper->passwordStrengths++; snmpHostPointer->weak = true; } // Host stripQuotes(command.part[4], snmpHostPointer->host, sizeof(snmpHostPointer->host)); // Options and Trap version tempInt = 5; while (tempInt < command.parts) { // Source Interface... if (strcasecmp(command.part[tempInt], "src-interface") == 0) { tempInt++; stripQuotes(command.part[tempInt], snmpHostPointer->sourceInterface, sizeof(snmpHostPointer->sourceInterface)); } // trap... else if (strcasecmp(command.part[tempInt], "trap") == 0) { tempInt++; if (strcasecmp(command.part[tempInt], "v1") == 0) snmpHostPointer->version = snmp1; else if ((strcasecmp(command.part[tempInt], "v2") == 0) || (strcasecmp(command.part[tempInt], "v2c") == 0)) snmpHostPointer->version = snmp2c; } tempInt++; } } }
// Process NTP void processNtp(char *line, struct nipperConfig *nipper) { // Variables struct ntpKey *ntpKeyPointer = 0; struct ntpHost *ntpHostPointer = 0; struct ntpAccessGroup *ntpAccessPointer = 0; int tempInt = 0; // Debug if (nipper->debugMode == true) { printf("NTP Line: %s\n", line); } // Check to see if NTP already exists if (nipper->ios->ntp == 0) { nipper->ios->ntp = malloc(sizeof(struct ntpConfig)); memset(nipper->ios->ntp, 0, sizeof(struct ntpConfig)); // Init nipper->ios->ntp->enabled = true; nipper->ios->ntp->master = false; nipper->ios->ntp->authentication = false; } // ntp disable? if (strncmp(line, "ntp disable", 11) == 0) nipper->ios->ntp->enabled = false; // ntp master? else if (strncmp(line, "ntp master", 10) == 0) nipper->ios->ntp->master = true; // ntp server / peer? else if ((strncmp(line, "ntp server ", 11) == 0) || (strncmp(line, "ntp peer ", 9) == 0)) { // create ntp host struct ntpHostPointer = malloc(sizeof(struct ntpHost)); memset(ntpHostPointer, 0, sizeof(struct ntpHost)); // Sort out Pointers if (strncmp(line, "ntp server ", 11) == 0) { ntpHostPointer->next = nipper->ios->ntp->server; nipper->ios->ntp->server = ntpHostPointer; } else { ntpHostPointer->next = nipper->ios->ntp->peer; nipper->ios->ntp->peer = ntpHostPointer; } // Init ntpHostPointer->keyNum = -1; // Get info tempInt = nextSpace(line + 11); if (line[11 + tempInt] == 0) { strncpy(ntpHostPointer->ntpHost, line + 11, sizeof(ntpHostPointer->ntpHost)); } else { line[11 + tempInt] = 0; strncpy(ntpHostPointer->ntpHost, line + 11, sizeof(ntpHostPointer->ntpHost)); // If key exists if (strncmp(line + 11 + tempInt, "key ", 4) == 0) { ntpHostPointer->keyNum = atoi(line + 15 + tempInt); } } } // ntp authentication? else if (strncmp(line, "ntp authenticate", 16) == 0) nipper->ios->ntp->authentication = true; // ntp authentication key? else if (strncmp(line, "ntp authentication-key ", 23) == 0) { // create ntp key struct ntpKeyPointer = malloc(sizeof(struct ntpKey)); memset(ntpKeyPointer, 0, sizeof(struct ntpKey)); // Sort out Pointers ntpKeyPointer->next = nipper->ios->ntp->key; nipper->ios->ntp->key = ntpKeyPointer; // Init ntpKeyPointer->trusted = false; ntpKeyPointer->weak = false; ntpKeyPointer->dictionary = false; tempInt = nextSpace(line + 23); line[23 + tempInt] = 0; ntpKeyPointer->keyNum = atoi(line + 23); strncpy(ntpKeyPointer->key, line + 27 + tempInt, sizeof(ntpKeyPointer->key)); if (simplePassword(ntpKeyPointer->key, nipper) == true) { nipper->simplePasswords++; ntpKeyPointer->dictionary = true; } if (passwordStrength(ntpKeyPointer->key, nipper) == false) { nipper->passwordStrengths++; ntpKeyPointer->weak = true; } } // ntp authentication key trusted? else if (strncmp(line, "ntp trusted-key ", 16) == 0) { // Init ntpKeyPointer = nipper->ios->ntp->key; tempInt = atoi(line + 16); // Find key while ((ntpKeyPointer != 0) && (ntpKeyPointer->keyNum != tempInt)) { ntpKeyPointer = ntpKeyPointer->next; } // Set trusted if found if (ntpKeyPointer->keyNum == tempInt) ntpKeyPointer->trusted = true; } // ntp access-group? else if (strncmp(line, "ntp access-group ", 17) == 0) { // create ntp access-group struct ntpAccessPointer = malloc(sizeof(struct ntpAccessGroup)); memset(ntpAccessPointer, 0, sizeof(struct ntpAccessGroup)); // Sort out Pointers ntpAccessPointer->next = nipper->ios->ntp->access; nipper->ios->ntp->access = ntpAccessPointer; // Get access type if (strncmp(line + 17, "peer ", 5) == 0) ntpAccessPointer->accessType = ntp_peer; else if (strncmp(line + 17, "serve ", 6) == 0) ntpAccessPointer->accessType = ntp_serve; else if (strncmp(line + 17, "serve-only ", 11) == 0) ntpAccessPointer->accessType = ntp_serve_only; else ntpAccessPointer->accessType = ntp_query_only; // Get access-list num tempInt = nextSpace(line + 17); strncpy(ntpAccessPointer->accessList, line + 18 + tempInt, sizeof(ntpAccessPointer->accessList) - 1); } }