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

Skip to content

Commit eb08c8d

Browse files
committed
Another update for an Issue #352
1 parent 2f43c3e commit eb08c8d

4 files changed

Lines changed: 72 additions & 4 deletions

File tree

lib/core/common.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,13 +1697,14 @@ def stdev(values):
16971697

16981698
key = (values[0], values[-1], len(values))
16991699

1700-
if key in kb.cache.stdev:
1700+
if kb.get("cache") and key in kb.cache.stdev:
17011701
retVal = kb.cache.stdev[key]
17021702
else:
17031703
avg = average(values)
17041704
_ = reduce(lambda x, y: x + pow((y or 0) - avg, 2), values, 0.0)
17051705
retVal = sqrt(_ / (len(values) - 1))
1706-
kb.cache.stdev[key] = retVal
1706+
if kb.get("cache"):
1707+
kb.cache.stdev[key] = retVal
17071708

17081709
return retVal
17091710

@@ -2876,6 +2877,9 @@ def normalizeUnicode(value):
28762877
"""
28772878
Does an ASCII normalization of unicode strings
28782879
Reference: http://www.peterbe.com/plog/unicode-to-ascii
2880+
2881+
>>> normalizeUnicode(u'\u0161u\u0107uraj')
2882+
'sucuraj'
28792883
"""
28802884

28812885
return unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') if isinstance(value, unicode) else value
@@ -2965,6 +2969,8 @@ def isNullValue(value):
29652969
29662970
>>> isNullValue(u'NULL')
29672971
True
2972+
>>> isNullValue(u'foobar')
2973+
False
29682974
"""
29692975

29702976
return isinstance(value, basestring) and value.upper() == NULL
@@ -3090,6 +3096,12 @@ def filterPairValues(values):
30903096
def randomizeParameterValue(value):
30913097
"""
30923098
Randomize a parameter value based on occurances of alphanumeric characters
3099+
3100+
>>> random.seed(0)
3101+
>>> randomizeParameterValue('foobar')
3102+
'rnvnav'
3103+
>>> randomizeParameterValue('17')
3104+
'83'
30933105
"""
30943106

30953107
retVal = value
@@ -3119,6 +3131,9 @@ def asciifyUrl(url, forceQuote=False):
31193131
See also RFC 3987.
31203132
31213133
Reference: http://blog.elsdoerfer.name/2008/12/12/opening-iris-in-python/
3134+
3135+
>>> asciifyUrl(u'http://www.\u0161u\u0107uraj.com')
3136+
u'http://www.xn--uuraj-gxa24d.com'
31223137
"""
31233138

31243139
parts = urlparse.urlsplit(url)
@@ -3290,6 +3305,9 @@ def geturl(self):
32903305
def getHostHeader(url):
32913306
"""
32923307
Returns proper Host header value for a given target URL
3308+
3309+
>>> getHostHeader('http://www.target.com/vuln.php?id=1')
3310+
'www.target.com'
32933311
"""
32943312

32953313
retVal = url
@@ -3339,6 +3357,9 @@ def serializeObject(object_):
33393357
def unserializeObject(value):
33403358
"""
33413359
Unserializes object from given serialized form
3360+
3361+
>>> unserializeObject(serializeObject([1, 2, 3])) == [1, 2, 3]
3362+
True
33423363
"""
33433364

33443365
return base64unpickle(value) if value else None
@@ -3367,6 +3388,9 @@ def getCounter(technique):
33673388
def applyFunctionRecursively(value, function):
33683389
"""
33693390
Applies function recursively through list-like structures
3391+
3392+
>>> applyFunctionRecursively([1, 2, [3, 4, [19]], -9], lambda _: _ > 0)
3393+
[True, True, [True, True, [True]], False]
33703394
"""
33713395

33723396
if isListLike(value):
@@ -3379,6 +3403,9 @@ def applyFunctionRecursively(value, function):
33793403
def decodeHexValue(value):
33803404
"""
33813405
Returns value decoded from DBMS specific hexadecimal representation
3406+
3407+
>>> decodeHexValue('3132332031')
3408+
u'123 1'
33823409
"""
33833410

33843411
retVal = value
@@ -3409,6 +3436,11 @@ def _(value):
34093436
def extractExpectedValue(value, expected):
34103437
"""
34113438
Extracts and returns expected value by a given type
3439+
3440+
>>> extractExpectedValue(['1'], EXPECTED.BOOL)
3441+
True
3442+
>>> extractExpectedValue('1', EXPECTED.INT)
3443+
1
34123444
"""
34133445

34143446
if expected:
@@ -3516,6 +3548,9 @@ def prioritySortColumns(columns):
35163548
"""
35173549
Sorts given column names by length in ascending order while those containing
35183550
string 'id' go first
3551+
3552+
>>> prioritySortColumns(['password', 'userid', 'name'])
3553+
['userid', 'name', 'password']
35193554
"""
35203555

35213556
_ = lambda x: x and "id" in x.lower()
@@ -3536,6 +3571,13 @@ def getRequestHeader(request, name):
35363571
def isNumber(value):
35373572
"""
35383573
Returns True if the given value is a number-like object
3574+
3575+
>>> isNumber(1)
3576+
True
3577+
>>> isNumber('0')
3578+
True
3579+
>>> isNumber('foobar')
3580+
False
35393581
"""
35403582

35413583
try:
@@ -3566,7 +3608,10 @@ def zeroDepthSearch(expression, value):
35663608

35673609
def splitFields(fields, delimiter=','):
35683610
"""
3569-
Returns list of fields splitted by delimiter
3611+
Returns list of (0-depth) fields splitted by delimiter
3612+
3613+
>>> splitFields('foo, bar, max(foo, bar)')
3614+
['foo', 'bar', 'max(foo,bar)']
35703615
"""
35713616

35723617
fields = fields.replace("%s " % delimiter, delimiter)

lib/core/datatype.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class AttribDict(dict):
1414
"""
1515
This class defines the sqlmap object, inheriting from Python data
1616
type dictionary.
17+
18+
>>> foo = AttribDict()
19+
>>> foo.bar = 1
20+
>>> foo.bar
21+
1
1722
"""
1823

1924
def __init__(self, indict=None, attribute=None):

lib/request/basic.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,23 @@ def parseResponse(page, headers):
9999
htmlParser(page)
100100

101101
def checkCharEncoding(encoding, warn=True):
102+
"""
103+
Checks encoding name, repairs common misspellings and adjusts to
104+
proper namings used in codecs module
105+
106+
>>> checkCharEncoding('iso-8858', False)
107+
'iso8859-1'
108+
>>> checkCharEncoding('en_us', False)
109+
'utf8'
110+
"""
111+
102112
if encoding:
103113
encoding = encoding.lower()
104114
else:
105115
return encoding
106116

107117
# Reference: http://www.destructor.de/charsets/index.htm
108-
translate = {"windows-874": "iso-8859-11", "en_us": "utf8", "macintosh": "iso-8859-1", "euc_tw": "big5_tw", "th": "tis-620", "unicode": "utf8", "utc8": "utf8", "ebcdic": "ebcdic-cp-be"}
118+
translate = {"windows-874": "iso-8859-11", "en_us": "utf8", "macintosh": "iso-8859-1", "euc_tw": "big5_tw", "th": "tis-620", "unicode": "utf8", "utc8": "utf8", "ebcdic": "ebcdic-cp-be", "iso-8859": "iso8859-1"}
109119

110120
for delimiter in (';', ',', '('):
111121
if delimiter in encoding:

lib/utils/xrange.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ class xrange(object):
99
"""
1010
Advanced (re)implementation of xrange (supports slice/copy/etc.)
1111
Reference: http://code.activestate.com/recipes/521885-a-pythonic-implementation-of-xrange/
12+
13+
>>> foobar = xrange(1, 10)
14+
>>> 7 in foobar
15+
True
16+
>>> 11 in foobar
17+
False
18+
>>> foobar[0]
19+
1
1220
"""
1321

1422
__slots__ = ['_slice']

0 commit comments

Comments
 (0)