-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python: XML RPC Dotted Names #3910
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
Open
dilanbhalla
wants to merge
2
commits into
github:main
Choose a base branch
from
dilanbhalla:xmlrpcdottednames
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
17 changes: 17 additions & 0 deletions
17
python/ql/src/experimental/Security/XmlRpcDottedNames.qhelp
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 @@ | ||
<!DOCTYPE qhelp PUBLIC | ||
"-//Semmle//qhelp//EN" | ||
"qhelp.dtd"> | ||
<qhelp> | ||
<overview> | ||
<p>Enabling the <code>allow_dotted_names</code> option allows intruders to access your module’s global | ||
variables and may allow intruders to execute arbitrary code on your machine. Only use this example only within a secure, closed network. | ||
</p> | ||
|
||
<references> | ||
|
||
<li>Python Language Reference: <a href="https://docs.python.org/3/library/xmlrpc.server.html#xmlrpc.server.SimpleXMLRPCServer"> | ||
Basic XML-RPC servers</a>. | ||
</li> | ||
|
||
</references> | ||
</qhelp> |
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 @@ | ||
/** | ||
* @name The allow_dotted_names option may allow intruders to execute arbitrary code | ||
* @description Enabling the allow_dotted_names option allows intruders to access your module’s global variables and may allow intruders to execute arbitrary code on your machine. | ||
* @kind problem | ||
* @problem.severity warning | ||
* @id python/xml-rpc-dotted-names | ||
* @tags reliability | ||
* security | ||
*/ | ||
|
||
import python | ||
|
||
from CallNode call, ControlFlowNode allow_dotted_names, Attribute a | ||
where | ||
a.getLocation().getStartLine() = call.getLocation().getStartLine() and | ||
a.getName() = "register_instance" and | ||
not call.getLocation().getFile().inStdlib() and | ||
( | ||
allow_dotted_names = call.getArgByName("allow_dotted_names") or | ||
allow_dotted_names = call.getArg(1) | ||
) and | ||
allow_dotted_names.getNode().toString() = "True" | ||
select a, | ||
"Enabling the allow_dotted_names option allows intruders to access your module’s global variables and may allow intruders to execute arbitrary code on your machine." | ||
1 change: 1 addition & 0 deletions
1
python/ql/test/experimental/Security/XmlRpcDottedNames.expected
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 @@ | ||
| XmlRpcDottedNames.py:19:5:19:28 | Attribute | Enabling the allow_dotted_names option allows intruders to access your module\u2019s global variables and may allow intruders to execute arbitrary code on your machine. | |
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,26 @@ | ||
# Copied from official python 3 documentation, at https://docs.python.org/3/library/xmlrpc.server.html#xmlrpc.server.SimpleXMLRPCServer | ||
|
||
import sys, datetime | ||
from xmlrpc.server import SimpleXMLRPCServer | ||
|
||
class ExampleService: | ||
def getData(self): | ||
return '42' | ||
|
||
class currentTime: | ||
@staticmethod | ||
def getCurrentTime(): | ||
return datetime.datetime.now() | ||
|
||
with SimpleXMLRPCServer(("localhost", 8000)) as server: | ||
server.register_function(pow) | ||
server.register_function(lambda x,y: x+y, 'add') | ||
# WARNING: Only set the allow_dotted_names flag to true within a secure, closed network. | ||
server.register_instance(ExampleService(), allow_dotted_names=True) | ||
server.register_multicall_functions() | ||
print('Serving XML-RPC on localhost port 8000') | ||
try: | ||
server.serve_forever() | ||
except KeyboardInterrupt: | ||
print("\nKeyboard interrupt received, exiting.") | ||
sys.exit(0) |
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 @@ | ||
experimental/Security/XmlRpcDottedNames.ql |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A modern way to write this would be