How to get full data flow starting at declared source point?
Hello, I plan to get all the variables in the access path starting at given source method to do some analysis, so I need to get full data flow with a static style method. I want to use FlowDroid to do it, which I think is part of the process of taint analysis. How to modify the code to achieve my goal? Are these paths data stored in some intermediate variables? Thanks.
What do you mean by "all the variables in the access path"? An access path is a sequence of field dereferences, which, in the case of a taint on a non-static field, is rooted in a variable.
"runInfoflow()" method returns an empty result if there is no leak in app. However, I want to get that path and the tainted field rooted in a defined variable or method, no matter whether the information leak really exists.
For example, I declared method a() in "SourcesAndSinks.txt" as SOURCE. In the app code, return value of a() is passed to variable b and then passed to method c(), e.t.c. c() may not be a sink point, and I can't know how is method c() looked like. I want to get the sequence of location, name of b and c. I'm not sure whether this should be called as "access path", "data flow" or something else. I'm a freshman in code analysis area. Thanks.
You are essentially asking for data flows paths through the program. Note that this will usually be a graph, because data can flow from, e.g., one call site to multiple callees. Let's take the following code:
List a = null;
if (new Random().nextBoolean())
a =new LinkedList();
else
a = new ArrayList();
a.add(x);
In the last line, if we assume that x is tained, the flow goes to both LinkedList.add() and ArrayList.add(), because both branches of the conditional are possible. In a realistic program, such taint graphs get huge. Therefore, FlowDroid does not store this graph as an accessible data structure, but tries to keep as little information about its tracking history as possible. So, in short: FlowDroid can't give you that information, and that's for a good reason.
Still, you can extend FlowDroid if you really need the full graph and are willing to accept the performance drop and the huge memory consumption. You can create your own implementation of the ISourceSinkManager interface that marks all statements as possible sinks and then records all taint abstractions that are passed into getSinkInfo().
I'll try it. Thanks a lot.
Hello Steven, I want to make a follow-up about the question of "extracting tainted fields from a source".
I am working on a tool that aims to find the set of statements which are impacted (have either data or control dependence) by a source. For that purpose, I planned to conduct a "OneSourceAtATime" analysis and then dump the tainted fields.
I don't quite understand the inner working of Flowdroid. I got two questions when reading the code:
-
What the "Stmt sCallSite" parameter of getSinkInfo() method means here? Is it always the statement with a tainted variable?
-
Could you extend more on why should we "marks all statements as possible sinks" in a customized ISourceSinkManager interface?
Thanks!
FlowDroid computes data flow connections between sources and sinks. In the case discussed in this issue, there is no explicit sink. Instead, the user was interested in finding connections to all possible statements. This is not in the concept of FlowDroid, so we need to play some tricks. The easiest one is to mark everything as a sink, to avoid FlowDroid filtering out data flows, because they cannot reach a sink.
The getSinkInfo() method gets passed the current statement. If then has to decide whether that statement is considered a sink or not. In your approach, that's always the case.
Once the complete data flow analysis has finished, FlowDroid will compute paths from all sinks (all statements in your case) back to the original sources. Only then, you can know which source you were dealing with. The ISourceSinkManager can't.
Still, keep in mind my original word of warning. This approach is not what FlowDroid was originally about and you might end up with all sorts of scalability issues.
In fact you can also implement the interface of soot.jimple.infoflow.handlers.TaintPropagationHandler, and process the tainted AccessPath except the sink point.
In fact you can also implement the interface of soot.jimple.infoflow.handlers.TaintPropagationHandler, and process the tainted AccessPath except the sink point.
Hi, can please provide more context to how you implement this?