|
| 1 | +/** |
| 2 | + * Provides default sources, sinks and sanitizers for reasoning about |
| 3 | + * unsafe deserialization vulnerabilities, as well as extension points for |
| 4 | + * adding your own. |
| 5 | + */ |
| 6 | + |
| 7 | +private import semmle.code.powershell.dataflow.DataFlow |
| 8 | +import semmle.code.powershell.ApiGraphs |
| 9 | +private import semmle.code.powershell.dataflow.flowsources.FlowSources |
| 10 | +private import semmle.code.powershell.Cfg |
| 11 | + |
| 12 | +module UnsafeDeserialization { |
| 13 | + /** |
| 14 | + * A data flow source for SQL-injection vulnerabilities. |
| 15 | + */ |
| 16 | + abstract class Source extends DataFlow::Node { |
| 17 | + /** Gets a string that describes the type of this flow source. */ |
| 18 | + abstract string getSourceType(); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * A data flow sink for SQL-injection vulnerabilities. |
| 23 | + */ |
| 24 | + abstract class Sink extends DataFlow::Node { |
| 25 | + /** Gets a description of this sink. */ |
| 26 | + abstract string getSinkType(); |
| 27 | + |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * A sanitizer for Unsafe Deserialization vulnerabilities. |
| 32 | + */ |
| 33 | + abstract class Sanitizer extends DataFlow::Node { } |
| 34 | + |
| 35 | + /** A source of user input, considered as a flow source for unsafe deserialization. */ |
| 36 | + class FlowSourceAsSource extends Source instanceof SourceNode { |
| 37 | + override string getSourceType() { result = SourceNode.super.getSourceType() } |
| 38 | + } |
| 39 | + |
| 40 | + class BinaryFormatterDeserializeSink extends Sink { |
| 41 | + BinaryFormatterDeserializeSink() { |
| 42 | + exists(DataFlow::ObjectCreationNode ocn, DataFlow::CallNode cn | |
| 43 | + cn.getQualifier().getALocalSource() = ocn and |
| 44 | + ocn.getExprNode().getExpr().(CallExpr).getAnArgument().getValue().asString() = "System.Runtime.Serialization.Formatters.Binary.BinaryFormatter" and |
| 45 | + cn.getLowerCaseName() = "deserialize" and |
| 46 | + cn.getAnArgument() = this |
| 47 | + ) |
| 48 | + } |
| 49 | + |
| 50 | + override string getSinkType() { result = "call to BinaryFormatter.Deserialize" } |
| 51 | + |
| 52 | + } |
| 53 | +} |
0 commit comments