diff --git a/examples/contrib/xss_scanner.py b/examples/contrib/xss_scanner.py index 4cb03ad71..683f23fdd 100644 --- a/examples/contrib/xss_scanner.py +++ b/examples/contrib/xss_scanner.py @@ -54,6 +54,7 @@ BACK_WALL = b"3847asd" PAYLOAD = b"""s'd"aoso[sb]po(pc)se;sl/bsl\\eq=""" FULL_PAYLOAD = FRONT_WALL + PAYLOAD + BACK_WALL + # A XSSData is a named tuple with the following fields: # - url -> str # - injection_point -> str @@ -65,6 +66,7 @@ class XSSData(NamedTuple): exploit: str line: str + # A SQLiData is named tuple with the following fields: # - url -> str # - injection_point -> str diff --git a/mitmproxy/contrib/kaitaistruct/gif.py b/mitmproxy/contrib/kaitaistruct/gif.py index 5279fe0e0..76d7fc167 100644 --- a/mitmproxy/contrib/kaitaistruct/gif.py +++ b/mitmproxy/contrib/kaitaistruct/gif.py @@ -30,7 +30,7 @@ class Gif(KaitaiStruct): self.hdr = self._root.Header(self._io, self, self._root) self.logical_screen_descriptor = self._root.LogicalScreenDescriptorStruct(self._io, self, self._root) if self.logical_screen_descriptor.has_color_table: - self._raw_global_color_table = self._io.read_bytes(self.logical_screen_descriptor.color_table_size * 3) + self._raw_global_color_table = self._io.read_bytes((self.logical_screen_descriptor.color_table_size * 3)) io = KaitaiStream(BytesIO(self._raw_global_color_table)) self.global_color_table = self._root.ColorTable(io, self, self._root) @@ -99,7 +99,7 @@ class Gif(KaitaiStruct): self.height = self._io.read_u2le() self.flags = self._io.read_u1() if self.has_color_table: - self._raw_local_color_table = self._io.read_bytes(self.color_table_size * 3) + self._raw_local_color_table = self._io.read_bytes((self.color_table_size * 3)) io = KaitaiStream(BytesIO(self._raw_local_color_table)) self.local_color_table = self._root.ColorTable(io, self, self._root) @@ -168,7 +168,7 @@ class Gif(KaitaiStruct): self._parent = _parent self._root = _root if _root else self self.magic = self._io.ensure_fixed_contents(struct.pack('3b', 71, 73, 70)) - self.version = (self._io.read_bytes(3)).decode("ASCII") + self.version = (self._io.read_bytes(3)).decode(u"ASCII") class ExtGraphicControl(KaitaiStruct): diff --git a/mitmproxy/contrib/kaitaistruct/google_protobuf.py b/mitmproxy/contrib/kaitaistruct/google_protobuf.py index c0b90b264..fe2336cc9 100644 --- a/mitmproxy/contrib/kaitaistruct/google_protobuf.py +++ b/mitmproxy/contrib/kaitaistruct/google_protobuf.py @@ -94,7 +94,7 @@ class GoogleProtobuf(KaitaiStruct): if hasattr(self, '_m_wire_type'): return self._m_wire_type if hasattr(self, '_m_wire_type') else None - self._m_wire_type = self._root.Pair.WireTypes(self.key.value & 7) + self._m_wire_type = self._root.Pair.WireTypes((self.key.value & 7)) return self._m_wire_type if hasattr(self, '_m_wire_type') else None @property diff --git a/mitmproxy/contrib/kaitaistruct/jpeg.py b/mitmproxy/contrib/kaitaistruct/jpeg.py index 6c97a3f7c..33fc012fa 100644 --- a/mitmproxy/contrib/kaitaistruct/jpeg.py +++ b/mitmproxy/contrib/kaitaistruct/jpeg.py @@ -79,23 +79,23 @@ class Jpeg(KaitaiStruct): if ((self.marker != self._root.Segment.MarkerEnum.soi) and (self.marker != self._root.Segment.MarkerEnum.eoi)) : _on = self.marker if _on == self._root.Segment.MarkerEnum.sos: - self._raw_data = self._io.read_bytes(self.length - 2) + self._raw_data = self._io.read_bytes((self.length - 2)) io = KaitaiStream(BytesIO(self._raw_data)) self.data = self._root.SegmentSos(io, self, self._root) elif _on == self._root.Segment.MarkerEnum.app1: - self._raw_data = self._io.read_bytes(self.length - 2) + self._raw_data = self._io.read_bytes((self.length - 2)) io = KaitaiStream(BytesIO(self._raw_data)) self.data = self._root.SegmentApp1(io, self, self._root) elif _on == self._root.Segment.MarkerEnum.sof0: - self._raw_data = self._io.read_bytes(self.length - 2) + self._raw_data = self._io.read_bytes((self.length - 2)) io = KaitaiStream(BytesIO(self._raw_data)) self.data = self._root.SegmentSof0(io, self, self._root) elif _on == self._root.Segment.MarkerEnum.app0: - self._raw_data = self._io.read_bytes(self.length - 2) + self._raw_data = self._io.read_bytes((self.length - 2)) io = KaitaiStream(BytesIO(self._raw_data)) self.data = self._root.SegmentApp0(io, self, self._root) else: - self.data = self._io.read_bytes(self.length - 2) + self.data = self._io.read_bytes((self.length - 2)) if self.marker == self._root.Segment.MarkerEnum.sos: self.image_data = self._io.read_bytes_full() @@ -131,9 +131,9 @@ class Jpeg(KaitaiStruct): self._io = _io self._parent = _parent self._root = _root if _root else self - self.magic = (self._io.read_bytes_term(0, False, True, True)).decode("ASCII") + self.magic = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") _on = self.magic - if _on == "Exif": + if _on == u"Exif": self.body = self._root.ExifInJpeg(self._io, self, self._root) @@ -199,7 +199,7 @@ class Jpeg(KaitaiStruct): self._io = _io self._parent = _parent self._root = _root if _root else self - self.magic = (self._io.read_bytes(5)).decode("ASCII") + self.magic = (self._io.read_bytes(5)).decode(u"ASCII") self.version_major = self._io.read_u1() self.version_minor = self._io.read_u1() self.density_units = self._root.SegmentApp0.DensityUnit(self._io.read_u1()) @@ -207,4 +207,4 @@ class Jpeg(KaitaiStruct): self.density_y = self._io.read_u2be() self.thumbnail_x = self._io.read_u1() self.thumbnail_y = self._io.read_u1() - self.thumbnail = self._io.read_bytes((self.thumbnail_x * self.thumbnail_y) * 3) + self.thumbnail = self._io.read_bytes(((self.thumbnail_x * self.thumbnail_y) * 3)) diff --git a/mitmproxy/contrib/kaitaistruct/png.py b/mitmproxy/contrib/kaitaistruct/png.py index 95ef365ef..45074d703 100644 --- a/mitmproxy/contrib/kaitaistruct/png.py +++ b/mitmproxy/contrib/kaitaistruct/png.py @@ -37,7 +37,7 @@ class Png(KaitaiStruct): while True: _ = self._root.Chunk(self._io, self, self._root) self.chunks.append(_) - if ((_.type == "IEND") or (self._io.is_eof())) : + if ((_.type == u"IEND") or (self._io.is_eof())) : break class Rgb(KaitaiStruct): @@ -56,45 +56,45 @@ class Png(KaitaiStruct): self._parent = _parent self._root = _root if _root else self self.len = self._io.read_u4be() - self.type = (self._io.read_bytes(4)).decode("UTF-8") + self.type = (self._io.read_bytes(4)).decode(u"UTF-8") _on = self.type - if _on == "iTXt": + if _on == u"iTXt": self._raw_body = self._io.read_bytes(self.len) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.InternationalTextChunk(io, self, self._root) - elif _on == "gAMA": + elif _on == u"gAMA": self._raw_body = self._io.read_bytes(self.len) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.GamaChunk(io, self, self._root) - elif _on == "tIME": + elif _on == u"tIME": self._raw_body = self._io.read_bytes(self.len) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.TimeChunk(io, self, self._root) - elif _on == "PLTE": + elif _on == u"PLTE": self._raw_body = self._io.read_bytes(self.len) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.PlteChunk(io, self, self._root) - elif _on == "bKGD": + elif _on == u"bKGD": self._raw_body = self._io.read_bytes(self.len) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.BkgdChunk(io, self, self._root) - elif _on == "pHYs": + elif _on == u"pHYs": self._raw_body = self._io.read_bytes(self.len) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.PhysChunk(io, self, self._root) - elif _on == "tEXt": + elif _on == u"tEXt": self._raw_body = self._io.read_bytes(self.len) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.TextChunk(io, self, self._root) - elif _on == "cHRM": + elif _on == u"cHRM": self._raw_body = self._io.read_bytes(self.len) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.ChrmChunk(io, self, self._root) - elif _on == "sRGB": + elif _on == u"sRGB": self._raw_body = self._io.read_bytes(self.len) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.SrgbChunk(io, self, self._root) - elif _on == "zTXt": + elif _on == u"zTXt": self._raw_body = self._io.read_bytes(self.len) io = KaitaiStream(BytesIO(self._raw_body)) self.body = self._root.CompressedTextChunk(io, self, self._root) @@ -199,7 +199,7 @@ class Png(KaitaiStruct): self._io = _io self._parent = _parent self._root = _root if _root else self - self.keyword = (self._io.read_bytes_term(0, False, True, True)).decode("UTF-8") + self.keyword = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") self.compression_method = self._io.read_u1() self._raw_text_datastream = self._io.read_bytes_full() self.text_datastream = zlib.decompress(self._raw_text_datastream) @@ -264,12 +264,12 @@ class Png(KaitaiStruct): self._io = _io self._parent = _parent self._root = _root if _root else self - self.keyword = (self._io.read_bytes_term(0, False, True, True)).decode("UTF-8") + self.keyword = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") self.compression_flag = self._io.read_u1() self.compression_method = self._io.read_u1() - self.language_tag = (self._io.read_bytes_term(0, False, True, True)).decode("ASCII") - self.translated_keyword = (self._io.read_bytes_term(0, False, True, True)).decode("UTF-8") - self.text = (self._io.read_bytes_full()).decode("UTF-8") + self.language_tag = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") + self.translated_keyword = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") + self.text = (self._io.read_bytes_full()).decode(u"UTF-8") class TextChunk(KaitaiStruct): @@ -277,8 +277,8 @@ class Png(KaitaiStruct): self._io = _io self._parent = _parent self._root = _root if _root else self - self.keyword = (self._io.read_bytes_term(0, False, True, True)).decode("iso8859-1") - self.text = (self._io.read_bytes_full()).decode("iso8859-1") + self.keyword = (self._io.read_bytes_term(0, False, True, True)).decode(u"iso8859-1") + self.text = (self._io.read_bytes_full()).decode(u"iso8859-1") class TimeChunk(KaitaiStruct): diff --git a/mitmproxy/contrib/wbxml/ASCommandResponse.py b/mitmproxy/contrib/wbxml/ASCommandResponse.py index c11cc9e5b..34755cbe6 100644 --- a/mitmproxy/contrib/wbxml/ASCommandResponse.py +++ b/mitmproxy/contrib/wbxml/ASCommandResponse.py @@ -41,7 +41,7 @@ class ASCommandResponse: raise ValueError("Empty WBXML body passed") except Exception as e: self.xmlString = None - raise ValueError(f"Error: {e}") + raise ValueError("Error: {0}".format(e)) def getWBXMLBytes(self): return self.wbxmlBytes diff --git a/mitmproxy/contrib/wbxml/ASWBXML.py b/mitmproxy/contrib/wbxml/ASWBXML.py index cd56d7c6e..b63838a75 100644 --- a/mitmproxy/contrib/wbxml/ASWBXML.py +++ b/mitmproxy/contrib/wbxml/ASWBXML.py @@ -861,7 +861,7 @@ class ASWBXML: if (newCodePage >= 0 and newCodePage < 25): self.currentCodePage = newCodePage else: - raise InvalidDataException(f"Unknown code page ID 0x{currentByte:X} encountered in WBXML") + raise InvalidDataException("Unknown code page ID 0x{0:X} encountered in WBXML".format(currentByte)) elif ( currentByte == GlobalTokens.END ): if (currentNode != None and currentNode.parentNode != None): currentNode = currentNode.parentNode @@ -878,14 +878,14 @@ class ASWBXML: currentNode.appendChild(newTextNode) elif ( currentByte in unusedArray): - raise InvalidDataException(f"Encountered unknown global token 0x{currentByte:X}.") + raise InvalidDataException("Encountered unknown global token 0x{0:X}.".format(currentByte)) else: hasAttributes = (currentByte & 0x80) > 0 hasContent = (currentByte & 0x40) > 0 token = currentByte & 0x3F if (hasAttributes): - raise InvalidDataException(f"Token 0x{token:X} has attributes.") + raise InvalidDataException("Token 0x{0:X} has attributes.".format(token)) strTag = self.codePages[self.currentCodePage].getTag(token) if (strTag == None): diff --git a/mitmproxy/contrib/wbxml/ASWBXMLByteQueue.py b/mitmproxy/contrib/wbxml/ASWBXMLByteQueue.py index 49aef9a3d..e457fc509 100644 --- a/mitmproxy/contrib/wbxml/ASWBXMLByteQueue.py +++ b/mitmproxy/contrib/wbxml/ASWBXMLByteQueue.py @@ -52,7 +52,7 @@ class ASWBXMLByteQueue(Queue): def dequeueAndLog(self): singleByte = self.get() self.bytesDequeued += 1 - logging.debug(f"Dequeued byte 0x{singleByte:X} ({self.bytesDequeued} total)") + logging.debug("Dequeued byte 0x{0:X} ({1} total)".format(singleByte, self.bytesDequeued)) return singleByte """ diff --git a/mitmproxy/platform/windows.py b/mitmproxy/platform/windows.py index ce92c0e78..46047a954 100644 --- a/mitmproxy/platform/windows.py +++ b/mitmproxy/platform/windows.py @@ -288,7 +288,7 @@ class Redirect(threading.Thread): while True: try: packet = self.windivert.recv() - except OSError as e: + except WindowsError as e: if e.winerror == 995: return else: @@ -306,7 +306,7 @@ class Redirect(threading.Thread): """ try: return self.windivert.recv() - except OSError as e: + except WindowsError as e: if e.winerror == 995: return None else: diff --git a/mitmproxy/proxy/protocol/websocket.py b/mitmproxy/proxy/protocol/websocket.py index a754b2193..32d170b48 100644 --- a/mitmproxy/proxy/protocol/websocket.py +++ b/mitmproxy/proxy/protocol/websocket.py @@ -1,5 +1,4 @@ import queue -import socket from OpenSSL import SSL import wsproto diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py index 01e17c1b4..60c3e2e86 100644 --- a/mitmproxy/tools/main.py +++ b/mitmproxy/tools/main.py @@ -3,6 +3,7 @@ This file must be kept in a python2.7 and python3.5 compatible syntax! DO NOT use type annotations or other python3.6-only features that makes this file unparsable by older interpreters! """ +from __future__ import print_function # this is here for the version check to work on Python 2. import sys diff --git a/tox.ini b/tox.ini index 6df8dd72e..e3ba52d2e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py35, py36, py37, py38, flake8, filename_matching, mypy, individual_coverage, docs +envlist = py35, py36, py37, py38, py39, flake8, filename_matching, mypy, individual_coverage, docs skipsdist = True toxworkdir={env:TOX_WORK_DIR:.tox}