2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2012-12-20 18:59:11 +04:00
|
|
|
|
|
|
|
"""
|
2024-01-04 01:11:52 +03:00
|
|
|
Copyright (c) 2006-2024 sqlmap developers (https://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2012-12-20 18:59:11 +04:00
|
|
|
"""
|
|
|
|
|
2016-02-13 23:28:02 +03:00
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.dont_write_bytecode = True
|
2012-12-20 18:59:11 +04:00
|
|
|
|
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
|
2019-06-06 14:40:32 +03:00
|
|
|
import os
|
2017-09-09 23:27:40 +03:00
|
|
|
import warnings
|
|
|
|
|
2019-12-06 18:11:22 +03:00
|
|
|
warnings.filterwarnings(action="ignore", category=UserWarning)
|
2017-09-09 23:27:40 +03:00
|
|
|
warnings.filterwarnings(action="ignore", category=DeprecationWarning)
|
|
|
|
|
2024-01-15 00:57:30 +03:00
|
|
|
try:
|
|
|
|
from optparse import OptionGroup
|
|
|
|
from optparse import OptionParser as ArgumentParser
|
|
|
|
|
|
|
|
ArgumentParser.add_argument = ArgumentParser.add_option
|
|
|
|
|
|
|
|
def _add_argument(self, *args, **kwargs):
|
|
|
|
return self.add_option(*args, **kwargs)
|
|
|
|
|
|
|
|
OptionGroup.add_argument = _add_argument
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
|
|
finally:
|
|
|
|
def get_actions(instance):
|
|
|
|
for attr in ("option_list", "_group_actions", "_actions"):
|
|
|
|
if hasattr(instance, attr):
|
|
|
|
return getattr(instance, attr)
|
|
|
|
|
|
|
|
def get_groups(parser):
|
|
|
|
return getattr(parser, "option_groups", None) or getattr(parser, "_action_groups")
|
|
|
|
|
|
|
|
def get_all_options(parser):
|
|
|
|
retVal = set()
|
|
|
|
|
|
|
|
for option in get_actions(parser):
|
|
|
|
if hasattr(option, "option_strings"):
|
|
|
|
retVal.update(option.option_strings)
|
|
|
|
else:
|
|
|
|
retVal.update(option._long_opts)
|
|
|
|
retVal.update(option._short_opts)
|
|
|
|
|
|
|
|
for group in get_groups(parser):
|
|
|
|
for option in get_actions(group):
|
|
|
|
if hasattr(option, "option_strings"):
|
|
|
|
retVal.update(option.option_strings)
|
|
|
|
else:
|
|
|
|
retVal.update(option._long_opts)
|
|
|
|
retVal.update(option._short_opts)
|
|
|
|
|
|
|
|
return retVal
|
|
|
|
|
2019-06-06 14:40:32 +03:00
|
|
|
from lib.core.common import getUnicode
|
2012-12-20 18:59:11 +04:00
|
|
|
from lib.core.common import setPaths
|
|
|
|
from lib.core.data import logger
|
2019-05-08 03:40:36 +03:00
|
|
|
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
|
2019-06-06 14:40:32 +03:00
|
|
|
from lib.core.settings import UNICODE_ENCODING
|
2012-12-20 18:59:11 +04:00
|
|
|
from lib.utils.api import client
|
|
|
|
from lib.utils.api import server
|
|
|
|
|
2019-06-06 14:40:32 +03:00
|
|
|
try:
|
|
|
|
from sqlmap import modulePath
|
|
|
|
except ImportError:
|
|
|
|
def modulePath():
|
|
|
|
return getUnicode(os.path.dirname(os.path.realpath(__file__)), encoding=sys.getfilesystemencoding() or UNICODE_ENCODING)
|
|
|
|
|
2016-01-07 23:46:20 +03:00
|
|
|
def main():
|
2012-12-20 18:59:11 +04:00
|
|
|
"""
|
|
|
|
REST-JSON API main function
|
|
|
|
"""
|
2016-01-07 23:46:20 +03:00
|
|
|
|
2019-05-08 03:40:36 +03:00
|
|
|
dirtyPatches()
|
|
|
|
resolveCrossReferences()
|
|
|
|
|
2012-12-20 18:59:11 +04:00
|
|
|
# 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 18:59:11 +04:00
|
|
|
|
2012-12-20 20:53:43 +04:00
|
|
|
# Parse command line options
|
2024-01-15 00:57:30 +03:00
|
|
|
apiparser = ArgumentParser()
|
|
|
|
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)
|
2024-04-12 17:18:02 +03:00
|
|
|
apiparser.add_argument("-p", "--port", help="Port of the REST-JSON API server (default %d)" % RESTAPI_DEFAULT_PORT, default=RESTAPI_DEFAULT_PORT, type=int)
|
2024-01-15 00:57:30 +03:00
|
|
|
apiparser.add_argument("--adapter", help="Server (bottle) adapter to use (default \"%s\")" % RESTAPI_DEFAULT_ADAPTER, default=RESTAPI_DEFAULT_ADAPTER)
|
|
|
|
apiparser.add_argument("--database", help="Set IPC database filepath (optional)")
|
|
|
|
apiparser.add_argument("--username", help="Basic authentication username (optional)")
|
|
|
|
apiparser.add_argument("--password", help="Basic authentication password (optional)")
|
|
|
|
(args, _) = apiparser.parse_known_args() if hasattr(apiparser, "parse_known_args") else apiparser.parse_args()
|
|
|
|
|
2012-12-20 18:59:11 +04:00
|
|
|
|
2012-12-20 20:53:43 +04:00
|
|
|
# Start the client or the server
|
2019-12-09 23:49:11 +03:00
|
|
|
if args.server:
|
2024-01-11 18:11:40 +03:00
|
|
|
server(args.host, args.port, adapter=args.adapter, username=args.username, password=args.password, database=args.database)
|
2019-12-09 23:49:11 +03:00
|
|
|
elif args.client:
|
2017-08-04 14:37:49 +03:00
|
|
|
client(args.host, args.port, username=args.username, password=args.password)
|
2013-07-10 18:57:44 +04:00
|
|
|
else:
|
|
|
|
apiparser.print_help()
|
2016-01-07 23:46:20 +03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|