Exemple #1
0
        /*public static List<O2Finding> glueSinksToSources(O2Assessment o2AssessmentWithSinks, O2Assessment o2AssessmentWithSources)
         * {
         *  var webLayerSources = getO2StringIndexes(webLayer, TraceType.Source);
         *
         *  foreach (var clickButtonFinding in clickButton.o2Findings)
         *  {
         *      results.Add(clickButtonFinding);
         *      var sink = OzasmtUtils.getKnownSink(clickButtonFinding.o2Trace);
         *      PublicDI.log.debug(sink.signature);
         *      if (webLayerSources.ContainsKey(sink.signature))
         *          foreach (var webLayerSource in webLayerSources[sink.signature])
         *          {
         *              results.Add(OzasmtGlue.createCopyAndGlueTraceAndSink(clickButtonFinding,
         *                                                                   OzasmtUtils.getSource(
         *                                                                       webLayerSource.o2Trace)));
         *              /*var o2NewFinding = OzasmtCopy.createCopy(clickButtonFinding);
         *              var newFindingSink = OzasmtUtils.getKnownSink(o2NewFinding.o2Trace);
         *              newFindingSink.traceType = TraceType.Type_4;
         *              var sourceToGlue = OzasmtCopy.createCopy(OzasmtUtils.getSource(webLayerSource.o2Trace));
         *              sourceToGlue.traceType = TraceType.Type_0;
         *              newFindingSink.childTraces.Add(sourceToGlue);
         *              results.Add(o2NewFinding);*/
        /*         }
         * }*/

        public static IO2Finding createCopyAndGlueTraceSinkWithSource(IO2Finding o2TemplateFinding,
                                                                      IO2Trace o2TraceWithSource)
        {
            IO2Trace sourceToGlue = OzasmtCopy.createCopy(OzasmtUtils.getSource(o2TraceWithSource));

            return(createCopyAndGlueTraceSinkWithTrace(o2TemplateFinding, sourceToGlue));
        }
Exemple #2
0
        private string getNodeText(IO2Trace o2TraceToLoad)
        {
            string nodeText = "";

            if (tracePropertyToUseAsNodeText == "SourceCode")
            {
                nodeText = Files.getLineFromSourceCode(o2TraceToLoad.file, o2TraceToLoad.lineNumber);
                if (nodeText == "")
                {
                    nodeText = "[no source code available]";
                }
                //Files.getLineFromSourceCode(o2TraceToLoad.file, o2TraceToLoad.lineNumber) :
            }
            else
            {
                nodeText = DI.reflection.getProperty(tracePropertyToUseAsNodeText, o2TraceToLoad).ToString();
            }
            if (nodeText == "")
            {
                nodeText = (o2TraceToLoad.signature != "") ? o2TraceToLoad.signature : o2TraceToLoad.method;
            }

            // hack to deal with encoded quotes
            nodeText = nodeText.Replace("&quot;", "\"");
            return(nodeText);
        }
        public static IO2Trace createCopy(IO2Trace o2Trace, bool processChildTraces)
        {
            if (o2Trace == null)
            {
                return(null);
            }

            var newO2Trace = new O2Trace
            {
                clazz            = o2Trace.clazz,
                columnNumber     = o2Trace.columnNumber,
                context          = o2Trace.context,
                file             = o2Trace.file,
                method           = o2Trace.method,
                lineNumber       = o2Trace.lineNumber,
                ordinal          = o2Trace.ordinal,
                signature        = o2Trace.signature,
                taintPropagation = o2Trace.taintPropagation,
                traceType        = o2Trace.traceType,
                text             = createCopy(o2Trace.text)
            };

            if (processChildTraces)
            {
                newO2Trace.childTraces = createCopy(o2Trace.childTraces);
            }
            return(newO2Trace);
        }
 private static void setSafeO2TraceContextValue(IO2Trace o2Trace, string value)
 {
     if (o2Trace != null)
     {
         o2Trace.context = value;
     }
 }
        public static CallInvocation getCallInvocationObjectFromO2Trace(IO2Trace o2Trace, Dictionary <string, uint> dStringIndexes, Dictionary <string, uint> dFilesIndexes)
        {
            //  return new CallInvocation();
            var callInvocation = new CallInvocation
            {
                cn_id             = addTextToStringIndexes(o2Trace.clazz, dStringIndexes),
                column_number     = o2Trace.columnNumber,
                cxt_id            = addTextToStringIndexes(o2Trace.context, dStringIndexes),
                fn_id             = addTextToFileIndexes(o2Trace.file, dFilesIndexes),
                line_number       = o2Trace.lineNumber,
                mn_id             = addTextToStringIndexes(o2Trace.method, dStringIndexes),
                ordinal           = o2Trace.ordinal,
                sig_id            = addTextToStringIndexes(o2Trace.signature, dStringIndexes),
                taint_propagation = o2Trace.taintPropagation,
                Text       = o2Trace.text.ToArray(),
                trace_type = Convert.ToUInt32(o2Trace.traceType)
            };

            if (o2Trace.childTraces != null) // means there are child traces
            {
                var childCallInvocation = new List <CallInvocation>();
                foreach (O2Trace childO2trace in o2Trace.childTraces)
                {
                    childCallInvocation.Add(getCallInvocationObjectFromO2Trace(childO2trace, dStringIndexes, dFilesIndexes));
                }
                callInvocation.CallInvocation1 = childCallInvocation.ToArray();
            }
            return(callInvocation);
        }
Exemple #6
0
        public static IO2Trace createCopy(IO2Trace o2Trace, bool processChildTraces)
        {
            if (o2Trace == null)
            {
                return(null);
            }

            var newO2Trace = new O2Trace();

            newO2Trace.text             = createCopy(o2Trace.text);
            newO2Trace.traceType        = o2Trace.traceType;
            newO2Trace.taintPropagation = o2Trace.taintPropagation;
            newO2Trace.signature        = o2Trace.signature;
            newO2Trace.ordinal          = o2Trace.ordinal;
            newO2Trace.lineNumber       = o2Trace.lineNumber;
            newO2Trace.method           = o2Trace.method;
            newO2Trace.file             = o2Trace.file;
            newO2Trace.context          = o2Trace.context;
            newO2Trace.columnNumber     = o2Trace.columnNumber;
            newO2Trace.clazz            = o2Trace.clazz;

            if (processChildTraces)
            {
                newO2Trace.childTraces = createCopy(o2Trace.childTraces);
            }
            return(newO2Trace);
        }
Exemple #7
0
        public void showO2Trace(IO2Trace o2Trace)
        {
            this.invokeOnThread(() =>
            {
                currentO2Trace = o2Trace;
                btSaveChangesToTrace.Visible = false;
                if (o2Trace != null)
                {
                    dgvTraceDetails.Visible = false;
                    dgvTraceDetails.Rows.Clear();

                    foreach (PropertyInfo property in o2Trace.GetType().GetProperties())
                    {
                        if (property.Name != "childTraces")
                        {
                            var newRow   = new DataGridViewRow();
                            var cellName = new DataGridViewTextBoxCell {
                                Value = property.Name
                            };
                            var cellValue = new DataGridViewTextBoxCell
                            {
                                ValueType = property.PropertyType,
                                Value     = DI.reflection.getProperty(property.Name, o2Trace)
                            };

                            newRow.Cells.AddRange(new[] { cellName, cellValue });
                            dgvTraceDetails.Rows.Add(newRow);
                        }
                    }
                    cbCurrentO2TraceType.Text =
                        getCellWithCurrentO2TraceText("traceType").Value.ToString();
                    dgvTraceDetails.Visible = true;
                }
            });
        }
 public void onTraceSelectedEvent(IO2Trace o2SelectedTrace)
 {
     if (o2SelectedTrace != null && invokeOnTraceSelectedEvent)
     {
         DI.log.info("onTraceSelectedEvent :{0}", o2SelectedTrace.signature);
         rulePackViewer.editRule(o2SelectedTrace.signature);
     }
 }
Exemple #9
0
 public void onTraceSelectedEvent(IO2Trace o2SelectedTrace)
 {
     if (o2SelectedTrace != null && invokeOnTraceSelectedEvent)
     {
         DI.log.info("onTraceSelectedEvent :{0}", o2SelectedTrace.signature);
         rulePackViewer.editRule(o2SelectedTrace.signature);
     }
 }
 private void dynamicJoin_onTraceSelected(IO2Trace o2TraceSelected)
 {
     if (o2TraceSelected.traceType == TraceType.Lost_Sink)
     {
         var sources = JoinFindings_OnInterfaces.getSources(findingsViewer_SourcesMappedToInterfaces.currentO2Findings);
         if (sources.ContainsKey(o2TraceSelected.signature))
         {
             findingsViewers_withSourcesForInterfaces.loadO2Findings(sources[o2TraceSelected.signature], true);
         }
     }
 }
        public void loadO2TraceIntoTreeNodeCollection(IO2Trace o2TraceToLoad, TreeNodeCollection treeNodeCollection)
        {
            string nodeText = getNodeText(o2TraceToLoad);

            TreeNode newNode = O2Forms.newTreeNode(nodeText, nodeText, 0, o2TraceToLoad);
            newNode.ForeColor = OzasmtUtils.getTraceColorBasedOnTraceType(o2TraceToLoad);
            treeNodeCollection.Add(newNode);
            if (o2TraceToLoad == o2Trace)
                tvSmartTrace.SelectedNode = newNode;
            foreach (O2Trace childO2Trace in o2TraceToLoad.childTraces)
                loadO2TraceIntoTreeNodeCollection(childO2Trace, newNode.Nodes);
        }
 public static SourceCodeEditor show(this SourceCodeEditor codeEditor, IO2Trace o2Trace)
 {
     codeEditor.open(o2Trace.file);
     if (o2Trace.lineNumber > 0)
     {
         codeEditor.editor().gotoLine((int)o2Trace.lineNumber - 1);
         //codeViewer.editor().caret_Line();
         codeEditor.editor().caret_Line((int)o2Trace.lineNumber - 1);
         codeEditor.editor().caret_Column((int)o2Trace.columnNumber);
     }
     return(codeEditor);
 }
Exemple #13
0
 public static bool isO2TraceAChildTraceOfO2Trace(IO2Trace rootO2Trace, IO2Trace o2TraceToFind)
 {
     if (rootO2Trace != null)
         foreach (IO2Trace o2ChildTrace in rootO2Trace.childTraces)
         {
             if (o2ChildTrace == o2TraceToFind)
                 return true;
             bool match = isO2TraceAChildTraceOfO2Trace(o2ChildTrace, o2TraceToFind);
             if (match)
                 return true;
         }
     return false;
 }
        private void dynamicJoin_onTraceSelected(IO2Trace o2TraceSelected)
        {
            if (o2TraceSelected.traceType == TraceType.Lost_Sink)
            {
                var sources = JoinFindings_OnInterfaces.getSources(findingsViewer_SourcesMappedToInterfaces.currentO2Findings);                
                if (sources.ContainsKey(o2TraceSelected.signature))
                {
                    findingsViewers_withSourcesForInterfaces.loadO2Findings(sources[o2TraceSelected.signature],true);
                }

            }
            
        }
        public static List <IO2Finding> getFindingsWithSink(List <IO2Finding> findings, string regExToFind)
        {
            var results = new List <IO2Finding>();

            foreach (IO2Finding o2Finding in findings)
            {
                IO2Trace sink = OzasmtUtils.getKnownSink(o2Finding.o2Traces);
                if (sink != null && sink.signature != "" && RegEx.findStringInString(sink.signature, regExToFind))
                {
                    results.Add(o2Finding);
                }
            }
            return(results);
        }
Exemple #16
0
        public static IO2Finding createCopyAndGlueTraceSinkWithTrace(IO2Finding o2TemplateFinding,
                                                                     List <IO2Trace> o2TracesToGlue)
        {
            IO2Finding o2NewFinding = OzasmtCopy.createCopy(o2TemplateFinding);
            //IO2Trace newFindingSink = OzasmtUtils.getKnownSink(o2NewFinding.o2Traces);
            IO2Trace newFindingSink = OzasmtUtils.getSink(o2NewFinding.o2Traces);

            newFindingSink.traceType = TraceType.Root_Call;
            foreach (O2Trace o2TraceToGlue in o2TracesToGlue)
            {
                o2TraceToGlue.traceType = TraceType.Root_Call;
                newFindingSink.childTraces.Add(o2TraceToGlue);
            }
            return(o2NewFinding);
        }
Exemple #17
0
 public static void deleteO2Trace(List<IO2Trace> o2Traces, IO2Trace o2TraceToDelete)
 {
     foreach (O2Trace o2Trace in o2Traces)
     {
         if (o2Trace == o2TraceToDelete)
         {
             o2Traces.Remove(o2TraceToDelete);
             return;
         }
         if (deleteO2Trace(o2Trace, o2TraceToDelete))
             return;
     }
     /*if (o2Finding.o2Traces == o2TraceToDelete)
         o2Finding.o2Trace = null;
     else*/
 }
Exemple #18
0
 public static IO2Trace findO2TraceSignature(IO2Trace o2Trace, string signatureToFind)
 {
     if (o2Trace != null)
     {
         if (o2Trace.signature == signatureToFind)
             return o2Trace;
         if (o2Trace.childTraces != null)
             foreach (IO2Trace o2ChildTrace in o2Trace.childTraces)
             {
                 IO2Trace match = findO2TraceSignature(o2ChildTrace, signatureToFind);
                 if (match != null)
                     return match;
             }
     }
     return null;
 }
Exemple #19
0
        public static IO2Finding createO2FindingFromTrace(IO2Trace o2Trace)
        {
            var o2Finding = new O2Finding();

            o2Finding.vulnType     = "FindingFromTrace";
            o2Finding.vulnName     = o2Trace.signature;
            o2Finding.text         = OzasmtCopy.createCopy(o2Trace.text);
            o2Finding.ordinal      = o2Trace.ordinal;
            o2Finding.o2Traces     = new List <IO2Trace>().add(OzasmtCopy.createCopy(o2Trace));
            o2Finding.lineNumber   = o2Trace.lineNumber;
            o2Finding.file         = o2Trace.file;
            o2Finding.columnNumber = o2Trace.columnNumber;
            o2Finding.context      = o2Trace.context;
            o2Finding.callerName   = o2Trace.signature;
            return(o2Finding);
        }
Exemple #20
0
        public void loadO2TraceIntoTreeNodeCollection(IO2Trace o2TraceToLoad, TreeNodeCollection treeNodeCollection)
        {
            string nodeText = getNodeText(o2TraceToLoad);

            TreeNode newNode = O2Forms.newTreeNode(nodeText, nodeText, 0, o2TraceToLoad);

            newNode.ForeColor = OzasmtUtils.getTraceColorBasedOnTraceType(o2TraceToLoad);
            treeNodeCollection.Add(newNode);
            if (o2TraceToLoad == o2Trace)
            {
                tvSmartTrace.SelectedNode = newNode;
            }
            foreach (O2Trace childO2Trace in o2TraceToLoad.childTraces)
            {
                loadO2TraceIntoTreeNodeCollection(childO2Trace, newNode.Nodes);
            }
        }
Exemple #21
0
 public static IO2Finding createO2FindingFromTrace(IO2Trace o2Trace)
 {
     var o2Finding = new O2Finding
                         {
                             callerName = o2Trace.signature,
                             context = o2Trace.context,
                             columnNumber = o2Trace.columnNumber,
                             file = o2Trace.file,
                             lineNumber = o2Trace.lineNumber,
                             o2Traces = new List<IO2Trace> {OzasmtCopy.createCopy(o2Trace)},
                             ordinal = o2Trace.ordinal,
                             text = OzasmtCopy.createCopy(o2Trace.text),
                             vulnName = o2Trace.signature,
                             vulnType = "FindingFromTrace"
                         };
     return o2Finding;
 }
Exemple #22
0
        public static O2Finding createO2FindingFromWebInspectFinding(WebInspectFinding webInspectFinding, string keyword)
        {
            var      o2Trace = new O2Trace("WebInspect -> Ounce Mapping (Sql Injection)");
            IO2Trace sink    = createSink(webInspectFinding);

            o2Trace.childTraces.Add(sink);

            return(new O2Finding
            {
                o2Traces = new List <IO2Trace> {
                    o2Trace
                },
                //context = webInspectFinding.payload,
                context = webInspectFinding.fullUrl,
                vulnName = keyword + "_" + webInspectFinding.param,
                vulnType = "Sql Injection (from WebInspect)"
            });
        }
        public static List <IO2Finding> findWebControlSources(List <IO2Finding> o2Findings)
        {
            var methodsToFind = new RegEx("System.Web.UI.WebControls.*get_Text");
            //var methodsToFind = new RegEx("HttpRequest");
            var results = new List <IO2Finding>();

            foreach (IO2Finding o2Finding in o2Findings)
            {
                IO2Trace source = ((O2Finding)o2Finding).getSource();
                if (source != null && methodsToFind.find(source.ToString()))
                // && o2Finding.getSource.ToString() != "")
                {
                    if (source.context.Contains("txt"))
                    {
                        // DI.log.info(source + " -> " + (o2Finding.getSink != null ? o2Finding.getSink.ToString() : ""));
                        string variableName = OzasmtContext.getVariableNameFromThisObject(source);
                        // DI.log.info(o2Finding.o2Trace + "  :::  " + );// + "    :    " + source.context);
                        foreach (IO2Trace o2Trace in o2Finding.o2Traces)
                        {
                            List <string> wordsFromSignature =
                                OzasmtUtils.getListWithWordsFromSignature(o2Trace.signature);
                            foreach (string word in wordsFromSignature)
                            {
                                //           var sourceO2Trace = new O2Trace("OunceLabs:  " + word);
                                //           var sinkO2Trace = new O2Trace("OunceLabs:   " + variableName);
                                //           sinkO2Trace.childTraces.Add(o2Finding.o2Trace);
                                //           sourceO2Trace.childTraces.Add(sinkO2Trace);

                                var newO2Finding = new O2Finding
                                {
                                    vulnType = "ASP.NET Attack Surface",
                                    vulnName = word + "_" + variableName,
                                    //o2Trace = sourceO2Trace
                                    o2Traces = o2Finding.o2Traces
                                };
                                results.Add(newO2Finding);
                            }
                        }
                    }
                    // DI.log.info("    " + o2Finding.getSource + " -> " + o2Finding.getSource.context + "\n\n");
                }
            }
            return(results);
        }
        private static bool applyRuleToTrace(IO2Trace o2Trace, ICollection <IO2Trace> o2PartialTraces, IO2Finding parentO2Finding, List <IO2Finding> findingsCreated, IDictionary <string, List <IO2Rule> > indexedRules)
        {
//            if (o2Trace.signature.IndexOf("System.Data.SqlClient.SqlCommand") > -1)
//                DI.log.info(o2Trace.signature);
            var signatureToFind = MakeSignatureCompatibleWithOunceRules(o2Trace.signature);


            //           if (signatureToFind.IndexOf("System.Data.SqlClient") > -1)
            //               DI.log.info(signatureToFind);

            if (indexedRules.ContainsKey(signatureToFind))  // means we have a match
            {
                // rename to shouldAbortRulesCreation
                if (shouldAbortRulesExecution(indexedRules[signatureToFind]))
                {
                    if (o2Trace.traceType == TraceType.Known_Sink || o2Trace.traceType == TraceType.Lost_Sink)
                    {
                        return(false);
                    }
                    return(true);
                }
                // check if we are a sink at the root of the tree with no child nodes (and if so skip trace creation)
                if (parentO2Finding.o2Traces.Count == 0) //; && (o2Trace.traceType == TraceType.Known_Sink || o2Trace.traceType == TraceType.Lost_Sink || o2Trace.traceType == TraceType.Root_Call))
                {
                    return(true);
                }
                // check if there are no sources on the trace
                if (((O2Finding)parentO2Finding).Source == "")
                {
                    return(false);
                }

                var newTrace = OzasmtCopy.createCopy(o2Trace, false);                                                                          //create new trace (which will be modified
                newTrace.traceType = TraceType.Known_Sink;                                                                                     // make the trace  a sink
                o2PartialTraces.Add(newTrace);                                                                                                 // add it to the partial trace

                var newFindingWithSinkTrace = OzasmtCopy.createCopy(parentO2Finding);                                                          // create template finding which will be applied the rules
                findingsCreated.AddRange(FiltersUtils.applySinkRuleToFindingAndTrace(newFindingWithSinkTrace, signatureToFind, indexedRules)); // apply rules and add resulting findings to findingsCreated list
                //remove the new trace since the invokeOnAllPartialTraces loop will add its own copy
                o2PartialTraces.Remove(newTrace);
            }
            return(true); // in this case return true since we want to process ALL traces
        }
Exemple #25
0
        public static void deleteO2Trace(List <IO2Trace> o2Traces, IO2Trace o2TraceToDelete)
        {
            foreach (O2Trace o2Trace in o2Traces)
            {
                if (o2Trace == o2TraceToDelete)
                {
                    o2Traces.Remove(o2TraceToDelete);
                    return;
                }
                if (deleteO2Trace(o2Trace, o2TraceToDelete))
                {
                    return;
                }
            }

            /*if (o2Finding.o2Traces == o2TraceToDelete)
             *  o2Finding.o2Trace = null;
             * else*/
        }
 public static bool isO2TraceAChildTraceOfO2Trace(IO2Trace rootO2Trace, IO2Trace o2TraceToFind)
 {
     if (rootO2Trace != null)
     {
         foreach (IO2Trace o2ChildTrace in rootO2Trace.childTraces)
         {
             if (o2ChildTrace == o2TraceToFind)
             {
                 return(true);
             }
             bool match = isO2TraceAChildTraceOfO2Trace(o2ChildTrace, o2TraceToFind);
             if (match)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        private string getNodeText(IO2Trace o2TraceToLoad)
        {
            string nodeText = "";
            if (tracePropertyToUseAsNodeText == "SourceCode")
            {
                nodeText = Files.getLineFromSourceCode(o2TraceToLoad.file, o2TraceToLoad.lineNumber);
                if (nodeText == "")
                    nodeText = "[no source code available]";
                //Files.getLineFromSourceCode(o2TraceToLoad.file, o2TraceToLoad.lineNumber) :
            }
            else
                nodeText = DI.reflection.getProperty(tracePropertyToUseAsNodeText, o2TraceToLoad).ToString();
            if (nodeText == "")
                nodeText = (o2TraceToLoad.signature != "") ? o2TraceToLoad.signature : o2TraceToLoad.method;

            // hack to deal with encoded quotes
            nodeText = nodeText.Replace("&quot;","\"");
            return nodeText;
        }
Exemple #28
0
 public static bool deleteO2Trace(IO2Trace o2RootTrace, IO2Trace o2TraceToDelete)
 {
     foreach (O2Trace o2ChildTrace in o2RootTrace.childTraces)
     {
         if (o2ChildTrace == o2TraceToDelete)
         {
             o2RootTrace.childTraces.Remove(o2ChildTrace);
             return(true);
         }
         else
         {
             bool foundItemToDelete = deleteO2Trace(o2ChildTrace, o2TraceToDelete);
             if (foundItemToDelete)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
 public static IO2Trace getTraceType(List <IO2Trace> o2Traces, TraceType traceType)
 {
     foreach (IO2Trace o2Trace in o2Traces)
     {
         if (o2Trace.traceType == traceType)
         {
             return(o2Trace);
         }
         if (o2Trace.childTraces != null)
         //foreach (O2Trace childO2Trace in o2Trace.childTraces)
         {
             IO2Trace result = getTraceType(o2Trace.childTraces, traceType);
             if (null != result)
             {
                 return(result);
             }
         }
     }
     return(null);
 }
Exemple #30
0
        public static IO2Finding createO2FindingFromTrace(IO2Trace o2Trace)
        {
            var o2Finding = new O2Finding
            {
                callerName   = o2Trace.signature,
                context      = o2Trace.context,
                columnNumber = o2Trace.columnNumber,
                file         = o2Trace.file,
                lineNumber   = o2Trace.lineNumber,
                o2Traces     = new List <IO2Trace> {
                    OzasmtCopy.createCopy(o2Trace)
                },
                ordinal  = o2Trace.ordinal,
                text     = OzasmtCopy.createCopy(o2Trace.text),
                vulnName = o2Trace.signature,
                vulnType = "FindingFromTrace"
            };

            return(o2Finding);
        }
        public static Color getTraceColorBasedOnTraceType(IO2Trace o2Trace)
        {
            switch (o2Trace.traceType)
            {
            case TraceType.Type_0:
                return(Color.DarkBlue);

            case TraceType.Known_Sink:
                return(KnownSinkColor);

            case TraceType.Lost_Sink:
                return(LostSinkColor);

            case TraceType.Root_Call:
            case TraceType.Type_6:
                return(Color.DarkBlue);

            case TraceType.Source:
                return(SourceColor);

            case TraceType.Type_4:
                return(Color.Green);

            case TraceType.O2JoinSink:
                return(Color.DeepSkyBlue);

            case TraceType.O2JoinSource:
                return(Color.LimeGreen);

            case TraceType.O2JoinLocation:
                return(Color.Purple);

            case TraceType.O2Info:
                return(Color.Black);

            default:
                return(Color.Gray);
            }
        }
Exemple #32
0
        public static IO2Trace createCopy(IO2Trace o2Trace, bool processChildTraces)
        {
            if (o2Trace == null)
                return null;

            var newO2Trace = new O2Trace();
            newO2Trace.text = createCopy(o2Trace.text);
            newO2Trace.traceType = o2Trace.traceType;
            newO2Trace.taintPropagation = o2Trace.taintPropagation;
            newO2Trace.signature = o2Trace.signature;
            newO2Trace.ordinal = o2Trace.ordinal;
            newO2Trace.lineNumber = o2Trace.lineNumber;
            newO2Trace.method = o2Trace.method;
            newO2Trace.file = o2Trace.file;
            newO2Trace.context = o2Trace.context;
            newO2Trace.columnNumber = o2Trace.columnNumber;
            newO2Trace.clazz = o2Trace.clazz;

            if (processChildTraces)
                newO2Trace.childTraces = createCopy(o2Trace.childTraces);
            return newO2Trace;
        }
        private static bool applyRuleToTrace(IO2Trace o2Trace, ICollection<IO2Trace> o2PartialTraces, IO2Finding parentO2Finding, List<IO2Finding> findingsCreated, IDictionary<string, List<IO2Rule>> indexedRules)
        {

//            if (o2Trace.signature.IndexOf("System.Data.SqlClient.SqlCommand") > -1)
//                DI.log.info(o2Trace.signature);
            var signatureToFind = MakeSignatureCompatibleWithOunceRules(o2Trace.signature);


 //           if (signatureToFind.IndexOf("System.Data.SqlClient") > -1)
 //               DI.log.info(signatureToFind);
            
            if (indexedRules.ContainsKey(signatureToFind))  // means we have a match
            {
                // rename to shouldAbortRulesCreation
                if (shouldAbortRulesExecution(indexedRules[signatureToFind]))
                {
                    if (o2Trace.traceType == TraceType.Known_Sink || o2Trace.traceType == TraceType.Lost_Sink)
                        return false;                    
                    return true;
                }
                // check if we are a sink at the root of the tree with no child nodes (and if so skip trace creation)
                if (parentO2Finding.o2Traces.Count == 0 )//; && (o2Trace.traceType == TraceType.Known_Sink || o2Trace.traceType == TraceType.Lost_Sink || o2Trace.traceType == TraceType.Root_Call))                
                    return true;                
                // check if there are no sources on the trace
                if (((O2Finding)parentO2Finding).Source == "")
                    return false;

                var newTrace = OzasmtCopy.createCopy(o2Trace, false); //create new trace (which will be modified
                newTrace.traceType = TraceType.Known_Sink; // make the trace  a sink
                o2PartialTraces.Add(newTrace); // add it to the partial trace
                
                var newFindingWithSinkTrace = OzasmtCopy.createCopy(parentO2Finding); // create template finding which will be applied the rules
                findingsCreated.AddRange(FiltersUtils.applySinkRuleToFindingAndTrace(newFindingWithSinkTrace, signatureToFind, indexedRules)); // apply rules and add resulting findings to findingsCreated list
                //remove the new trace since the invokeOnAllPartialTraces loop will add its own copy
                o2PartialTraces.Remove(newTrace);

            }            
            return true; // in this case return true since we want to process ALL traces
        }
 public static IO2Trace findO2TraceSignature(IO2Trace o2Trace, string signatureToFind)
 {
     if (o2Trace != null)
     {
         if (o2Trace.signature == signatureToFind)
         {
             return(o2Trace);
         }
         if (o2Trace.childTraces != null)
         {
             foreach (IO2Trace o2ChildTrace in o2Trace.childTraces)
             {
                 IO2Trace match = findO2TraceSignature(o2ChildTrace, signatureToFind);
                 if (match != null)
                 {
                     return(match);
                 }
             }
         }
     }
     return(null);
 }
Exemple #35
0
        private void addTrace(string filename, int line, string traceText)
        {
            if (traceText == null)
            {
                return;
            }
            var o2Trace = new O2Trace(traceText);

            o2Trace.file       = filename ?? "";
            o2Trace.lineNumber = (uint)line;
            if (true || currentO2Trace == null)
            {
                o2Trace.traceType = TraceType.Source;
                currentDynamicO2Finding.o2Traces.Add(o2Trace);
                currentO2Trace = o2Trace;
            }
            else
            {
                currentO2Trace.childTraces.Add(o2Trace);
                currentO2Trace = o2Trace;
            }
            reloadTraceViewer();
        }
Exemple #36
0
        public static IO2Trace createCopy(IO2Trace o2Trace, bool processChildTraces)
        {
            if (o2Trace == null)
                return null;

            var newO2Trace = new O2Trace
                                 {
                                     clazz = o2Trace.clazz,
                                     columnNumber = o2Trace.columnNumber,
                                     context = o2Trace.context,
                                     file = o2Trace.file,
                                     method = o2Trace.method,
                                     lineNumber = o2Trace.lineNumber,
                                     ordinal = o2Trace.ordinal,
                                     signature = o2Trace.signature,
                                     taintPropagation = o2Trace.taintPropagation,
                                     traceType = o2Trace.traceType,
                                     text = createCopy(o2Trace.text)
                                 };
            if (processChildTraces)
                newO2Trace.childTraces = createCopy(o2Trace.childTraces);
            return newO2Trace;
        }
Exemple #37
0
 public static IO2Finding createCopyAndGlueTraceSinkWithTrace(IO2Finding o2TemplateFinding, IO2Trace o2TracesToGlue)
 {
     return(createCopyAndGlueTraceSinkWithTrace(o2TemplateFinding, new List <IO2Trace>().add(o2TracesToGlue)));
 }
 public void addTrace(IO2Trace targetTrace, string traceSignature, TraceType traceType)
 {
     ((O2Trace)targetTrace).addTrace(traceSignature, traceType);
 }
        public void showO2Trace(IO2Trace o2Trace)
        {
            this.invokeOnThread(() =>
                                    {
                                        currentO2Trace = o2Trace;
                                        btSaveChangesToTrace.Visible = false;
                                        if (o2Trace != null)
                                        {
                                            dgvTraceDetails.Visible = false;
                                            dgvTraceDetails.Rows.Clear();

                                            foreach (PropertyInfo property in o2Trace.GetType().GetProperties())
                                            {
                                                if (property.Name != "childTraces")
                                                {
                                                    var newRow = new DataGridViewRow();
                                                    var cellName = new DataGridViewTextBoxCell {Value = property.Name};
                                                    var cellValue = new DataGridViewTextBoxCell
                                                                        {
                                                                            ValueType = property.PropertyType,
                                                                            Value = DI.reflection.getProperty(property.Name, o2Trace)
                                                                        };

                                                    newRow.Cells.AddRange(new[] {cellName, cellValue});
                                                    dgvTraceDetails.Rows.Add(newRow);
                                                }
                                            }
                                            cbCurrentO2TraceType.Text =
                                                getCellWithCurrentO2TraceText("traceType").Value.ToString();
                                            dgvTraceDetails.Visible = true;
                                        }
                                    });
        }
        public static CallInvocation getCallInvocationObjectFromO2Trace(IO2Trace o2Trace, Dictionary<string, uint> dStringIndexes, Dictionary<string, uint> dFilesIndexes)
        {
          //  return new CallInvocation();
            var callInvocation = new CallInvocation
                                     {
                                         cn_id = addTextToStringIndexes(o2Trace.clazz, dStringIndexes),
                                         column_number = o2Trace.columnNumber,
                                         cxt_id = addTextToStringIndexes(o2Trace.context, dStringIndexes),
                                         fn_id = addTextToFileIndexes(o2Trace.file, dFilesIndexes),
                                         line_number = o2Trace.lineNumber,
                                         mn_id = addTextToStringIndexes(o2Trace.method, dStringIndexes),
                                         ordinal = o2Trace.ordinal,
                                         sig_id = addTextToStringIndexes(o2Trace.signature, dStringIndexes),
                                         taint_propagation = o2Trace.taintPropagation,
                                         Text = o2Trace.text.ToArray(),
                                         trace_type = Convert.ToUInt32(o2Trace.traceType)
                                     };

            if (o2Trace.childTraces != null) // means there are child traces
            {
                var childCallInvocation = new List<CallInvocation>();
                foreach (O2Trace childO2trace in o2Trace.childTraces)
                    childCallInvocation.Add(getCallInvocationObjectFromO2Trace(childO2trace, dStringIndexes, dFilesIndexes));
                callInvocation.CallInvocation1 = childCallInvocation.ToArray();
            }            
            return callInvocation;
        }
Exemple #41
0
 public static IO2Trace getLostSink(IO2Trace o2Trace)
 {
     return getTraceType(new List<IO2Trace>().add(o2Trace), TraceType.Lost_Sink);
 }
		public static ascx_SourceCodeViewer show(this ascx_SourceCodeViewer codeViewer, IO2Trace o2Trace)
		{								
			"in show".info();
			codeViewer.open(o2Trace.file);
			if (o2Trace.lineNumber > 0)
			{
				codeViewer.editor().gotoLine((int)o2Trace.lineNumber-1);
				//codeViewer.editor().caret_Line();
				codeViewer.editor().caret_Line((int)o2Trace.lineNumber-1);
				codeViewer.editor().caret_Column((int)o2Trace.columnNumber);
			}
			return codeViewer;
		}
		public static ascx_SourceCodeViewer show(this ascx_SourceCodeViewer codeViewer, IO2Trace o2Trace)
		{
			codeViewer.editor().show(o2Trace);
			return codeViewer;
		}
Exemple #44
0
 public static string getVariableNameFromThisObject(IO2Trace o2Trace)
 {
     return getVariableNameFromThisObject(o2Trace.context);
 }
 private void onTraceSelected(IO2Trace o2SelectedTrace)
 {
     Callbacks.raiseRegistedCallbacks(_onTraceSelected, new object[] {o2SelectedTrace});
 }        
Exemple #46
0
 public static IO2Finding createCopyAndGlueTraceSinkWithTrace(IO2Finding o2TemplateFinding, IO2Trace o2TracesToGlue)
 {
     return createCopyAndGlueTraceSinkWithTrace(o2TemplateFinding, new List<IO2Trace>().add(o2TracesToGlue));
 }
 private void ascxTraceTreeView__onTraceSelected(IO2Trace o2SelectedTrace)
 {
     onTraceSelected(o2SelectedTrace);
 }
 private void ascxTraceTreeView__onTraceSelected(IO2Trace o2SelectedTrace)
 {
     onTraceSelected(o2SelectedTrace);
 }
Exemple #49
0
 public static bool deleteO2Trace(IO2Trace o2RootTrace, IO2Trace o2TraceToDelete)
 {
     foreach (O2Trace o2ChildTrace in o2RootTrace.childTraces)
         if (o2ChildTrace == o2TraceToDelete)
         {
             o2RootTrace.childTraces.Remove(o2ChildTrace);
             return true;
         }
         else
         {
             bool foundItemToDelete = deleteO2Trace(o2ChildTrace, o2TraceToDelete);
             if (foundItemToDelete)
                 return true;
         }
     return false;
 }
 private static void setSafeO2TraceContextValue(IO2Trace o2Trace, string value)
 {
     if (o2Trace != null)
         o2Trace.context = value;
 }
 private static string getSafeO2TraceContextValue(IO2Trace o2Trace)
 {
     return (o2Trace != null) ? o2Trace.context : "";
 }
Exemple #52
0
 public static IO2Trace createCopy(IO2Trace o2Trace)
 {
     return createCopy(o2Trace, true);
 }
Exemple #53
0
 private void onTraceSelected(IO2Trace o2SelectedTrace)
 {
     Callbacks.raiseRegistedCallbacks(_onTraceSelected, new object[] { o2SelectedTrace });
 }
Exemple #54
0
        /*public static List<O2Finding> glueSinksToSources(O2Assessment o2AssessmentWithSinks, O2Assessment o2AssessmentWithSources)
        {
            var webLayerSources = getO2StringIndexes(webLayer, TraceType.Source);

            foreach (var clickButtonFinding in clickButton.o2Findings)
            {
                results.Add(clickButtonFinding);
                var sink = OzasmtUtils.getKnownSink(clickButtonFinding.o2Trace);
                PublicDI.log.debug(sink.signature);
                if (webLayerSources.ContainsKey(sink.signature))
                    foreach (var webLayerSource in webLayerSources[sink.signature])
                    {
                        results.Add(OzasmtGlue.createCopyAndGlueTraceAndSink(clickButtonFinding,
                                                                             OzasmtUtils.getSource(
                                                                                 webLayerSource.o2Trace)));
                        /*var o2NewFinding = OzasmtCopy.createCopy(clickButtonFinding);
                        var newFindingSink = OzasmtUtils.getKnownSink(o2NewFinding.o2Trace);
                        newFindingSink.traceType = TraceType.Type_4;
                        var sourceToGlue = OzasmtCopy.createCopy(OzasmtUtils.getSource(webLayerSource.o2Trace));
                        sourceToGlue.traceType = TraceType.Type_0;
                        newFindingSink.childTraces.Add(sourceToGlue);
                        results.Add(o2NewFinding);*/
        /*         }
        }*/
        public static IO2Finding createCopyAndGlueTraceSinkWithSource(IO2Finding o2TemplateFinding,
                                                                      IO2Trace o2TraceWithSource)
        {
            IO2Trace sourceToGlue = OzasmtCopy.createCopy(OzasmtUtils.getSource(o2TraceWithSource));
            return createCopyAndGlueTraceSinkWithTrace(o2TemplateFinding, sourceToGlue);
        }
Exemple #55
0
 public static IO2Trace getSource(IO2Trace o2Trace)
 {
     return getTraceType(new List<IO2Trace>().add(o2Trace), TraceType.Source);
 }
Exemple #56
0
 public static IO2Trace getKnownSink(IO2Trace o2Trace)
 {
     return getTraceType(new List<IO2Trace>().add(o2Trace), TraceType.Known_Sink);
 }
 private void findingsViewer_DynamicJoin__onTraceSelected(IO2Trace o2TraceSelected)
 {
     dynamicJoin_onTraceSelected(o2TraceSelected);
 }
Exemple #58
0
        public static Color getTraceColorBasedOnTraceType(IO2Trace o2Trace)
        {
            switch (o2Trace.traceType)
            {
                case TraceType.Type_0:
                    return Color.DarkBlue;
                case TraceType.Known_Sink:
                    return KnownSinkColor;
                case TraceType.Lost_Sink:
                    return LostSinkColor;
                case TraceType.Root_Call:
                case TraceType.Type_6:
                    return Color.DarkBlue;
                case TraceType.Source:
                    return SourceColor;
                case TraceType.Type_4:
                    return Color.Green;
                case TraceType.O2JoinSink:
                    return Color.DeepSkyBlue;
                case TraceType.O2JoinSource:
                    return Color.LimeGreen;
                case TraceType.O2JoinLocation:
                    return Color.Purple;
                case TraceType.O2Info:
                    return Color.Black;

                default:
                    return Color.Gray;
            }
        }
        private static bool applyRuleToTrace(IO2Trace o2Trace, IO2Finding parentO2Finding, List <IO2Finding> findingsCreated, IDictionary <string, List <IO2Rule> > indexedRules)
        {
            var signatureToFind = o2Trace.signature;

            if (indexedRules.ContainsKey(signatureToFind))    // means we have a match
            {
                if (o2Trace.traceType == TraceType.Source)
                {
                    // if the trace is of TraceType.Source by there is a rule with O2RuleType.NotASource we need are not going to add the current finding
                    foreach (var o2Rule in indexedRules[signatureToFind])
                    {
                        if (o2Rule.RuleType == O2RuleType.NotASource)
                        {
                            return(false);
                        }
                    }
                    // since this is a Source, we can just add it and terminate the trace (this assumes that there is only one trace per finding
                    findingsCreated.Add(parentO2Finding);
                    return(true);
                }
                // if we have a source lets add it has a new finding
                foreach (var o2Rule in indexedRules[signatureToFind])
                {
                    if (o2Rule.RuleType != O2RuleType.NotASource)
                    {
                        // before we copy the finding we have to sort out who is a source in this finding
                        var currentSource = ((O2Finding)parentO2Finding).getSource();
                        // make it a normal trace
                        if (currentSource != null)
                        {
                            currentSource.traceType = TraceType.Type_4;
                        }
                        // then save the current trace trace type
                        var currentO2TraceTraceType = o2Trace.traceType;
                        // set it to Source
                        o2Trace.traceType = TraceType.Source;
                        // copy the whole finding and traces
                        var newSourceFinding = OzasmtCopy.createCopy(parentO2Finding);
                        // add it to the list of created findings
                        findingsCreated.Add(newSourceFinding);
                        // and restore the trace types we modified above
                        if (currentSource != null)
                        {
                            currentSource.traceType = TraceType.Source;
                        }
                        o2Trace.traceType = currentO2TraceTraceType;
                        // all done :)
                    }
                }

                /*      // rename to shouldAbortRulesCreation
                 *    if (shouldAbortRulesExecution(indexedRules[signatureToFind]))
                 *    {
                 *        if (o2Trace.traceType == TraceType.Known_Sink || o2Trace.traceType == TraceType.Lost_Sink)
                 *            return false;
                 *        return true;
                 *    }
                 *    // check if we are a sink at the root of the tree with no child nodes (and if so cancel)
                 *    if (parentO2Finding.o2Traces.Count == 0)//; && (o2Trace.traceType == TraceType.Known_Sink || o2Trace.traceType == TraceType.Lost_Sink || o2Trace.traceType == TraceType.Root_Call))
                 *        return true;
                 *    // check if there are no sources on the trace
                 *    if (((O2Finding)parentO2Finding).Source == "")
                 *        return false;
                 *
                 *    var newTrace = OzasmtCopy.createCopy(o2Trace, false); //create new trace (which will be modified
                 *    newTrace.traceType = TraceType.Known_Sink; // make the trace  a sink
                 *    o2PartialTraces.Add(newTrace); // add it to the partial trace
                 *
                 *    var newFindingWithSinkTrace = OzasmtCopy.createCopy(parentO2Finding); // create template finding which will be applied the rules
                 *    findingsCreated.AddRange(FiltersUtils.applySinkRuleToFindingAndTrace(newFindingWithSinkTrace, o2Trace.signature, indexedRules)); // apply rules and add resulting findings to findingsCreated list
                 *    //remove the new trace since the invokeOnAllPartialTraces loop will add its own copy
                 *    o2PartialTraces.Remove(newTrace);
                 */
            }
            return(true); // in this case return true since we want to process ALL traces
        }
 public static IO2Trace createCopy(IO2Trace o2Trace)
 {
     return(createCopy(o2Trace, true));
 }