diff --git a/lib/core/common.py b/lib/core/common.py index dcb60caad..3a99cc794 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -3236,7 +3236,7 @@ def logHTTPTraffic(requestLogMsg, responseLogMsg, startTime=None, endTime=None): """ if conf.harFile: - conf.httpCollector.collectRequest(requestLogMsg, responseLogMsg, startTime, endTime) + conf.httpCollector.collectRequest(requestLogMsg, responseLogMsg, startTime, endTime, scheme=conf.scheme) if conf.trafficFile: with kb.locks.log: diff --git a/lib/core/settings.py b/lib/core/settings.py index 5ad34c3a9..1886520a3 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.1" +VERSION = "1.10.11.2" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) diff --git a/lib/utils/har.py b/lib/utils/har.py index 0eb31a1c1..c684ed499 100644 --- a/lib/utils/har.py +++ b/lib/utils/har.py @@ -36,10 +36,10 @@ class HTTPCollector(object): def setExtendedArguments(self, arguments): self.extendedArguments = arguments - def collectRequest(self, requestMessage, responseMessage, startTime=None, endTime=None): + def collectRequest(self, requestMessage, responseMessage, startTime=None, endTime=None, scheme=None): self.messages.append(RawPair(requestMessage, responseMessage, startTime=startTime, endTime=endTime, - extendedArguments=self.extendedArguments)) + extendedArguments=self.extendedArguments, scheme=scheme)) def obtain(self): return {"log": { @@ -49,15 +49,16 @@ class HTTPCollector(object): }} class RawPair(object): - def __init__(self, request, response, startTime=None, endTime=None, extendedArguments=None): + def __init__(self, request, response, startTime=None, endTime=None, extendedArguments=None, scheme=None): self.request = getBytes(request) self.response = getBytes(response) self.startTime = startTime self.endTime = endTime self.extendedArguments = extendedArguments or {} + self.scheme = scheme # Note: of the target at the time of the request (as origin-form request lines don't carry one) def toEntry(self): - return Entry(request=Request.parse(self.request), response=Response.parse(self.response), + return Entry(request=Request.parse(self.request, self.scheme), response=Response.parse(self.response), startTime=self.startTime, endTime=self.endTime, extendedArguments=self.extendedArguments) @@ -86,7 +87,7 @@ class Entry(object): return out class Request(object): - def __init__(self, method, path, httpVersion, headers, postBody=None, raw=None, comment=None): + def __init__(self, method, path, httpVersion, headers, postBody=None, raw=None, comment=None, scheme=None): self.method = method self.path = path self.httpVersion = httpVersion @@ -94,9 +95,10 @@ class Request(object): self.postBody = postBody self.comment = comment.strip() if comment else comment self.raw = raw + self.scheme = scheme @classmethod - def parse(cls, raw): + def parse(cls, raw, scheme=None): request = HTTPRequest(raw) return cls(method=request.command, path=request.path, @@ -104,12 +106,16 @@ class Request(object): headers=request.headers, postBody=request.rfile.read(), comment=request.comment, - raw=raw) + raw=raw, + scheme=scheme) @property def url(self): + if re.search(r"(?i)\Ahttps?://", self.path or ""): # Note: absolute-form request target (e.g. refreshing/crawling/checking requests) + return self.path + host = self.headers.get("Host", "unknown") - return "http://%s%s" % (host, self.path) + return "%s://%s%s" % (self.scheme or "http", host, self.path) def toDict(self): out = { diff --git a/tests/test_har.py b/tests/test_har.py index 9b6142624..3ca6b547e 100644 --- a/tests/test_har.py +++ b/tests/test_har.py @@ -52,6 +52,14 @@ class TestHTTPCollector(unittest.TestCase): self.assertEqual(entries[0]["request"]["method"], "GET") self.assertEqual(entries[0]["response"]["status"], 200) + def test_request_url_scheme(self): + # Note: origin-form request lines carry no scheme (HTTPS targets used to be logged as 'http://'), while + # absolute-form ones (refreshing/crawling/checking requests) used to get the Host prepended to them + c = H.HTTPCollector() + for line, scheme in (("GET /?id=1", "https"), ("GET /?id=1", None), ("GET https://other.com:8443/x?id=1", "http")): + c.collectRequest(("%s HTTP/1.1\r\nHost: example.com\r\n\r\n" % line).encode(), b"HTTP/1.1 200 OK\r\n\r\n", startTime=1000, endTime=2000, scheme=scheme) + self.assertEqual([_["request"]["url"] for _ in c.obtain()["log"]["entries"]], ["https://example.com/?id=1", "http://example.com/?id=1", "https://other.com:8443/x?id=1"]) + class TestHTTPCollectorFactory(unittest.TestCase): def test_create_returns_collector(self):