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

Skip to content

Commit e1ffdde

Browse files
committed
Little cleaning a mess with url encoding and post hint types
1 parent c19a283 commit e1ffdde

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

lib/core/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,10 @@
518518
MULTIPART_RECOGNITION_REGEX = r"(?i)Content-Disposition:[^;]+;\s*name="
519519

520520
# Default POST data content-type
521-
DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded"
521+
DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded; charset=utf-8"
522+
523+
# Raw text POST data content-type
524+
PLAIN_TEXT_CONTENT_TYPE = "text/plain; charset=utf-8"
522525

523526
# Length used while checking for existence of Suhosin-patch (like) protection mechanism
524527
SUHOSIN_MAX_VALUE_LENGTH = 512

lib/request/connect.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
from lib.core.settings import LARGE_CHUNK_TRIM_MARKER
7777
from lib.core.settings import PAYLOAD_DELIMITER
7878
from lib.core.settings import PERMISSION_DENIED_REGEX
79+
from lib.core.settings import PLAIN_TEXT_CONTENT_TYPE
7980
from lib.core.settings import UNENCODED_ORIGINAL_VALUE
8081
from lib.core.settings import URI_HTTP_HEADER
8182
from lib.core.settings import WARN_TIME_STDEV
@@ -586,7 +587,7 @@ def queryPage(value=None, place=None, content=False, getRatioValue=False, silent
586587
pageLength = None
587588
uri = None
588589
code = None
589-
skipUrlEncode = conf.skipUrlEncode
590+
urlEncodePost = None
590591

591592
if not place:
592593
place = kb.injection.place or PLACE.GET
@@ -597,11 +598,16 @@ def queryPage(value=None, place=None, content=False, getRatioValue=False, silent
597598
payload = agent.extractPayload(value)
598599
threadData = getCurrentThreadData()
599600

600-
if skipUrlEncode is None and conf.httpHeaders:
601+
if conf.httpHeaders:
601602
headers = dict(conf.httpHeaders)
602-
_ = max(headers[_] if _.upper() == HTTP_HEADER.CONTENT_TYPE.upper() else None for _ in headers.keys())
603-
if _ and "urlencoded" not in _:
604-
skipUrlEncode = True
603+
contentType = max(headers[_] if _.upper() == HTTP_HEADER.CONTENT_TYPE.upper() else None for _ in headers.keys())
604+
urlEncodePost = contentType and "urlencoded" in contentType
605+
606+
if conf.skipUrlEncode and urlEncodePost:
607+
urlEncodePost = False
608+
conf.httpHeaders = [_ for _ in conf.httpHeaders if _[1] != contentType]
609+
contentType = POST_HINT_CONTENT_TYPES.get(kb.postHint, PLAIN_TEXT_CONTENT_TYPE)
610+
conf.httpHeaders.append((HTTP_HEADER.CONTENT_TYPE, contentType))
605611

606612
if payload:
607613
if kb.tamperFunctions:
@@ -628,8 +634,8 @@ def queryPage(value=None, place=None, content=False, getRatioValue=False, silent
628634
payload = json.dumps(payload)[1:-1]
629635
value = agent.replacePayload(value, payload)
630636
else:
631-
if not skipUrlEncode and place in (PLACE.GET, PLACE.POST, PLACE.COOKIE, PLACE.URI):
632-
# GET, POST, URI and Cookie payload needs to be throughly URL encoded
637+
# GET, POST, URI and Cookie payload needs to be throughly URL encoded
638+
if place in (PLACE.GET, PLACE.URI, PLACE.COOKIE) and not conf.skipUrlEncode or place in (PLACE.POST,) and urlEncodePost:
633639
payload = urlencode(payload, '%', False, place != PLACE.URI)
634640
value = agent.replacePayload(value, payload)
635641

@@ -745,13 +751,13 @@ def _randomizeParameter(paramString, randomParameter):
745751
else:
746752
get += "%s%s=%s" % (delimiter, name, value)
747753

748-
if not skipUrlEncode:
754+
if not conf.skipUrlEncode:
749755
get = urlencode(get, limit=True)
750756

751757
if post is not None:
752-
if place not in (PLACE.POST, PLACE.CUSTOM_POST) and '%' in getattr(post, UNENCODED_ORIGINAL_VALUE, ""):
758+
if place not in (PLACE.POST, PLACE.CUSTOM_POST) and hasattr(post, UNENCODED_ORIGINAL_VALUE):
753759
post = getattr(post, UNENCODED_ORIGINAL_VALUE)
754-
elif not skipUrlEncode and kb.postHint not in POST_HINT_CONTENT_TYPES.keys():
760+
elif urlEncodePost:
755761
post = urlencode(post, spaceplus=kb.postSpaceToPlus)
756762

757763
if timeBasedCompare:

0 commit comments

Comments
 (0)