|
27 | 27 | from extra.bottle.bottle import static_file |
28 | 28 | from extra.bottle.bottle import template |
29 | 29 | from lib.controller.controller import start |
30 | | -from lib.core.common import setPaths |
31 | 30 | from lib.core.convert import hexencode |
32 | 31 | from lib.core.convert import stdoutencode |
33 | 32 | from lib.core.data import paths |
|
41 | 40 | from lib.core.exception import SqlmapMissingDependence |
42 | 41 | from lib.core.option import init |
43 | 42 | from lib.core.settings import UNICODE_ENCODING |
44 | | -from _sqlmap import modulePath |
| 43 | +from lib.parse.cmdline import cmdLineParser |
45 | 44 |
|
46 | 45 | RESTAPI_SERVER_HOST = "127.0.0.1" |
47 | 46 | RESTAPI_SERVER_PORT = 8775 |
@@ -107,6 +106,8 @@ def task_new(): |
107 | 106 | """ |
108 | 107 | global tasks |
109 | 108 |
|
| 109 | + optset() |
| 110 | + |
110 | 111 | taskid = hexencode(os.urandom(16)) |
111 | 112 | tasks[taskid] = AttribDict(cmdLineOptions) |
112 | 113 |
|
@@ -327,13 +328,21 @@ def download(taskid, target, filename): |
327 | 328 | else: |
328 | 329 | abort(500) |
329 | 330 |
|
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): |
331 | 336 | """ |
332 | 337 | REST-JSON API server |
333 | 338 | """ |
334 | 339 | global adminid |
335 | 340 | global tasks |
336 | 341 |
|
| 342 | + # Enforce batch mode and disable coloring |
| 343 | + cmdLineOptions.batch = True |
| 344 | + cmdLineOptions.disableColoring = True |
| 345 | + |
337 | 346 | adminid = hexencode(os.urandom(16)) |
338 | 347 | tasks[adminid] = AttribDict(cmdLineOptions) |
339 | 348 |
|
@@ -367,29 +376,3 @@ def client(host=RESTAPI_SERVER_HOST, port=RESTAPI_SERVER_PORT): |
367 | 376 | 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) |
368 | 377 | print "\t$ curl http://%s:%d/scan/:taskid/output" % (host, port) |
369 | 378 | 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) |
0 commit comments