Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
799d509
Upload LDAP Injection query, qhelp and tests
jorgectf Mar 18, 2021
719b48c
Move to experimental folder
jorgectf Mar 18, 2021
95a1dae
Precision warn and Remove CWE reference
jorgectf Mar 18, 2021
85ec82a
Refactor in progress
jorgectf Mar 28, 2021
ad36bea
Refactor LDAP3 stuff (untested)
jorgectf Mar 29, 2021
8223539
Add a test without attributes
jorgectf Mar 29, 2021
3cda2e5
Polish up ldap3 tests
jorgectf Mar 29, 2021
8faafb6
Update Sink
jorgectf Mar 30, 2021
4328ff3
Remove attrs feature
jorgectf Mar 31, 2021
9b43031
Improve Sanitizer calls
jorgectf Mar 31, 2021
1bcb9cd
Simplify query
jorgectf Apr 6, 2021
33423ea
Optimize calls
jorgectf Apr 7, 2021
a1850dd
Change LDAP config (qll) filename
jorgectf Apr 8, 2021
8661cb0
Polish LDAP3Query
jorgectf Apr 8, 2021
7296879
Polish tests
jorgectf Apr 8, 2021
3c1ca72
Improve qhelp
jorgectf Apr 8, 2021
1554f4f
Create qhelp examples
jorgectf Apr 8, 2021
95bfdc4
Move tests to /test
jorgectf Apr 8, 2021
4f85de8
Add qlref
jorgectf Apr 8, 2021
7819d1a
Generate .expected
jorgectf Apr 8, 2021
b405c67
Add qhelp last newline
jorgectf Apr 8, 2021
82f47f8
Polish metadata
jorgectf Apr 8, 2021
cd75433
Fix qhelp examples extension
jorgectf Apr 8, 2021
a2e8d88
Write documentation
jorgectf Apr 8, 2021
b020ea6
Polish documentation
jorgectf Apr 8, 2021
1c34230
Fix documentation typo
jorgectf Apr 8, 2021
c2b96b3
Add documentation to main classes' functions.
jorgectf May 7, 2021
34b8af3
Move structure to LDAP.qll
jorgectf May 7, 2021
6159fbe
Update functions naming
jorgectf May 7, 2021
2ad72ad
Add LDAP framework entry in Frameworks.qll
jorgectf May 7, 2021
8665747
Update sink and sanitizer to match new naming
jorgectf May 8, 2021
9e9678b
Apply documentation suggestions
jorgectf May 21, 2021
37d6ff7
Update tests and .expected
jorgectf May 21, 2021
d5f2846
Merge branch 'main' into jorgectf/python/ldapInjection
RasmusWL May 26, 2021
f807c2f
Python: autoformat
RasmusWL May 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Write documentation
  • Loading branch information
jorgectf committed Apr 8, 2021
commit a2e8d88a07df14cf22bbca4e3039b54107f8983a
32 changes: 32 additions & 0 deletions python/ql/src/experimental/semmle/python/Concepts.qll
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@ private import semmle.python.dataflow.new.RemoteFlowSources
private import semmle.python.dataflow.new.TaintTracking
private import experimental.semmle.python.Frameworks

/** Provides classes for modeling LDAP-related APIs. */
module LDAPQuery {
/**
* A data-flow node that collects methods executing a LDAP query.
*
* Extend this class to model new APIs. If you want to refine existing API models,
* extend `LDAPQuery` instead.
*/
abstract class Range extends DataFlow::Node {
/**
* Gets the argument containing the executed expression.
*/
abstract DataFlow::Node getLDAPNode();
}
}

/**
* A data-flow node that collect methods executing a LDAP query.
*
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `LDAPQuery::Range` instead.
*/
class LDAPQuery extends DataFlow::Node {
LDAPQuery::Range range;

Expand All @@ -28,12 +44,28 @@ class LDAPQuery extends DataFlow::Node {
DataFlow::Node getLDAPNode() { result = range.getLDAPNode() }
Comment thread
jorgectf marked this conversation as resolved.
Outdated
}

/** Provides classes for modeling LDAP components escape-related APIs. */
module LDAPEscape {
/**
* A data-flow node that collects functions escaping LDAP components.
*
* Extend this class to model new APIs. If you want to refine existing API models,
* extend `LDAPEscape` instead.
*/
abstract class Range extends DataFlow::Node {
/**
* Gets the argument containing the escaped expression.
*/
abstract DataFlow::Node getEscapeNode();
}
}

/**
* A data-flow node that collects functions escaping LDAP components.
*
* Extend this class to refine existing API models. If you want to model new APIs,
* extend `RegexEscape::Range` instead.
*/
class LDAPEscape extends DataFlow::Node {
LDAPEscape::Range range;

Expand Down
46 changes: 46 additions & 0 deletions python/ql/src/experimental/semmle/python/frameworks/Stdlib.qll
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,32 @@ private import semmle.python.dataflow.new.RemoteFlowSources
private import experimental.semmle.python.Concepts
private import semmle.python.ApiGraphs

/**
* Provides models for Python's ldap-related libraries.
*/
private module LDAP {
/**
* Provides models for Python's `ldap` library.
*
* See https://www.python-ldap.org/en/python-ldap-3.3.0/index.html
*/
private module LDAP2 {
/**
* List of `ldap` methods used to execute a query.
*
* See https://www.python-ldap.org/en/python-ldap-3.3.0/reference/ldap.html#functions
*/
private class LDAP2QueryMethods extends string {
LDAP2QueryMethods() {
this in ["search", "search_s", "search_st", "search_ext", "search_ext_s"]
}
}

/**
* A class to find `ldap` methods executing a query.
*
* See `LDAP2QueryMethods`
*/
private class LDAP2Query extends DataFlow::CallCfgNode, LDAPQuery::Range {
DataFlow::Node ldapNode;

Expand All @@ -41,6 +59,11 @@ private module LDAP {
override DataFlow::Node getLDAPNode() { result = ldapNode }
}

/**
* A class to find calls to `ldap.dn.escape_dn_chars`.
*
* See https://github.com/python-ldap/python-ldap/blob/7ce471e238cdd9a4dd8d17baccd1c9e05e6f894a/Lib/ldap/dn.py#L17
*/
private class LDAP2EscapeDNCall extends DataFlow::CallCfgNode, LDAPEscape::Range {
LDAP2EscapeDNCall() {
this = API::moduleImport("ldap").getMember("dn").getMember("escape_dn_chars").getACall()
Expand All @@ -49,6 +72,11 @@ private module LDAP {
override DataFlow::Node getEscapeNode() { result = this.getArg(0) }
}

/**
* A class to find calls to `ldap.filter.escape_filter_chars`.
*
* See https://www.python-ldap.org/en/python-ldap-3.3.0/reference/ldap-filter.html#ldap.filter.escape_filter_chars
*/
private class LDAP2EscapeFilterCall extends DataFlow::CallCfgNode, LDAPEscape::Range {
LDAP2EscapeFilterCall() {
this =
Expand All @@ -59,7 +87,15 @@ private module LDAP {
}
}

/**
* Provides models for Python's `ldap3` library.
*
* See https://pypi.org/project/ldap3/
*/
private module LDAP3 {
/**
* A class to find `ldap3` methods executing a query.
*/
private class LDAP3Query extends DataFlow::CallCfgNode, LDAPQuery::Range {
DataFlow::Node ldapNode;

Expand All @@ -79,6 +115,11 @@ private module LDAP {
override DataFlow::Node getLDAPNode() { result = ldapNode }
}

/**
* A class to find calls to `ldap3.utils.dn.escape_rdn`.
*
* See https://github.com/cannatag/ldap3/blob/4d33166f0869b929f59c6e6825a1b9505eb99967/ldap3/utils/dn.py#L390
*/
private class LDAP3EscapeDNCall extends DataFlow::CallCfgNode, LDAPEscape::Range {
LDAP3EscapeDNCall() {
this =
Expand All @@ -92,6 +133,11 @@ private module LDAP {
override DataFlow::Node getEscapeNode() { result = this.getArg(0) }
}

/**
* A class to find calls to `ldap3.utils.conv.escape_filter_chars`.
*
* See https://github.com/cannatag/ldap3/blob/4d33166f0869b929f59c6e6825a1b9505eb99967/ldap3/utils/conv.py#L91
*/
private class LDAP3EscapeFilterCall extends DataFlow::CallCfgNode, LDAPEscape::Range {
LDAP3EscapeFilterCall() {
this =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import semmle.python.dataflow.new.TaintTracking
import semmle.python.dataflow.new.RemoteFlowSources

/**
* A taint-tracking configuration for detecting regular expression injections.
* A taint-tracking configuration for detecting LDAP injections.
*/
class LDAPInjectionFlowConfig extends TaintTracking::Configuration {
LDAPInjectionFlowConfig() { this = "LDAPInjectionFlowConfig" }
Expand Down