Esempio n. 1
0
        // Execute Loki Silently
        public static void execute()
        {
            try
            {
                ProcessStartInfo lokiStartInfo = new ProcessStartInfo();
                lokiStartInfo.FileName        = LOKI_PATH + "\\loki\\loki.exe";
                lokiStartInfo.Arguments       = "--noindicator --dontwait -l " + LOKI_PATH + "\\loki\\results.log";
                lokiStartInfo.UseShellExecute = false;
                lokiStartInfo.CreateNoWindow  = true;

                Process lokiProc = new Process();
                lokiProc.StartInfo           = lokiStartInfo;
                lokiProc.EnableRaisingEvents = true;
                lokiProc.Start();
            } catch
            {
                PlatformConnector.reportErrorExit("Failed to start loki");
            }
        }
Esempio n. 2
0
 // Retreive Scan Results
 public static string getResults()
 {
     // read loki-results.log file
     try
     {
         string[] loki_logs = Directory.GetFiles(LOKI_PATH + "\\loki", "*.log");
         foreach (string log_file in loki_logs)
         {
             if (log_file.IndexOf("loki-upgrade") >= 0)
             {
                 continue;
             }
             return(File.ReadAllText(log_file));
         }
         return("");
     } catch
     {
         PlatformConnector.reportErrorExit("Failed to read loki scan results file");
         return(""); // just to evade IDE warnings
     }
 }
Esempio n. 3
0
        // Download Loki Zip file from the platform and extract its contents
        public static void getLoki()
        {
            // Download Loki
            try
            {
                WebClient loki_downloader = new WebClient();
                loki_downloader.DownloadFile("https://" + PlatformConnector.PLATFORM_IP + "/be/api/get/loki", LOKI_PATH + "\\loki.tar.gz");
            } catch
            {
                PlatformConnector.reportErrorExit("Failed to download Loki compressed file");
            }

            // Extract loki.gz
            try
            {
                Tar.ExtractTarGz(LOKI_PATH + "\\loki.tar.gz", LOKI_PATH);
            } catch
            {
                PlatformConnector.reportErrorExit("Failed to extract Loki compressed file");
            }
        }
Esempio n. 4
0
 // Initalize loki
 public static void initLoki(string PATH)
 {
     LOKI_PATH = PATH;
     // Create Lokix folder
     try
     {
         if (Directory.Exists(LOKI_PATH))
         {
             // Remove old folder
             try
             {
                 Directory.Delete(LOKI_PATH, true);
             } catch
             {
                 PlatformConnector.reportErrorExit("Could not remove previous lokix folder in temp");
             }
         }
         // Create a new Lokix folder
         Directory.CreateDirectory(LOKI_PATH);
     } catch
     {
         PlatformConnector.reportErrorExit("Could not create a folder for lokix in temp");
     }
 }
Esempio n. 5
0
        // Submit Results to the platform
        public static void submitResults(String results)
        {
            // Count alrts/warnings/notices
            int alerts    = 0;
            int warnings  = 0;
            int notices   = 0;
            int completed = 1;

            try
            {
                string[] stats = { "alerts", "warnings", "notices" };
                foreach (string stat_type in stats)
                {
                    string parseTemp  = "";
                    int    index_ptr  = results.IndexOf(stat_type) - 2;
                    bool   spaceFound = false;
                    while (!spaceFound)
                    {
                        parseTemp = results[index_ptr].ToString() + parseTemp;
                        index_ptr--;
                        if (results[index_ptr] == ' ')
                        {
                            spaceFound = true;
                            int numResult = Int32.Parse(parseTemp);
                            if (completed == 1)
                            {
                                alerts = numResult;
                            }
                            else if (completed == 2)
                            {
                                warnings = numResult;
                            }
                            else
                            {
                                notices = numResult;
                            }
                            completed++;
                        }
                    }
                }
            } catch
            {
                alerts   = 999;
                warnings = 999;
                notices  = 999;
            }

            // Submit results
            int  fail_count = 3; // how many times to try to submit results in case the request fails
            bool isFailed;

            do
            {
                isFailed = false;
                string response = postToApi("https://" + PLATFORM_IP + "/be/api/scan_done", "{" +
                                            "\"token\":\"" + API_TOKEN + "\", \"results\":\"" + SimpleJSON.EscapeString(results) + "\"," +
                                            "\"alerts\":\"" + alerts.ToString() + "\", \"warnings\":\"" + warnings.ToString() + "\", \"notices\":\"" + notices.ToString()
                                            + "\"}");

                if (response.IndexOf("failed") >= 0)
                {
                    isFailed = true;
                    fail_count--;
                }
            } while (isFailed && fail_count > 0);

            // Report error if not done successfully
            if (isFailed)
            {
                PlatformConnector.reportErrorExit("Failed to submit results to LokiX platform");
            }
        }