From b0635bddcc3aaba5312ff68c44c362fb43325ff2 Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Thu, 20 Dec 2012 15:29:23 +0000 Subject: [PATCH] adjustments --- lib/utils/api.py | 41 ++++++++++++----------------------------- sqlmapapi.py | 14 +++++++------- 2 files changed, 19 insertions(+), 36 deletions(-) mode change 100755 => 100644 lib/utils/api.py diff --git a/lib/utils/api.py b/lib/utils/api.py old mode 100755 new mode 100644 index ee34d74b7..9473f53d5 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -27,7 +27,6 @@ from extra.bottle.bottle import run from extra.bottle.bottle import static_file from extra.bottle.bottle import template from lib.controller.controller import start -from lib.core.common import setPaths from lib.core.convert import hexencode from lib.core.convert import stdoutencode from lib.core.data import paths @@ -41,7 +40,7 @@ from lib.core.log import LOGGER_OUTPUT from lib.core.exception import SqlmapMissingDependence from lib.core.option import init from lib.core.settings import UNICODE_ENCODING -from _sqlmap import modulePath +from lib.parse.cmdline import cmdLineParser RESTAPI_SERVER_HOST = "127.0.0.1" RESTAPI_SERVER_PORT = 8775 @@ -107,6 +106,8 @@ def task_new(): """ global tasks + optset() + taskid = hexencode(os.urandom(16)) tasks[taskid] = AttribDict(cmdLineOptions) @@ -327,13 +328,21 @@ def download(taskid, target, filename): else: abort(500) -def restAPIRun(host="0.0.0.0", port=RESTAPI_SERVER_PORT): +def optset(): + # Store original command line options for possible later restoration + cmdLineOptions.update(cmdLineParser().__dict__) + +def server(host="0.0.0.0", port=RESTAPI_SERVER_PORT): """ REST-JSON API server """ global adminid global tasks + # Enforce batch mode and disable coloring + cmdLineOptions.batch = True + cmdLineOptions.disableColoring = True + adminid = hexencode(os.urandom(16)) tasks[adminid] = AttribDict(cmdLineOptions) @@ -367,29 +376,3 @@ def client(host=RESTAPI_SERVER_HOST, port=RESTAPI_SERVER_PORT): print "\t$ curl -H \"Content-Type: application/json\" -X POST -d '{\"url\": \"http://testphp.vulnweb.com/artists.php?artist=1\"}' http://%s:%d/scan/:taskid/start" % (host, port) print "\t$ curl http://%s:%d/scan/:taskid/output" % (host, port) print "\t$ curl http://%s:%d/scan/:taskid/log\n" % (host, port) - -if __name__ == "__main__": - """ - REST-JSON API main function - """ - # Set default logging level to debug - logger.setLevel(logging.DEBUG) - - paths.SQLMAP_ROOT_PATH = modulePath() - setPaths() - - # Enforce batch mode and disable coloring - cmdLineOptions.batch = True - cmdLineOptions.disableColoring = True - - parser = optparse.OptionParser() - parser.add_option("-s", "--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true") - parser.add_option("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_SERVER_PORT, action="store_true") - parser.add_option("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_SERVER_HOST, action="store") - parser.add_option("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_SERVER_PORT, type="int", action="store") - (args, _) = parser.parse_args() - - if args.server is True: - restAPIRun(args.host, args.port) - elif args.client is True: - client(args.host, args.port) diff --git a/sqlmapapi.py b/sqlmapapi.py index a7bbb8ba7..07fe561ad 100755 --- a/sqlmapapi.py +++ b/sqlmapapi.py @@ -5,8 +5,8 @@ Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) See the file 'doc/COPYING' for copying permission """ -import argparse import logging +import optparse from _sqlmap import modulePath from lib.core.common import setPaths @@ -28,12 +28,12 @@ if __name__ == "__main__": paths.SQLMAP_ROOT_PATH = modulePath() setPaths() - parser = argparse.ArgumentParser() - parser.add_argument("-s", "--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true") - parser.add_argument("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_SERVER_PORT, action="store_true") - parser.add_argument("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_SERVER_HOST, action="store") - parser.add_argument("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store") - args = parser.parse_args() + apiparser = optparse.OptionParser() + apiparser.add_option("--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true") + apiparser.add_option("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_SERVER_PORT, action="store_true") + apiparser.add_option("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_SERVER_HOST, action="store") + apiparser.add_option("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_SERVER_PORT, type="int", action="store") + (args, _) = apiparser.parse_args() if args.server is True: server(args.host, args.port)