Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for json file output
  • Loading branch information
bkbilly committed Nov 16, 2023
commit 3ca23364a3f6ab6daa9c78cdd83b5820d051b1fd
9 changes: 9 additions & 0 deletions lib/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ def _showInjections():
else:
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:
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)
Expand Down
7 changes: 7 additions & 0 deletions lib/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,13 @@ def dataToDumpFile(dumpFile, data):
errMsg = "error occurred when writing dump data to file ('%s')" % getUnicode(ex)
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):
"""
Saves data to filename
Expand Down
4 changes: 4 additions & 0 deletions lib/core/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from lib.core.common import Backend
from lib.core.common import checkFile
from lib.core.common import dataToDumpFile
from lib.core.common import dataToJsonFile
from lib.core.common import dataToStdout
from lib.core.common import filterNone
from lib.core.common import getSafeExString
Expand Down Expand Up @@ -143,6 +144,9 @@ def string(self, header, data, content_type=None, sort=True):
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):
if elements and sort:
try:
Expand Down
1 change: 1 addition & 0 deletions lib/core/optiondict.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
"crawlExclude": "string",
"csvDel": "string",
"dumpFile": "string",
"jsonFile": "string",
"dumpFormat": "string",
"encoding": "string",
"eta": "boolean",
Expand Down
3 changes: 3 additions & 0 deletions lib/parse/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ def cmdLineParser(argv=None):
general.add_argument("--dump-file", dest="dumpFile",
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",
help="Format of dumped data (CSV (default), HTML or SQLITE)")

Expand Down
3 changes: 3 additions & 0 deletions sqlmap.conf
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,9 @@ csvDel = ,
# Store dumped data to a custom file.
dumpFile =

# Store json data to a custom file.
jsonFile =

# Format of dumped data
# Valid: CSV, HTML or SQLITE
dumpFormat = CSV
Expand Down