-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need help on JNDI injection query, does not work for log4j test project #7621
Comments
I don't know which part is wrong, I also created another project to test:
It does not work either. |
You may need to consult that the test code has statements and control flows like: ql/java/ql/src/Security/CWE/CWE-074/JndiInjection.java, or not. |
@KeuntaeShin Thanks for the heads up, this looks exactly same to the second test I've done. I believe the query is suitable for my code too, not sure why it didn't work.
|
Additionally, the test code's lookup is one of those? /** CSV sink models representing methods susceptible to JNDI injection attacks. */ |
@KeuntaeShin This is the full source code I'm using. The item to lookup is dynamic determined by user input:
|
Codeql's path-problem depends on a concept of source and sink. It means specific statements such as functions, variables, and etc must be explicitly defined in the query statements or .qlls, and the target source code must meet the conditions and data flows. I made an example to help your understand. A method - jndiLookup_your_codebase will not be detected like your code, because there is no source the query expect.
|
Did you mean |
Yes. FYI: class JndiInjectionFlowConfig extends TaintTracking::Configuration { abstract class RemoteFlowSource extends DataFlow::Node { private class SpringServletInputParameterSource extends RemoteFlowSource { override string getSourceType() { result = "Spring servlet input parameter" } |
CodeQL distinguishes between sources that can be remotely "reached" and those that can not. On the other hand, there are sources that are NOT remotely reachable. The JNDI query only concerns itself with remote flow sources. /**
* @name JNDI lookup with user-controlled name
* @description Performing a JNDI lookup with a user-controlled name can lead to the download of an untrusted
* object and to execution of arbitrary code.
* @kind path-problem
* @problem.severity error
* @precision high
* @id java/jndi-injection
* @tags security
* external/cwe/cwe-074
*/
import java
import semmle.code.java.security.JndiInjectionQuery
import DataFlow::PathGraph
import semmle.code.java.dataflow.DataFlow
private class CustomJndiInjectionFlowConfig extends JndiInjectionFlowConfig {
CustomJndiInjectionFlowConfig(){ this = "CustomJndiInjectionFlowConfig"}
override predicate isSource(DataFlow::Node source) {
source instanceof LocalUserInput
}
}
from DataFlow::PathNode source, DataFlow::PathNode sink, CustomJndiInjectionFlowConfig conf
where conf.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "JNDI lookup might include name from $@.", source.getNode(),
"this user input" The new query now only considers local flow sources. |
I understand cli arguments is not reachable remotely, just trying to create a simple case and learn CodeQL.
|
|
@intrigus-lgtm This works for for simple context lookup, but not the log4j project I uploaded earlier: log4j-test.zip It also uses LocalUserInput as source, but the query above didn't find anything:
|
Do you have |
CodeQL creates a complete database of your project; for dependencies of your project (such as log4j in this case) it only extracts a limited amount of data. This extracted data is not sufficient to enable data flow on dependencies. There are three possible solutions to this problem depending on the exact problem:
|
Understood, now I'm going to analyze log4j 2.11 directly.
I first verified that lookup() method call exists in log4j
Then I created a flow query from AbstractLogger.debug() to Context.lookup(), but no results is found:
What was wrong? |
Did you try doing partial dataflow as described in the article I posted earlier? (https://codeql.github.com/docs/writing-codeql-queries/debugging-data-flow-queries-using-partial-flow/) |
I've created a simple log4j project: log4j-test.zip
It uses log4j 2.11 which is vulnerable to JNDI injection, and I've verified the vulnerability exists. Now I need to verify codeql also works. So I created the java database with:
Then I opened the starter project and uses
ql/java/ql/src/Security/CWE/CWE-074/JndiInjection.ql
to test it, but no results came out.What was wrong?
The text was updated successfully, but these errors were encountered: