C++ code to create a vulnerability scanner

Start
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <fstream>

using namespace std;

// enum for the different vulnerability types
enum VulnerabilityType {WEAK_CREDENTIALS, SQL_INJECTION, XSS, OS_COMMAND_INJECTION};

// struct for storing vulnerabilties
struct Vulnerability {
    VulnerabilityType type;
    string description;
};

// vector for storing vulnerabilities
vector<Vulnerability> vulnerabilities;

// function to read from a file
void readFromFile(string fileName) {
    ifstream inFile;
    inFile.open(fileName);
    if (inFile.is_open()) {
        string line;
        while (getline(inFile, line)) {
            string type;
            string description;
            size_t pos = line.find(":");
            if (pos != string::npos) {
                type = line.substr(0, pos);
                description = line.substr(pos + 1);
                VulnerabilityType t;
                if (type == "Weak Credentials") t = WEAK_CREDENTIALS;
                else if (type == "SQL Injection") t = SQL_INJECTION;
                else if (type == "XSS") t = XSS;
                else if (type == "OS Command Injection") t = OS_COMMAND_INJECTION;
                Vulnerability v = {t, description};
                vulnerabilities.push_back(v);
            }
        }
        inFile.close();
    }
}

// function to print out the vulnerabilities
void printVulnerabilities() {
    for (Vulnerability v : vulnerabilities) {
        cout << v.description << endl;
    }
}

// function to scan a given file for vulnerabilities
void scanFile(string fileName) {
    ifstream inFile;
    inFile.open(fileName);
    if (inFile.is_open()) {
        string line;
        while (getline(inFile, line)) {
            for (Vulnerability v : vulnerabilities) {
                if (line.find(v.description) != string::npos) {
                    cout << "Vulnerability Found: " << v.description << endl;
                }
            }
        }
        inFile.close();
    }
}

int main() {
    // read in the vulnerabilities from a file
    readFromFile("vulnerabilities.txt");
    // print out the vulnerabilities
    cout << "Known Vulnerabilities:" << endl;
    printVulnerabilities();
    // scan a file for vulnerabilities
    scanFile("fileToScan.txt");
    return 0;
}
Previous Story

San Francisco Nancy at Starbucks

Next Story

We love John Lennon