mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-01-24 08:14:24 +03:00
minor code cleaning
This commit is contained in:
parent
769b0d0ae7
commit
7fd64df167
|
@ -161,9 +161,7 @@ class UnicodeRawConfigParser(RawConfigParser):
|
||||||
class Format:
|
class Format:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def humanize(values, chain=" or "):
|
def humanize(values, chain=" or "):
|
||||||
strJoin = "|".join(v for v in values)
|
return chain.join(values)
|
||||||
|
|
||||||
return strJoin.replace("|", chain)
|
|
||||||
|
|
||||||
# Get methods
|
# Get methods
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -179,10 +177,7 @@ class Format:
|
||||||
if versions is None and Backend.getVersionList():
|
if versions is None and Backend.getVersionList():
|
||||||
versions = Backend.getVersionList()
|
versions = Backend.getVersionList()
|
||||||
|
|
||||||
if versions is None:
|
return Backend.getDbms() if versions is None else "%s %s" % (Backend.getDbms(), " and ".join(v for v in versions))
|
||||||
return Backend.getDbms()
|
|
||||||
else:
|
|
||||||
return "%s %s" % (Backend.getDbms(), " and ".join(v for v in versions))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getErrorParsedDBMSes():
|
def getErrorParsedDBMSes():
|
||||||
|
@ -195,14 +190,14 @@ class Format:
|
||||||
@rtype: C{str}
|
@rtype: C{str}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
htmlParsed = ""
|
htmlParsed = None
|
||||||
|
|
||||||
if len(kb.htmlFp) == 0 or kb.heuristicTest is None:
|
if len(kb.htmlFp) == 0 or kb.heuristicTest is None:
|
||||||
return None
|
pass
|
||||||
elif len(kb.htmlFp) == 1:
|
elif len(kb.htmlFp) == 1:
|
||||||
htmlParsed = kb.htmlFp[0]
|
htmlParsed = kb.htmlFp[0]
|
||||||
elif len(kb.htmlFp) > 1:
|
elif len(kb.htmlFp) > 1:
|
||||||
htmlParsed = " or ".join(htmlFp for htmlFp in kb.htmlFp)
|
htmlParsed = " or ".join(kb.htmlFp)
|
||||||
|
|
||||||
return htmlParsed
|
return htmlParsed
|
||||||
|
|
||||||
|
@ -378,7 +373,6 @@ class Backend:
|
||||||
|
|
||||||
if isinstance(_, basestring) and _.isdigit() and int(_) in (1, 2):
|
if isinstance(_, basestring) and _.isdigit() and int(_) in (1, 2):
|
||||||
kb.arch = 32 if int(_) == 1 else 64
|
kb.arch = 32 if int(_) == 1 else 64
|
||||||
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
warnMsg = "invalid value. Valid values are 1 and 2"
|
warnMsg = "invalid value. Valid values are 1 and 2"
|
||||||
|
@ -458,7 +452,6 @@ class Backend:
|
||||||
def getArch():
|
def getArch():
|
||||||
if kb.arch is None:
|
if kb.arch is None:
|
||||||
Backend.setArch()
|
Backend.setArch()
|
||||||
|
|
||||||
return kb.arch
|
return kb.arch
|
||||||
|
|
||||||
# Comparison methods
|
# Comparison methods
|
||||||
|
@ -773,36 +766,16 @@ def dataToOutFile(data):
|
||||||
|
|
||||||
return rFilePath
|
return rFilePath
|
||||||
|
|
||||||
def strToHex(inpStr):
|
def strToHex(value):
|
||||||
"""
|
"""
|
||||||
@param inpStr: inpStr to be converted into its hexadecimal value.
|
Converts string value to it's hexadecimal representation
|
||||||
@type inpStr: C{str}
|
|
||||||
|
|
||||||
@return: the hexadecimal converted inpStr.
|
|
||||||
@rtype: C{str}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hexStr = ""
|
return (value if not isinstance(value, unicode) else value.encode(UNICODE_ENCODING)).encode("hex").upper()
|
||||||
|
|
||||||
for character in inpStr:
|
|
||||||
if character == "\n":
|
|
||||||
character = " "
|
|
||||||
|
|
||||||
hexChar = "%2x" % ord(character)
|
|
||||||
hexChar = hexChar.replace(" ", "0")
|
|
||||||
hexChar = hexChar.upper()
|
|
||||||
|
|
||||||
hexStr += hexChar
|
|
||||||
|
|
||||||
return hexStr
|
|
||||||
|
|
||||||
def readInput(message, default=None, checkBatch=True):
|
def readInput(message, default=None, checkBatch=True):
|
||||||
"""
|
"""
|
||||||
@param message: message to display on terminal.
|
Reads input from terminal
|
||||||
@type message: C{str}
|
|
||||||
|
|
||||||
@return: a string read from keyboard as input.
|
|
||||||
@rtype: C{str}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if "\n" in message:
|
if "\n" in message:
|
||||||
|
@ -839,36 +812,21 @@ def readInput(message, default=None, checkBatch=True):
|
||||||
|
|
||||||
def randomRange(start=0, stop=1000):
|
def randomRange(start=0, stop=1000):
|
||||||
"""
|
"""
|
||||||
@param start: starting number.
|
Returns random integer value in given range
|
||||||
@type start: C{int}
|
|
||||||
|
|
||||||
@param stop: last number.
|
|
||||||
@type stop: C{int}
|
|
||||||
|
|
||||||
@return: a random number within the range.
|
|
||||||
@rtype: C{int}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return int(random.randint(start, stop))
|
return int(random.randint(start, stop))
|
||||||
|
|
||||||
def randomInt(length=4):
|
def randomInt(length=4):
|
||||||
"""
|
"""
|
||||||
@param length: length of the random string.
|
Returns random integer value with provided number of digits
|
||||||
@type length: C{int}
|
|
||||||
|
|
||||||
@return: a random string of digits.
|
|
||||||
@rtype: C{str}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return int("".join(random.choice(string.digits if i!=0 else string.digits.replace('0', '')) for i in xrange(0, length)))
|
return int("".join(random.choice(string.digits if i!=0 else string.digits.replace('0', '')) for i in xrange(0, length)))
|
||||||
|
|
||||||
def randomStr(length=4, lowercase=False, alphabet=None):
|
def randomStr(length=4, lowercase=False, alphabet=None):
|
||||||
"""
|
"""
|
||||||
@param length: length of the random string.
|
Returns random string value with provided number of characters
|
||||||
@type length: C{int}
|
|
||||||
|
|
||||||
@return: a random string of characters.
|
|
||||||
@rtype: C{str}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if alphabet:
|
if alphabet:
|
||||||
|
@ -882,20 +840,14 @@ def randomStr(length=4, lowercase=False, alphabet=None):
|
||||||
|
|
||||||
def sanitizeStr(value):
|
def sanitizeStr(value):
|
||||||
"""
|
"""
|
||||||
@param value: value to sanitize: cast to str datatype and replace
|
Sanitizes string value in respect to newline and line-feed characters
|
||||||
newlines with one space and strip carriage returns.
|
|
||||||
@type value: C{str}
|
|
||||||
|
|
||||||
@return: sanitized value
|
|
||||||
@rtype: C{str}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return getUnicode(value).replace("\n", " ").replace("\r", "")
|
return getUnicode(value).replace("\n", " ").replace("\r", "")
|
||||||
|
|
||||||
def checkFile(filename):
|
def checkFile(filename):
|
||||||
"""
|
"""
|
||||||
@param filename: filename to check if it exists.
|
Checks for file existence
|
||||||
@type filename: C{str}
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
|
@ -2997,6 +2949,7 @@ def findPageForms(content, url, raise_=False, addToTargets=False):
|
||||||
forms = None
|
forms = None
|
||||||
retVal = set()
|
retVal = set()
|
||||||
response = _(content, url)
|
response = _(content, url)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
forms = ParseResponse(response, backwards_compat=False)
|
forms = ParseResponse(response, backwards_compat=False)
|
||||||
except ParseError:
|
except ParseError:
|
||||||
|
|
|
@ -419,7 +419,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
|
||||||
# If we have got one single character not correctly fetched it
|
# If we have got one single character not correctly fetched it
|
||||||
# can mean that the connection to the target url was lost
|
# can mean that the connection to the target url was lost
|
||||||
if None in value:
|
if None in value:
|
||||||
partialValue = "".join(_ for _ in value[:value.index(None)])
|
partialValue = "".join(value[:value.index(None)])
|
||||||
|
|
||||||
if partialValue:
|
if partialValue:
|
||||||
infoMsg = "\r[%s] [INFO] partially retrieved: %s" % (time.strftime("%X"), filterControlChars(partialValue))
|
infoMsg = "\r[%s] [INFO] partially retrieved: %s" % (time.strftime("%X"), filterControlChars(partialValue))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user