diff --git a/lib/request/basic.py b/lib/request/basic.py index fc3685cd1..4882b0def 100644 --- a/lib/request/basic.py +++ b/lib/request/basic.py @@ -5,6 +5,7 @@ Copyright (c) 2006-2017 sqlmap developers (http://sqlmap.org/) See the file 'doc/COPYING' for copying permission """ +import cgi import codecs import gzip import logging @@ -338,8 +339,33 @@ def decodePage(page, contentEncoding, contentType): # e.g. ζ 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 +def _xlsx2html(fio): + sio = StringIO.StringIO() + try: + import openpyxl + wb = openpyxl.load_workbook(fio) + for ws in wb: + sio.write(u'

{0}

'.format(ws.title)) + sio.write(u'') + rows, cols = len(ws.rows), len(ws.columns) + for y in range(1, rows + 1): + sio.write(u'') + 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''.format(value)) + sio.write(u'') + sio.write(u'
{0}
') + except Exception as e: + singleTimeLogMessage(e, logging.ERROR) + raise e + return sio.getvalue() + def processResponse(page, responseHeaders): kb.processResponseCounter += 1