sqlmap/sqlmapapi.py

67 lines
2.6 KiB
Python
Raw Normal View History

2019-05-08 13:47:52 +03:00
#!/usr/bin/env python
"""
2019-01-05 23:38:52 +03:00
Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
2017-10-11 15:50:46 +03:00
See the file 'LICENSE' for copying permission
"""
2016-02-13 23:28:02 +03:00
import sys
sys.dont_write_bytecode = True
2016-12-20 11:53:44 +03:00
__import__("lib.utils.versioncheck") # this has to be the first non-standard import
2015-11-08 02:10:28 +03:00
2017-09-09 23:27:40 +03:00
import logging
import optparse
import warnings
warnings.filterwarnings(action="ignore", message=".*was already imported", category=UserWarning)
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
2013-02-06 13:30:54 +04:00
from sqlmap import modulePath
from lib.core.common import setPaths
from lib.core.data import logger
from lib.core.patch import dirtyPatches
from lib.core.patch import resolveCrossReferences
2016-01-27 12:03:30 +03:00
from lib.core.settings import RESTAPI_DEFAULT_ADAPTER
2015-12-13 01:48:30 +03:00
from lib.core.settings import RESTAPI_DEFAULT_ADDRESS
from lib.core.settings import RESTAPI_DEFAULT_PORT
from lib.utils.api import client
from lib.utils.api import server
2016-01-07 23:46:20 +03:00
def main():
"""
REST-JSON API main function
"""
2016-01-07 23:46:20 +03:00
dirtyPatches()
resolveCrossReferences()
# Set default logging level to debug
logger.setLevel(logging.DEBUG)
2016-08-02 01:17:59 +03:00
# Initialize paths
setPaths(modulePath())
2012-12-20 20:53:43 +04:00
# Parse command line options
2012-12-20 19:29:23 +04:00
apiparser = optparse.OptionParser()
2018-09-05 01:15:15 +03:00
apiparser.add_option("-s", "--server", help="Run as a REST-JSON API server", default=RESTAPI_DEFAULT_PORT, action="store_true")
apiparser.add_option("-c", "--client", help="Run as a REST-JSON API client", default=RESTAPI_DEFAULT_PORT, action="store_true")
2016-11-25 14:34:13 +03:00
apiparser.add_option("-H", "--host", help="Host of the REST-JSON API server (default \"%s\")" % RESTAPI_DEFAULT_ADDRESS, default=RESTAPI_DEFAULT_ADDRESS, action="store")
apiparser.add_option("-p", "--port", help="Port of the the REST-JSON API server (default %d)" % RESTAPI_DEFAULT_PORT, default=RESTAPI_DEFAULT_PORT, type="int", action="store")
apiparser.add_option("--adapter", help="Server (bottle) adapter to use (default \"%s\")" % RESTAPI_DEFAULT_ADAPTER, default=RESTAPI_DEFAULT_ADAPTER, action="store")
apiparser.add_option("--username", help="Basic authentication username (optional)", action="store")
apiparser.add_option("--password", help="Basic authentication password (optional)", action="store")
2012-12-20 19:29:23 +04:00
(args, _) = apiparser.parse_args()
2012-12-20 20:53:43 +04:00
# Start the client or the server
if args.server is True:
server(args.host, args.port, adapter=args.adapter, username=args.username, password=args.password)
elif args.client is True:
client(args.host, args.port, username=args.username, password=args.password)
else:
apiparser.print_help()
2016-01-07 23:46:20 +03:00
if __name__ == "__main__":
main()