mirror of
https://github.com/jtesta/ssh-audit.git
synced 2024-12-23 06:27:41 +01:00
Improved IPv4/IPv6 error handling during client testing.
This commit is contained in:
parent
e3a59a3e21
commit
fd85e247e7
13
ssh-audit.py
13
ssh-audit.py
@ -2004,13 +2004,18 @@ class SSH(object): # pylint: disable=too-few-public-methods
|
|||||||
# auditing client connections).
|
# auditing client connections).
|
||||||
def listen_and_accept(self):
|
def listen_and_accept(self):
|
||||||
|
|
||||||
|
try:
|
||||||
# Socket to listen on all IPv4 addresses.
|
# Socket to listen on all IPv4 addresses.
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
s.bind(('0.0.0.0', self.__port))
|
s.bind(('0.0.0.0', self.__port))
|
||||||
s.listen()
|
s.listen()
|
||||||
self.__sock_map[s.fileno()] = s
|
self.__sock_map[s.fileno()] = s
|
||||||
|
except Exception as e:
|
||||||
|
print("Warning: failed to listen on any IPv4 interfaces.")
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
# Socket to listen on all IPv6 addresses.
|
# Socket to listen on all IPv6 addresses.
|
||||||
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
@ -2018,6 +2023,14 @@ class SSH(object): # pylint: disable=too-few-public-methods
|
|||||||
s.bind(('::', self.__port))
|
s.bind(('::', self.__port))
|
||||||
s.listen()
|
s.listen()
|
||||||
self.__sock_map[s.fileno()] = s
|
self.__sock_map[s.fileno()] = s
|
||||||
|
except Exception as e:
|
||||||
|
print("Warning: failed to listen on any IPv6 interfaces.")
|
||||||
|
pass
|
||||||
|
|
||||||
|
# If we failed to listen on any interfaces, terminate.
|
||||||
|
if len(self.__sock_map.keys()) == 0:
|
||||||
|
print("Error: failed to listen on any IPv4 and IPv6 interfaces!")
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
# Wait for a connection on either socket.
|
# Wait for a connection on either socket.
|
||||||
fds = select.select(self.__sock_map.keys(), [], [])
|
fds = select.select(self.__sock_map.keys(), [], [])
|
||||||
|
Loading…
Reference in New Issue
Block a user