public static O2TraceBlock_OunceV6 getTraceBlockToGlueFinding(AssessmentAssessmentFileFinding fFinding,
                                                                      TraceType ttTraceType,
                                                                      O2AssessmentData_OunceV6 oadO2AssessmentDataOunceV6,
                                                                      Dictionary <String, O2TraceBlock_OunceV6> dO2TraceBlock)
        {
            CallInvocation ciCallInvocation =
                AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fFinding.Trace, ttTraceType);

            if (ciCallInvocation == null)
            {
                return(null);
            }
            String sSourceSignature = OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.sig_id, oadO2AssessmentDataOunceV6);
            String sFile            = OzasmtUtils_OunceV6.getFileIndexValue(ciCallInvocation.fn_id, oadO2AssessmentDataOunceV6);
            String sLineNumber      = ciCallInvocation.line_number.ToString();
            String sTraceRootText   = OzasmtUtils_OunceV6.getStringIndexValue(fFinding.Trace[0].sig_id, oadO2AssessmentDataOunceV6);
            String sUniqueName      = String.Format("{0}      {1}      {2}", sSourceSignature, sFile, sLineNumber);

            // need to find a better way to clue the final sinks since at the moment I am getting a couple sinks trown by the cases when a sink also become a source of tainted data
            //String sUniqueName = String.Format("{0} {1} {2} {3}", sSourceSignature, sFile, sLineNumber, sTraceRootText);

            if (false == dO2TraceBlock.ContainsKey(sUniqueName))
            {
                dO2TraceBlock.Add(sUniqueName, new O2TraceBlock_OunceV6());
                dO2TraceBlock[sUniqueName].sSignature     = sSourceSignature;
                dO2TraceBlock[sUniqueName].sFile          = sFile;
                dO2TraceBlock[sUniqueName].sLineNumber    = sLineNumber;
                dO2TraceBlock[sUniqueName].sTraceRootText = sTraceRootText;
                dO2TraceBlock[sUniqueName].sUniqueName    = sUniqueName;
            }
            return(dO2TraceBlock[sUniqueName]);
        }
 public static void MakeAllLostSinksIntoKnownSinks(O2AssessmentData_OunceV6 oadO2AssessmentDataOunceV6)
 {
     foreach (AssessmentAssessmentFileFinding fFinding in oadO2AssessmentDataOunceV6.dFindings.Keys)
     {
         CallInvocation ciLostSink =
             AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fFinding.Trace,
                                                                                     TraceType.Lost_Sink);
         if (ciLostSink != null)
         {
             ciLostSink.trace_type = (UInt32)TraceType.Known_Sink;
         }
     }
 }
        public static String getSource(AssessmentAssessmentFileFinding fFinding, O2AssessmentData_OunceV6 oadF1AssessmentDataOunceV6)
        {
            CallInvocation ciCallInvocation =
                AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fFinding.Trace,
                                                                                        TraceType.Source);

            if (ciCallInvocation != null)
            {
                return(OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.sig_id, oadF1AssessmentDataOunceV6));
            }

            return("");
        }
Exemplo n.º 4
0
            public static void addSuportForDynamicMethodsOnSinks(TreeView tvRawData, ICirData cdCirData,
                                                                 bool bAddGluedTracesAsRealTraces)
            {
                O2Timer tTimer = new O2Timer("Adding Support for Dynamic Methods on Sinks").start();
                // first get a unique list of Sink Traces
                Dictionary <AssessmentAssessmentFileFinding, O2AssessmentData_OunceV6> dAllSinkFindings =
                    analyzer.getUniqueListOfSinks(tvRawData);

                //List<String> lsMatches = new List<string>();
                foreach (AssessmentAssessmentFileFinding fFinding in dAllSinkFindings.Keys)
                {
                    CallInvocation ciSink =
                        AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fFinding.Trace,
                                                                                                TraceType.
                                                                                                Known_Sink);
                    if (ciSink != null)
                    {
                        String sContext = OzasmtUtils_OunceV6.getStringIndexValue(ciSink.cxt_id, dAllSinkFindings[fFinding]);
//                        var fsFilteredSignature = new FilteredSignature(sContext);
                        if (sContext.IndexOf("java.lang.Object.getClass()") > -1 && sContext.IndexOf("new") > -1 &&
                            sContext.IndexOf("$") > -1)
                        {
                            // we have a match lets get the class out
                            String sClass = sContext.Substring(sContext.IndexOf("new") + 4);
                            sClass = sClass.Substring(0, sClass.IndexOf(' '));

                            // Find traces that match the found class and add them as GluedSinks
                            foreach (TreeNode tnMatchNode in tvRawData.Nodes)
                            {
                                if (tnMatchNode.Text.IndexOf(sClass) > -1)
                                {
                                    addFindingAsGlueTrace((O2TraceBlock_OunceV6)tnMatchNode.Tag, fFinding,
                                                          dAllSinkFindings[fFinding], tvRawData,
                                                          bAddGluedTracesAsRealTraces);
                                }
                            }
                        }
                    }
                }

                tTimer.stop();
            }
        public static String getUniqueSignature(AssessmentAssessmentFileFinding fFinding, TraceType ttTraceType,
                                                O2AssessmentData_OunceV6 oadO2AssessmentDataOunceV6, bool bShowFullPathForFileName)
        {
            CallInvocation ciCallInvocation =
                AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fFinding.Trace, ttTraceType);

            if (ciCallInvocation == null)
            {
                return(null);
            }
            String sSourceSignature = OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.sig_id, oadO2AssessmentDataOunceV6);
            String sFile            = OzasmtUtils_OunceV6.getFileIndexValue(ciCallInvocation.fn_id, oadO2AssessmentDataOunceV6);
            String sLineNumber      = ciCallInvocation.line_number.ToString();

            if (bShowFullPathForFileName)
            {
                return(String.Format("{0}      {1}      {2}", sSourceSignature, sFile, sLineNumber));
            }
            else
            {
                return(String.Format("{0}      {1}      {2}", sSourceSignature, Path.GetFileName(sFile), sLineNumber));
            }
        }
            public bool appendTrace_FindingSourceToFindingSink(AssessmentAssessmentFileFinding fJoinAtSink,
                                                               FindingViewItem fviJoinAtSource)
            {
                //Get the Sink of the first trace
                CallInvocation ciSinkNode =
                    AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fJoinAtSink.Trace,
                                                                                            TraceType.Known_Sink);

                if (ciSinkNode == null)
                {
                    //              DI.log.error("in appendTrace_FindingSourceToFindingSink, could not find the Sink of fviJoinAtSink");
                    return(false);
                }

                // get the source of the 2nd trace

                // There are 3 possible Gluing Scenarios
                //   a source that has child nodes (when it is a callback)
                //   a source trace that has a compatible signature with the sink trace (when it was creted via a source of tainded data rule).  For this one we will have to find the correct injection point
                //   a source trace that has nothing do with the source (interfaces gluing for example) and we have the same two cases above
                // the strategy to find a gluing point (on the fviJoinAtSource is to find the first trace that has a sink

                // try to get case 1 see if the current source has child nodes
                CallInvocation ciSourceNode =
                    AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(
                        fviJoinAtSource.fFinding.Trace, TraceType.Source);

                if (ciSourceNode == null)
                {
                    DI.log.error(
                        "in appendTrace_FindingSourceToFindingSink, could not find the Source of fviJoinAtSource");
                    return(false);
                }

                if (ciSourceNode.CallInvocation1 == null) // means we are case 2 or 3
                {
                    CallInvocation ciSourceNodeWithSink =
                        AnalysisSearch.fromSourceFindFirstTraceWithAChildSink(fviJoinAtSource.fFinding,
                                                                              fviJoinAtSource.oadO2AssessmentDataOunceV6);
                    if (ciSourceNodeWithSink != null)
                    {
                        // if we found this it means that we are now on Trace that the first child node goes to the source and the 2nd goes to the Sink
                        ciSourceNode = ciSourceNodeWithSink.CallInvocation1[1];
                    }
                }

                // make the previous Sink that Type 4 that doesn't seem to be used (could make it sources but it is cleaner with using this extra trace type for the joins
                ciSinkNode.trace_type = (int)TraceType.Type_4;


                CallInvocation[] aciCallInvocation;
                if (AnalysisUtils.getSink(fJoinAtSink, oadNewO2AssessmentDataOunceV6) ==
                    AnalysisUtils.getSource(fviJoinAtSource.fFinding, fviJoinAtSource.oadO2AssessmentDataOunceV6))
                {
                    aciCallInvocation = ciSourceNode.CallInvocation1;
                }
                else
                {
                    aciCallInvocation = new[] { ciSourceNode }
                };
                var lciTempNewCallInvocation = new List <CallInvocation>(); // used by the recursive function

                ciSinkNode.CallInvocation1 = updateAssessmentRunWithTraceReferences_recursive(
                    lciTempNewCallInvocation,
                    aciCallInvocation,
                    dNewStringIndex,
                    dNewFileIndex,
                    fviJoinAtSource.oadO2AssessmentDataOunceV6);


                return(true);
            }
Exemplo n.º 7
0
            public static void findSpringAttributes(TreeView tvRawData)
            {
                String  sFunctionSignature = "ModelMap.addAttribute";
                O2Timer tTimer             = new O2Timer("Resolving attribute based function: {0} ").start();

                Dictionary <AssessmentAssessmentFileFinding, O2AssessmentData_OunceV6> dMatches =
                    analyzer.getSinksFindingsThatMatchRegEx(tvRawData, sFunctionSignature);

                foreach (AssessmentAssessmentFileFinding fFinding in dMatches.Keys)
                {
                    // resolve addAddtibute name
                    String sSinkContext        = AnalysisUtils.getSinkContext(fFinding, dMatches[fFinding]);
                    var    fsFilteredSignature = new FilteredSignature(sSinkContext);
                    String sParameters         = fsFilteredSignature.sParameters.Replace("\"", "");
                    String sSpringParameter    = sParameters.Substring(0, sParameters.IndexOf(',')).Trim();

                    // create a unique name for it:
                    String sSink = AnalysisUtils.getSink(fFinding, dMatches[fFinding]);
                    String sSinkWithAttributeName = sSink.Replace("(", "_" + sSpringParameter + "(");
                    // make sure we have not added this already
                    if (sSink.IndexOf(sSpringParameter) == -1)
                    {
                        //     String sSinkWithAttributeName = sSink.Replace("(", "_" + sSpringParameter + "(");
                        //      String sSinkWithAttributeName = sSpringParameter;
                        String sUniqueSignature = analyzer.getUniqueSignature(fFinding, TraceType.Known_Sink,
                                                                              dMatches[fFinding], true);
                        var otbO2TraceBlockOfThisFinding = (O2TraceBlock_OunceV6)tvRawData.Nodes[sUniqueSignature].Tag;

                        CallInvocation ciCallInvocation =
                            AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(
                                fFinding.Trace, TraceType.Known_Sink);
                        UInt32 uNewId = OzasmtUtils_OunceV6.addTextToStringIndexes(sSinkWithAttributeName,
                                                                                   dMatches[fFinding].arAssessmentRun);
                        ;
                        ciCallInvocation.sig_id = uNewId;
                        DI.log.debug(" Found spring attribute '{0}' on sinks and modified to {1}", sSpringParameter,
                                     sSinkWithAttributeName);
                        //o2.analysis.Analysis.getSink(fFinding, dMatches[fFinding]));
                        otbO2TraceBlockOfThisFinding.sSignature  = sSinkWithAttributeName;
                        otbO2TraceBlockOfThisFinding.sUniqueName = analyzer.getUniqueSignature(fFinding,
                                                                                               TraceType.
                                                                                               Known_Sink,
                                                                                               dMatches[fFinding], true);

                        List <O2TraceBlock_OunceV6> lotbO2TraceBlockWithVelocityMappings =
                            analyzer.getO2TraceBlocksThatMatchSignature(sSinkWithAttributeName, tvRawData);


/*                        String sVelocityMapping = String.Format("{0}            0", sSinkWithAttributeName);
 *                      TreeNode tnVelocityNode = tvRawData.Nodes[sVelocityMapping];
 *                      if (tnVelocityNode != null)
 */
                        foreach (
                            O2TraceBlock_OunceV6 otbO2TraceBlockWithVelocityMappings in lotbO2TraceBlockWithVelocityMappings)
                        {
                            if (otbO2TraceBlockWithVelocityMappings.sFile.IndexOf(".vm") > -1)
                            {
                                //O2TraceBlock_OunceV6 otbO2TraceBlockWithVelocityMappings = (O2TraceBlock_OunceV6)tnVelocityNode.Tag;
                                foreach (
                                    AssessmentAssessmentFileFinding fVelocityFinding in
                                    otbO2TraceBlockWithVelocityMappings.dSinks.Keys)
                                {
                                    if (false == otbO2TraceBlockOfThisFinding.dGluedSinks.ContainsKey(fVelocityFinding))
                                    {
                                        otbO2TraceBlockOfThisFinding.dGluedSinks.Add(fVelocityFinding,
                                                                                     otbO2TraceBlockWithVelocityMappings
                                                                                     .dSinks[fVelocityFinding]);
                                    }
                                    if (false == otbO2TraceBlockOfThisFinding.dSinks.ContainsKey(fVelocityFinding))
                                    {
                                        otbO2TraceBlockOfThisFinding.dSinks.Add(fVelocityFinding,
                                                                                otbO2TraceBlockWithVelocityMappings.
                                                                                dSinks[fVelocityFinding]);
                                    }
                                }
                            }
                        }
                    }
                }
                tTimer.stop();
            }