2019-05-08 12:47:52 +02:00
#!/usr/bin/env python
2012-12-20 14:59:11 +00:00
"""
2024-01-03 23:11:52 +01:00
Copyright (c) 2006-2024 sqlmap developers (https://sqlmap.org/)
2017-10-11 14:50:46 +02:00
See the file ' LICENSE ' for copying permission
2012-12-20 14:59:11 +00:00
"""
2016-02-13 21:28:02 +01:00
import sys
sys . dont_write_bytecode = True
2012-12-20 14:59:11 +00:00
2016-12-20 09:53:44 +01:00
__import__ ( " lib.utils.versioncheck " ) # this has to be the first non-standard import
2015-11-08 00:10:28 +01:00
2017-09-09 22:27:40 +02:00
import logging
import optparse
2019-06-06 13:40:32 +02:00
import os
2017-09-09 22:27:40 +02:00
import warnings
2019-12-06 16:11:22 +01:00
warnings . filterwarnings ( action = " ignore " , category = UserWarning )
2017-09-09 22:27:40 +02:00
warnings . filterwarnings ( action = " ignore " , category = DeprecationWarning )
2019-06-06 13:40:32 +02:00
from lib . core . common import getUnicode
2012-12-20 14:59:11 +00:00
from lib . core . common import setPaths
from lib . core . data import logger
2019-05-08 02:40:36 +02:00
from lib . core . patch import dirtyPatches
from lib . core . patch import resolveCrossReferences
2016-01-27 10:03:30 +01:00
from lib . core . settings import RESTAPI_DEFAULT_ADAPTER
2015-12-12 23:48:30 +01:00
from lib . core . settings import RESTAPI_DEFAULT_ADDRESS
from lib . core . settings import RESTAPI_DEFAULT_PORT
2019-06-06 13:40:32 +02:00
from lib . core . settings import UNICODE_ENCODING
2012-12-20 14:59:11 +00:00
from lib . utils . api import client
from lib . utils . api import server
2019-06-06 13:40:32 +02: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 21:46:20 +01:00
def main ( ) :
2012-12-20 14:59:11 +00:00
"""
REST-JSON API main function
"""
2016-01-07 21:46:20 +01:00
2019-05-08 02:40:36 +02:00
dirtyPatches ( )
resolveCrossReferences ( )
2012-12-20 14:59:11 +00:00
# Set default logging level to debug
logger . setLevel ( logging . DEBUG )
2016-08-02 00:17:59 +02:00
# Initialize paths
setPaths ( modulePath ( ) )
2012-12-20 14:59:11 +00:00
2012-12-20 16:53:43 +00:00
# Parse command line options
2012-12-20 15:29:23 +00:00
apiparser = optparse . OptionParser ( )
2019-12-18 11:30:13 +01:00
apiparser . add_option ( " -s " , " --server " , help = " Run as a REST-JSON API server " , action = " store_true " )
apiparser . add_option ( " -c " , " --client " , help = " Run as a REST-JSON API client " , action = " store_true " )
2016-11-25 12:34:13 +01: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 " )
2017-08-04 13:37:49 +02:00
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 15:29:23 +00:00
( args , _ ) = apiparser . parse_args ( )
2012-12-20 14:59:11 +00:00
2012-12-20 16:53:43 +00:00
# Start the client or the server
2019-12-09 17:49:11 -03:00
if args . server :
2017-08-04 13:37:49 +02:00
server ( args . host , args . port , adapter = args . adapter , username = args . username , password = args . password )
2019-12-09 17:49:11 -03:00
elif args . client :
2017-08-04 13:37:49 +02:00
client ( args . host , args . port , username = args . username , password = args . password )
2013-07-10 16:57:44 +02:00
else :
apiparser . print_help ( )
2016-01-07 21:46:20 +01:00
if __name__ == " __main__ " :
main ( )