mirror of
https://github.com/jtesta/ssh-audit.git
synced 2024-11-26 04:21:41 +01:00
Do not capture unnecessary regex groups.
This commit is contained in:
parent
c68211b8e7
commit
d07d5078cb
13
ssh-audit.py
13
ssh-audit.py
@ -210,8 +210,9 @@ class SSH(object):
|
|||||||
MSG_KEXDH_REPLY = 32
|
MSG_KEXDH_REPLY = 32
|
||||||
|
|
||||||
class Banner(object):
|
class Banner(object):
|
||||||
_RXP, _RXR = r'SSH-(\d)\.\s*?(\d+)', r'(|-([^\s]*)(\s+(.*))?)'
|
_RXP, _RXR = r'SSH-\d\.\s*?\d+', r'(-([^\s]*)(?:\s+(.*))?)?'
|
||||||
RX_BANNER = re.compile(r'^({0}((-{0})*)){1}$'.format(_RXP, _RXR))
|
RX_PROTOCOL = re.compile(_RXP.replace('\d', '(\d)'))
|
||||||
|
RX_BANNER = re.compile(r'^({0}(?:(?:-{0})*)){1}$'.format(_RXP, _RXR))
|
||||||
|
|
||||||
def __init__(self, protocol, software, comments):
|
def __init__(self, protocol, software, comments):
|
||||||
self.__protocol = protocol
|
self.__protocol = protocol
|
||||||
@ -252,12 +253,12 @@ class SSH(object):
|
|||||||
mx = cls.RX_BANNER.match(banner)
|
mx = cls.RX_BANNER.match(banner)
|
||||||
if mx is None:
|
if mx is None:
|
||||||
return None
|
return None
|
||||||
protocol = min(re.findall(cls._RXP, mx.group(1)))
|
protocol = min(re.findall(cls.RX_PROTOCOL, mx.group(1)))
|
||||||
protocol = (int(protocol[0]), int(protocol[1]))
|
protocol = (int(protocol[0]), int(protocol[1]))
|
||||||
software = (mx.group(9) or '').strip() or None
|
software = (mx.group(3) or '').strip() or None
|
||||||
if software is None and mx.group(8).startswith('-'):
|
if software is None and (mx.group(2) or '').startswith('-'):
|
||||||
software = ''
|
software = ''
|
||||||
comments = (mx.group(11) or '').strip() or None
|
comments = (mx.group(4) or '').strip() or None
|
||||||
return cls(protocol, software, comments)
|
return cls(protocol, software, comments)
|
||||||
|
|
||||||
class Socket(ReadBuf, WriteBuf):
|
class Socket(ReadBuf, WriteBuf):
|
||||||
|
Loading…
Reference in New Issue
Block a user