Skip to content

Commit 9744073

Browse files
committed
Doing some more style updating (capitalization of exception classes; using _ is enough for private members - __ is used in Python specific methods)
1 parent 003d21e commit 9744073

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1118
-1094
lines changed

_sqlmap.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
from lib.core.data import paths
2929
from lib.core.common import unhandledExceptionMessage
3030
from lib.core.exception import exceptionsTuple
31-
from lib.core.exception import sqlmapSilentQuitException
32-
from lib.core.exception import sqlmapUserQuitException
31+
from lib.core.exception import SqlmapSilentQuitException
32+
from lib.core.exception import SqlmapUserQuitException
3333
from lib.core.option import init
3434
from lib.core.profiling import profile
3535
from lib.core.settings import LEGAL_DISCLAIMER
@@ -72,11 +72,11 @@ def main():
7272
else:
7373
start()
7474

75-
except sqlmapUserQuitException:
75+
except SqlmapUserQuitException:
7676
errMsg = "user quit"
7777
logger.error(errMsg)
7878

79-
except (sqlmapSilentQuitException, bdb.BdbQuit):
79+
except (SqlmapSilentQuitException, bdb.BdbQuit):
8080
pass
8181

8282
except exceptionsTuple, e:

lib/controller/action.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from lib.core.data import kb
1414
from lib.core.data import logger
1515
from lib.core.data import paths
16-
from lib.core.exception import sqlmapNoneDataException
17-
from lib.core.exception import sqlmapUnsupportedDBMSException
16+
from lib.core.exception import SqlmapNoneDataException
17+
from lib.core.exception import SqlmapUnsupportedDBMSException
1818
from lib.core.settings import SUPPORTED_DBMS
1919
from lib.techniques.brute.use import columnExists
2020
from lib.techniques.brute.use import tableExists
@@ -52,7 +52,7 @@ def action():
5252
errMsg += ". Support for this DBMS will be implemented at "
5353
errMsg += "some point"
5454

55-
raise sqlmapUnsupportedDBMSException, errMsg
55+
raise SqlmapUnsupportedDBMSException, errMsg
5656

5757
dataToStdout("%s\n" % conf.dbmsHandler.getFingerprint())
5858

@@ -79,7 +79,7 @@ def action():
7979
try:
8080
conf.dumper.userSettings("database management system users password hashes",
8181
conf.dbmsHandler.getPasswordHashes(), "password hash")
82-
except sqlmapNoneDataException, ex:
82+
except SqlmapNoneDataException, ex:
8383
logger.critical(ex)
8484
except:
8585
raise
@@ -88,7 +88,7 @@ def action():
8888
try:
8989
conf.dumper.userSettings("database management system users privileges",
9090
conf.dbmsHandler.getPrivileges(), "privilege")
91-
except sqlmapNoneDataException, ex:
91+
except SqlmapNoneDataException, ex:
9292
logger.critical(ex)
9393
except:
9494
raise
@@ -97,7 +97,7 @@ def action():
9797
try:
9898
conf.dumper.userSettings("database management system users roles",
9999
conf.dbmsHandler.getRoles(), "role")
100-
except sqlmapNoneDataException, ex:
100+
except SqlmapNoneDataException, ex:
101101
logger.critical(ex)
102102
except:
103103
raise

lib/controller/checks.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
from lib.core.enums import NULLCONNECTION
4848
from lib.core.enums import PAYLOAD
4949
from lib.core.enums import PLACE
50-
from lib.core.exception import sqlmapConnectionException
51-
from lib.core.exception import sqlmapNoneDataException
52-
from lib.core.exception import sqlmapSilentQuitException
53-
from lib.core.exception import sqlmapUserQuitException
50+
from lib.core.exception import SqlmapConnectionException
51+
from lib.core.exception import SqlmapNoneDataException
52+
from lib.core.exception import SqlmapSilentQuitException
53+
from lib.core.exception import SqlmapUserQuitException
5454
from lib.core.settings import FORMAT_EXCEPTION_STRINGS
5555
from lib.core.settings import HEURISTIC_CHECK_ALPHABET
5656
from lib.core.settings import SUHOSHIN_MAX_VALUE_LENGTH
@@ -407,7 +407,7 @@ def genCmpPayload():
407407

408408
injectable = True
409409

410-
except sqlmapConnectionException, msg:
410+
except SqlmapConnectionException, msg:
411411
debugMsg = "problem occured most likely because the "
412412
debugMsg += "server hasn't recovered as expected from the "
413413
debugMsg += "error-based payload used ('%s')" % msg
@@ -546,7 +546,7 @@ def genCmpPayload():
546546
elif choice[0] in ("e", "E"):
547547
kb.endDetection = True
548548
elif choice[0] in ("q", "Q"):
549-
raise sqlmapUserQuitException
549+
raise SqlmapUserQuitException
550550

551551
finally:
552552
# Reset forced back-end DBMS value
@@ -749,7 +749,7 @@ def checkDynParam(place, parameter, value):
749749
randInt = randomInt()
750750
payload = agent.payload(place, parameter, value, getUnicode(randInt))
751751
dynResult = Request.queryPage(payload, place, raise404=False)
752-
except sqlmapConnectionException:
752+
except SqlmapConnectionException:
753753
pass
754754

755755
result = None if dynResult is None else not dynResult
@@ -848,7 +848,7 @@ def checkStability():
848848
test = readInput(message, default="C")
849849

850850
if test and test[0] in ("q", "Q"):
851-
raise sqlmapUserQuitException
851+
raise SqlmapUserQuitException
852852

853853
elif test and test[0] in ("s", "S"):
854854
showStaticWords(firstPage, secondPage)
@@ -867,7 +867,7 @@ def checkStability():
867867
kb.nullConnection = None
868868
else:
869869
errMsg = "Empty value supplied"
870-
raise sqlmapNoneDataException, errMsg
870+
raise SqlmapNoneDataException, errMsg
871871

872872
elif test and test[0] in ("r", "R"):
873873
message = "please enter value for parameter 'regex': "
@@ -884,7 +884,7 @@ def checkStability():
884884
kb.nullConnection = None
885885
else:
886886
errMsg = "Empty value supplied"
887-
raise sqlmapNoneDataException, errMsg
887+
raise SqlmapNoneDataException, errMsg
888888

889889
else:
890890
checkDynamicContent(firstPage, secondPage)
@@ -1013,9 +1013,9 @@ def checkNullConnection():
10131013
infoMsg += "'%s'" % kb.nullConnection
10141014
logger.info(infoMsg)
10151015

1016-
except sqlmapConnectionException, errMsg:
1016+
except SqlmapConnectionException, errMsg:
10171017
errMsg = getUnicode(errMsg)
1018-
raise sqlmapConnectionException, errMsg
1018+
raise SqlmapConnectionException, errMsg
10191019

10201020
return kb.nullConnection is not None
10211021

@@ -1025,7 +1025,7 @@ def checkConnection(suppressOutput=False):
10251025
socket.getaddrinfo(conf.hostname, None)
10261026
except socket.gaierror:
10271027
errMsg = "host '%s' does not exist" % conf.hostname
1028-
raise sqlmapConnectionException, errMsg
1028+
raise SqlmapConnectionException, errMsg
10291029

10301030
if not suppressOutput:
10311031
infoMsg = "testing connection to the target url"
@@ -1039,7 +1039,7 @@ def checkConnection(suppressOutput=False):
10391039

10401040
if not kb.originalPage and wasLastRequestHTTPError():
10411041
errMsg = "unable to retrieve page content"
1042-
raise sqlmapConnectionException, errMsg
1042+
raise SqlmapConnectionException, errMsg
10431043
elif wasLastRequestDBMSError():
10441044
warnMsg = "there is a DBMS error found in the HTTP response body "
10451045
warnMsg += "which could interfere with the results of the tests"
@@ -1051,7 +1051,7 @@ def checkConnection(suppressOutput=False):
10511051
else:
10521052
kb.errorIsNone = True
10531053

1054-
except sqlmapConnectionException, errMsg:
1054+
except SqlmapConnectionException, errMsg:
10551055
errMsg = getUnicode(errMsg)
10561056
logger.critical(errMsg)
10571057

@@ -1069,7 +1069,7 @@ def checkConnection(suppressOutput=False):
10691069

10701070
msg = "it is not recommended to continue in this kind of cases. Do you want to quit and make sure that everything is set up properly? [Y/n] "
10711071
if readInput(msg, default="Y") not in ("n", "N"):
1072-
raise sqlmapSilentQuitException
1072+
raise SqlmapSilentQuitException
10731073
else:
10741074
kb.ignoreNotFound = True
10751075
else:

lib/controller/controller.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
from lib.core.enums import PAYLOAD
4242
from lib.core.enums import PLACE
4343
from lib.core.exception import exceptionsTuple
44-
from lib.core.exception import sqlmapNoneDataException
45-
from lib.core.exception import sqlmapNotVulnerableException
46-
from lib.core.exception import sqlmapSilentQuitException
47-
from lib.core.exception import sqlmapValueException
48-
from lib.core.exception import sqlmapUserQuitException
44+
from lib.core.exception import SqlmapNoneDataException
45+
from lib.core.exception import SqlmapNotVulnerableException
46+
from lib.core.exception import SqlmapSilentQuitException
47+
from lib.core.exception import SqlmapValueException
48+
from lib.core.exception import SqlmapUserQuitException
4949
from lib.core.settings import ASP_NET_CONTROL_REGEX
5050
from lib.core.settings import DEFAULT_GET_POST_DELIMITER
5151
from lib.core.settings import EMPTY_FORM_FIELDS_REGEX
@@ -58,7 +58,7 @@
5858
from lib.core.target import setupTargetEnv
5959
from thirdparty.pagerank.pagerank import get_pagerank
6060

61-
def __selectInjection():
61+
def _selectInjection():
6262
"""
6363
Selection function for injection place, parameters and type.
6464
"""
@@ -113,14 +113,14 @@ def __selectInjection():
113113
if select.isdigit() and int(select) < len(kb.injections) and int(select) >= 0:
114114
index = int(select)
115115
elif select[0] in ( "Q", "q" ):
116-
raise sqlmapUserQuitException
116+
raise SqlmapUserQuitException
117117
else:
118118
errMsg = "invalid choice"
119-
raise sqlmapValueException, errMsg
119+
raise SqlmapValueException, errMsg
120120

121121
kb.injection = kb.injections[index]
122122

123-
def __formatInjection(inj):
123+
def _formatInjection(inj):
124124
data = "Place: %s\n" % inj.place
125125
data += "Parameter: %s\n" % inj.parameter
126126

@@ -143,11 +143,11 @@ def __formatInjection(inj):
143143

144144
return data
145145

146-
def __showInjections():
146+
def _showInjections():
147147
header = "sqlmap identified the following injection points with "
148148
header += "a total of %d HTTP(s) requests" % kb.testQueryCount
149149

150-
data = "".join(set(map(lambda x: __formatInjection(x), kb.injections))).rstrip("\n")
150+
data = "".join(set(map(lambda x: _formatInjection(x), kb.injections))).rstrip("\n")
151151

152152
conf.dumper.technic(header, data)
153153

@@ -156,7 +156,7 @@ def __showInjections():
156156
infoMsg += "included in shown payload content(s)"
157157
logger.info(infoMsg)
158158

159-
def __randomFillBlankFields(value):
159+
def _randomFillBlankFields(value):
160160
retVal = value
161161

162162
if extractRegexResult(EMPTY_FORM_FIELDS_REGEX, value):
@@ -173,7 +173,7 @@ def __randomFillBlankFields(value):
173173

174174
return retVal
175175

176-
def __saveToHashDB():
176+
def _saveToHashDB():
177177
injections = hashDBRetrieve(HASHDB_KEYS.KB_INJECTIONS, True) or []
178178
injections.extend(_ for _ in kb.injections if _ and _.place is not None and _.parameter is not None)
179179

@@ -196,7 +196,7 @@ def __saveToHashDB():
196196
if not hashDBRetrieve(HASHDB_KEYS.KB_DYNAMIC_MARKINGS):
197197
hashDBWrite(HASHDB_KEYS.KB_DYNAMIC_MARKINGS, kb.dynamicMarkings, True)
198198

199-
def __saveToResultsFile():
199+
def _saveToResultsFile():
200200
if not conf.resultsFP:
201201
return
202202

@@ -310,7 +310,7 @@ def start():
310310
if conf.method == HTTPMETHOD.POST:
311311
message = "Edit POST data [default: %s]%s: " % (urlencode(conf.data) if conf.data else "None", " (Warning: blank fields detected)" if conf.data and extractRegexResult(EMPTY_FORM_FIELDS_REGEX, conf.data) else "")
312312
conf.data = readInput(message, default=conf.data)
313-
conf.data = __randomFillBlankFields(conf.data)
313+
conf.data = _randomFillBlankFields(conf.data)
314314
conf.data = urldecode(conf.data) if conf.data and urlencode(DEFAULT_GET_POST_DELIMITER, None) not in conf.data else conf.data
315315

316316
elif conf.method == HTTPMETHOD.GET:
@@ -319,7 +319,7 @@ def start():
319319
secondPart = targetUrl[targetUrl.find("?")+1:]
320320
message = "Edit GET data [default: %s]: " % secondPart
321321
test = readInput(message, default=secondPart)
322-
test = __randomFillBlankFields(test)
322+
test = _randomFillBlankFields(test)
323323
conf.url = "%s?%s" % (firstPart, test)
324324

325325
parseTargetUrl()
@@ -493,7 +493,7 @@ def start():
493493
if kb.vainRun and not conf.multipleTargets:
494494
errMsg = "no parameter(s) found for testing in the provided data "
495495
errMsg += "(e.g. GET parameter 'id' in 'www.site.com/index.php?id=1')"
496-
raise sqlmapNoneDataException, errMsg
496+
raise SqlmapNoneDataException, errMsg
497497
else:
498498
errMsg = "all tested parameters appear to be not injectable."
499499

@@ -541,15 +541,15 @@ def start():
541541
errMsg += "expression that you have choosen "
542542
errMsg += "does not match exclusively True responses"
543543

544-
raise sqlmapNotVulnerableException, errMsg
544+
raise SqlmapNotVulnerableException, errMsg
545545
else:
546546
# Flush the flag
547547
kb.testMode = False
548548

549-
__saveToResultsFile()
550-
__saveToHashDB()
551-
__showInjections()
552-
__selectInjection()
549+
_saveToResultsFile()
550+
_saveToHashDB()
551+
_showInjections()
552+
_selectInjection()
553553

554554
if kb.injection.place is not None and kb.injection.parameter is not None:
555555
if conf.multipleTargets:
@@ -576,14 +576,14 @@ def start():
576576
elif test[0] in ("n", "N"):
577577
return False
578578
elif test[0] in ("q", "Q"):
579-
raise sqlmapUserQuitException
579+
raise SqlmapUserQuitException
580580
else:
581581
raise
582582

583-
except sqlmapUserQuitException:
583+
except SqlmapUserQuitException:
584584
raise
585585

586-
except sqlmapSilentQuitException:
586+
except SqlmapSilentQuitException:
587587
raise
588588

589589
except exceptionsTuple, e:

lib/core/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from lib.core.enums import PAYLOAD
2525
from lib.core.enums import PLACE
2626
from lib.core.enums import POST_HINT
27-
from lib.core.exception import sqlmapNoneDataException
27+
from lib.core.exception import SqlmapNoneDataException
2828
from lib.core.settings import ASTERISK_MARKER
2929
from lib.core.settings import CUSTOM_INJECTION_MARK_CHAR
3030
from lib.core.settings import GENERIC_SQL_COMMENT
@@ -252,7 +252,7 @@ def cleanupPayload(self, payload, origValue=None):
252252
else:
253253
errMsg = "invalid usage of inference payload without "
254254
errMsg += "knowledge of underlying DBMS"
255-
raise sqlmapNoneDataException, errMsg
255+
raise SqlmapNoneDataException, errMsg
256256

257257
return payload
258258

0 commit comments

Comments
 (0)