From 72984a578df61f4913c8026c3d9315ea34e4bc1b Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 12 Feb 2013 12:42:12 +0100 Subject: [PATCH] Update for --load-cookies --- lib/core/common.py | 12 ++++++++++-- lib/core/settings.py | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 20da2d876..6ff351807 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -104,6 +104,7 @@ from lib.core.settings import MIN_ENCODED_LEN_CHECK from lib.core.settings import MIN_TIME_RESPONSES from lib.core.settings import MIN_VALID_DELAYED_RESPONSE from lib.core.settings import ML +from lib.core.settings import NETSCAPE_FORMAT_HEADER_COOKIES from lib.core.settings import NULL from lib.core.settings import PARAMETER_AMP_MARKER from lib.core.settings import PARAMETER_SEMICOLON_MARKER @@ -3354,8 +3355,15 @@ def resetCookieJar(cookieJar): cookieJar.clear() else: try: - cookieJar.load(conf.loadCookies) - cookieJar.clear_expired_cookies() + content = readCachedFileContent(conf.loadCookies) + lines = filter(None, (line.strip() for line in content.split("\n") if not line.startswith('#'))) + handle, filename = tempfile.mkstemp() + os.close(handle) + with open(filename, "w+b") as f: + f.write("%s\n" % NETSCAPE_FORMAT_HEADER_COOKIES) + for line in lines: + f.write("\n%s" % "\t".join(line.split())) + cookieJar.load(filename) except cookielib.LoadError, msg: errMsg = "there was a problem loading " errMsg += "cookies file ('%s')" % msg diff --git a/lib/core/settings.py b/lib/core/settings.py index b433d9f8e..eff5545ef 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -516,6 +516,9 @@ MIN_ENCODED_LEN_CHECK = 5 # Timeout in seconds in which Metasploit remote session has to be initialized METASPLOIT_SESSION_TIMEOUT = 120 +# Reference: http://www.cookiecentral.com/faq/#3.5 +NETSCAPE_FORMAT_HEADER_COOKIES = "# Netscape HTTP Cookie File." + # CSS style used in HTML dump format HTML_DUMP_CSS_STYLE = """