some code refactoring

This commit is contained in:
Miroslav Stampar 2010-04-16 19:57:00 +00:00
parent 1bdf94f236
commit 915d3441e9
5 changed files with 23 additions and 18 deletions

View File

@ -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
@ -1085,3 +1087,11 @@ def getConsoleWidth(default=80):
pass
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()

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)