#!/usr/bin/env python3 """ Copyright (c) 2006-2023 sqlmap developers (https://sqlmap.org/) See the file 'LICENSE' for copying permission """ import sys sys.dont_write_bytecode = True from lib.core.common import getUnicode from lib.core.common import setPaths from lib.core.data import logger from lib.core.patch import dirtyPatches from lib.core.patch import resolveCrossReferences from lib.core.settings import RESTAPI_DEFAULT_ADAPTER from lib.core.settings import RESTAPI_DEFAULT_ADDRESS from lib.core.settings import RESTAPI_DEFAULT_PORT from lib.core.settings import UNICODE_ENCODING from lib.utils.api import client from lib.utils.api import server import logging import argparse import os import warnings warnings.filterwarnings("ignore", category=UserWarning) warnings.filterwarnings("ignore", category=DeprecationWarning) try: from sqlmap import modulePath except ImportError: def modulePath(): return getUnicode(os.path.dirname(os.path.realpath(__file__)) def main(): """ REST-JSON API main function """ dirtyPatches() resolveCrossReferences() # Set default logging level to debug logger.setLevel(logging.DEBUG) # Initialize paths setPaths(modulePath()) # Parse command line options apiparser = argparse.ArgumentParser(description="REST-JSON API server and client") apiparser.add_argument("-s", "--server", help="Run as a REST-JSON API server", action="store_true") apiparser.add_argument("-c", "--client", help="Run as a REST-JSON API client", action="store_true") apiparser.add_argument("-H", "--host", help="Host of the REST-JSON API server (default \"%s\")" % RESTAPI_DEFAULT_ADDRESS, default=RESTAPI_DEFAULT_ADDRESS) apiparser.add_argument("-p", "--port", help="Port of the REST-JSON API server (default %d)" % RESTAPI_DEFAULT_PORT, default=RESTAPI_DEFAULT_PORT, type=int) apiparser.add_argument("--adapter", help="Server (bottle) adapter to use (default \"%s\")" % RESTAPI_DEFAULT_ADAPTER, default=RESTAPI_DEFAULT_ADAPTER) apiparser.add_argument("--username", help="Basic authentication username (optional)") apiparser.add_argument("--password", help="Basic authentication password (optional)") args = apiparser.parse_args() # Start the client or the server if args.server: server(args.host, args.port, adapter=args.adapter, username=args.username, password=args.password) elif args.client: client(args.host, args.port, username=args.username, password=args.password) else: apiparser.print_help() if __name__ == "__main__": main()