Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for json file output #5478

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
45 changes: 45 additions & 0 deletions lib/controller/controller.py
Original file line number Diff line number Diff line change
@@ -167,6 +167,38 @@ def _formatInjection(inj):

return data

def _formatDictInjection(inj):
paramType = conf.method if conf.method not in (None, HTTPMETHOD.GET, HTTPMETHOD.POST) else inj.place
data = {
"parameter": inj.parameter,
"paramtype": paramType,
"injection": []
}

for stype, sdata in inj.data.items():
title = sdata.title
vector = sdata.vector
comment = sdata.comment
payload = agent.adjustLateValues(sdata.payload)
if inj.place == PLACE.CUSTOM_HEADER:
payload = payload.split(',', 1)[1]
if stype == PAYLOAD.TECHNIQUE.UNION:
count = re.sub(r"(?i)(\(.+\))|(\blimit[^a-z]+)", "", sdata.payload).count(',') + 1
title = re.sub(r"\d+ to \d+", str(count), title)
vector = agent.forgeUnionQuery("[QUERY]", vector[0], vector[1], vector[2], None, None, vector[5], vector[6])
if count == 1:
title = title.replace("columns", "column")
elif comment:
vector = "%s%s" % (vector, comment)
injection = {
"type": PAYLOAD.SQLINJECTION[stype],
"payload": urldecode(payload, unsafe="&", spaceplus=(inj.place != PLACE.GET and kb.postSpaceToPlus)),
"vector": vector
}
data["injection"].append(injection)

return data

def _showInjections():
if conf.wizard and kb.wizardMode:
kb.wizardMode = False
@@ -194,6 +226,18 @@ def _showInjections():
warnMsg += "included in shown payload content(s)"
logger.warning(warnMsg)

def _saveInjections():
data = [_formatDictInjection(inj) for inj in kb.injections]

if conf.jsonFile:
data = {
"url": conf.url,
"query": conf.parameters.get(PLACE.GET),
"data": conf.parameters.get(PLACE.POST),
"injections": data,
}
conf.dumper.json(conf.jsonFile, data)

def _randomFillBlankFields(value):
retVal = value

@@ -649,6 +693,7 @@ def start():
if place == PLACE.COOKIE:
kb.mergeCookies = popValue()

_saveInjections()
if len(kb.injections) == 0 or (len(kb.injections) == 1 and kb.injections[0].place is None):
if kb.vainRun and not conf.multipleTargets:
errMsg = "no parameter(s) found for testing in the provided data "
4 changes: 4 additions & 0 deletions lib/core/common.py
Original file line number Diff line number Diff line change
@@ -1071,6 +1071,10 @@ def dataToDumpFile(dumpFile, data):
errMsg = "error occurred when writing dump data to file ('%s')" % getUnicode(ex)
logger.error(errMsg)

def dataToJsonFile(jsonFile, data):
with open(jsonFile, 'w') as f:
f.write(json.dumps(data))

def dataToOutFile(filename, data):
"""
Saves data to filename
4 changes: 4 additions & 0 deletions lib/core/dump.py
Original file line number Diff line number Diff line change
@@ -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
@@ -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:
1 change: 1 addition & 0 deletions lib/core/optiondict.py
Original file line number Diff line number Diff line change
@@ -219,6 +219,7 @@
"crawlExclude": "string",
"csvDel": "string",
"dumpFile": "string",
"jsonFile": "string",
"dumpFormat": "string",
"encoding": "string",
"eta": "boolean",
2 changes: 1 addition & 1 deletion lib/core/settings.py
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
from thirdparty.six import unichr as _unichr

# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.7.11.2"
VERSION = "1.7.11.3"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
3 changes: 3 additions & 0 deletions lib/parse/cmdline.py
Original file line number Diff line number Diff line change
@@ -673,6 +673,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)")

3 changes: 3 additions & 0 deletions sqlmap.conf
Original file line number Diff line number Diff line change
@@ -753,6 +753,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