MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / client

Function client

lib/utils/api.py:761–918  ·  view source on GitHub ↗

REST-JSON API client

(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=None, password=None)

Source from the content-addressed store, hash-verified

759 return text
760
761def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=None, password=None):
762 """
763 REST-JSON API client
764 """
765
766 DataStore.username = username
767 DataStore.password = password
768
769 dbgMsg = "Example client access from command line:"
770 dbgMsg += "\n\t$ taskid=$(curl http://%s:%d/task/new 2>1 | grep -o -I '[a-f0-9]\\{16\\}') && echo $taskid" % (host, port)
771 dbgMsg += "\n\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)
772 dbgMsg += "\n\t$ curl http://%s:%d/scan/$taskid/data" % (host, port)
773 dbgMsg += "\n\t$ curl http://%s:%d/scan/$taskid/log" % (host, port)
774 logger.debug(dbgMsg)
775
776 addr = "http://%s:%d" % (host, port)
777 logger.info("Starting REST-JSON API client to '%s'..." % addr)
778
779 try:
780 _client(addr)
781 except Exception as ex:
782 if not isinstance(ex, _urllib.error.HTTPError) or ex.code == _http_client.UNAUTHORIZED:
783 errMsg = "There has been a problem while connecting to the "
784 errMsg += "REST-JSON API server at '%s' " % addr
785 errMsg += "(%s)" % getSafeExString(ex)
786 logger.critical(errMsg)
787 return
788
789 commands = ("help", "new", "use", "data", "log", "status", "option", "stop", "kill", "list", "flush", "version", "exit", "bye", "quit")
790 colors = ('red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'lightgrey', 'lightred', 'lightgreen', 'lightyellow', 'lightblue', 'lightmagenta', 'lightcyan')
791 autoCompletion(AUTOCOMPLETE_TYPE.API, commands=commands)
792
793 taskid = None
794 logger.info("Type 'help' or '?' for list of available commands")
795
796 while True:
797 try:
798 color = colors[int(taskid or "0", 16) % len(colors)]
799 command = _input("api%s> " % (" (%s)" % setColor(taskid, color) if taskid else "")).strip()
800 command = re.sub(r"\A(\w+)", lambda match: match.group(1).lower(), command)
801 except (EOFError, KeyboardInterrupt):
802 print()
803 break
804
805 if command in ("data", "log", "status", "stop", "kill"):
806 if not taskid:
807 logger.error("No task ID in use")
808 continue
809 raw = _client("%s/scan/%s/%s" % (addr, taskid, command))
810 res = dejsonize(raw)
811 if not res["success"]:
812 logger.error("Failed to execute command %s" % command)
813 dataToStdout("%s\n" % raw)
814
815 elif command.startswith("option"):
816 if not taskid:
817 logger.error("No task ID in use")
818 continue

Callers 1

mainFunction · 0.90

Calls 12

getSafeExStringFunction · 0.90
autoCompletionFunction · 0.90
setColorFunction · 0.90
dejsonizeFunction · 0.90
dataToStdoutFunction · 0.90
cmdLineParserFunction · 0.90
_clientFunction · 0.85
debugMethod · 0.80
infoMethod · 0.80
errorMethod · 0.45
getMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…