mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-25 19:13:48 +03:00
Minor update for an Issue #287
This commit is contained in:
parent
32b39c72e4
commit
c3f20a136f
24
_sqlmap.py
24
_sqlmap.py
|
@ -8,6 +8,7 @@ See the file 'doc/COPYING' for copying permission
|
||||||
import bdb
|
import bdb
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import StringIO
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -22,6 +23,7 @@ from lib.core.common import dataToStdout
|
||||||
from lib.core.common import getUnicode
|
from lib.core.common import getUnicode
|
||||||
from lib.core.common import setPaths
|
from lib.core.common import setPaths
|
||||||
from lib.core.common import weAreFrozen
|
from lib.core.common import weAreFrozen
|
||||||
|
from lib.core.convert import stdoutencode
|
||||||
from lib.core.data import cmdLineOptions
|
from lib.core.data import cmdLineOptions
|
||||||
from lib.core.data import conf
|
from lib.core.data import conf
|
||||||
from lib.core.data import kb
|
from lib.core.data import kb
|
||||||
|
@ -31,6 +33,8 @@ from lib.core.common import unhandledExceptionMessage
|
||||||
from lib.core.exception import exceptionsTuple
|
from lib.core.exception import exceptionsTuple
|
||||||
from lib.core.exception import SqlmapSilentQuitException
|
from lib.core.exception import SqlmapSilentQuitException
|
||||||
from lib.core.exception import SqlmapUserQuitException
|
from lib.core.exception import SqlmapUserQuitException
|
||||||
|
from lib.core.log import FORMATTER
|
||||||
|
from lib.core.log import setLoggerHandler
|
||||||
from lib.core.option import init
|
from lib.core.option import init
|
||||||
from lib.core.profiling import profile
|
from lib.core.profiling import profile
|
||||||
from lib.core.settings import LEGAL_DISCLAIMER
|
from lib.core.settings import LEGAL_DISCLAIMER
|
||||||
|
@ -48,6 +52,22 @@ def modulePath():
|
||||||
|
|
||||||
return os.path.dirname(getUnicode(sys.executable if weAreFrozen() else __file__, sys.getfilesystemencoding()))
|
return os.path.dirname(getUnicode(sys.executable if weAreFrozen() else __file__, sys.getfilesystemencoding()))
|
||||||
|
|
||||||
|
def xmlRpcServe():
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
server = XMLRPCServer(cmdLineOptions.xmlRpcPort or XMLRPC_SERVER_PORT)
|
||||||
|
class _(logging.Handler):
|
||||||
|
def emit(self, record):
|
||||||
|
message = stdoutencode(self.format(record))
|
||||||
|
sys.stdout.write("%s\n" % message)
|
||||||
|
handler = _()
|
||||||
|
handler.is_tty = False
|
||||||
|
handler.disableColoring = True
|
||||||
|
handler.setFormatter(FORMATTER)
|
||||||
|
setLoggerHandler(handler)
|
||||||
|
sys.stdout = StringIO.StringIO()
|
||||||
|
sys.stderr = StringIO.StringIO()
|
||||||
|
server.serve()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
Main function of sqlmap when running from command line.
|
Main function of sqlmap when running from command line.
|
||||||
|
@ -65,9 +85,7 @@ def main():
|
||||||
cmdLineOptions.update(cmdLineParser().__dict__)
|
cmdLineOptions.update(cmdLineParser().__dict__)
|
||||||
|
|
||||||
if cmdLineOptions.xmlRpc:
|
if cmdLineOptions.xmlRpc:
|
||||||
logger.setLevel(logging.INFO)
|
xmlRpcServe()
|
||||||
server = XMLRPCServer(cmdLineOptions.xmlRpcPort or XMLRPC_SERVER_PORT)
|
|
||||||
server.serve()
|
|
||||||
else:
|
else:
|
||||||
init(cmdLineOptions)
|
init(cmdLineOptions)
|
||||||
|
|
||||||
|
|
|
@ -228,6 +228,13 @@ def _saveToResultsFile():
|
||||||
conf.resultsFP.writelines(line)
|
conf.resultsFP.writelines(line)
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
|
kb.busyFlag = True
|
||||||
|
retVal = _start()
|
||||||
|
kb.busyFlag = False
|
||||||
|
|
||||||
|
return retVal
|
||||||
|
|
||||||
|
def _start():
|
||||||
"""
|
"""
|
||||||
This function calls a function that performs checks on both URL
|
This function calls a function that performs checks on both URL
|
||||||
stability and all GET, POST, Cookie and User-Agent parameters to
|
stability and all GET, POST, Cookie and User-Agent parameters to
|
||||||
|
|
|
@ -31,3 +31,7 @@ FORMATTER = logging.Formatter("\r[%(asctime)s] [%(levelname)s] %(message)s", "%H
|
||||||
LOGGER_HANDLER.setFormatter(FORMATTER)
|
LOGGER_HANDLER.setFormatter(FORMATTER)
|
||||||
LOGGER.addHandler(LOGGER_HANDLER)
|
LOGGER.addHandler(LOGGER_HANDLER)
|
||||||
LOGGER.setLevel(logging.WARN)
|
LOGGER.setLevel(logging.WARN)
|
||||||
|
|
||||||
|
def setLoggerHandler(handler):
|
||||||
|
LOGGER.handlers = []
|
||||||
|
LOGGER.addHandler(handler)
|
||||||
|
|
|
@ -1487,6 +1487,7 @@ def _setKnowledgeBaseAttributes(flushAll=True):
|
||||||
|
|
||||||
kb.brute = AttribDict({"tables":[], "columns":[]})
|
kb.brute = AttribDict({"tables":[], "columns":[]})
|
||||||
kb.bruteMode = False
|
kb.bruteMode = False
|
||||||
|
kb.busyFlag = False
|
||||||
|
|
||||||
kb.cache = AttribDict()
|
kb.cache = AttribDict()
|
||||||
kb.cache.content = {}
|
kb.cache.content = {}
|
||||||
|
|
|
@ -6,6 +6,7 @@ See the file 'doc/COPYING' for copying permission
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -14,6 +15,7 @@ try:
|
||||||
from lib.controller.controller import start
|
from lib.controller.controller import start
|
||||||
from lib.core.datatype import AttribDict
|
from lib.core.datatype import AttribDict
|
||||||
from lib.core.data import cmdLineOptions
|
from lib.core.data import cmdLineOptions
|
||||||
|
from lib.core.data import kb
|
||||||
from lib.core.data import logger
|
from lib.core.data import logger
|
||||||
from lib.core.option import init
|
from lib.core.option import init
|
||||||
from lib.core.settings import UNICODE_ENCODING
|
from lib.core.settings import UNICODE_ENCODING
|
||||||
|
@ -26,6 +28,16 @@ class XMLRPCServer:
|
||||||
self.port = port
|
self.port = port
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
|
self.server = SimpleXMLRPCServer(addr=("", self.port), logRequests=False, allow_none=True, encoding=UNICODE_ENCODING)
|
||||||
|
self.server.register_function(self.reset)
|
||||||
|
self.server.register_function(self.set_option)
|
||||||
|
self.server.register_function(self.get_option)
|
||||||
|
self.server.register_function(self.get_option_names)
|
||||||
|
self.server.register_function(self.run)
|
||||||
|
logger.info("Registering RPC methods: %s" % str(self.server.system_listMethods()).strip("[]"))
|
||||||
|
self.server.register_introspection_functions()
|
||||||
|
logger.info("Running XML-RPC server at '0.0.0.0:%d'..." % self.port)
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.options = AttribDict(cmdLineOptions)
|
self.options = AttribDict(cmdLineOptions)
|
||||||
|
|
||||||
|
@ -38,21 +50,20 @@ class XMLRPCServer:
|
||||||
def get_option_names(self):
|
def get_option_names(self):
|
||||||
return self.options.keys()
|
return self.options.keys()
|
||||||
|
|
||||||
|
def is_busy(self):
|
||||||
|
return kb.get("busyFlag")
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
init(self.options, True)
|
if not self.is_busy():
|
||||||
return start()
|
init(self.options, True)
|
||||||
|
thread = threading.Thread(target=start)
|
||||||
|
thread.daemon = True
|
||||||
|
thread.start()
|
||||||
|
else:
|
||||||
|
raise Exception, "sqlmap busy"
|
||||||
|
|
||||||
def serve(self):
|
def serve(self):
|
||||||
server = SimpleXMLRPCServer(addr=("", self.port), logRequests=False, allow_none=True, encoding=UNICODE_ENCODING)
|
self.server.serve_forever()
|
||||||
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)
|
|
||||||
logger.info("Registering RPC methods: %s" % str(server.system_listMethods()).strip("[]"))
|
|
||||||
server.register_introspection_functions()
|
|
||||||
logger.info("Running XML-RPC server at '0.0.0.0:%d'..." % self.port)
|
|
||||||
server.serve_forever()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
|
@ -69,7 +80,8 @@ if __name__ == "__main__":
|
||||||
print "[i] Server instance name: 'server'"
|
print "[i] Server instance name: 'server'"
|
||||||
print "[i] Sample usage: 'server.system.listMethods()'"
|
print "[i] Sample usage: 'server.system.listMethods()'"
|
||||||
except Exception, ex:
|
except Exception, ex:
|
||||||
print "[x] '%s'" % str(ex)
|
if ex:
|
||||||
|
print "[x] '%s'" % str(ex)
|
||||||
else:
|
else:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user