在Python2.7文档 for SimpleXMLRPCServer中,以下代码设置服务器:
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
# Create server
server = SimpleXMLRPCServer(("localhost", 8000),
requestHandler=RequestHandler)
server.register_introspection_functions()
# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)
# Register a function under a different name
def adder_function(x,y):
return x + y
server.register_function(adder_function, 'add')
# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
def div(self, x, y):
return x // y
server.register_instance(MyFuncs())
# Run the server's main loop
server.serve_forever()我读过Python的XMLRPC服务器可以是易受某些XML攻击,特别是“10亿笑”、“二次爆破”和“解压缩炸弹”。文档中的示例代码是否易受这些攻击的影响,是否需要进一步的方法来保护其免受这些漏洞的攻击?在这个示例代码之后,我正在对一些客户机-服务器代码进行建模,并想知道SimpleXMLRPCServer有多脆弱。如果这个示例代码易受攻击,那么我想我也需要在我的应用程序中做些什么。
编辑:
这就是我为解决XML漏洞而实现的。这是正确的吗?保护示例代码所需要的就足够了吗?
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
from defusedxml.xmlrpc import monkey_patch # Protects against XML vulnerabilities. See https://docs.python.org/2/library/xml.html
monkey_patch()
# Rest of code is the same as above发布于 2019-05-20 04:02:50
库容易受到XML攻击的攻击,并且(攻击的性质就是它们的本质)示例代码不是攻击的证据,因为这不是漏洞所在:它们实际上存在于库对XML规范的正确实现中。对于客户端代码来说,保护自己不受API调用的正确执行并不容易。
如果您关心这些问题,可以尝试使用库defusedxml。根据xmlrpc.server的文档(这是Python3版本的SimpleXMLRPCServer),库defusedxml和它的朋友defusedxpat将来可能会被包含在Python3标准库中,而不是现在,仅仅因为它们会破坏向后兼容性。
https://stackoverflow.com/questions/56213470
复制相似问题