mirror of
				https://github.com/jtesta/ssh-audit.git
				synced 2025-11-04 11:12:15 +01:00 
			
		
		
		
	Improved IPv4/IPv6 error handling during client testing.
This commit is contained in:
		
							
								
								
									
										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(), [], [])
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user