Skip to content

Commit b0635bd

Browse files
committed
adjustments
1 parent 12eadcf commit b0635bd

File tree

2 files changed

+19
-36
lines changed

2 files changed

+19
-36
lines changed

lib/utils/api.py

100755100644
+12-29
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from extra.bottle.bottle import static_file
2828
from extra.bottle.bottle import template
2929
from lib.controller.controller import start
30-
from lib.core.common import setPaths
3130
from lib.core.convert import hexencode
3231
from lib.core.convert import stdoutencode
3332
from lib.core.data import paths
@@ -41,7 +40,7 @@
4140
from lib.core.exception import SqlmapMissingDependence
4241
from lib.core.option import init
4342
from lib.core.settings import UNICODE_ENCODING
44-
from _sqlmap import modulePath
43+
from lib.parse.cmdline import cmdLineParser
4544

4645
RESTAPI_SERVER_HOST = "127.0.0.1"
4746
RESTAPI_SERVER_PORT = 8775
@@ -107,6 +106,8 @@ def task_new():
107106
"""
108107
global tasks
109108

109+
optset()
110+
110111
taskid = hexencode(os.urandom(16))
111112
tasks[taskid] = AttribDict(cmdLineOptions)
112113

@@ -327,13 +328,21 @@ def download(taskid, target, filename):
327328
else:
328329
abort(500)
329330

330-
def restAPIRun(host="0.0.0.0", port=RESTAPI_SERVER_PORT):
331+
def optset():
332+
# Store original command line options for possible later restoration
333+
cmdLineOptions.update(cmdLineParser().__dict__)
334+
335+
def server(host="0.0.0.0", port=RESTAPI_SERVER_PORT):
331336
"""
332337
REST-JSON API server
333338
"""
334339
global adminid
335340
global tasks
336341

342+
# Enforce batch mode and disable coloring
343+
cmdLineOptions.batch = True
344+
cmdLineOptions.disableColoring = True
345+
337346
adminid = hexencode(os.urandom(16))
338347
tasks[adminid] = AttribDict(cmdLineOptions)
339348

@@ -367,29 +376,3 @@ def client(host=RESTAPI_SERVER_HOST, port=RESTAPI_SERVER_PORT):
367376
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)
368377
print "\t$ curl http://%s:%d/scan/:taskid/output" % (host, port)
369378
print "\t$ curl http://%s:%d/scan/:taskid/log\n" % (host, port)
370-
371-
if __name__ == "__main__":
372-
"""
373-
REST-JSON API main function
374-
"""
375-
# Set default logging level to debug
376-
logger.setLevel(logging.DEBUG)
377-
378-
paths.SQLMAP_ROOT_PATH = modulePath()
379-
setPaths()
380-
381-
# Enforce batch mode and disable coloring
382-
cmdLineOptions.batch = True
383-
cmdLineOptions.disableColoring = True
384-
385-
parser = optparse.OptionParser()
386-
parser.add_option("-s", "--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true")
387-
parser.add_option("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_SERVER_PORT, action="store_true")
388-
parser.add_option("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_SERVER_HOST, action="store")
389-
parser.add_option("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_SERVER_PORT, type="int", action="store")
390-
(args, _) = parser.parse_args()
391-
392-
if args.server is True:
393-
restAPIRun(args.host, args.port)
394-
elif args.client is True:
395-
client(args.host, args.port)

sqlmapapi.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
See the file 'doc/COPYING' for copying permission
66
"""
77

8-
import argparse
98
import logging
9+
import optparse
1010

1111
from _sqlmap import modulePath
1212
from lib.core.common import setPaths
@@ -28,12 +28,12 @@
2828
paths.SQLMAP_ROOT_PATH = modulePath()
2929
setPaths()
3030

31-
parser = argparse.ArgumentParser()
32-
parser.add_argument("-s", "--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true")
33-
parser.add_argument("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_SERVER_PORT, action="store_true")
34-
parser.add_argument("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_SERVER_HOST, action="store")
35-
parser.add_argument("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store")
36-
args = parser.parse_args()
31+
apiparser = optparse.OptionParser()
32+
apiparser.add_option("--server", help="Act as a REST-JSON API server", default=RESTAPI_SERVER_PORT, action="store_true")
33+
apiparser.add_option("-c", "--client", help="Act as a REST-JSON API client", default=RESTAPI_SERVER_PORT, action="store_true")
34+
apiparser.add_option("-H", "--host", help="Host of the REST-JSON API server", default=RESTAPI_SERVER_HOST, action="store")
35+
apiparser.add_option("-p", "--port", help="Port of the the REST-JSON API server", default=RESTAPI_SERVER_PORT, type="int", action="store")
36+
(args, _) = apiparser.parse_args()
3737

3838
if args.server is True:
3939
server(args.host, args.port)

0 commit comments

Comments
 (0)