diff --git a/lib/core/common.py b/lib/core/common.py index 1affd5411..c175fa2fb 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -34,8 +34,10 @@ import ntpath import posixpath import subprocess +from StringIO import StringIO from tempfile import NamedTemporaryFile from tempfile import mkstemp +from xml.sax import parse from extra.cloak.cloak import decloak from lib.contrib import magic @@ -1084,4 +1086,12 @@ def getConsoleWidth(default=80): except: pass - return width if width else default \ No newline at end of file + return width if width else default + +def parseXmlFile(xmlFile, handler): + file = open(paths.GENERIC_XML) + content = file.read() + stream = StringIO(content) + parse(stream, handler) + stream.close() + file.close() diff --git a/lib/parse/banner.py b/lib/parse/banner.py index 127fa6d44..1c8c20eb6 100644 --- a/lib/parse/banner.py +++ b/lib/parse/banner.py @@ -24,11 +24,10 @@ Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import re -from StringIO import StringIO -from xml.sax import parse from xml.sax.handler import ContentHandler from lib.core.common import checkFile +from lib.core.common import parseXmlFile from lib.core.common import sanitizeStr from lib.core.data import kb from lib.core.data import paths @@ -122,11 +121,11 @@ def bannerParser(banner): if kb.dbms == "Microsoft SQL Server": handler = MSSQLBannerHandler(banner, kb.bannerFp) - parse(StringIO(open(xmlfile).read()), handler) + parseXmlFile(xmlfile, handler) handler = FingerprintHandler(banner, kb.bannerFp) - parse(StringIO(open(paths.GENERIC_XML).read()), handler) + parseXmlFile(paths.GENERIC_XML, handler) else: handler = FingerprintHandler(banner, kb.bannerFp) - parse(StringIO(open(xmlfile).read()), handler) - parse(StringIO(open(paths.GENERIC_XML).read()), handler) + parseXmlFile(xmlfile, handler) + parseXmlFile(paths.GENERIC_XML, handler) diff --git a/lib/parse/headers.py b/lib/parse/headers.py index 6fa0af714..89276a0aa 100644 --- a/lib/parse/headers.py +++ b/lib/parse/headers.py @@ -24,10 +24,8 @@ Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os -from StringIO import StringIO -from xml.sax import parse - from lib.core.common import checkFile +from lib.core.common import parseXmlFile from lib.core.data import kb from lib.core.data import paths from lib.parse.handler import FingerprintHandler @@ -64,5 +62,5 @@ def headersParser(headers): handler = FingerprintHandler(value, kb.headersFp) - parse(StringIO(open(xmlfile).read()), handler) - parse(StringIO(open(paths.GENERIC_XML).read()), handler) + parseXmlFile(xmlfile, handler) + parseXmlFile(paths.GENERIC_XML, handler) diff --git a/lib/parse/html.py b/lib/parse/html.py index 9ce1d946a..dda044219 100644 --- a/lib/parse/html.py +++ b/lib/parse/html.py @@ -24,11 +24,10 @@ Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import re -from StringIO import StringIO -from xml.sax import parse from xml.sax.handler import ContentHandler from lib.core.common import checkFile +from lib.core.common import parseXmlFile from lib.core.common import sanitizeStr from lib.core.data import kb from lib.core.data import paths @@ -69,7 +68,7 @@ def htmlParser(page): checkFile(xmlfile) page = sanitizeStr(page) handler = htmlHandler(page) - parse(StringIO(open(xmlfile).read()), handler) + parseXmlFile(xmlfile, handler) if handler.dbms and handler.dbms not in kb.htmlFp: kb.htmlFp.append(handler.dbms) diff --git a/lib/parse/queriesfile.py b/lib/parse/queriesfile.py index 97badf7ff..c1b2906b0 100644 --- a/lib/parse/queriesfile.py +++ b/lib/parse/queriesfile.py @@ -22,11 +22,10 @@ with sqlmap; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from StringIO import StringIO -from xml.sax import parse from xml.sax.handler import ContentHandler from lib.core.common import checkFile +from lib.core.common import parseXmlFile from lib.core.common import sanitizeStr from lib.core.data import logger from lib.core.data import queries @@ -235,4 +234,4 @@ def queriesParser(): checkFile(xmlfile) handler = queriesHandler() - parse(StringIO(open(xmlfile).read()), handler) + parseXmlFile(xmlfile, handler)