File tree Expand file tree Collapse file tree 4 files changed +69
-2
lines changed
src/experimental/semmle/python
test/experimental/query-tests/Security/CWE-074-SecondaryServerCmdInjection Expand file tree Collapse file tree 4 files changed +69
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ private import experimental.semmle.python.frameworks.Netmiko
1212private import experimental.semmle.python.frameworks.Paramiko
1313private import experimental.semmle.python.frameworks.Pexpect
1414private import experimental.semmle.python.frameworks.Scrapli
15+ private import experimental.semmle.python.frameworks.Twisted
1516private import experimental.semmle.python.frameworks.JWT
1617private import experimental.semmle.python.frameworks.Csv
1718private import experimental.semmle.python.libraries.PyJWT
Original file line number Diff line number Diff line change 1+ /**
2+ * Provides classes modeling security-relevant aspects of the `twisted` PyPI package.
3+ * See https://twistedmatrix.com/.
4+ */
5+
6+ private import python
7+ private import semmle.python.dataflow.new.DataFlow
8+ private import semmle.python.dataflow.new.RemoteFlowSources
9+ private import semmle.python.dataflow.new.TaintTracking
10+ private import semmle.python.Concepts
11+ private import semmle.python.ApiGraphs
12+ private import semmle.python.frameworks.internal.InstanceTaintStepsHelper
13+ import experimental.semmle.python.Concepts
14+
15+ /**
16+ * Provides models for the `twisted` PyPI package.
17+ * See https://twistedmatrix.com/.
18+ */
19+ private module Twisted {
20+ /**
21+ * The `newConnection` and `existingConnection` functions of `twisted.conch.endpoints.SSHCommandClientEndpoint` class execute command on ssh target server
22+ */
23+ class ParamikoExecCommand extends SecondaryCommandInjection {
24+ ParamikoExecCommand ( ) {
25+ this =
26+ API:: moduleImport ( "twisted" )
27+ .getMember ( "conch" )
28+ .getMember ( "endpoints" )
29+ .getMember ( "SSHCommandClientEndpoint" )
30+ .getMember ( [ "newConnection" , "existingConnection" ] )
31+ .getACall ( )
32+ .getParameter ( 1 , "command" )
33+ .asSink ( )
34+ }
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ from fastapi import FastAPI
4+ from twisted .conch .endpoints import SSHCommandClientEndpoint
5+ from twisted .internet .protocol import Factory
6+ from twisted .internet import reactor
7+
8+
9+ app = FastAPI ()
10+
11+
12+ @app .get ("/bad1" )
13+ async def bad1 (cmd : bytes ):
14+ endpoint = SSHCommandClientEndpoint .newConnection (
15+ reactor ,
16+ cmd , # $ result=BAD getSecondaryCommand=cmd
17+ b"username" ,
18+ b"ssh.example.com" ,
19+ 22 ,
20+ password = b"password" )
21+
22+ SSHCommandClientEndpoint .existingConnection (
23+ endpoint ,
24+ cmd ) # $ result=BAD getSecondaryCommand=cmd
25+
26+ factory = Factory ()
27+ d = endpoint .connect (factory )
28+ d .addCallback (lambda protocol : protocol .finished )
29+
30+ return {"success" : "Dangerous" }
Original file line number Diff line number Diff line change 1414@app .get ("/bad1" )
1515async def bad1 (cmd : str ):
1616 stdin , stdout , stderr = paramiko_ssh_client .exec_command (cmd ) # $ result=BAD getSecondaryCommand=cmd
17- return {"success" : stdout }
17+ return {"success" : "Dangerous" }
1818
1919@app .get ("/bad2" )
2020async def bad2 (cmd : str ):
2121 stdin , stdout , stderr = paramiko_ssh_client .exec_command (command = cmd ) # $ result=BAD getSecondaryCommand=cmd
22- return {"success" : "OK " }
22+ return {"success" : "Dangerous " }
You can’t perform that action at this time.
0 commit comments