mirror of
https://github.com/jtesta/ssh-audit.git
synced 2024-12-23 06:27:41 +01:00
Correct IPv6 parsing in command-line. Fixes #26.
This commit is contained in:
parent
96d442ec62
commit
d8eb46d766
15
ssh-audit.py
15
ssh-audit.py
@ -169,14 +169,17 @@ class AuditConf(object):
|
|||||||
usage_cb()
|
usage_cb()
|
||||||
if oport is not None:
|
if oport is not None:
|
||||||
host = args[0]
|
host = args[0]
|
||||||
port = utils.parse_int(oport)
|
|
||||||
else:
|
else:
|
||||||
s = args[0].split(':')
|
mx = re.match(r'^\[([^\]]+)\](?::(.*))?$', args[0])
|
||||||
host = s[0].strip()
|
if bool(mx):
|
||||||
if len(s) == 2:
|
host, oport = mx.group(1), mx.group(2)
|
||||||
oport, port = s[1], utils.parse_int(s[1])
|
|
||||||
else:
|
else:
|
||||||
oport, port = '22', 22
|
s = args[0].split(':')
|
||||||
|
if len(s) > 2:
|
||||||
|
host, oport = args[0], '22'
|
||||||
|
else:
|
||||||
|
host, oport = s[0], s[1] if len(s) > 1 else '22'
|
||||||
|
port = utils.parse_int(oport)
|
||||||
if not host:
|
if not host:
|
||||||
usage_cb('host is empty')
|
usage_cb('host is empty')
|
||||||
if port <= 0 or port > 65535:
|
if port <= 0 or port > 65535:
|
||||||
|
@ -148,6 +148,14 @@ class TestAuditConf(object):
|
|||||||
self._test_conf(conf, host='localhost', port=2222)
|
self._test_conf(conf, host='localhost', port=2222)
|
||||||
conf = c('-p 2222 localhost')
|
conf = c('-p 2222 localhost')
|
||||||
self._test_conf(conf, host='localhost', port=2222)
|
self._test_conf(conf, host='localhost', port=2222)
|
||||||
|
conf = c('2001:4860:4860::8888')
|
||||||
|
self._test_conf(conf, host='2001:4860:4860::8888')
|
||||||
|
conf = c('[2001:4860:4860::8888]:22')
|
||||||
|
self._test_conf(conf, host='2001:4860:4860::8888')
|
||||||
|
conf = c('[2001:4860:4860::8888]:2222')
|
||||||
|
self._test_conf(conf, host='2001:4860:4860::8888', port=2222)
|
||||||
|
conf = c('-p 2222 2001:4860:4860::8888')
|
||||||
|
self._test_conf(conf, host='2001:4860:4860::8888', port=2222)
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
conf = c('localhost:')
|
conf = c('localhost:')
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
|
Loading…
Reference in New Issue
Block a user