污点分析没有类作为其来源的非恒定场的流动路径
我有这个简单的测试课,我正在尝试模仿路径问题。 使用Message1
作为源,console.writeline(Message1)
作为接收器。
class Test
{
private const string Message1 = "Test Message 1";
private readonly string Message2 = "Test Message 2";
public void Run()
{
Console.WriteLine(Message1);
Console.WriteLine(Message2);
}
}
import csharp
import DataFlow::PathGraph
class Source extends DataFlow::Node {
Source() { this.asExpr() instanceof StringLiteral }
}
class WriteLineMethod extends Method {
WriteLineMethod() { this.hasQualifiedName("System.Console.WriteLine") }
}
class Sink extends DataFlow::Node {
Sink() {
exists(MethodCall m |
m.getTarget() instanceof WriteLineMethod and
this.asExpr() = m.getArgument(0)
)
}
}
class SimpleConfiguration extends TaintTracking::Configuration {
SimpleConfiguration() { this = "Simple configuration" }
override predicate isSource(DataFlow::Node source) { source instanceof Source }
override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
}
from DataFlow::PathNode source, DataFlow::PathNode sink, SimpleConfiguration cfg
where cfg.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "$@ is used in WriteLine method.", source.getNode(),
"String"
在这里,我使用上述查询在上述测试类上进行了简单的污点跟踪分析,用于const field private const字符串message1 =“ test message 1”;
作为source> source
和 console.writeline(Message1);
作为sink
我得到了正确的结果,但对于
private ReadOnly ReadOnly String Messages2 = “测试消息2”; 似乎不起作用。non Const
field
我在这里想念什么吗?为什么污点跟踪适用于静态类中的const字段或静态字段,而例如字段?
数据库zip文件: -database
I have this simple Test class, where I'm trying to mimic a path problem.
with Message1
as source and Console.WriteLine(Message1)
as sink.
class Test
{
private const string Message1 = "Test Message 1";
private readonly string Message2 = "Test Message 2";
public void Run()
{
Console.WriteLine(Message1);
Console.WriteLine(Message2);
}
}
import csharp
import DataFlow::PathGraph
class Source extends DataFlow::Node {
Source() { this.asExpr() instanceof StringLiteral }
}
class WriteLineMethod extends Method {
WriteLineMethod() { this.hasQualifiedName("System.Console.WriteLine") }
}
class Sink extends DataFlow::Node {
Sink() {
exists(MethodCall m |
m.getTarget() instanceof WriteLineMethod and
this.asExpr() = m.getArgument(0)
)
}
}
class SimpleConfiguration extends TaintTracking::Configuration {
SimpleConfiguration() { this = "Simple configuration" }
override predicate isSource(DataFlow::Node source) { source instanceof Source }
override predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
}
from DataFlow::PathNode source, DataFlow::PathNode sink, SimpleConfiguration cfg
where cfg.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "$@ is used in WriteLine method.", source.getNode(),
"String"
Here I did simple taint tracking analysis on above Test class using above query, for const field private const string Message1 = "Test Message 1";
as source
andConsole.WriteLine(Message1);
as sink
i'm getting correct result, But for non const
field private readonly string Message2 = "Test Message 2";
it doesn't seem to work.
Did i miss something here? why does taint tracking works for const field or static field in static class but not for instance field?
Database zip file:
codeql-test-database
Edit:
I have created an issue for same at github/codeql below is an link for reference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用链接 to github讨论答案。
Quoting this detailed analysis by tamasvajk and here is the link to github discussion answer.