Skip to content

Commit 723a744

Browse files
committed
minor refactoring
1 parent c714ac6 commit 723a744

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

lib/core/common.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,21 +2510,3 @@ def isBinaryData(value):
25102510
if isinstance(value, basestring):
25112511
retVal = reduce(lambda x, y: x or not (y in string.printable or ord(y) > 255), value, False)
25122512
return retVal
2513-
2514-
def getSafeHexEncodedBinaryData(value):
2515-
"""
2516-
Returns safe representation of given basestring value
2517-
2518-
>>> getSafeEncodedBinaryData(u'test123')
2519-
u'test123'
2520-
>>> getSafeEncodedBinaryData(u'test\01\02\03')
2521-
u'test\\1\\2\\3'
2522-
"""
2523-
2524-
retVal = value
2525-
if isinstance(value, basestring):
2526-
retVal = reduce(lambda x, y: x + (y if (y in string.printable or ord(y) > 255) else '\%x' % ord(y)), value, unicode())
2527-
elif isinstance(value, list):
2528-
for i in xrange(len(value)):
2529-
retVal[i] = getSafeHexEncodedBinaryData(value[i])
2530-
return retVal

lib/core/convert.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import pickle
1717
import sys
18+
import string
1819
import struct
1920
import urllib
2021

@@ -126,3 +127,21 @@ def htmlescape(value):
126127

127128
def htmlunescape(value):
128129
return value.replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"').replace('&#39;', "'").replace('&nbsp;', ' ')
130+
131+
def safehexencode(value):
132+
"""
133+
Returns safe hex representation of a given basestring value
134+
135+
>>> safehexencode(u'test123')
136+
u'test123'
137+
>>> safehexencode(u'test\x01\x02\xff')
138+
u'test\\01\\02\\03\\ff'
139+
"""
140+
141+
retVal = value
142+
if isinstance(value, basestring):
143+
retVal = reduce(lambda x, y: x + (y if (y in string.printable or ord(y) > 255) else '\%02x' % ord(y)), value, unicode())
144+
elif isinstance(value, list):
145+
for i in xrange(len(value)):
146+
retVal[i] = safehexencode(value[i])
147+
return retVal

lib/request/inject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from lib.core.common import dataToSessionFile
1818
from lib.core.common import expandAsteriskForColumns
1919
from lib.core.common import getPublicTypeMembers
20-
from lib.core.common import getSafeHexEncodedBinaryData
2120
from lib.core.common import initTechnique
2221
from lib.core.common import isNumPosStrValue
2322
from lib.core.common import isTechniqueAvailable
@@ -28,6 +27,7 @@
2827
from lib.core.common import readInput
2928
from lib.core.common import replaceNewlineTabs
3029
from lib.core.common import safeStringFormat
30+
from lib.core.convert import safehexencode
3131
from lib.core.data import conf
3232
from lib.core.data import kb
3333
from lib.core.data import logger
@@ -495,7 +495,7 @@ def getValue(expression, blind=True, inband=True, error=True, time=True, fromUse
495495
value = None
496496

497497
if safeHexEncode:
498-
value = getSafeHexEncodedBinaryData(value)
498+
value = safehexencode(value)
499499

500500
return value
501501

0 commit comments

Comments
 (0)