Skip to content

Commit 3ca2336

Browse files
committed
Add support for json file output
1 parent 0d19af8 commit 3ca2336

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

lib/controller/controller.py

+9
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ def _showInjections():
177177
else:
178178
header = "sqlmap resumed the following injection point(s) from stored session"
179179

180+
if conf.jsonFile:
181+
data = {
182+
"url": conf.url,
183+
"query": conf.parameters.get(PLACE.GET),
184+
"data": conf.parameters.get(PLACE.POST),
185+
"injections": kb.injections,
186+
}
187+
conf.dumper.json(conf.jsonFile, data)
188+
180189
if conf.api:
181190
conf.dumper.string("", {"url": conf.url, "query": conf.parameters.get(PLACE.GET), "data": conf.parameters.get(PLACE.POST)}, content_type=CONTENT_TYPE.TARGET)
182191
conf.dumper.string("", kb.injections, content_type=CONTENT_TYPE.TECHNIQUES)

lib/core/common.py

+7
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,13 @@ def dataToDumpFile(dumpFile, data):
10711071
errMsg = "error occurred when writing dump data to file ('%s')" % getUnicode(ex)
10721072
logger.error(errMsg)
10731073

1074+
def dataToJsonFile(jsonFile, data):
1075+
print("***************")
1076+
print(jsonFile, data)
1077+
print("***************")
1078+
with open(jsonFile, 'w') as f:
1079+
f.write(json.dumps(data))
1080+
10741081
def dataToOutFile(filename, data):
10751082
"""
10761083
Saves data to filename

lib/core/dump.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from lib.core.common import Backend
1616
from lib.core.common import checkFile
1717
from lib.core.common import dataToDumpFile
18+
from lib.core.common import dataToJsonFile
1819
from lib.core.common import dataToStdout
1920
from lib.core.common import filterNone
2021
from lib.core.common import getSafeExString
@@ -143,6 +144,9 @@ def string(self, header, data, content_type=None, sort=True):
143144
else:
144145
self._write("%s: %s" % (header, ("'%s'" % _) if isinstance(data, six.string_types) else _))
145146

147+
def json(self, jsonFile, data):
148+
dataToJsonFile(jsonFile, data)
149+
146150
def lister(self, header, elements, content_type=None, sort=True):
147151
if elements and sort:
148152
try:

lib/core/optiondict.py

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@
218218
"crawlExclude": "string",
219219
"csvDel": "string",
220220
"dumpFile": "string",
221+
"jsonFile": "string",
221222
"dumpFormat": "string",
222223
"encoding": "string",
223224
"eta": "boolean",

lib/parse/cmdline.py

+3
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ def cmdLineParser(argv=None):
670670
general.add_argument("--dump-file", dest="dumpFile",
671671
help="Store dumped data to a custom file")
672672

673+
general.add_argument("--json-file", dest="jsonFile",
674+
help="Store json data to a custom file")
675+
673676
general.add_argument("--dump-format", dest="dumpFormat",
674677
help="Format of dumped data (CSV (default), HTML or SQLITE)")
675678

sqlmap.conf

+3
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,9 @@ csvDel = ,
748748
# Store dumped data to a custom file.
749749
dumpFile =
750750

751+
# Store json data to a custom file.
752+
jsonFile =
753+
751754
# Format of dumped data
752755
# Valid: CSV, HTML or SQLITE
753756
dumpFormat = CSV

0 commit comments

Comments
 (0)