Skip to content

Commit 397a3bd

Browse files
committed
Implements #6177
1 parent 097f4d2 commit 397a3bd

5 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎lib/core/common.py‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5645,7 +5645,7 @@ def pollProcess(process, suppress_errors=False):
56455645

56465646
def parseRequestFile(reqFile, checkParams=True):
56475647
"""
5648-
Parses WebScarab and Burp logs and adds results to the target URL list
5648+
Parses WebScarab, Burp and HAR logs and adds results to the target URL list
56495649
56505650
>>> handle, reqFile = tempfile.mkstemp(suffix=".req")
56515651
>>> content = b"POST / HTTP/1.0\\nUser-agent: foobar\\nHost: www.example.com\\n\\nid=1\\n"
@@ -5689,7 +5689,23 @@ def _parseBurpLog(content):
56895689
Parses Burp logs
56905690
"""
56915691

5692-
if not re.search(BURP_REQUEST_REGEX, content, re.I | re.S):
5692+
if re.search(r"\A\s*\{.*\"entries\"", content[:1000], re.S):
5693+
reqResList = []
5694+
try:
5695+
entries = json.loads(content)["log"]["entries"]
5696+
except (ValueError, KeyError, TypeError):
5697+
entries = []
5698+
for entry in entries: # Note: HAR (HTTP Archive) logs (e.g. ZAP, browsers) - re-serialized into raw requests
5699+
try:
5700+
request = entry["request"]
5701+
url = request["url"]
5702+
headers = [(_["name"], _["value"]) for _ in request.get("headers", []) if not _["name"].startswith(':')]
5703+
if not any(_[0].upper() == HTTP_HEADER.HOST.upper() for _ in headers):
5704+
headers.insert(0, (HTTP_HEADER.HOST, _urllib.parse.urlsplit(url).netloc))
5705+
reqResList.append("%s %s HTTP/1.1\n%s\n\n%s" % (request["method"], url, "\n".join("%s: %s" % _ for _ in headers), (request.get("postData") or {}).get("text") or ""))
5706+
except (KeyError, TypeError, AttributeError):
5707+
continue
5708+
elif not re.search(BURP_REQUEST_REGEX, content, re.I | re.S):
56935709
if re.search(BURP_XML_HISTORY_REGEX, content, re.I | re.S):
56945710
reqResList = []
56955711
for match in re.finditer(BURP_XML_HISTORY_REGEX, content, re.I | re.S):

‎lib/core/settings.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from thirdparty import six
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.10.11.7"
22+
VERSION = "1.10.11.8"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

‎lib/parse/cmdline.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def cmdLineParser(argv=None):
130130
help="Connection string for direct database connection")
131131

132132
target.add_argument("-l", dest="logFile",
133-
help="Parse target(s) from Burp or WebScarab proxy log file")
133+
help="Parse target(s) from Burp, WebScarab or HAR log file")
134134

135135
target.add_argument("-m", dest="bulkFile",
136136
help="Scan multiple targets given in a textual file")

‎sqlmap.conf‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ url =
1212
# oracle://USER:PASSWORD@DBMS_IP:DBMS_PORT/DATABASE_SID
1313
direct =
1414

15-
# Parse targets from Burp or WebScarab logs
15+
# Parse targets from Burp, WebScarab or HAR logs
1616
# Valid: Burp proxy (http://portswigger.net/suite/) requests log file path
1717
# or WebScarab proxy (http://www.owasp.org/index.php/Category:OWASP_WebScarab_Project)
18-
# 'conversations/' folder path
18+
# 'conversations/' folder path or HAR (HTTP Archive) file path
1919
logFile =
2020

2121
# Scan multiple targets enlisted in a given textual file

‎tests/test_common.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import atexit
2323
import base64
24+
import json
2425
import os
2526
import shutil
2627
import sys
@@ -537,6 +538,22 @@ def test_burp_xml_history_protocol(self):
537538
self.assertEqual([_[0] for _ in targets], ["https://www.target.com:8443/vuln.php?id=1", "http://www.target.com:443/vuln.php?id=1", "https://www.target.com:443/vuln.php?id=1", "http://www.target.com:8080/vuln.php?id=1"])
538539
self.assertTrue(all("://" not in value for _ in targets for key, value in _[4] if key == "Host"))
539540

541+
def test_har_log(self):
542+
# Note: HAR (HTTP Archive) logs (e.g. ZAP, browsers), including HTTP/2 entries (pseudo-headers, no Host)
543+
entries = [
544+
{"request": {"method": "GET", "url": "https://www.target.com:8443/vuln.php?id=1", "headers": [{"name": "Host", "value": "www.target.com:8443"}, {"name": "Cookie", "value": "SID=xyz"}]}},
545+
{"request": {"method": "POST", "url": "https://www.target.com/api", "headers": [{"name": ":authority", "value": "www.target.com"}, {"name": "content-type", "value": "application/json"}], "postData": {"text": '{"id": 1}'}}},
546+
{"request": {"method": "GET", "url": "https://www.target.com/logo.png", "headers": []}},
547+
]
548+
path = _write_temp(json.dumps({"log": {"version": "1.2", "entries": entries}}), ".har")
549+
try:
550+
targets = list(parseRequestFile(path))
551+
finally:
552+
os.unlink(path)
553+
554+
self.assertEqual([_[:4] for _ in targets], [("https://www.target.com:8443/vuln.php?id=1", HTTPMETHOD.GET, None, "SID=xyz"), ("https://www.target.com/api", HTTPMETHOD.POST, '{"id": 1}', None)])
555+
self.assertEqual(targets[1][4], (("Host", "www.target.com"), ("content-type", "application/json")))
556+
540557
def test_post_body_captured(self):
541558
content = (
542559
"======================================================\n"

0 commit comments

Comments
 (0)