Place for "dirty" Python related patches
()
| 49 | _rand = 0 |
| 50 | |
| 51 | def dirtyPatches(): |
| 52 | """ |
| 53 | Place for "dirty" Python related patches |
| 54 | """ |
| 55 | |
| 56 | # accept overly long result lines (e.g. SQLi results in HTTP header responses) |
| 57 | _http_client._MAXLINE = 1 * 1024 * 1024 |
| 58 | |
| 59 | # prevent double chunked encoding in case of sqlmap chunking (Note: Python3 does it automatically if 'Content-length' is missing) |
| 60 | if six.PY3: |
| 61 | if not hasattr(_http_client.HTTPConnection, "__send_output"): |
| 62 | _http_client.HTTPConnection.__send_output = _http_client.HTTPConnection._send_output |
| 63 | |
| 64 | def _send_output(self, *args, **kwargs): |
| 65 | if conf.get("chunked") and "encode_chunked" in kwargs: |
| 66 | kwargs["encode_chunked"] = False |
| 67 | self.__send_output(*args, **kwargs) |
| 68 | |
| 69 | _http_client.HTTPConnection._send_output = _send_output |
| 70 | |
| 71 | # add support for inet_pton() on Windows OS |
| 72 | if IS_WIN: |
| 73 | from thirdparty.wininetpton import win_inet_pton |
| 74 | |
| 75 | # Reference: https://github.com/nodejs/node/issues/12786#issuecomment-298652440 |
| 76 | codecs.register(lambda name: codecs.lookup("utf-8") if name == "cp65001" else None) |
| 77 | |
| 78 | # Reference: http://bugs.python.org/issue17849 |
| 79 | if hasattr(_http_client, "LineAndFileWrapper"): |
| 80 | def _(self, *args): |
| 81 | return self._readline() |
| 82 | |
| 83 | _http_client.LineAndFileWrapper._readline = _http_client.LineAndFileWrapper.readline |
| 84 | _http_client.LineAndFileWrapper.readline = _ |
| 85 | |
| 86 | # to prevent too much "guessing" in case of binary data retrieval |
| 87 | thirdparty.chardet.universaldetector.MINIMUM_THRESHOLD = 0.90 |
| 88 | |
| 89 | match = re.search(r" --method[= ](\w+)", " ".join(sys.argv)) |
| 90 | if match and match.group(1).upper() != PLACE.POST: |
| 91 | PLACE.CUSTOM_POST = PLACE.CUSTOM_POST.replace("POST", "%s (body)" % match.group(1)) |
| 92 | |
| 93 | # Reference: https://github.com/sqlmapproject/sqlmap/issues/4314 |
| 94 | try: |
| 95 | os.urandom(1) |
| 96 | except NotImplementedError: |
| 97 | if six.PY3: |
| 98 | os.urandom = lambda size: bytes(random.randint(0, 255) for _ in range(size)) |
| 99 | else: |
| 100 | os.urandom = lambda size: "".join(chr(random.randint(0, 255)) for _ in xrange(size)) |
| 101 | |
| 102 | # Reference: https://github.com/sqlmapproject/sqlmap/issues/5929 |
| 103 | try: |
| 104 | global collections |
| 105 | if not hasattr(collections, "MutableSet"): |
| 106 | import collections.abc |
| 107 | collections.MutableSet = collections.abc.MutableSet |
| 108 | except ImportError: |