So I decided to write a rule to find out the call flows into/from a particular method, ie ‘Who calls this method and who it calls?’
With NDepend enabled on the source code of TeamMentor/Master , I opened a class and chose this option:
![image_thumb[59] image_thumb[59]](http://lh6.ggpht.com/-g5q6jA9MCiM/UbyoSn5nlDI/AAAAAAAAN9Q/-sj8XFMB54A/image_thumb%25255B59%25255D%25255B2%25255D.png?imgmax=800)
... which opened this Dependency Graph
![image_thumb[60] image_thumb[60]](http://lh4.ggpht.com/-ANUnvuBwMWI/UbyoTU4q0gI/AAAAAAAAN9Y/MQ3ey5XLx1M/image_thumb%25255B60%25255D%25255B2%25255D.png?imgmax=800)
If I now select a method, an helper tab will appear below:
![image_thumb[70] image_thumb[70]](http://lh5.ggpht.com/-PANrBRxqCLw/UbyoUW6DgKI/AAAAAAAAN9g/13krnb3dZ-k/image_thumb%25255B70%25255D%25255B2%25255D.png?imgmax=800)
... which for example, explains how to generate a call graph:
![image_thumb[81] image_thumb[81]](http://lh4.ggpht.com/-8CO0iMCkIPk/UbyoVeQaEnI/AAAAAAAAN9o/eCCgCbbtyUk/image_thumb%25255B81%25255D%25255B2%25255D.png?imgmax=800)
As per the instructions above, to create a call-graph, I select the direct/indirect callers
![image_thumb[89] image_thumb[89]](http://lh4.ggpht.com/-E3RdGl-bQo4/UbyoWD_n2JI/AAAAAAAAN9w/2O46aAnsQmY/image_thumb%25255B89%25255D%25255B2%25255D.png?imgmax=800)
... which creates a (custom) CQL rule and executes it:
![image_thumb[92] image_thumb[92]](http://lh5.ggpht.com/-2rHtPd_Y6_s/UbyoW1xd4XI/AAAAAAAAN94/X0gFb5WFINE/image_thumb%25255B92%25255D%25255B2%25255D.png?imgmax=800)
Following the 2nd step of the instructions, I clicked on the ‘Export to Graph’ button, and I got this nice graph:
![image_thumb[97] image_thumb[97]](http://lh4.ggpht.com/-_3u2KLCRXuM/UbyoXpppgAI/AAAAAAAAN-A/ZV1RbzFUdb0/image_thumb%25255B97%25255D%25255B2%25255D.png?imgmax=800)
Changing the query a little bit (from m.DepthOfIsUsing to m.DepthOfIsUsedBy )
![image_thumb[98] image_thumb[98]](http://lh3.ggpht.com/-Of9-3mqVAuw/UbyoYW5FtBI/AAAAAAAAN-I/A3jgJoiQWs4/image_thumb%25255B98%25255D%25255B2%25255D.png?imgmax=800)
Gives us a recursive mapping of all methods called by the original method, ie the call-flow FROM the current method (the first graph gave us the call-flow INTO the current method):
![image_thumb[106] image_thumb[106]](http://lh5.ggpht.com/-4KHRGfANTks/UbyoZIa8tBI/AAAAAAAAN-Q/oh0bhwymjNI/image_thumb%25255B106%25255D%25255B2%25255D.png?imgmax=800)
And I got this script right (see below), this is how we get both graphs together:
![image_thumb[113] image_thumb[113]](http://lh4.ggpht.com/-8-XwpNKAK-0/UbyoaPVvYKI/AAAAAAAAN-Y/UDSxTy4MqwI/image_thumb%25255B113%25255D%25255B2%25255D.png?imgmax=800)
.... which will create this graph:
![image_thumb[112] image_thumb[112]](http://lh5.ggpht.com/-xpgC-3Cyt0Q/UbyoaxkdGyI/AAAAAAAAN-g/Tio7Sk6jVUk/image_thumb%25255B112%25255D%25255B2%25255D.png?imgmax=800)
Now think of a similar view the attack surface at the top and the vulnerable APIs (like SQL execute) at the bottom :)
And although this would just be a call-flow analysis (vs taint analysis) my experience in doing similar analysis with the O2 Platform has shown that we can find A LOT of vulnerabilities this way (i.e. without needing the full taint analysis engine).