Beispiel #1
0
	def _mkSocket(self):
		if self._parentSocks5Proxy is not None:
			_sshInfo('Connecting to SSH server', (self._proxyAddress, self._proxyPort), 'over SOCKSv5 proxy', self['parentSocks5Proxy'])
			socket = _socksocket(_socket.AF_INET, _socket.SOCK_STREAM)
			socket.setproxy(_PROXY_TYPE_SOCKS5, self._parentSocks5Proxy['address'], self._parentSocks5Proxy['port'], username=self._parentSocks5Proxy['username'], password=self._parentSocks5Proxy['password'])
		else:
			_sshInfo('Connecting to SSH server', (self._proxyAddress, self._proxyPort))
			socket = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
		try:
			socket.connect((self._proxyAddress, self._proxyPort))
		except BaseException as e:
			if self._parentSocks5Proxy is not None:
				raise _MultiplexingProxy.Error('Could not connect to', (self._proxyAddress, self._proxyPort), 'over SOCKSv5 proxy', self['parentSocks5Proxy'], e)
			raise _MultiplexingProxy.Error('Could not connect to', (self._proxyAddress, self._proxyPort), e)
		transport = _paramiko.Transport(socket)
		transport.set_keepalive(self._timeout / 4)
		transport.get_security_options().ciphers = (self._cipher,)
		transport.get_security_options().digests = (self._hmac,)
		try:
			transport.start_client()
		except BaseException as e:
			raise _MultiplexingProxy.Error('Could not start an SSH client to', (self._proxyAddress, self._proxyPort), e)
		try:
			hostKey = transport.get_remote_server_key()
			if not self._publicKeyCompare(hostKey, self._serverFingerprintRSA) and not self._publicKeyCompare(hostKey, self._serverFingerprintECDSA):
				raise _MultiplexingProxy.Error('Host SSH fingerprint', self._prettyFingerprint(hostKey), 'did not match any of the fingerprints:', (self._serverFingerprintRSA, self._serverFingerprintECDSA))
			transport.auth_publickey(self._username, self._privateKey)
		except BaseException as e:
			raise _MultiplexingProxy.Error('Could not log in to the SSH server.', e)
		try:
			self._monitorThread = _SSHProxyMonitor(self, transport)
		except BaseException as e:
			raise _MultiplexingProxy.Error('Could not spawn a shell on the SSH server.', e)
		return transport
Beispiel #2
0
	def _mkOutgoingSocket(self):
		outgoingSocket = _socksocket(_socket.AF_INET, _socket.SOCK_STREAM)
		proxyAddress = self.getParentProxy().getProxyAddress()
		outgoingSocket.setproxy(_PROXY_TYPE_SOCKS5, proxyAddress['address'], proxyAddress['port'], username=proxyAddress['username'], password=proxyAddress['password'])
		outgoingSocket.connect(self.getDestination())
		return outgoingSocket
Beispiel #3
0
	def _mkOutgoingSocket(self):
		outgoingSocket = _socksocket(_socket.AF_INET, _socket.SOCK_STREAM)
		outgoingSocket.setproxy(_PROXY_TYPE_HTTP, self.getParentProxy().getProxyAddress(), self.getParentProxy().getProxyPort())
		outgoingSocket.connect(self.getDestination())
		return outgoingSocket