public bool executeCatNet(string fileToScan, Callbacks.dMethod_String logCallback,
                           Callbacks.dMethod_Object onProcessEndCallback, bool convertToOzasmt)
 {
     string resultsFile = Path.Combine(PublicDI.config.O2TempDir,
                                       Path.GetFileNameWithoutExtension(fileToScan) + "xml");
     return executeCatNet(fileToScan, resultsFile, logCallback, onProcessEndCallback, convertToOzasmt);
 }
        internal Process startCliProcessWithParameters(string parameters, Callbacks.dMethod_String logCallback)
        {
            try
            {
                string cliExe = Path.Combine(OunceCore.getPathToOunceInstallDirectory(),
                                             OunceCore.getCliExecutableName());
                            // OunceCore.getPathToOunceInstallDirectory() + @"\bin\cli.exe";

                DI.log.info("Scanning Ounce's CLI exe with parameters: {0}", parameters);
                return Processes.startProcessAsConsoleApplication(cliExe, parameters,
                                                                  (sender, e) =>
                                                                      {
                                                                          if (!string.IsNullOrEmpty(e.Data))
                                                                              if (logCallback != null)
                                                                                  logCallback(e.Data);
                                                                              else
                                                                                  DI.log.info("[CLI] {0}", e.Data);
                                                                      });
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in OunceCliScanning.startCliProcessWithParameters");
            }
            return null;
        }
 public static bool createCirDump(IScanTarget scScanTarget, Callbacks.dMethod_Object dProcessCompletionCallback, Callbacks.dMethod_String _logCallback,
                                  bool bDeleteAllRulesFromDbBeforeScan,
                                  bool bStoreControlFlowBlockRawDataInsideCirDataFile)
 {
     if (scScanTarget!=null)
         return createCirDump(scScanTarget.ApplicationFile, scScanTarget.WorkDirectory, dProcessCompletionCallback, _logCallback,
                              bDeleteAllRulesFromDbBeforeScan, bStoreControlFlowBlockRawDataInsideCirDataFile);
     return false;
 }
 public static bool ScanWithNoRules(String sApplicationToScan, String sScanResultsFolder,
                                    Callbacks.dMethod_Object dProcessCompletionCallback)
 {
     var srScanResults = new O2scanresults();
     srScanResults.bScanWithNoRules = true;
     bool bScanResult = srScanResults.scanApplication(sApplicationToScan);            
     DebugMsg.saveLogIntoFile(Path.Combine(sScanResultsFolder,
                                           Path.GetFileNameWithoutExtension(sApplicationToScan) +
                                           " - Scan_WithNoRules.txt"));
     return bScanResult;
 }
Ejemplo n.º 5
0
        public static bool sendMail(String sHost, String sFrom, String sTo, String sCC, String sSubject, String sMessage,
                                    List<String> lsAttachmentFiles, bool bSendSync, Callbacks.dMethod_Bool callback)
        {
            try
            {
                PublicDI.log.info("Sending email:\n" +
                            "/t/thost:{0}\n" +
                            "/t/tfrom:{1}\n" +
                            "/t/tto:{2}\n" +
                            "/t/tcc:{3}\n" +
                            "/t/tSubject:{4}\n" +
                            "/t/t# attachments:{5}",
                            sHost, sFrom, sTo, sCC, sSubject, lsAttachmentFiles.Count);
                var mmMailMessage = new MailMessage(new MailAddress(sFrom), new MailAddress(sTo));
                mmMailMessage.From = new MailAddress(sFrom);

                if (sCC != "")
                    mmMailMessage.CC.Add(new MailAddress(sCC));
                mmMailMessage.Subject = sSubject;
                mmMailMessage.Body = sMessage;
                foreach (String sAttachment in lsAttachmentFiles)
                {
                    mmMailMessage.Attachments.Add(new Attachment(sAttachment));
                }
                var scSmtpClient = new SmtpClient();
                scSmtpClient.Host = sHost;
                scSmtpClient.SendCompleted += scSmtpClient_SendCompleted;
                if (bSendSync)
                {
                    if (callback != null)
                        eventEmailCompleted += callback;
                    scSmtpClient.SendAsync(mmMailMessage, mmMailMessage.Subject);
                }
                else
                    scSmtpClient.Send(mmMailMessage);
            }
            catch (Exception ex)
            {
                PublicDI.log.error("In sendMail: {0}", ex.Message);
                callback(false);
                return false;
            }
            return true;
        }
        private bool executeCatNet(string fileToScan, string resultsFile,
                                   Callbacks.dMethod_String logCallback,
                                   Callbacks.dMethod_Object onProcessEndCallback,
                                   bool convertToOzasmt)
        {
            //string targetDirectory = (Path.GetDirectoryName(fileToScan));
            try
            {
                // if ("" != Files.checkIfDirectoryExistsAndCreateIfNot(targetDirectory))
                if (File.Exists(fileToScan))
                {
                    PublicDI.log.info("Scanning Dll {0} and saving results here {1}", fileToScan, resultsFile);
                    string sExecArguments = String.Format("/file:\"{0}\" /report:\"{1}\"", fileToScan, resultsFile);

                    Process msCatNetProcess = startCatNetProcessWithParameters(sExecArguments, logCallback);


                    Processes.waitForProcessExitAndInvokeCallBankOncompletion(msCatNetProcess,
                                                                              (executedProcess) =>
                                                                                  {
                                                                                      if (onProcessEndCallback !=
                                                                                          null)
                                                                                          onProcessEndCallback(
                                                                                              executedProcess);
                                                                                      if (convertToOzasmt &&
                                                                                          File.Exists(resultsFile))
                                                                                          new CatNetConverter(
                                                                                              resultsFile).convert();
                                                                                  }, true);
                    return true;
                }

                 PublicDI.log.error("File to scan doesn't exist: {0}", fileToScan);
                //executeCatNetCommand(sExecArguments, logCallback, onProcessEndCallback, convertToOzasmt);
            }
            catch (Exception ex)
            {
                 PublicDI.log.ex(ex, "in MsCatScan.executeCatNetCommandWithArguments");
            }

            return false;
        }
        public static void ScanWithSelectedAutomaticRuleSets(String sApplicationToScan, String sScanResultsFolder,
                                                             bool bCallBacksOnControlFlowGraphs_And_ExternalSinks,
                                                             bool bCallBacksOnEdges_And_ExternalSinks,
                                                             bool bSourcesAndSinks, String sExtraLogNameText,
                                                             Callbacks.dMethod_Object dProcessCompletionCallback,
                                                             Callbacks.dMethod_String logCallback)
        {
            O2Thread.mtaThread(() =>
                                   {
                                       DebugMsg.bLogCache = true; // enable LogCache (so that we can save it at the end
                                       var srScanResults = new O2scanresults();
                                       //if (File.Exists(CalculateCirDataFileNameInResultsFolder(sApplicationToScan, sScanResultsFolder)))
                                       //   srScanResults.sCirDataFile = CalculateCirDataFileNameInResultsFolder(sApplicationToScan, sScanResultsFolder);
                                       // load or create CirData file
                                       if (File.Exists(sApplicationToScan + ".CirData"))
                                           srScanResults.sCirDataFile = sApplicationToScan + ".CirData";
                                       else
                                           srScanResults.bCreateCirDataFile = true;
                                       // set scanning options (i.e. what to scan)
                                       srScanResults.bCallBacksOnControlFlowGraphs_And_ExternalSinks =
                                           bCallBacksOnControlFlowGraphs_And_ExternalSinks;
                                       srScanResults.bCallBacksOnEdges_And_ExternalSinks =
                                           bCallBacksOnEdges_And_ExternalSinks;
                                       srScanResults.bSourcesAndSinks = bSourcesAndSinks;

                                       srScanResults.dProcessCompletionCallback = dProcessCompletionCallback;
                                       srScanResults.logCallback = logCallback;

                                       // trigger scan
                                       bool bScanResult = srScanResults.scanApplication(sApplicationToScan);


                                       //  SaveCirDataFile(srScanResults, sScanResultsFolder);
                                       //SaveAssessmentFiles(srScanResults, sScanResultsFolder);
                                       DebugMsg.saveLogIntoFile(Path.Combine(sScanResultsFolder,
                                                                             Path.GetFileNameWithoutExtension(
                                                                                 sApplicationToScan) + " - " +
                                                                             sExtraLogNameText + ".txt"));
                                       DebugMsg.bLogCache = false;
                                   });

        }
        public bool scanApplication(string sApplicationToScan, string sPathToSaveAssessmentFile,
                                    Callbacks.dMethod_String logCallback, Callbacks.dMethod_Object onProcessEndCallback)
        {
            string cliParameters = "script \"" +
                                   getCliScript_ScanApplication(sApplicationToScan, sPathToSaveAssessmentFile) + "\"";

            scanProcess = startCliProcessWithParameters(cliParameters, logCallback);


            Processes.waitForProcessExitAndInvokeCallBankOncompletion(scanProcess,
                                                                      executedProcess =>
                                                                          {
                                                                              if (onProcessEndCallback != null)
                                                                                  onProcessEndCallback(executedProcess);
                                                                          }, true);
            return true;

            /*      Process pProcess = Processes.startProcessAsConsoleApplication(
                OunceCore.getPathToOunceInstallDirectory() + @"\bin\cli.exe", "script \"" + getCliScript_ScanApplication(sApplicationToScan,sPathToSaveAssessmentFile)+"\"");
            if (dProcessCompletionCallback != null)            
                Processes.waitForProcessExitAndInvokeCallBankOncompletion(pProcess, logCallback,  dProcessCompletionCallback, true);            
            return true;*/
        }
        public static bool createCirDump(String sApplicationToScan, String sScanResultsFolder,
                                         Callbacks.dMethod_Object dProcessCompletionCallback, Callbacks.dMethod_String _logCallback,
                                         bool bDeleteAllRulesFromDbBeforeScan,
                                         bool bStoreControlFlowBlockRawDataInsideCirDataFile)
        {
            var srScanResults = new O2scanresults
                                    {
                                        bDeleteAllRulesForCirCreation = bDeleteAllRulesFromDbBeforeScan,
                                        dProcessCompletionCallback = dProcessCompletionCallback,
                                        logCallback = _logCallback,
                                        bCreateCirDataFile = true,
                                        bStoreControlFlowBlockRawDataInsideCirDataFile =
                                            bStoreControlFlowBlockRawDataInsideCirDataFile,
                                        bDeleteCreatedAssessmentFile = true
                                    };
            // srScanResults.sPathToCirDumpFiles = sScanResultsFolder; // o2.rules.scan.CalculateCirDataFileNameInResultsFolder(sApplicationToScan, sScanResultsFolder);

            bool bScanResult = srScanResults.scanApplication(sApplicationToScan);


            //o2.rules.scan.SaveCirDataFile(srScanResults, sScanResultsFolder);
            DebugMsg.saveLogIntoFile(Path.Combine(sScanResultsFolder,
                                                  Path.GetFileNameWithoutExtension(sApplicationToScan) +
                                                  " - CreateConsolidatedCirDump.txt"));

            return bScanResult;
        }
 public void registerCallbackForNodeSignatureSelection(Callbacks.dMethod_String dDelegateString)
 {
     eNodeEvent_SignatureSelected += dDelegateString;
 }
Ejemplo n.º 11
0
 public void setCallBackWhenCompleted(Callbacks.dMethod_String _callbackWhenCompleted)
 {
     dCallbackWhenCompleted = _callbackWhenCompleted;
 }
Ejemplo n.º 12
0
        public static void downloadFileUsingAscxDownload(string sFileToDownload, String sTargetFileOrFolder,
                                                         Callbacks.dMethod_String dCallbackWhenCompleted)
        {
            O2Thread.mtaThread(
                () =>
                    {
                        var windowTitle = "{0} : {1}".format("Download File", sFileToDownload);
                        O2Messages.openControlInGUISync(typeof (DownloadFile), O2DockState.Float, windowTitle);

                        O2Messages.getAscx(windowTitle,
                                           guiControl =>
                                               {
                                                   if (guiControl != null && guiControl is DownloadFile)
                                                   {
                                                       //var downloadFile = (IControl_DownloadFile)guiControl;
                                                       //O2Messages.openAscxGui(typeof (DownloadFile), O2DockState.Float, "Download File");
                                                       var adfDownloadFile = (DownloadFile) guiControl;
                                                       // Exec.openNewWindowWithControl("DownloadFile");
                                                       adfDownloadFile.invokeOnThread(
                                                           delegate
                                                               {
                                                                   adfDownloadFile.setDownloadDetails(sFileToDownload,sTargetFileOrFolder);
                                                                   adfDownloadFile.setAutoCloseOnDownload(true);
                                                                   adfDownloadFile.setCallBackWhenCompleted(dCallbackWhenCompleted);
                                                                   adfDownloadFile.downloadFile();
                                                                   return default(object);
                                                               });

                                                   }
                                               });
                    });
        }
Ejemplo n.º 13
0
 public static void waitForProcessExitAndInvokeCallBankOncompletion_Thread(Process pProcess,
                                                                           Callbacks.dMethod_Object
                                                                               dProcessCompletionCallback,
                                                                           bool bNoExecutionTimeLimit)
 {
     try
     {
         if (pProcess != null)
         {
             if (bNoExecutionTimeLimit)
                 pProcess.WaitForExit();
             else
                 pProcess.WaitForExit(iMaxProcessExecutionTimeOut);
         }
         Callbacks.raiseRegistedCallbacks(dProcessCompletionCallback, new object[] {pProcess});
     }
     catch (Exception ex)
     {
         PublicDI.log.ex(ex, "In waitForProcessExitAndInvokeCallBankOncompletion:", true);
     }
 }
Ejemplo n.º 14
0
 public static void waitForProcessExitAndInvokeCallBankOncompletion(Process pProcess, Callbacks.dMethod_Object dProcessCompletionCallback,  bool bNoExecutionTimeLimit)
 {
     ThreadStart tsThreadStart =
         () => waitForProcessExitAndInvokeCallBankOncompletion_Thread(pProcess, dProcessCompletionCallback,
                                                                      bNoExecutionTimeLimit);
     new Thread(tsThreadStart).Start();
 }
        private void onAfterTreeViewCheck(TreeNode checkedTreeNode, ref bool _bRecursivelyCheckingAllSubNodes, TreeView targetTreeView, Callbacks.dMethod_ListString onTreeViewCheckClick)
        {
            if (false == _bRecursivelyCheckingAllSubNodes)
            {
                bRecursivelyCheckingAllSubNodes = true;
                O2Forms.setCheckBoxStatusForAllTreeNodeChilds_recursive(checkedTreeNode.Nodes, checkedTreeNode.Checked);
                O2Forms.setCheckBoxStatusForAllParentNodes_recursive(checkedTreeNode, false);

                var ltnCurrentlySelectedClasses = new List<TreeNode>();
                O2Forms.calculateListOfCurrentlySelectedClasses_Recursive(targetTreeView.Nodes,ltnCurrentlySelectedClasses);
                // clear this variable
                selectedFilteredSignatures = new List<FilteredSignature>();
                if (ltnCurrentlySelectedClasses.Count > 0)
                {
                    foreach (TreeNode tnTreeNode in ltnCurrentlySelectedClasses)
                    {
                        if (tnTreeNode.Tag != null)
                            switch (tnTreeNode.Tag.GetType().Name)
                            {
                                case "FilteredSignature":
                                    var fsFilteredSig = (FilteredSignature) tnTreeNode.Tag;
                                    if (false == selectedFilteredSignatures.Contains(fsFilteredSig))
                                        selectedFilteredSignatures.Add(fsFilteredSig);

                                    break;
                                case "List`1":
                                    //Type tTyp = tnTreeNode.Tag.GetType();
                                    var lfsFilteredSignatures = (List<FilteredSignature>) tnTreeNode.Tag;
                                    selectedFilteredSignatures.AddRange(lfsFilteredSignatures);
                                    break;
                                default:
                                    break;
                            }
                    }
                }

                // fire sevent with selected signatures
                Callbacks.raiseRegistedCallbacks(_onAfterSelect, new object[] {selectedFilteredSignatures});
                // create  list of signatures and fire event
                var lsCurrentlySelectedClasses = new List<String>();
                foreach (var fsFilteredSignature in selectedFilteredSignatures)
                    if (false == lsCurrentlySelectedClasses.Contains(fsFilteredSignature.sOriginalSignature))
                        lsCurrentlySelectedClasses.Add(fsFilteredSignature.sOriginalSignature);

                if (onTreeViewCheckClick != null)
                    onTreeViewCheckClick.Invoke(lsCurrentlySelectedClasses);

                bRecursivelyCheckingAllSubNodes = false;
            }
        }
 public testCirDumpLoad_thread(String sFileToLoad, List<String> lFilesThatLoadOk,
                               List<String> lFilesThatDontLoad, Callbacks.dMethod_Int dCallback)
 {
     this.sFileToLoad = sFileToLoad;
     this.lFilesThatLoadOk = lFilesThatLoadOk;
     this.lFilesThatDontLoad = lFilesThatDontLoad;
     dTestCompleted += dCallback;
 }
Ejemplo n.º 17
0
 public static void downloadFileUsingAscxDownload(String sFileToDownload,
                                                  Callbacks.dMethod_String downloadDemoFileCallback)
 {
     if (String.IsNullOrEmpty(sFileToDownload))
         PublicDI.log.error("in downloadFileUsingAscxDownload: No file provided");
     else
     {
         string sTargetFile = Path.Combine(PublicDI.config.O2TempDir, Path.GetFileName(sFileToDownload));
         downloadFileUsingAscxDownload(sFileToDownload, sTargetFile, downloadDemoFileCallback);
     }
 }
 public void scan(IScanTarget scanTarget, Callbacks.dMethod_String logCallback,
                  Callbacks.dMethod_Object onProcessEndCallback, bool convertToOzasmt)
 {
     if (false == MsCatNetConfig.isCatScannerAvailable())
     {
         PublicDI.log.error("Could not find MSCatNet Scanner on this box, aborting scan");
     }
     string fileToScan = scanTarget.Target;
     string reportFile = Path.Combine(scanTarget.WorkDirectory, Path.GetFileName(fileToScan) + ".xml");
     executeCatNet(fileToScan, reportFile, logCallback, onProcessEndCallback, convertToOzasmt);
 }
        /*   public static void runMSCatNetScan(string fileToScan, string pathToSaveResults, bool convertToOzasmt )
        {
            executeCatNet(fileToScan,pathToSaveResults, )
        }*/

        internal Process startCatNetProcessWithParameters(string parameters, Callbacks.dMethod_String logCallback)
        {
            try
            {
                 PublicDI.log.info("Scanning CAT.NET exe with parameters: {0}", parameters);
                return Processes.startProcessAsConsoleApplication(MsCatNetConfig.pathToCatCmdExe,
                                                                  parameters,
                                                                  (sender, e) =>
                                                                      {
                                                                          if (!string.IsNullOrEmpty(e.Data))
                                                                              if (logCallback != null)
                                                                                  logCallback(e.Data);
                                                                              else
                                                                                   PublicDI.log.info("[MsCatNet] {0}",
                                                                                                 e.Data);
                                                                      });
            }
            catch (Exception ex)
            {
                 PublicDI.log.ex(ex, "in MsCatScan.startCatNetProcessWithParameters");
            }
            return null;
        }
 public void registerSelectedFindingEventCallback(Callbacks.dMethod_Object callback)
 {
     eventFindingSelected += callback;
 }