Select the least protocol if banner has double protocol.

This commit is contained in:
Andris Raugulis 2016-09-07 12:22:51 +03:00
parent 19ee986e3d
commit 673b88b2b1

View File

@ -246,6 +246,12 @@ class SSH(object):
@classmethod
def parse(cls, banner):
mx = re.match(r'^SSH-(\d)\.\s*?(\d+)-SSH-(\d)\.\s*?(\d+)(|-.*)$', banner)
if mx is not None:
p1 = (int(mx.group(1)), int(mx.group(2)))
p2 = (int(mx.group(3)), int(mx.group(4)))
protocol = p1 if p1 < p2 else p2
banner = 'SSH-{0}.{1}{2}'.format(protocol[0], protocol[1], mx.group(5))
mx = re.match(r'^SSH-(\d)\.\s*?(\d+)(|-([^\s]*)(\s+(.*))?)$', banner)
if mx is None:
return None