From 6b826ef64d96c1d5f2d3a14bae495d1a8317c0c7 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 31 Jul 2013 20:41:19 +0200 Subject: [PATCH] Reintroducing option --cookie-del --- lib/core/common.py | 5 ++++- lib/core/optiondict.py | 1 + lib/parse/cmdline.py | 3 +++ lib/request/basic.py | 4 ++-- lib/request/connect.py | 4 ++-- lib/request/redirecthandler.py | 2 +- sqlmap.conf | 5 ++++- 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index a78703440..5825f0a59 100755 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -533,7 +533,10 @@ def paramToDict(place, parameters=None): parameters = parameters.replace(", ", ",") parameters = re.sub(r"&(\w{1,4});", r"%s\g<1>%s" % (PARAMETER_AMP_MARKER, PARAMETER_SEMICOLON_MARKER), parameters) - splitParams = parameters.split(conf.pDel or (DEFAULT_COOKIE_DELIMITER if place == PLACE.COOKIE else DEFAULT_GET_POST_DELIMITER)) + if place == PLACE.COOKIE: + splitParams = parameters.split(conf.cDel or DEFAULT_COOKIE_DELIMITER) + else: + splitParams = parameters.split(conf.pDel or DEFAULT_GET_POST_DELIMITER) for element in splitParams: element = re.sub(r"%s(.+?)%s" % (PARAMETER_AMP_MARKER, PARAMETER_SEMICOLON_MARKER), r"&\g<1>;", element) diff --git a/lib/core/optiondict.py b/lib/core/optiondict.py index 07f9321de..8671c6f82 100644 --- a/lib/core/optiondict.py +++ b/lib/core/optiondict.py @@ -25,6 +25,7 @@ optDict = { "data": "string", "pDel": "string", "cookie": "string", + "cDel": "string", "loadCookies": "string", "dropSetCookie": "boolean", "agent": "string", diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 5f4503c24..a4be932ae 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -82,6 +82,9 @@ def cmdLineParser(): request.add_option("--cookie", dest="cookie", help="HTTP Cookie header") + request.add_option("--cookie-del", dest="cDel", + help="Character used for splitting cookie values") + request.add_option("--load-cookies", dest="loadCookies", help="File containing cookies in Netscape/wget format") diff --git a/lib/request/basic.py b/lib/request/basic.py index 7ccb0c926..529e46289 100755 --- a/lib/request/basic.py +++ b/lib/request/basic.py @@ -73,7 +73,7 @@ def forgeHeaders(items=None): kb.mergeCookies = not _ or _[0] in ("y", "Y") if kb.mergeCookies: - _ = lambda x: re.sub("(?i)%s=[^%s]+" % (cookie.name, DEFAULT_COOKIE_DELIMITER), "%s=%s" % (cookie.name, cookie.value), x) + _ = lambda x: re.sub("(?i)%s=[^%s]+" % (cookie.name, conf.cDel or DEFAULT_COOKIE_DELIMITER), "%s=%s" % (cookie.name, cookie.value), x) headers[HTTP_HEADER.COOKIE] = _(headers[HTTP_HEADER.COOKIE]) if PLACE.COOKIE in conf.parameters: @@ -82,7 +82,7 @@ def forgeHeaders(items=None): conf.httpHeaders = [(item[0], item[1] if item[0] != HTTP_HEADER.COOKIE else _(item[1])) for item in conf.httpHeaders] elif not kb.testMode: - headers[HTTP_HEADER.COOKIE] += "%s %s=%s" % (DEFAULT_COOKIE_DELIMITER, cookie.name, cookie.value) + headers[HTTP_HEADER.COOKIE] += "%s %s=%s" % (conf.cDel or DEFAULT_COOKIE_DELIMITER, cookie.name, cookie.value) if kb.testMode: resetCookieJar(conf.cj) diff --git a/lib/request/connect.py b/lib/request/connect.py index 9056121dc..d7b135836 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -752,7 +752,7 @@ class Connect(object): evaluateCode("%s=%s" % (name, repr(value)), variables) if cookie: - for part in cookie.split(conf.pDel or DEFAULT_COOKIE_DELIMITER): + for part in cookie.split(conf.cDel or DEFAULT_COOKIE_DELIMITER): if '=' in part: name, value = part.split('=', 1) value = urldecode(value, convall=True) @@ -770,7 +770,7 @@ class Connect(object): elif re.search(r"\b%s=" % name, (post or "")): post = re.sub("((\A|\W)%s=)([^%s]+)" % (name, delimiter), "\g<1>%s" % value, post) elif re.search(r"\b%s=" % name, (cookie or "")): - cookie = re.sub("((\A|\W)%s=)([^%s]+)" % (name, conf.pDel or DEFAULT_COOKIE_DELIMITER), "\g<1>%s" % value, cookie) + cookie = re.sub("((\A|\W)%s=)([^%s]+)" % (name, conf.cDel or DEFAULT_COOKIE_DELIMITER), "\g<1>%s" % value, cookie) elif post is not None: post += "%s%s=%s" % (delimiter, name, value) else: diff --git a/lib/request/redirecthandler.py b/lib/request/redirecthandler.py index 3e2376cbf..6b84dcecc 100644 --- a/lib/request/redirecthandler.py +++ b/lib/request/redirecthandler.py @@ -112,7 +112,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): if redurl and kb.redirectChoice == REDIRECTION.YES: req.headers[HTTP_HEADER.HOST] = getHostHeader(redurl) if headers and HTTP_HEADER.SET_COOKIE in headers: - req.headers[HTTP_HEADER.COOKIE] = headers[HTTP_HEADER.SET_COOKIE].split(DEFAULT_COOKIE_DELIMITER)[0] + req.headers[HTTP_HEADER.COOKIE] = headers[HTTP_HEADER.SET_COOKIE].split(conf.cDel or DEFAULT_COOKIE_DELIMITER)[0] result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) else: result = fp diff --git a/sqlmap.conf b/sqlmap.conf index 5f363c567..d67d5360f 100644 --- a/sqlmap.conf +++ b/sqlmap.conf @@ -36,12 +36,15 @@ googleDork = # Data string to be sent through POST. data = -# Character used for splitting cookie values +# Character used for splitting parameter values pDel = # HTTP Cookie header. cookie = +# Character used for splitting cookie values +cDel = + # File containing cookies in Netscape/wget format loadCookies =