MCPcopy Create free account
hub / github.com/USArmyResearchLab/Dshell / connection_handler

Method connection_handler

dshell/plugins/ssh/ssh-pubkey.py:23–98  ·  view source on GitHub ↗
(self, conn)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

messagefactoryFunction · 0.85
key_fingerprintFunction · 0.85
reassembleMethod · 0.80
writeMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected