Skip to content

XXE: Changes for review #9

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

Merged
merged 44 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
500e0ac
Python: Rewrite sax XML tests
RasmusWL Mar 1, 2022
ee23c05
Python: XML: Expose vuln kind on sink
RasmusWL Mar 1, 2022
aaf55b2
Python: Add XMLVulnerabilityKind
RasmusWL Mar 2, 2022
16e482b
Python: Improve QLDoc for XML parsing/parsers
RasmusWL Mar 2, 2022
6dd776b
Python: Only produce one alert per vulnerable XML sink
RasmusWL Mar 2, 2022
7f7758b
Python: rewrite xml sax modeling
RasmusWL Mar 2, 2022
515b824
Python: Add lxml positive test
RasmusWL Mar 3, 2022
661d8bf
Python: Better handling of `resolve_entities` arg in lxml
RasmusWL Mar 3, 2022
52891cb
Python: Add PoC for XML vulns
RasmusWL Mar 3, 2022
3c321dd
Python: Model `lxml.etree.get_default_parser` in own class
RasmusWL Mar 3, 2022
124c03c
Python: Expand lxml tests
RasmusWL Mar 3, 2022
e295399
Python: Properly handle `huge_tree` in lxml
RasmusWL Mar 3, 2022
703e3e8
Python: Handle DTD retrieval vuln in lxml
RasmusWL Mar 3, 2022
6129193
Python: Properly model `xml.etree`
RasmusWL Mar 3, 2022
3affa6c
Python: Annotate xmltodict tests
RasmusWL Mar 3, 2022
c4d08db
Python: Expand XML PoC with minidom/pulldom/expat
RasmusWL Mar 3, 2022
5a65248
Python: Annotate xml.dom tests
RasmusWL Mar 3, 2022
9406a97
Python: Fix vuln detection for xml.minidom with parser arg
RasmusWL Mar 3, 2022
7cda901
Python: Add separate query for SimpleXMLRPCServer
RasmusWL Mar 3, 2022
4b03f5c
Python: Rename xml.sax test for consistency
RasmusWL Mar 3, 2022
faebaee
Python: Use concept tests for XML Parsing
RasmusWL Mar 3, 2022
a7134ca
Python: Port xml.dom tests
RasmusWL Mar 3, 2022
5fb4c4d
Python: Port xml.etree tests
RasmusWL Mar 3, 2022
0b12d91
Python: Port xml.sax tests
RasmusWL Mar 3, 2022
c739ae4
Python: Port `xmltodict` tests
RasmusWL Mar 3, 2022
2451123
Python: Move XML PoC to new test dir
RasmusWL Mar 3, 2022
3278793
Python: Handle more functions and kw-args
RasmusWL Mar 3, 2022
f72f673
Python: Update `XmlEntityInjection.expected`
RasmusWL Mar 3, 2022
33ebcdf
Python: Support feed method of lxml/xml.etree Parsers
RasmusWL Mar 3, 2022
46238d5
Python: Add test for XMLPullParser
RasmusWL Mar 3, 2022
de0e67f
Python: Restructure overall XML modeling
RasmusWL Mar 3, 2022
a033b71
Python: Align QLdocs of XML modeling
RasmusWL Mar 3, 2022
c0a2c25
Python: Restructure modeling of `xml.etree` parsers
RasmusWL Mar 3, 2022
c0a6f9f
Python: Restructure lxml modeling
RasmusWL Mar 3, 2022
df8e0fc
Python: Minor fixup of qldoc
RasmusWL Mar 3, 2022
837daaa
Python: Remove XMLParser concept
RasmusWL Mar 3, 2022
0d69dc8
Python: Minor qldoc improvement
RasmusWL Mar 3, 2022
3f6c55e
Python: Rename `vulnerable` predicate => `vulnerableTo`
RasmusWL Mar 3, 2022
683c2fa
Apply suggestions from code review
jorgectf Mar 4, 2022
3cd165d
Python: Apply suggestions from code review
RasmusWL Mar 4, 2022
d6cbfec
Python: huge_tree tests were wrong
RasmusWL Mar 4, 2022
f0131af
Python: Fix `huge_tree` modeling
RasmusWL Mar 4, 2022
1a9620a
Python: Add conditional assignment check for sax parser
RasmusWL Mar 4, 2022
ef045a6
Python: Fix typo in set_default_parser
RasmusWL Mar 4, 2022
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
25 changes: 25 additions & 0 deletions python/ql/src/experimental/Security/CWE-611/SimpleXmlRpcServer.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @name SimpleXMLRPCServer DoS vulnerability
* @description SimpleXMLRPCServer is vulnerable to DoS attacks from untrusted user input
* @kind problem
* @problem.severity warning
* @precision high
* @id py/simple-xml-rpc-server-dos
* @tags security
* external/cwe/cwe-776
*/

private import python
private import experimental.semmle.python.Concepts
private import semmle.python.ApiGraphs

from DataFlow::CallCfgNode call, string kinds
where
call = API::moduleImport("xmlrpc").getMember("server").getMember("SimpleXMLRPCServer").getACall() and
kinds =
strictconcat(XML::XMLVulnerabilityKind kind |
kind.isBillionLaughs() or kind.isQuadraticBlowup()
|
kind, ", "
)
select call, "SimpleXMLRPCServer is vulnerable to: " + kinds + "."
15 changes: 12 additions & 3 deletions python/ql/src/experimental/Security/CWE-611/XmlEntityInjection.ql
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ import python
import experimental.semmle.python.security.dataflow.XmlEntityInjection
import DataFlow::PathGraph

from DataFlow::PathNode source, DataFlow::PathNode sink, string kind
where XmlEntityInjection::xmlEntityInjectionVulnerable(source, sink, kind)
from
XmlEntityInjection::XmlEntityInjectionConfiguration config, DataFlow::PathNode source,
DataFlow::PathNode sink, string kinds
where
config.hasFlowPath(source, sink) and
kinds =
strictconcat(string kind |
kind = sink.getNode().(XmlEntityInjection::Sink).getVulnerableKind()
|
kind, ", "
)
select sink.getNode(), source, sink,
"$@ XML input is constructed from a $@ and is vulnerable to " + kind + ".", sink.getNode(),
"$@ XML input is constructed from a $@ and is vulnerable to: " + kinds + ".", sink.getNode(),
"This", source.getNode(), "user-provided value"
68 changes: 26 additions & 42 deletions python/ql/src/experimental/semmle/python/Concepts.qll
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,53 @@ private import experimental.semmle.python.Frameworks

module XML {
/**
* A data-flow node that collects functions parsing XML.
* A kind of XML vulnerability.
*
* Extend this class to model new APIs. If you want to refine existing API models,
* extend `XMLParsing` instead.
* See https://pypi.org/project/defusedxml/#python-xml-libraries
*/
class XMLParsing extends DataFlow::Node instanceof XMLParsing::Range {
/**
* Gets the argument containing the content to parse.
*/
DataFlow::Node getAnInput() { result = super.getAnInput() }
class XMLVulnerabilityKind extends string {
XMLVulnerabilityKind() {
this in ["Billion Laughs", "Quadratic Blowup", "XXE", "DTD retrieval"]
}

/**
* Holds if the parsing method or the parser holding it is vulnerable to `kind`.
*/
predicate vulnerable(string kind) { super.vulnerable(kind) }
}
/** Holds for Billion Laughs vulnerability kind. */
predicate isBillionLaughs() { this = "Billion Laughs" }

/** Provides classes for modeling XML parsing APIs. */
module XMLParsing {
/**
* A data-flow node that collects functions parsing XML.
*
* Extend this class to model new APIs. If you want to refine existing API models,
* extend `XMLParsing` instead.
*/
abstract class Range extends DataFlow::Node {
/**
* Gets the argument containing the content to parse.
*/
abstract DataFlow::Node getAnInput();
/** Holds for Quadratic Blowup vulnerability kind. */
predicate isQuadraticBlowup() { this = "Quadratic Blowup" }

/**
* Holds if the parsing method or the parser holding it is vulnerable to `kind`.
*/
abstract predicate vulnerable(string kind);
}
/** Holds for XXE vulnerability kind. */
predicate isXxe() { this = "XXE" }

/** Holds for DTD retrieval vulnerability kind. */
predicate isDtdRetrieval() { this = "DTD retrieval" }
}

/**
* A data-flow node that collects XML parsers.
* A data-flow node that parses XML.
*
* Extend this class to model new APIs. If you want to refine existing API models,
* extend `XMLParser` instead.
* extend `XMLParsing` instead.
*/
class XMLParser extends DataFlow::Node instanceof XMLParser::Range {
class XMLParsing extends DataFlow::Node instanceof XMLParsing::Range {
/**
* Gets the argument containing the content to parse.
*/
DataFlow::Node getAnInput() { result = super.getAnInput() }

/**
* Holds if the parser is vulnerable to `kind`.
* Holds if this XML parsing is vulnerable to `kind`.
*/
predicate vulnerable(string kind) { super.vulnerable(kind) }
predicate vulnerableTo(XMLVulnerabilityKind kind) { super.vulnerableTo(kind) }
}

/** Provides classes for modeling XML parsers. */
module XMLParser {
/** Provides classes for modeling XML parsing APIs. */
module XMLParsing {
/**
* A data-flow node that collects XML parsers.
* A data-flow node that parses XML.
*
* Extend this class to model new APIs. If you want to refine existing API models,
* extend `XMLParser` instead.
* extend `XMLParsing` instead.
*/
abstract class Range extends DataFlow::Node {
/**
Expand All @@ -87,9 +71,9 @@ module XML {
abstract DataFlow::Node getAnInput();

/**
* Holds if the parser is vulnerable to `kind`.
* Holds if this XML parsing is vulnerable to `kind`.
*/
abstract predicate vulnerable(string kind);
abstract predicate vulnerableTo(XMLVulnerabilityKind kind);
}
}
}
Expand Down
Loading