2012-12-11 19:02:06 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
|
|
|
|
See the file 'doc/COPYING' for copying permission
|
|
|
|
"""
|
|
|
|
|
2012-12-12 14:54:59 +04:00
|
|
|
import sys
|
2012-12-12 17:03:03 +04:00
|
|
|
import threading
|
2012-12-12 19:31:20 +04:00
|
|
|
import types
|
2012-12-12 14:54:59 +04:00
|
|
|
import xmlrpclib
|
2012-12-11 19:02:06 +04:00
|
|
|
|
2012-12-12 14:54:59 +04:00
|
|
|
try:
|
|
|
|
from SimpleXMLRPCServer import SimpleXMLRPCServer
|
|
|
|
|
|
|
|
from lib.controller.controller import start
|
|
|
|
from lib.core.datatype import AttribDict
|
|
|
|
from lib.core.data import cmdLineOptions
|
2012-12-12 17:03:03 +04:00
|
|
|
from lib.core.data import kb
|
2012-12-12 14:54:59 +04:00
|
|
|
from lib.core.data import logger
|
|
|
|
from lib.core.option import init
|
|
|
|
from lib.core.settings import UNICODE_ENCODING
|
|
|
|
from lib.core.settings import XMLRPC_SERVER_PORT
|
|
|
|
except ImportError:
|
2012-12-12 15:07:56 +04:00
|
|
|
XMLRPC_SERVER_PORT = 8776
|
2012-12-11 19:02:06 +04:00
|
|
|
|
|
|
|
class XMLRPCServer:
|
2012-12-12 14:54:59 +04:00
|
|
|
def __init__(self, port):
|
|
|
|
self.port = port
|
2012-12-11 19:02:06 +04:00
|
|
|
self.reset()
|
|
|
|
|
2012-12-12 17:03:03 +04:00
|
|
|
self.server = SimpleXMLRPCServer(addr=("", self.port), logRequests=False, allow_none=True, encoding=UNICODE_ENCODING)
|
2012-12-12 19:31:20 +04:00
|
|
|
for _ in dir(self):
|
2012-12-13 17:55:20 +04:00
|
|
|
if _.startswith("serve"):
|
|
|
|
continue
|
2012-12-12 19:31:20 +04:00
|
|
|
if not _.startswith('_') and isinstance(getattr(self, _), types.MethodType):
|
|
|
|
self.server.register_function(getattr(self, _))
|
2012-12-12 17:03:03 +04:00
|
|
|
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)
|
|
|
|
|
2012-12-11 19:02:06 +04:00
|
|
|
def reset(self):
|
|
|
|
self.options = AttribDict(cmdLineOptions)
|
|
|
|
|
|
|
|
def set_option(self, name, value):
|
|
|
|
self.options[name] = value
|
2012-12-12 19:31:20 +04:00
|
|
|
return value
|
2012-12-11 19:02:06 +04:00
|
|
|
|
|
|
|
def get_option(self, name):
|
|
|
|
return self.options[name]
|
|
|
|
|
|
|
|
def get_option_names(self):
|
2012-12-12 19:31:20 +04:00
|
|
|
return sorted(self.options.keys())
|
2012-12-11 19:02:06 +04:00
|
|
|
|
2012-12-12 17:03:03 +04:00
|
|
|
def is_busy(self):
|
|
|
|
return kb.get("busyFlag")
|
|
|
|
|
2012-12-12 19:31:20 +04:00
|
|
|
def read_output(self):
|
2012-12-12 20:17:36 +04:00
|
|
|
sys.stdout.seek(0)
|
|
|
|
retval = sys.stdout.read()
|
|
|
|
sys.stdout.truncate(0)
|
|
|
|
|
|
|
|
if not retval and not self.is_busy():
|
2012-12-12 19:31:20 +04:00
|
|
|
retval = None
|
2012-12-12 20:17:36 +04:00
|
|
|
|
2012-12-12 19:31:20 +04:00
|
|
|
return retval
|
|
|
|
|
2012-12-11 19:02:06 +04:00
|
|
|
def run(self):
|
2012-12-12 17:03:03 +04:00
|
|
|
if not self.is_busy():
|
|
|
|
init(self.options, True)
|
|
|
|
thread = threading.Thread(target=start)
|
|
|
|
thread.daemon = True
|
|
|
|
thread.start()
|
|
|
|
else:
|
|
|
|
raise Exception, "sqlmap busy"
|
2012-12-11 19:02:06 +04:00
|
|
|
|
|
|
|
def serve(self):
|
2012-12-12 17:03:03 +04:00
|
|
|
self.server.serve_forever()
|
2012-12-12 14:54:59 +04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
import readline
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2012-12-12 15:01:18 +04:00
|
|
|
try:
|
2012-12-12 15:07:56 +04:00
|
|
|
addr = "http://localhost:%d" % (int(sys.argv[1]) if len(sys.argv) > 1 else XMLRPC_SERVER_PORT)
|
2012-12-12 15:01:18 +04:00
|
|
|
print "[i] Starting debug XML-RPC client to '%s'..." % addr
|
2012-12-12 15:07:56 +04:00
|
|
|
|
2012-12-12 15:01:18 +04:00
|
|
|
server = xmlrpclib.ServerProxy(addr)
|
|
|
|
print "[i] Available RPC methods: %s" % str(server.system.listMethods()).strip("[]")
|
|
|
|
print "[i] Server instance name: 'server'"
|
|
|
|
print "[i] Sample usage: 'server.system.listMethods()'"
|
|
|
|
except Exception, ex:
|
2012-12-12 17:03:03 +04:00
|
|
|
if ex:
|
|
|
|
print "[x] '%s'" % str(ex)
|
2012-12-12 15:01:18 +04:00
|
|
|
else:
|
|
|
|
while True:
|
|
|
|
try:
|
2012-12-12 19:31:20 +04:00
|
|
|
cmd = raw_input("> ")
|
|
|
|
try:
|
|
|
|
result = eval(cmd)
|
|
|
|
print result if result is not None else ""
|
|
|
|
except SyntaxError:
|
|
|
|
exec(cmd)
|
2012-12-12 15:01:18 +04:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
exit(0)
|
|
|
|
except Exception, ex:
|
|
|
|
print "[x] '%s'" % str(ex)
|