public static NetworkResult guessHTTPService() { NetworkResult result = new NetworkResult("Unknown", 100.0f); NeuralNetwork.Network net = new NeuralNetwork.Network(); net.addInput("Windows"); net.addInput("Linux"); net.addInput("FreeBSD"); net.addInput("PHP"); net.addInput("ASP.NET"); net.addInput("Static"); net.addInput("Ruby/Node.js"); return(result); }
public static OSResult guessOS(string[] foundServices) { OSResult result; // Initialize objects NeuralNetwork.Network net = new NeuralNetwork.Network(); // Load in data to memory if (!File.Exists(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents", "Gerbil", "memstore", "OSServiceTraining.ini"))) { return(new OSResult("ERROR", 0.0f)); } string[] trainingData = File.ReadAllLines(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents", "Gerbil", "memstore", "OSServiceTraining.ini")); // Calculate weights PairCounter pc = new PairCounter(); foreach (string i in trainingData) { string sName = i.Split('=')[0]; string fOS = i.Split('=')[1]; pc.Add(new Pair(sName, fOS)); } Dictionary <Pair, float> connectionWeights = getPercentagesFromPair(pc.getResults()); // TODO: Train network foreach (KeyValuePair <Pair, float> i in connectionWeights) { net.addInput(i.Key.item1); net.addOutput(i.Key.item2, i.Key.item1 + "Connector", i.Value, i.Key.item1); } // Feed data into tranined neural network foreach (string i in foundServices) { try { net.fireInput(i); } catch (NeuralNetwork.NodeNotFoundException e) { // Serive does not exist, since we are not in training mode, ignore. } catch { // A serious engine error occured. Throw fatal error. throw new FatalEngineException(); } } // Get outputs Dictionary <string, float> results = net.getResults(); string resultName = "Unknown"; float resultCertainty = 0.0f; float maxCertainty = 0.0f; // Find most likely answer foreach (KeyValuePair <string, float> i in results) { if (i.Value > resultCertainty) { resultName = i.Key; resultCertainty = i.Value; maxCertainty += i.Value; } } resultCertainty = resultCertainty / maxCertainty; result = new OSResult(resultName, resultCertainty); return(result); }