First commit (and working one) for an Issue #287 (XML-RPC server)

This commit is contained in:
Miroslav Stampar 2012-12-11 16:02:06 +01:00
parent b5884c7eda
commit b9f6fc5f4e
4 changed files with 66 additions and 9 deletions

View File

@ -36,6 +36,7 @@ from lib.core.settings import LEGAL_DISCLAIMER
from lib.core.testing import smokeTest
from lib.core.testing import liveTest
from lib.parse.cmdline import cmdLineParser
from lib.utils.xmlrpc import XMLRPCServer
def modulePath():
"""
@ -61,16 +62,20 @@ def main():
# Store original command line options for possible later restoration
cmdLineOptions.update(cmdLineParser().__dict__)
init(cmdLineOptions)
if conf.profile:
profile()
elif conf.smokeTest:
smokeTest()
elif conf.liveTest:
liveTest()
if cmdLineOptions.xmlRpc:
server = XMLRPCServer()
server.serve()
else:
start()
init(cmdLineOptions)
if conf.profile:
profile()
elif conf.smokeTest:
smokeTest()
elif conf.liveTest:
liveTest()
else:
start()
except SqlmapUserQuitException:
errMsg = "user quit"

View File

@ -482,6 +482,9 @@ EVENTVALIDATION_REGEX = r'(?i)(?P<name>__EVENTVALIDATION[^"]*)[^>]+value="(?P<re
# Number of rows to generate inside the full union test for limited output (mustn't be too large to prevent payload length problems)
LIMITED_ROWS_TEST_NUMBER = 15
# Default TCP port used for XML-RPC server instance
XML_RPC_SERVER_PORT = 8776
# Regular expression for SOAP-like POST data
SOAP_RECOGNITION_REGEX = r"(?s)\A(<\?xml[^>]+>)?\s*<([^> ]+)( [^>]+)?>.+</\2.*>\s*\Z"

View File

@ -682,6 +682,9 @@ def cmdLineParser():
parser.add_option("--run-case", dest="runCase", type="int",
help=SUPPRESS_HELP)
parser.add_option("--xmlrpc", dest="xmlRpc", action="store_true",
help=SUPPRESS_HELP)
parser.add_option_group(target)
parser.add_option_group(request)
parser.add_option_group(optimization)

46
lib/utils/xmlrpc.py Normal file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env python
"""
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
See the file 'doc/COPYING' for copying permission
"""
from SimpleXMLRPCServer import SimpleXMLRPCServer
from lib.controller.controller import start
from lib.core.datatype import AttribDict
from lib.core.data import cmdLineOptions
from lib.core.data import logger
from lib.core.option import init
from lib.core.settings import XML_RPC_SERVER_PORT
from lib.core.settings import UNICODE_ENCODING
class XMLRPCServer:
def __init__(self):
self.reset()
def reset(self):
self.options = AttribDict(cmdLineOptions)
def set_option(self, name, value):
self.options[name] = value
def get_option(self, name):
return self.options[name]
def get_option_names(self):
return self.options.keys()
def run(self):
init(self.options, True)
return start()
def serve(self):
server = SimpleXMLRPCServer(addr=("", XML_RPC_SERVER_PORT), logRequests=False, allow_none=True, encoding=UNICODE_ENCODING)
server.register_introspection_functions()
server.register_function(self.reset)
server.register_function(self.set_option)
server.register_function(self.get_option)
server.register_function(self.get_option_names)
server.register_function(self.run)
server.serve_forever()