Example #1
0
        public static PlaybookTaskResult GetTaskResult(string results)
        {
            PlaybookTaskResult  taskresult = new PlaybookTaskResult();
            List <TaskDebugMsg> debugmsgs  = new List <TaskDebugMsg>();


            string[] lines = results.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string line in lines)
            {
                if (line.Contains("Starting"))
                {
                    taskresult.timestamp = line.Substring(0, line.IndexOf('[')).Trim();

                    string strip = line.Substring(line.LastIndexOf("]") + 1).Replace("Starting ", "").Replace("Simulation on ", "").Trim();

                    taskresult.technique = strip.Split(' ')[0];
                    //taskresult.host = strip.Split(' ')[1];
                }
                else if (line.Contains("Simulator"))
                {
                    //string strip = line.Substring(line.LastIndexOf("]") + 1).Replace("Simulator running from ", "").Replace("with PID:", "").Trim();
                    //string strip = line.Substring(line.LastIndexOf("]") + 1).Replace("Simulator running from ", "").Replace("with PID:", "").Replace("as ", "").Trim();
                    string strip = line.Substring(line.LastIndexOf("]") + 1).Replace("Simulator running from ", "").Replace("with PID:", "|").Replace("as ", "|").Trim();

                    //taskresult.simprocess = strip.Split('|')[0];
                    //taskresult.simprocessid = Int32.Parse(strip.Split('|')[1]);
                    //taskresult.user = strip.Split('|')[2];
                }
                else if (line.Contains("Simulation Finished"))
                {
                    taskresult.success = true;
                }
                else if (line.Contains("Simulation Failed"))
                {
                    taskresult.success = false;
                }
                else
                {
                    TaskDebugMsg debugmsg = new TaskDebugMsg();
                    debugmsg.msg = line;
                    debugmsgs.Add(debugmsg);
                }
                //Console.WriteLine(line.Substring(line.LastIndexOf(']') + 1));
            }
            taskresult.debugmsgs = debugmsgs;
            return(taskresult);
            //File.WriteAllText("result.json", JsonConvert.SerializeObject(taskresult));
        }
Example #2
0
        public static SimulationExerciseResult GetSimulationExerciseResult(string results)
        {
            SimulationExerciseResult simulationresult = new SimulationExerciseResult();

            simulationresult.playbookresults = new List <SimulationPlaybookResult>();
            string[] lines = results.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < lines.Length; i++)
            {
                string strip = "";

                if (lines[i].Contains("Running Playbook"))
                {
                    SimulationPlaybookResult  playbookresult = new SimulationPlaybookResult();
                    List <PlaybookTaskResult> taskresults    = new List <PlaybookTaskResult>();

                    PlaybookTaskResult  taskresult = new PlaybookTaskResult();
                    List <TaskDebugMsg> debugmsgs  = new List <TaskDebugMsg>();

                    strip = lines[i].Substring(lines[i].LastIndexOf("]") + 1).Replace("Running Playbook", "").Trim();
                    playbookresult.name = strip;
                    bool finished = false;
                    int  skipped  = 0;

                    for (int k = i + 1; finished == false; k++)
                    {
                        if (lines[k].Contains("Starting"))
                        {
                            taskresult.timestamp = lines[i].Substring(0, lines[i].IndexOf('[')).Trim();
                            strip = lines[k].Substring(lines[k].LastIndexOf("]") + 1).Replace("Starting ", "").Replace("Simulation on ", "").Trim();
                            taskresult.technique = strip.Split(' ')[0];
                            playbookresult.host  = strip.Split(' ')[1];
                        }
                        else if (lines[k].Contains("Simulator"))
                        {
                            strip = lines[k].Substring(lines[k].LastIndexOf("]") + 1).Replace("Simulator running from ", "").Replace("with PID:", "|").Replace("as ", "|").Trim();
                            playbookresult.simprocess   = strip.Split('|')[0].TrimEnd();
                            playbookresult.simprocessid = Int32.Parse(strip.Split('|')[1]);
                            playbookresult.user         = strip.Split('|')[2];
                        }
                        else if (lines[k].Contains("Simulation Finished"))
                        {
                            //finished = true;
                            taskresult.success   = true;
                            taskresult.debugmsgs = debugmsgs;
                            taskresults.Add(taskresult);
                            //playbookresult.taskresults = taskresults;

                            taskresult = new PlaybookTaskResult();
                            debugmsgs  = new List <TaskDebugMsg>();
                        }
                        else if (lines[k].Contains("Simulation Failed"))
                        {
                            //finished = true;
                            taskresult.success   = false;
                            taskresult.debugmsgs = debugmsgs;
                            taskresults.Add(taskresult);
                            //playbookresult.taskresults = taskresults;

                            taskresult = new PlaybookTaskResult();
                            debugmsgs  = new List <TaskDebugMsg>();
                        }
                        else if (lines[k].Contains("Playbook Finished"))
                        {
                            finished = true;
                        }
                        else
                        {
                            TaskDebugMsg debugmsg = new TaskDebugMsg();
                            debugmsg.msg = lines[k];
                            debugmsgs.Add(debugmsg);
                        }
                        skipped += 1;
                    }
                    i += skipped;
                    playbookresult.taskresults = taskresults;
                    simulationresult.playbookresults.Add(playbookresult);
                }
            }
            return(simulationresult);
        }
Example #3
0
        /*
         * public static SimulationExerciseResult GetSimulationExerciseResultOld(string results)
         * {
         *  SimulationExerciseResult simulationresult = new SimulationExerciseResult();
         *  simulationresult.playbookresults = new List<SimulationPlaybookResult>();
         *  string[] lines = results.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
         *  for (int i = 0; i < lines.Length; i++)
         *  {
         *      string strip = "";
         *      SimulationPlaybookResult playbookresult = new SimulationPlaybookResult();
         *      List<PlaybookTaskResult> taskresults = new List<PlaybookTaskResult>();
         *
         *
         *      if (lines[i].Contains("Running Playbook"))
         *      {
         *          strip = lines[i].Substring(lines[i].LastIndexOf("]") + 1).Replace("Running Playbook", "").Trim();
         *          playbookresult.name = strip;
         *
         *      }
         *      else if (lines[i].Contains("Starting"))
         *      {
         *          PlaybookTaskResult taskresult = new PlaybookTaskResult();
         *          List<TaskDebugMsg> debugmsgs = new List<TaskDebugMsg>();
         *
         *          taskresult.timestamp = lines[i].Substring(0, lines[i].IndexOf('[')).Trim();
         *          strip = lines[i].Substring(lines[i].LastIndexOf("]") + 1).Replace("Starting ", "").Replace("Simulation on ", "").Trim();
         *          taskresult.technique = strip.Split(' ')[0];
         *          playbookresult.host = strip.Split(' ')[1];
         *          bool finished = false;
         *          int skipped = 0;
         *          for (int k = i + 1; finished == false; k++)
         *          {
         *              if (lines[k].Contains("Simulator"))
         *              {
         *                  strip = lines[k].Substring(lines[k].LastIndexOf("]") + 1).Replace("Simulator running from ", "").Replace("with PID:", "|").Replace("as ", "|").Trim();
         *                  playbookresult.simprocess = strip.Split('|')[0].TrimEnd();
         *                  playbookresult.simprocessid = Int32.Parse(strip.Split('|')[1]);
         *                  playbookresult.user = strip.Split('|')[2];
         *              }
         *              else if (lines[k].Contains("Simulation Finished"))
         *              {
         *                  taskresult.success = true;
         *                  finished = true;
         *              }
         *              else if (lines[k].Contains("Simulation Failed"))
         *              {
         *                  taskresult.success = false;
         *                  finished = true;
         *              }
         *              else
         *              {
         *                  TaskDebugMsg debugmsg = new TaskDebugMsg();
         *                  debugmsg.msg = lines[k];
         *                  debugmsgs.Add(debugmsg);
         *              }
         *              skipped += 1;
         *          }
         *          taskresult.debugmsgs = debugmsgs;
         *          taskresults.Add(taskresult);
         *          playbookresult.taskresults = taskresults;
         *          i += skipped;
         *          simulationresult.playbookresults.Add(playbookresult);
         *      }
         *  }
         *  return simulationresult;
         * }
         */

        public static SimulationPlaybookResult GetPlaybookResult(string results)
        {
            SimulationPlaybookResult  playbookresult = new SimulationPlaybookResult();
            List <PlaybookTaskResult> taskresults    = new List <PlaybookTaskResult>();

            string[] lines = results.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            //foreach (string line in lines)
            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Contains("Starting"))
                {
                    PlaybookTaskResult  taskresult = new PlaybookTaskResult();
                    List <TaskDebugMsg> debugmsgs  = new List <TaskDebugMsg>();

                    taskresult.timestamp = lines[i].Substring(0, lines[i].IndexOf('[')).Trim();
                    string strip = lines[i].Substring(lines[i].LastIndexOf("]") + 1).Replace("Starting ", "").Replace("Simulation on ", "").Trim();
                    taskresult.technique = strip.Split(' ')[0];
                    playbookresult.host  = strip.Split(' ')[1];
                    bool finished = false;
                    int  skipped  = 0;
                    for (int k = i + 1; finished == false; k++)
                    {
                        if (lines[k].Contains("Simulator"))
                        {
                            //string strip = line.Substring(line.LastIndexOf("]") + 1).Replace("Simulator running from ", "").Replace("with PID:", "").Trim();
                            //string strip = line.Substring(line.LastIndexOf("]") + 1).Replace("Simulator running from ", "").Replace("with PID:", "").Replace("as ", "").Trim();
                            strip = lines[k].Substring(lines[k].LastIndexOf("]") + 1).Replace("Simulator running from ", "").Replace("with PID:", "|").Replace("as ", "|").Trim();

                            playbookresult.simprocess   = strip.Split('|')[0].TrimEnd();
                            playbookresult.simprocessid = Int32.Parse(strip.Split('|')[1]);
                            playbookresult.user         = strip.Split('|')[2];
                        }
                        else if (lines[k].Contains("Simulation Finished"))
                        {
                            taskresult.success = true;
                            finished           = true;
                        }
                        else if (lines[k].Contains("Simulation Failed"))
                        {
                            taskresult.success = false;
                            finished           = true;
                        }
                        else
                        {
                            TaskDebugMsg debugmsg = new TaskDebugMsg();
                            debugmsg.msg = lines[k];
                            debugmsgs.Add(debugmsg);
                        }
                        skipped += 1;
                    }
                    taskresult.debugmsgs = debugmsgs;
                    taskresults.Add(taskresult);
                    i += skipped;
                }


                //Console.WriteLine(line.Substring(line.LastIndexOf(']') + 1));
            }
            playbookresult.taskresults = taskresults;
            return(playbookresult);
            //File.WriteAllText("result.json", JsonConvert.SerializeObject(taskresult));
        }