-
Notifications
You must be signed in to change notification settings - Fork 20
feat: Create Debugging Pack and add Queries #66
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
Draft
GeekMasher
wants to merge
6
commits into
main
Choose a base branch
from
python-debugging-pack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fe02d67
feat: Create Debugging Pack and add Queries
GeekMasher 77ebe01
Update python/debugging/basics/Sinks.ql
GeekMasher b26e567
Update python/debugging/diagnostics/SourcesLocal.ql
GeekMasher ec180d8
Update python/debugging/suites/default.qls
GeekMasher 5b798ee
Update python/debugging/partials/PartialPathsFromSource.ql
GeekMasher 9c77ef9
Update python/debugging/partials/PartialPathsFromSink.ql
GeekMasher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Python - Debugging | ||
|
||
This Pack is a collection of Python debugging tips and tricks. | ||
|
||
## Basics | ||
|
||
- [`Sources.ql`](./basics/Sources.ql) | ||
- List of the sources in the Application | ||
- [`Sinks.ql`](./basics/Sinks.ql) | ||
- List of the sinks in the Application | ||
|
||
## Partials | ||
|
||
- [`PartialPathsFromSource.ql`](./partials/PartialPathsFromSource.ql) | ||
- List of partial paths from a sources to nodes in the Application | ||
- [`PartialPathsFromSink.ql`](./partials/PartialPathsFromSink.ql) | ||
- List of partial paths from a sink to nodes in the Application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @name Sinks | ||
* @kind problem | ||
* @problem.severity warning | ||
* @security-severity 1.0 | ||
* @sub-severity low | ||
* @precision low | ||
* @id py/debugging/sinks | ||
* @tags debugging | ||
*/ | ||
|
||
import python | ||
import semmle.python.dataflow.new.DataFlow | ||
// Helpers | ||
private import ghsl.Helpers | ||
|
||
from DataFlow::Node sinks | ||
where | ||
dangerousSinks(sinks) and | ||
sinks.getScope().inSource() | ||
select sinks, "sink" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @name Sources | ||
* @kind problem | ||
* @problem.severity warning | ||
* @security-severity 1.0 | ||
* @sub-severity low | ||
* @precision low | ||
* @id py/debugging/sources | ||
* @tags debugging | ||
*/ | ||
|
||
import python | ||
import semmle.python.dataflow.new.DataFlow | ||
import semmle.python.dataflow.new.RemoteFlowSources | ||
// Helpers | ||
private import ghsl.Helpers | ||
private import ghsl.LocalSources | ||
|
||
class Sources extends DataFlow::Node { | ||
Sources() { | ||
this instanceof RemoteFlowSource | ||
or | ||
this instanceof LocalSources::Range | ||
} | ||
} | ||
|
||
from Sources sources | ||
where sources.getScope().inSource() | ||
select sources, "source" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
lockVersion: 1.0.0 | ||
dependencies: | ||
codeql/dataflow: | ||
version: 1.0.1 | ||
codeql/mad: | ||
version: 1.0.1 | ||
codeql/python-all: | ||
version: 1.0.1 | ||
codeql/regex: | ||
version: 1.0.1 | ||
codeql/ssa: | ||
version: 1.0.1 | ||
codeql/tutorial: | ||
version: 1.0.1 | ||
codeql/typetracking: | ||
version: 1.0.1 | ||
codeql/util: | ||
version: 1.0.1 | ||
codeql/xml: | ||
version: 1.0.1 | ||
codeql/yaml: | ||
version: 1.0.1 | ||
compiled: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @name Database Sinks Diagnostic | ||
* @id ghsl/diagnostics/database-sinks | ||
* @description List all database sinks | ||
* @kind diagnostic | ||
*/ | ||
|
||
import python | ||
import semmle.python.dataflow.new.DataFlow | ||
import semmle.python.security.dataflow.SqlInjectionCustomizations | ||
|
||
from SqlInjection::Sink s, Expr n | ||
where | ||
s.getScope().inSource() and | ||
n = s.asExpr() | ||
select n, "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @name Local Sources Diagnostic | ||
* @id ghsl/diagnostics/local-sources | ||
* @description List all local sources | ||
* @kind diagnostic | ||
*/ | ||
|
||
import python | ||
import semmle.python.dataflow.new.DataFlow | ||
// Helpers | ||
import ghsl.LocalSources | ||
|
||
from LocalSources::Range s, Expr n | ||
where | ||
s.getScope().inSource() and | ||
n = s.asExpr() | ||
select n, "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @name Remote Sources Diagnostic | ||
* @id ghsl/diagnostics/remote-sources | ||
* @description List all remote sources | ||
* @kind diagnostic | ||
*/ | ||
|
||
import python | ||
import semmle.python.dataflow.new.DataFlow | ||
import semmle.python.dataflow.new.RemoteFlowSources | ||
|
||
from RemoteFlowSource s, Expr n | ||
where | ||
s.getScope().inSource() and | ||
n = s.asExpr() | ||
select n, "" |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @name Partial Path Query from Sink | ||
* @kind path-problem | ||
* @problem.severity warning | ||
* @security-severity 1.0 | ||
* @sub-severity low | ||
* @precision low | ||
* @id py/debugging/partial-path-from-sink | ||
* @tags debugging | ||
*/ | ||
|
||
import python | ||
import semmle.python.dataflow.new.DataFlow | ||
import semmle.python.dataflow.new.TaintTracking | ||
import semmle.python.Concepts | ||
import semmle.python.dataflow.new.RemoteFlowSources | ||
import semmle.python.dataflow.new.BarrierGuards | ||
import semmle.python.ApiGraphs | ||
// Helpers | ||
private import ghsl.Helpers | ||
|
||
// Manual Sinks | ||
class ManualSinks extends DataFlow::Node { | ||
ManualSinks() { this = API::moduleImport("any").getMember("any").getACall() } | ||
} | ||
|
||
/** | ||
* Partial Graph module interface | ||
*/ | ||
module RemoteFlowsConfig implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node source) { none() } | ||
|
||
predicate isSink(DataFlow::Node sink) { | ||
// List of dangerous sinks (SQL Injection, Command Injection, etc.) | ||
dangerousSinks(sink) | ||
or | ||
// List of manually added sinks (above) | ||
sink instanceof ManualSinks | ||
} | ||
} | ||
|
||
// Set the limit of the exloration depth | ||
int explorationLimit() { result = 10 } | ||
|
||
module RemoteFlows = DataFlow::Global<RemoteFlowsConfig>; | ||
|
||
module RemoteFlowsPartial = RemoteFlows::FlowExplorationRev<explorationLimit/0>; | ||
|
||
import RemoteFlowsPartial::PartialPathGraph | ||
|
||
from RemoteFlowsPartial::PartialPathNode source, RemoteFlowsPartial::PartialPathNode sink | ||
where RemoteFlowsPartial::partialFlow(source, sink, _) | ||
/// Filter by location | ||
// and findByLocation(source.getNode(), "app.py", 20) | ||
// | ||
/// Filter by Function Parameters | ||
// and functionParameters(source.getNode()) | ||
// | ||
select sink.getNode(), source, sink, "Partial Graph $@.", source.getNode(), "user-provided value" |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @name Partial Path Query from Source | ||
* @kind path-problem | ||
* @problem.severity warning | ||
* @security-severity 1.0 | ||
* @sub-severity low | ||
* @precision low | ||
* @id py/debugging/partial-path-from-source | ||
* @tags debugging | ||
*/ | ||
|
||
import python | ||
import semmle.python.dataflow.new.DataFlow | ||
import semmle.python.dataflow.new.TaintTracking | ||
import semmle.python.Concepts | ||
import semmle.python.dataflow.new.RemoteFlowSources | ||
import semmle.python.dataflow.new.BarrierGuards | ||
import semmle.python.ApiGraphs | ||
// Helpers | ||
private import ghsl.Helpers | ||
private import ghsl.LocalSources | ||
|
||
// Partial Graph | ||
module RemoteFlowsConfig implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node source) { | ||
source instanceof RemoteFlowSource | ||
or | ||
// Local Sources | ||
source instanceof LocalSources::Range | ||
} | ||
|
||
predicate isSink(DataFlow::Node sink) { none() } | ||
} | ||
|
||
int explorationLimit() { result = 10 } | ||
|
||
module RemoteFlows = DataFlow::Global<RemoteFlowsConfig>; | ||
|
||
module RemoteFlowsPartial = RemoteFlows::FlowExplorationFwd<explorationLimit/0>; | ||
|
||
import RemoteFlowsPartial::PartialPathGraph | ||
|
||
from RemoteFlowsPartial::PartialPathNode source, RemoteFlowsPartial::PartialPathNode sink | ||
where RemoteFlowsPartial::partialFlow(source, sink, _) | ||
/// Filter by location | ||
// and findByLocation(source.getNode(), "app.py", 50) | ||
/// Filter by Function Parameters | ||
// and functionParameters(sink.getNode()) | ||
// | ||
select sink.getNode(), source, sink, "Partial Graph $@.", source.getNode(), "user-provided value" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
library: false | ||
name: githubsecuritylab/codeql-python-debugging | ||
version: 0.1.0 | ||
suites: suites | ||
defaultSuiteFile: suites/default.qls | ||
dependencies: | ||
codeql/python-all: '^1.0.0' | ||
githubsecuritylab/codeql-python-libs: "${workspace}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
- description: "GitHub's Community Packs Python Debugging Suite" | ||
|
||
# Field query pack with some audit queries | ||
- queries: "." | ||
from: githubsecuritylab/codeql-python-debugging | ||
|
||
- include: | ||
kind: | ||
- problem | ||
- path-problem | ||
- metric | ||
- diagnostic |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.