(self, conn)
| 21 | ) |
| 22 | |
| 23 | def connection_handler(self, conn): |
| 24 | |
| 25 | server_banner = '' |
| 26 | sc_blob_count = 0 |
| 27 | cs_blob_count = 0 |
| 28 | |
| 29 | info = {} |
| 30 | |
| 31 | for blob in conn.blobs: |
| 32 | |
| 33 | # |
| 34 | # CS Blobs: Only interest is a client banner |
| 35 | # |
| 36 | if blob.direction == 'cs': |
| 37 | cs_blob_count += 1 |
| 38 | if cs_blob_count > 1: |
| 39 | continue |
| 40 | else: |
| 41 | blob.reassemble(allow_overlap=True, allow_padding=True) |
| 42 | if not blob.data: |
| 43 | continue |
| 44 | info['clientbanner'] = blob.data.split(b'\x0d')[0].rstrip() |
| 45 | if not info['clientbanner'].startswith(b'SSH'): |
| 46 | return conn # NOT AN SSH CONNECTION |
| 47 | try: |
| 48 | info['clientbanner'] = info['clientbanner'].decode( |
| 49 | 'utf-8') |
| 50 | except UnicodeDecodeError: |
| 51 | return conn |
| 52 | continue |
| 53 | |
| 54 | # |
| 55 | # SC Blobs: Banner and public key |
| 56 | # |
| 57 | sc_blob_count += 1 |
| 58 | blob.reassemble(allow_overlap=True, allow_padding=True) |
| 59 | if not blob.data: |
| 60 | continue |
| 61 | d = blob.data |
| 62 | |
| 63 | # Server Banner |
| 64 | if sc_blob_count == 1: |
| 65 | info['serverbanner'] = d.split(b'\x0d')[0].rstrip() |
| 66 | if not info['serverbanner'].startswith(b'SSH'): |
| 67 | return conn # NOT AN SSH CONNECTION |
| 68 | try: |
| 69 | info['serverbanner'] = info['serverbanner'].decode('utf-8') |
| 70 | except UnicodeDecodeError: |
| 71 | pass |
| 72 | continue |
| 73 | |
| 74 | # Key Exchange Packet/Messages |
| 75 | mlist = messagefactory(d) |
| 76 | stop_blobs = False |
| 77 | for m in mlist: |
| 78 | if m.message_code == 31 or m.message_code == 33: |
| 79 | info['host_pubkey'] = m.host_pub_key |
| 80 | stop_blobs = True |
nothing calls this directly
no test coverage detected