From a6c26fe7926b21aea774f97a1c08e517c14f764b Mon Sep 17 00:00:00 2001 From: Tomas Zellerin Date: Wed, 15 Jan 2020 22:36:49 +0100 Subject: [PATCH] Python 3 binary-character fixes for two urllib requests (#4077) * Fix python3 binary - character mismatch in api.py Convert between text and binary data in api.py call to urllib.request and response from it. In python3 sqlmapapi -c it fixes, at least - not nice output from log/list commands - any command that POSTs data (including new) crashing sqlmapapi * Fix python3 binary - character mismatch in search.py Before: python3 sqlmap.py -g (...) [18:35:17] [INFO] using search result page #1 no usable links found. What do you want to do? [1] (re)try with DuckDuckGo (default) [2] (re)try with Bing [3] quit > 1 [18:35:21] [CRITICAL] unable to connect After: python3 sqlmap.py -g asfafw2fwesvzsdvaw (...) [18:37:30] [INFO] using search result page #1 no usable links found. What do you want to do? [1] (re)try with DuckDuckGo (default) [2] (re)try with Bing [3] quit > 1 [18:37:34] [INFO] found 26 results for your search dork expression, 16 of them are testable targets [18:37:34] [INFO] found a total of 16 targets URL 1: GET https:... do you want to test this URL? [Y/n/q] --- lib/utils/api.py | 4 ++-- lib/utils/search.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/utils/api.py b/lib/utils/api.py index 19593fc94..480193148 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -713,7 +713,7 @@ def _client(url, options=None): try: data = None if options is not None: - data = jsonize(options) + data = jsonize(options).encode("utf-8") headers = {"Content-Type": "application/json"} if DataStore.username or DataStore.password: @@ -721,7 +721,7 @@ def _client(url, options=None): req = _urllib.request.Request(url, data, headers) response = _urllib.request.urlopen(req) - text = response.read() + text = response.read().decode("utf-8") except: if options: logger.error("Failed to load and parse %s" % url) diff --git a/lib/utils/search.py b/lib/utils/search.py index 8c239b7df..616e58ffe 100644 --- a/lib/utils/search.py +++ b/lib/utils/search.py @@ -132,7 +132,7 @@ def _search(dork): regex = DUCKDUCKGO_REGEX try: - req = _urllib.request.Request(url, data=data, headers=requestHeaders) + req = _urllib.request.Request(url, data=data.encode("utf-8"), headers=requestHeaders) conn = _urllib.request.urlopen(req) requestMsg = "HTTP request:\nGET %s" % url