Add support for json file output

This commit is contained in:
bkbilly 2023-07-25 13:09:04 +03:00
parent 0d19af8bbc
commit 3ca23364a3
6 changed files with 27 additions and 0 deletions

View File

@ -177,6 +177,15 @@ def _showInjections():
else: else:
header = "sqlmap resumed the following injection point(s) from stored session" header = "sqlmap resumed the following injection point(s) from stored session"
if conf.jsonFile:
data = {
"url": conf.url,
"query": conf.parameters.get(PLACE.GET),
"data": conf.parameters.get(PLACE.POST),
"injections": kb.injections,
}
conf.dumper.json(conf.jsonFile, data)
if conf.api: if conf.api:
conf.dumper.string("", {"url": conf.url, "query": conf.parameters.get(PLACE.GET), "data": conf.parameters.get(PLACE.POST)}, content_type=CONTENT_TYPE.TARGET) conf.dumper.string("", {"url": conf.url, "query": conf.parameters.get(PLACE.GET), "data": conf.parameters.get(PLACE.POST)}, content_type=CONTENT_TYPE.TARGET)
conf.dumper.string("", kb.injections, content_type=CONTENT_TYPE.TECHNIQUES) conf.dumper.string("", kb.injections, content_type=CONTENT_TYPE.TECHNIQUES)

View File

@ -1071,6 +1071,13 @@ def dataToDumpFile(dumpFile, data):
errMsg = "error occurred when writing dump data to file ('%s')" % getUnicode(ex) errMsg = "error occurred when writing dump data to file ('%s')" % getUnicode(ex)
logger.error(errMsg) logger.error(errMsg)
def dataToJsonFile(jsonFile, data):
print("***************")
print(jsonFile, data)
print("***************")
with open(jsonFile, 'w') as f:
f.write(json.dumps(data))
def dataToOutFile(filename, data): def dataToOutFile(filename, data):
""" """
Saves data to filename Saves data to filename

View File

@ -15,6 +15,7 @@ import threading
from lib.core.common import Backend from lib.core.common import Backend
from lib.core.common import checkFile from lib.core.common import checkFile
from lib.core.common import dataToDumpFile from lib.core.common import dataToDumpFile
from lib.core.common import dataToJsonFile
from lib.core.common import dataToStdout from lib.core.common import dataToStdout
from lib.core.common import filterNone from lib.core.common import filterNone
from lib.core.common import getSafeExString from lib.core.common import getSafeExString
@ -143,6 +144,9 @@ class Dump(object):
else: else:
self._write("%s: %s" % (header, ("'%s'" % _) if isinstance(data, six.string_types) else _)) self._write("%s: %s" % (header, ("'%s'" % _) if isinstance(data, six.string_types) else _))
def json(self, jsonFile, data):
dataToJsonFile(jsonFile, data)
def lister(self, header, elements, content_type=None, sort=True): def lister(self, header, elements, content_type=None, sort=True):
if elements and sort: if elements and sort:
try: try:

View File

@ -218,6 +218,7 @@ optDict = {
"crawlExclude": "string", "crawlExclude": "string",
"csvDel": "string", "csvDel": "string",
"dumpFile": "string", "dumpFile": "string",
"jsonFile": "string",
"dumpFormat": "string", "dumpFormat": "string",
"encoding": "string", "encoding": "string",
"eta": "boolean", "eta": "boolean",

View File

@ -670,6 +670,9 @@ def cmdLineParser(argv=None):
general.add_argument("--dump-file", dest="dumpFile", general.add_argument("--dump-file", dest="dumpFile",
help="Store dumped data to a custom file") help="Store dumped data to a custom file")
general.add_argument("--json-file", dest="jsonFile",
help="Store json data to a custom file")
general.add_argument("--dump-format", dest="dumpFormat", general.add_argument("--dump-format", dest="dumpFormat",
help="Format of dumped data (CSV (default), HTML or SQLITE)") help="Format of dumped data (CSV (default), HTML or SQLITE)")

View File

@ -748,6 +748,9 @@ csvDel = ,
# Store dumped data to a custom file. # Store dumped data to a custom file.
dumpFile = dumpFile =
# Store json data to a custom file.
jsonFile =
# Format of dumped data # Format of dumped data
# Valid: CSV, HTML or SQLITE # Valid: CSV, HTML or SQLITE
dumpFormat = CSV dumpFormat = CSV