Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f191f6

Browse files
committed
Taking some goodies from Pull request #284
1 parent 6b39e66 commit 0f191f6

18 files changed

Lines changed: 49 additions & 55 deletions

File tree

lib/core/xmldump.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
IS_DBA_ELEM_NAME = "isDBA"
3333
FILE_CONTENT_ELEM_NAME = "FileContent"
3434
DB_ATTR = "db"
35-
UNKNOWN_COLUMN_TYPE= "unknown"
35+
UNKNOWN_COLUMN_TYPE = "unknown"
3636
USER_SETTINGS_ELEM_NAME = "UserSettings"
3737
USER_SETTING_ELEM_NAME = "UserSetting"
3838
USERS_ELEM_NAME = "Users"
@@ -72,7 +72,7 @@
7272
SCHEME_NAME = "sqlmap.xsd"
7373
SCHEME_NAME_ATTR = "xsi:noNamespaceSchemaLocation"
7474
CHARACTERS_TO_ENCODE = range(32) + range(127, 256)
75-
ENTITIES = {'"':'"',"'":"'"}
75+
ENTITIES = {'"': '"', "'": "'"}
7676

7777
class XMLDump:
7878
'''
@@ -86,7 +86,7 @@ def __init__(self):
8686
self.__root = None
8787
self.__doc = Document()
8888

89-
def __addToRoot(self,element):
89+
def __addToRoot(self, element):
9090
'''
9191
Adds element to the root element
9292
'''
@@ -105,36 +105,36 @@ def __write(self, data, n=True):
105105

106106
kb.dataOutputFlag = True
107107

108-
def __getRootChild(self,elemName):
108+
def __getRootChild(self, elemName):
109109
'''
110110
Returns the child of the root with the described name
111111
'''
112112
elements = self.__root.getElementsByTagName(elemName)
113-
if elements :
113+
if elements:
114114
return elements[0]
115115

116116
return elements
117117

118-
def __createTextNode(self,data):
118+
def __createTextNode(self, data):
119119
'''
120120
Creates a text node with utf8 data inside.
121121
The text is escaped to an fit the xml text Format.
122122
'''
123-
if data is None :
123+
if data is None:
124124
return self.__doc.createTextNode(u'')
125-
else :
125+
else:
126126
escaped_data = saxutils.escape(data, ENTITIES)
127127
return self.__doc.createTextNode(escaped_data)
128128

129-
def __createAttribute(self,attrName,attrValue):
129+
def __createAttribute(self, attrName, attrValue):
130130
'''
131131
Creates an attribute node with utf8 data inside.
132132
The text is escaped to an fit the xml text Format.
133133
'''
134134
attr = self.__doc.createAttribute(attrName)
135-
if attrValue is None :
135+
if attrValue is None:
136136
attr.nodeValue = u''
137-
else :
137+
else:
138138
attr.nodeValue = getUnicode(attrValue)
139139
return attr
140140

@@ -153,7 +153,7 @@ def string(self, header, data, sort=True):
153153

154154
if data:
155155
data = self.__formatString(data)
156-
else :
156+
else:
157157
data = ""
158158

159159
elem = self.__doc.createElement(MESSAGE_ELEM)
@@ -168,7 +168,6 @@ def lister(self, header, elements, sort=True):
168168
lstElem = self.__doc.createElement(LST_ELEM_NAME)
169169
lstElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, header))
170170
if elements:
171-
172171
if sort:
173172
try:
174173
elements = set(elements)
@@ -185,7 +184,7 @@ def lister(self, header, elements, sort=True):
185184
memberElem.appendChild(self.__createTextNode(element))
186185
elif isinstance(element, (list, tuple, set)):
187186
memberElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, "list"))
188-
for e in element :
187+
for e in element:
189188
memberElemStr = self.__doc.createElement(MEMBER_ELEM)
190189
memberElemStr.setAttributeNode(self.__createAttribute(TYPE_ATTR, "string"))
191190
memberElemStr.appendChild(self.__createTextNode(getUnicode(e)))
@@ -196,7 +195,7 @@ def lister(self, header, elements, sort=True):
196195
self.__addToRoot(listsElem)
197196
listsElem.appendChild(lstElem)
198197

199-
def technic(self,technicType,data):
198+
def technic(self, technicType, data):
200199
'''
201200
Adds information about the technic used to extract data from the db
202201
'''
@@ -210,7 +209,7 @@ def technic(self,technicType,data):
210209
self.__addToRoot(technicsElem)
211210
technicsElem.appendChild(technicElem)
212211

213-
def banner(self,data):
212+
def banner(self, data):
214213
'''
215214
Adds information about the database banner to the xml.
216215
The banner contains information about the type and the version of the database.
@@ -219,7 +218,7 @@ def banner(self,data):
219218
bannerElem.appendChild(self.__createTextNode(data))
220219
self.__addToRoot(bannerElem)
221220

222-
def currentUser(self,data):
221+
def currentUser(self, data):
223222
'''
224223
Adds information about the current database user to the xml
225224
'''
@@ -228,7 +227,7 @@ def currentUser(self,data):
228227
currentUserElem.appendChild(textNode)
229228
self.__addToRoot(currentUserElem)
230229

231-
def currentDb(self,data):
230+
def currentDb(self, data):
232231
'''
233232
Adds information about the current database is use to the xml
234233
'''
@@ -237,15 +236,15 @@ def currentDb(self,data):
237236
currentDBElem.appendChild(textNode)
238237
self.__addToRoot(currentDBElem)
239238

240-
def dba(self,isDBA):
239+
def dba(self, isDBA):
241240
'''
242241
Adds information to the xml that indicates whether the user has DBA privileges
243242
'''
244243
isDBAElem = self.__doc.createElement(IS_DBA_ELEM_NAME)
245244
isDBAElem.setAttributeNode(self.__createAttribute(VALUE_ATTR, getUnicode(isDBA)))
246245
self.__addToRoot(isDBAElem)
247246

248-
def users(self,users):
247+
def users(self, users):
249248
'''
250249
Adds a list of the existing users to the xml
251250
'''
@@ -325,7 +324,7 @@ def dbTables(self, dbTables):
325324
for db, tables in dbTables.items():
326325
tables.sort(key=lambda x: x.lower())
327326
dbElem = self.__doc.createElement(DATABASE_ELEM_NAME)
328-
dbElem.setAttributeNode(self.__createAttribute(NAME_ATTR,db))
327+
dbElem.setAttributeNode(self.__createAttribute(NAME_ATTR, db))
329328
dbTablesElem.appendChild(dbElem)
330329
for table in tables:
331330
tableElem = self.__doc.createElement(DB_TABLE_ELEM_NAME)
@@ -361,7 +360,7 @@ def dbTableColumns(self, tableColumns):
361360
colElem = self.__doc.createElement(COLUMN_ELEM_NAME)
362361
if colType is not None:
363362
colElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, colType))
364-
else :
363+
else:
365364
colElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, UNKNOWN_COLUMN_TYPE))
366365
colElem.appendChild(self.__createTextNode(column))
367366
tableElem.appendChild(colElem)
@@ -426,16 +425,16 @@ def dbColumns(self, dbColumns, colConsider, dbs):
426425
if tbl in printDbs[db]:
427426
printDbs[db][tbl][col] = dataType
428427
else:
429-
printDbs[db][tbl] = { col: dataType }
428+
printDbs[db][tbl] = {col: dataType}
430429
else:
431430
printDbs[db] = {}
432-
printDbs[db][tbl] = { col: dataType }
431+
printDbs[db][tbl] = {col: dataType}
433432

434433
continue
435434

436435
self.dbTableColumns(printDbs)
437436

438-
def query(self,query,queryRes):
437+
def query(self, query, queryRes):
439438
'''
440439
Adds details of an executed query to the xml.
441440
The query details are the query itself and it's results.
@@ -449,7 +448,7 @@ def query(self,query,queryRes):
449448
self.__addToRoot(queriesElem)
450449
queriesElem.appendChild(queryElem)
451450

452-
def registerValue(self,registerData):
451+
def registerValue(self, registerData):
453452
'''
454453
Adds information about an extracted registry key to the xml
455454
'''
@@ -474,8 +473,8 @@ def setOutputFile(self):
474473
'''
475474
Initiates the xml file from the configuration.
476475
'''
477-
if (conf.xmlFile) :
478-
try :
476+
if (conf.xmlFile):
477+
try:
479478
self.__outputFile = conf.xmlFile
480479
self.__root = None
481480

@@ -490,8 +489,8 @@ def setOutputFile(self):
490489

491490
if self.__root is None:
492491
self.__root = self.__doc.createElementNS(NAME_SPACE_ATTR, RESULTS_ELEM_NAME)
493-
self.__root.setAttributeNode(self.__createAttribute(XMLNS_ATTR,NAME_SPACE_ATTR))
494-
self.__root.setAttributeNode(self.__createAttribute(SCHEME_NAME_ATTR,SCHEME_NAME))
492+
self.__root.setAttributeNode(self.__createAttribute(XMLNS_ATTR, NAME_SPACE_ATTR))
493+
self.__root.setAttributeNode(self.__createAttribute(SCHEME_NAME_ATTR, SCHEME_NAME))
495494
self.__doc.appendChild(self.__root)
496495
except IOError:
497496
raise sqlmapFilePathException("Wrong filename provided for saving the xml file: %s" % conf.xmlFile)
@@ -508,7 +507,7 @@ def finish(self, resultStatus, resultMsg=""):
508507
'''
509508
if ((self.__outputFP is not None) and not(self.__outputFP.closed)):
510509
statusElem = self.__doc.createElement(STATUS_ELEM_NAME)
511-
statusElem.setAttributeNode(self.__createAttribute(SUCESS_ATTR,getUnicode(resultStatus)))
510+
statusElem.setAttributeNode(self.__createAttribute(SUCESS_ATTR, getUnicode(resultStatus)))
512511

513512
if not resultStatus:
514513
errorElem = self.__doc.createElement(ERROR_ELEM_NAME)
@@ -525,6 +524,7 @@ def finish(self, resultStatus, resultMsg=""):
525524
self.__write(prettyprint.formatXML(self.__doc, encoding=UNICODE_ENCODING))
526525
self.__outputFP.close()
527526

527+
528528
def closeDumper(status, msg=""):
529529
"""
530530
Closes the dumper of the session

lib/request/rangehandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HTTPRangeHandler(urllib2.BaseHandler):
1818
1919
This was extremely simple. The Range header is a HTTP feature to
2020
begin with so all this class does is tell urllib2 that the
21-
"206 Partial Content" reponse from the HTTP server is what we
21+
"206 Partial Content" response from the HTTP server is what we
2222
expected.
2323
2424
Example:

lib/utils/deps.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def checkDependencies():
3939
import pyodbc
4040
elif dbmsName == DBMS.FIREBIRD:
4141
import kinterbasdb
42-
except ImportError, _:
42+
except ImportError:
4343
warnMsg = "sqlmap requires '%s' third-party library " % data[1]
4444
warnMsg += "in order to directly connect to the database "
4545
warnMsg += "%s. Download from %s" % (dbmsName, data[2])
@@ -55,7 +55,7 @@ def checkDependencies():
5555
import impacket
5656
debugMsg = "'python-impacket' third-party library is found"
5757
logger.debug(debugMsg)
58-
except ImportError, _:
58+
except ImportError:
5959
warnMsg = "sqlmap requires 'python-impacket' third-party library for "
6060
warnMsg += "out-of-band takeover feature. Download from "
6161
warnMsg += "http://code.google.com/p/impacket/"
@@ -66,7 +66,7 @@ def checkDependencies():
6666
import ntlm
6767
debugMsg = "'python-ntlm' third-party library is found"
6868
logger.debug(debugMsg)
69-
except ImportError, _:
69+
except ImportError:
7070
warnMsg = "sqlmap requires 'python-ntlm' third-party library for "
7171
warnMsg += "if you plan to attack a web application behind NTLM "
7272
warnMsg += "authentication. Download from http://code.google.com/p/python-ntlm/"
@@ -78,7 +78,7 @@ def checkDependencies():
7878
import pyreadline
7979
debugMsg = "'python-pyreadline' third-party library is found"
8080
logger.debug(debugMsg)
81-
except ImportError, _:
81+
except ImportError:
8282
warnMsg = "sqlmap requires 'pyreadline' third-party library to "
8383
warnMsg += "be able to take advantage of the sqlmap TAB "
8484
warnMsg += "completion and history support features in the SQL "

lib/utils/hash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
try:
99
from crypt import crypt
10-
except ImportError, _:
10+
except ImportError:
1111
from thirdparty.fcrypt.fcrypt import crypt
1212

1313
_multiprocessing = None

plugins/dbms/access/connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
try:
99
import pyodbc
10-
except ImportError, _:
10+
except ImportError:
1111
pass
1212

1313
import logging

plugins/dbms/db2/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python
22

33
"""
4-
$Id$
5-
64
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
75
See the file 'doc/COPYING' for copying permission
86
"""

plugins/dbms/db2/connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
try:
99
import ibm_db_dbi
10-
except ImportError, _:
10+
except ImportError:
1111
pass
1212

1313
import logging

plugins/dbms/db2/enumeration.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python
22

33
"""
4-
$Id$
5-
64
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
75
See the file 'doc/COPYING' for copying permission
86
"""

plugins/dbms/db2/syntax.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env python
22

33
"""
4-
$Id$
5-
64
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
75
See the file 'doc/COPYING' for copying permission
86
"""

plugins/dbms/firebird/connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
try:
99
import kinterbasdb
10-
except ImportError, _:
10+
except ImportError:
1111
pass
1212

1313
import logging

0 commit comments

Comments
 (0)