The encrypted_data is the encrypted version of mac+msg+pad.
| 65 | |
| 66 | |
| 67 | class SSLv2(TLS): |
| 68 | """ |
| 69 | The encrypted_data is the encrypted version of mac+msg+pad. |
| 70 | """ |
| 71 | __slots__ = ["with_padding", "protected_record"] |
| 72 | name = "SSLv2" |
| 73 | fields_desc = [_SSLv2LengthField("len", None), |
| 74 | _SSLv2PadLenField("padlen", None), |
| 75 | _TLSMACField("mac", b""), |
| 76 | _SSLv2MsgListField("msg", []), |
| 77 | _SSLv2PadField("pad", "")] |
| 78 | |
| 79 | def __init__(self, *args, **kargs): |
| 80 | self.with_padding = kargs.get("with_padding", False) |
| 81 | self.protected_record = kargs.get("protected_record", None) |
| 82 | super(SSLv2, self).__init__(*args, **kargs) |
| 83 | |
| 84 | # Parsing methods |
| 85 | |
| 86 | def _sslv2_mac_verify(self, msg, mac): |
| 87 | secret = self.tls_session.rcs.cipher.key |
| 88 | if secret is None: |
| 89 | return True |
| 90 | |
| 91 | mac_len = self.tls_session.rcs.mac_len |
| 92 | if mac_len == 0: # should be TLS_NULL_WITH_NULL_NULL |
| 93 | return True |
| 94 | if len(mac) != mac_len: |
| 95 | return False |
| 96 | |
| 97 | read_seq_num = struct.pack("!I", self.tls_session.rcs.seq_num) |
| 98 | alg = self.tls_session.rcs.hash |
| 99 | h = alg.digest(secret + msg + read_seq_num) |
| 100 | return h == mac |
| 101 | |
| 102 | def pre_dissect(self, s): |
| 103 | if len(s) < 2: |
| 104 | raise Exception("Invalid record: header is too short.") |
| 105 | |
| 106 | msglen = struct.unpack("!H", s[:2])[0] |
| 107 | if msglen & 0x8000: |
| 108 | hdrlen = 2 |
| 109 | msglen_clean = msglen & 0x7fff |
| 110 | else: |
| 111 | hdrlen = 3 |
| 112 | msglen_clean = msglen & 0x3fff |
| 113 | |
| 114 | hdr = s[:hdrlen] |
| 115 | efrag = s[hdrlen:hdrlen + msglen_clean] |
| 116 | self.protected_record = s[:hdrlen + msglen_clean] |
| 117 | r = s[hdrlen + msglen_clean:] |
| 118 | |
| 119 | mac = pad = b"" |
| 120 | |
| 121 | # Decrypt (with implicit IV if block cipher) |
| 122 | mfrag = self._tls_decrypt(efrag) |
| 123 | |
| 124 | # Extract MAC |
no test coverage detected
searching dependent graphs…