Skip to content

Commit b9edcb7

Browse files
committed
rename secondary to remote :), complete the previous commit changes
1 parent 52a8091 commit b9edcb7

File tree

21 files changed

+60
-45
lines changed

21 files changed

+60
-45
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<qhelp>
33
<overview>
44
<p>
5-
Allowing users to execute arbitrary commands using an SSH connection on a secondary server can lead to security issues unless you implement proper authorization.
5+
Allowing users to execute arbitrary commands using an SSH connection on a remote server can lead to security issues unless you implement proper authorization.
66
</p>
77
<p>
8-
Assume that you connect to a secondary system via SSH connection from your main or local server that accepts user-controlled data and has interaction with users that you don't trust, passing these data to SSH API as a part of a command that will be executed on a secondary remote server can lead to security issues. You should consider proper authorization rules very carefully.
8+
Assume that you connect to a remote system via SSH connection from your main or local server that accepts user-controlled data and has interaction with users that you don't trust, passing these data to SSH API as a part of a command that will be executed on a secondary remote server can lead to security issues. You should consider proper authorization rules very carefully.
99
</p>
1010
</overview>
1111
<recommendation>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
*/
1313

1414
import python
15-
import experimental.semmle.python.security.SecondaryServerCmdInjection
16-
import SecondaryCommandInjectionFlow::PathGraph
15+
import experimental.semmle.python.security.RemoteCommandExecution
16+
import RemoteCommandExecutionFlow::PathGraph
1717

18-
from SecondaryCommandInjectionFlow::PathNode source, SecondaryCommandInjectionFlow::PathNode sink
19-
where SecondaryCommandInjectionFlow::flowPath(source, sink)
18+
from RemoteCommandExecutionFlow::PathNode source, RemoteCommandExecutionFlow::PathNode sink
19+
where RemoteCommandExecutionFlow::flowPath(source, sink)
2020
select sink.getNode(), source, sink, "This code execution depends on a $@.", source.getNode(),
2121
"a user-provided value"

python/ql/src/experimental/semmle/python/Concepts.qll

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,29 @@ private import semmle.python.dataflow.new.TaintTracking
1515
private import experimental.semmle.python.Frameworks
1616
private import semmle.python.Concepts
1717

18-
/** Provides classes for modeling remote server command execution related APIs. */
18+
/**
19+
* A data-flow node that executes an operating system command,
20+
* on a remote server likely by SSH connections.
21+
*
22+
* Extend this class to refine existing API models. If you want to model new APIs,
23+
* extend `RemoteCommandExecution::Range` instead.
24+
*/
25+
class RemoteCommandExecution extends DataFlow::Node instanceof RemoteCommandExecution::Range {
26+
/** Holds if a shell interprets `arg`. */
27+
predicate isShellInterpreted(DataFlow::Node arg) { super.isShellInterpreted(arg) }
28+
29+
/** Gets the argument that specifies the command to be executed. */
30+
DataFlow::Node getCommand() { result = super.getCommand() }
31+
}
32+
33+
/** Provides classes for modeling new remote server command execution APIs. */
1934
module RemoteCommandExecution {
2035
/**
2136
* A data-flow node that executes an operating system command,
2237
* on a remote server likely by SSH connections.
2338
*
2439
* Extend this class to model new APIs. If you want to refine existing API models,
25-
* extend `SystemCommandExecution` instead.
40+
* extend `RemoteCommandExecution` instead.
2641
*/
2742
abstract class Range extends DataFlow::Node {
2843
/** Gets the argument that specifies the command to be executed. */

python/ql/src/experimental/semmle/python/security/SecondaryServerCmdInjection.qll renamed to python/ql/src/experimental/semmle/python/security/RemoteCommandExecution.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import semmle.python.dataflow.new.internal.DataFlowPublic
66
import codeql.util.Unit
77
import experimental.semmle.python.Concepts
88

9-
module SecondaryCommandInjectionConfig implements DataFlow::ConfigSig {
9+
module RemoteCommandExecutionConfig implements DataFlow::ConfigSig {
1010
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
1111

12-
predicate isSink(DataFlow::Node sink) { sink instanceof SecondaryCommandInjection }
12+
predicate isSink(DataFlow::Node sink) { sink = any(RemoteCommandExecution rce).getCommand() }
1313
}
1414

1515
/** Global taint-tracking for detecting "secondary server command injection" vulnerabilities. */
16-
module SecondaryCommandInjectionFlow = TaintTracking::Global<SecondaryCommandInjectionConfig>;
16+
module RemoteCommandExecutionFlow = TaintTracking::Global<RemoteCommandExecutionConfig>;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
@app.get("/bad1")
1515
async def bad1(cmd: str):
1616
async with asyncssh.connect('localhost') as conn:
17-
result = await conn.run(cmd, check=True) # $ result=BAD getSecondaryCommand=cmd
17+
result = await conn.run(cmd, check=True) # $ result=BAD getRemoteCommand=cmd
1818
print(result.stdout, end='')
1919
return {"success": "Dangerous"}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ private import semmle.python.dataflow.new.internal.PrintNode
66
import experimental.semmle.python.Concepts
77

88
module SystemCommandExecutionTest implements TestSig {
9-
string getARelevantTag() { result = "getSecondaryCommand" }
9+
string getARelevantTag() { result = "getRemoteCommand" }
1010

1111
predicate hasActualResult(Location location, string element, string tag, string value) {
1212
exists(location.getFile().getRelativePath()) and
13-
exists(SecondaryCommandInjection sci, DataFlow::Node command |
14-
command = sci and
13+
exists(RemoteCommandExecution sci, DataFlow::Node command |
14+
command = sci.getCommand() and
1515
location = command.getLocation() and
1616
element = command.toString() and
1717
value = prettyNodeForInlineTest(command) and
18-
tag = "getSecondaryCommand"
18+
tag = "getRemoteCommand"
1919
)
2020
}
2121
}

0 commit comments

Comments
 (0)