| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,6 @@ | |||
| 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,7 +40,7 @@ | |||
| 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) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,8 @@ | |||
| 5 | 5 | See the file 'doc/COPYING' for copying permission | |
| 6 | 6 | """ | |
| 7 | 7 | ||
| 8 | - import argparse | ||
| 9 | 8 | import logging | |
| 9 | + import optparse | ||
| 10 | 10 | ||
| 11 | 11 | from _sqlmap import modulePath | |
| 12 | 12 | from lib.core.common import setPaths | |
@@ -28,12 +28,12 @@ | |||
| 28 | 28 | paths.SQLMAP_ROOT_PATH = modulePath() | |
| 29 | 29 | setPaths() | |
| 30 | 30 | ||
| 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() | ||
| 37 | 37 | ||
| 38 | 38 | if args.server is True: | |
| 39 | 39 | server(args.host, args.port) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments