Example #1
0
 public bool executeCatNet(string fileToScan, Callbacks.dMethod_String logCallback,
                           Callbacks.dMethod_Object onProcessEndCallback, bool convertToOzasmt)
 {
     string resultsFile = Path.Combine(DI.config.O2TempDir,
                                       Path.GetFileNameWithoutExtension(fileToScan) + "xml");
     return executeCatNet(fileToScan, resultsFile, logCallback, onProcessEndCallback, convertToOzasmt);
 }
Example #2
0
        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 void downloadFileUsingAscxDownload(string sFileToDownload, String sTargetFileOrFolder,
                                                         Callbacks.dMethod_String dCallbackWhenCompleted)
        {
            O2Thread.mtaThread(
                () =>
                    {
                        var windowTitle = string.Format("{0} : {1}", "Download File", sFileToDownload);
                        O2Messages.openControlInGUISync(typeof (ascx_DownloadFile), O2DockState.Float, windowTitle);

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

                                                   }
                                               });
                    });
        }
Example #4
0
 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;
 }
Example #5
0
 public ascx_InstallFirefox(Callbacks.dMethod _callbackToRecheckIfFireFoxIsNowInstalled)
 {
     InitializeComponent();
     if (DesignMode == false)
     {
         callbackToRecheckIfFireFoxIsNowInstalled = _callbackToRecheckIfFireFoxIsNowInstalled;
         configureControl();
     }
 }
Example #6
0
 public static void waitForProcessExitAndInvokeCallBankOncompletion(Process pProcess,
                                                                    Callbacks.dMethod_Object
                                                                        dProcessCompletionCallback,
                                                                    bool bNoExecutionTimeLimit)
 {
     ThreadStart tsThreadStart =
         () => waitForProcessExitAndInvokeCallBankOncompletion_Thread(pProcess, dProcessCompletionCallback,
                                                                      bNoExecutionTimeLimit);
     new Thread(tsThreadStart).Start();
 }
Example #7
0
 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;
 }
 public static void downloadFileUsingAscxDownload(String sFileToDownload,
                                                  Callbacks.dMethod_String downloadDemoFileCallback)
 {
     if (String.IsNullOrEmpty(sFileToDownload))
         DI.log.error("in downloadFileUsingAscxDownload: No file provided");
     else
     {
         string sTargetFile = Path.Combine(DI.config.O2TempDir, Path.GetFileName(sFileToDownload));
         downloadFileUsingAscxDownload(sFileToDownload, sTargetFile, downloadDemoFileCallback);
     }
 }
Example #9
0
 public static void unzipFileAndInvokeCallback(string assessmentFile, FlowLayoutPanel taskHostControl,
                                               Callbacks.dMethod_String callbackToInvokeForEachUnzippedFile)
 {
     executeTask(new Task_Unzip(assessmentFile, DI.config.TempFolderInTempDirectory),
                 taskHostControl,
                 resultObject =>
                     {
                         if (resultObject is List<string>)
                             foreach (string item in (List<string>)resultObject)
                                 callbackToInvokeForEachUnzippedFile(item);
                     });
 }
Example #10
0
        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;
                                   });

        }
Example #11
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
     {
         DI.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, sFrom, sCC, sSubject, lsAttachmentFiles.Count);
         var mmMailMessage = new MailMessage(new MailAddress(sFrom), new MailAddress(sTo))
                                 {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 {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)
     {
         DI.log.error("In sendMail: {0}", ex.Message);
         callback(false);
         return false;
     }
     return true;
 }
Example #12
0
        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))
                {
                     DI.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;
                }

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

            return false;
        }
Example #13
0
        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;*/
        }
Example #14
0
 public void scan(IScanTarget scanTarget, Callbacks.dMethod_String logCallback,
                  Callbacks.dMethod_Object onProcessEndCallback, bool convertToOzasmt)
 {
     if (false == MsCatNetConfig.isCatScannerAvailable())
     {
         DI.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);
 }
Example #15
0
 public void registerCallbackForNodeSignatureSelection(Callbacks.dMethod_String dDelegateString)
 {
     eNodeEvent_SignatureSelected += dDelegateString;
 }
Example #16
0
        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;
        }
        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 void registerSelectedFindingEventCallback(Callbacks.dMethod_Object callback)
 {
     eventFindingSelected += callback;
 }        
Example #19
0
 public void executeCatNetCommand(string commandToExecute, Callbacks.dMethod_String callbackCatNetLogEvent)
 {
     if (commandToExecute != "")
     {
         new MsCatNetScanner().startCatNetProcessWithParameters(commandToExecute, callbackCatNetLogEvent);
             //, callbackCatNetScanComplete);
     }
 }
Example #20
0
 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;
 }
Example #21
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)
     {
         DI.log.ex(ex, "In waitForProcessExitAndInvokeCallBankOncompletion:", true);
     }
 }
Example #22
0
        /*   public static void runMSCatNetScan(string fileToScan, string pathToSaveResults, bool convertToOzasmt )
        {
            executeCatNet(fileToScan,pathToSaveResults, )
        }*/

        internal Process startCatNetProcessWithParameters(string parameters, Callbacks.dMethod_String logCallback)
        {
            try
            {
                 DI.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
                                                                                   DI.log.info("[MsCatNet] {0}",
                                                                                                 e.Data);
                                                                      });
            }
            catch (Exception ex)
            {
                 DI.log.ex(ex, "in MsCatScan.startCatNetProcessWithParameters");
            }
            return null;
        }
 public void setCallBackWhenCompleted(Callbacks.dMethod_String _callbackWhenCompleted)
 {
     dCallbackWhenCompleted = _callbackWhenCompleted;
 }