mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-07-30 01:50:01 +03:00
Add Excel (xlsx) output parsing support.
This commit is contained in:
parent
d7cdb6cbd8
commit
01a431c2e4
|
@ -5,6 +5,7 @@ Copyright (c) 2006-2016 sqlmap developers (http://sqlmap.org/)
|
||||||
See the file 'doc/COPYING' for copying permission
|
See the file 'doc/COPYING' for copying permission
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import cgi
|
||||||
import codecs
|
import codecs
|
||||||
import gzip
|
import gzip
|
||||||
import logging
|
import logging
|
||||||
|
@ -321,8 +322,33 @@ def decodePage(page, contentEncoding, contentType):
|
||||||
# e.g. ζ
|
# e.g. ζ
|
||||||
page = re.sub(r"&([^;]+);", lambda _: unichr(htmlEntities[_.group(1)]) if htmlEntities.get(_.group(1), 0) > 255 else _.group(0), page)
|
page = re.sub(r"&([^;]+);", lambda _: unichr(htmlEntities[_.group(1)]) if htmlEntities.get(_.group(1), 0) > 255 else _.group(0), page)
|
||||||
|
|
||||||
|
if contentType and contentType.lower() == 'application/vnd.ms-excel':
|
||||||
|
page = _xlsx2html(StringIO.StringIO(page))
|
||||||
|
|
||||||
return page
|
return page
|
||||||
|
|
||||||
|
def _xlsx2html(fio):
|
||||||
|
sio = StringIO.StringIO()
|
||||||
|
try:
|
||||||
|
import openpyxl
|
||||||
|
wb = openpyxl.load_workbook(fio)
|
||||||
|
for ws in wb:
|
||||||
|
sio.write(u'<h1>{0}</h1>'.format(ws.title))
|
||||||
|
sio.write(u'<table border="1">')
|
||||||
|
rows, cols = len(ws.rows), len(ws.columns)
|
||||||
|
for y in range(1, rows + 1):
|
||||||
|
sio.write(u'<tr>')
|
||||||
|
for x in range(1, cols + 1):
|
||||||
|
value = unicode(ws.cell(row=y, column=x).value or '')
|
||||||
|
value = cgi.escape(value).encode('ascii', 'xmlcharrefreplace')
|
||||||
|
sio.write(u'<td>{0}</td>'.format(value))
|
||||||
|
sio.write(u'</tr>')
|
||||||
|
sio.write(u'</table>')
|
||||||
|
except Exception as e:
|
||||||
|
singleTimeLogMessage(e, logging.ERROR)
|
||||||
|
raise e
|
||||||
|
return sio.getvalue()
|
||||||
|
|
||||||
def processResponse(page, responseHeaders):
|
def processResponse(page, responseHeaders):
|
||||||
kb.processResponseCounter += 1
|
kb.processResponseCounter += 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user