def setUp(self): self.underlyingTransport = StringTransport() self.pt = insults.ServerProtocol() self.p = recvline.HistoricRecvLine() self.pt.protocolFactory = lambda: self.p self.pt.factory = self self.pt.makeConnection(self.underlyingTransport)
def manhole(username, password, globals): """Starts a ssh listener with password authentication using the given username and password. Clients connecting to the ssh listener will find themselves in a colored python shell with the supplied globals. Args: username(str): The username ssh clients should auth with. password(str): The password ssh clients should auth with. globals(dict): The variables to expose in the shell. Returns: twisted.internet.protocol.Factory: A factory to pass to ``listenTCP`` """ checker = checkers.InMemoryUsernamePasswordDatabaseDontUse( **{username: password}) rlm = manhole_ssh.TerminalRealm() rlm.chainedProtocolFactory = lambda: insults.ServerProtocol( ColoredManhole, dict(globals, __name__="__console__")) factory = manhole_ssh.ConchFactory(portal.Portal(rlm, [checker])) factory.publicKeys['ssh-rsa'] = Key.fromString(PUBLIC_KEY) factory.privateKeys['ssh-rsa'] = Key.fromString(PRIVATE_KEY) return factory
def start_listening(self): config = self.get_config() for listener in config.listeners: if listener["type"] == "http": self._listener_http(config, listener) elif listener["type"] == "manhole": checker = checkers.InMemoryUsernamePasswordDatabaseDontUse( matrix="rabbithole") rlm = manhole_ssh.TerminalRealm() rlm.chainedProtocolFactory = lambda: insults.ServerProtocol( ColoredManhole, { "__name__": "__console__", "hs": self, }) f = manhole_ssh.ConchFactory(portal.Portal(rlm, [checker])) reactor.listenTCP(listener["port"], f, interface=listener.get( "bind_address", '127.0.0.1')) else: logger.warn("Unrecognized listener type: %s", listener["type"])
def openShell(self, protocol): #serverProtocol = insults.ServerProtocol(remoteCLI, self) control = self.service.root.getServiceNamed('control').handle_command serverProtocol = insults.ServerProtocol(manhole.ColoredManhole, { 'app': self.service.root, 'stop': reactor.stop, 'c': control }) serverProtocol.makeConnection(protocol) protocol.makeConnection(session.wrapProtocol(serverProtocol))
def build_service(endpoint, authorized_keys, server_keys=None, namespace=dict()): realm = manhole_ssh.TerminalRealm() realm.chainedProtocolFactory = lambda:\ insults.ServerProtocol(ModifiedColoredManhole, namespace) factory = CustomKeysConch( portal.Portal(realm, [AuthorizedKeysChecker(authorized_keys)]), server_keys) return strports.service(endpoint, factory)
def test_interruptResetsInterpreterBuffer(self): """ L{manhole.Manhole.handle_INT} should cause the interpreter input buffer to be reset. """ transport = StringTransport() terminal = insults.ServerProtocol(manhole.Manhole) terminal.makeConnection(transport) protocol = terminal.terminalProtocol interpreter = protocol.interpreter interpreter.buffer.extend(["1", "2"]) protocol.handle_INT() self.assertFalse(interpreter.buffer)
def __init__(self): TerminalRealm.__init__(self) def userFactory(original, avatarId): user = OmsTerminalUser(original, avatarId) auth = getUtility(IAuthentication, context=None) user.principal = auth.getPrincipal(avatarId) return user self.chainedProtocolFactory = lambda: insults.ServerProtocol(OmsShellProtocol) self.sessionFactory = OmsTerminalSession self.userFactory = userFactory self.transportFactory = OmsTerminalSessionTransport
def setUp(self): if not ssh: raise unittest.SkipTest( "cryptography requirements missing, can't run historic " "recvline tests over ssh") u, p = b'testuser', b'testpass' rlm = TerminalRealm() rlm.userFactory = TestUser rlm.chainedProtocolFactory = lambda: insultsServer checker = checkers.InMemoryUsernamePasswordDatabaseDontUse() checker.addUser(u, p) ptl = portal.Portal(rlm) ptl.registerChecker(checker) sshFactory = ConchFactory(ptl) sshKey = keys._getPersistentRSAKey(filepath.FilePath(self.mktemp()), keySize=512) sshFactory.publicKeys[b"ssh-rsa"] = sshKey sshFactory.privateKeys[b"ssh-rsa"] = sshKey sshFactory.serverProtocol = self.serverProtocol sshFactory.startFactory() recvlineServer = self.serverProtocol() insultsServer = insults.ServerProtocol(lambda: recvlineServer) sshServer = sshFactory.buildProtocol(None) clientTransport = LoopbackRelay(sshServer) recvlineClient = NotifyingExpectableBuffer() insultsClient = insults.ClientProtocol(lambda: recvlineClient) sshClient = TestTransport(lambda: insultsClient, (), {}, u, p, self.WIDTH, self.HEIGHT) serverTransport = LoopbackRelay(sshClient) sshClient.makeConnection(clientTransport) sshServer.makeConnection(serverTransport) self.recvlineClient = recvlineClient self.sshClient = sshClient self.sshServer = sshServer self.clientTransport = clientTransport self.serverTransport = serverTransport return recvlineClient.onConnection
def execCommand(self, proto, cmd): try: chained_protocol = insults.ServerProtocol(BatchOmsShellProtocol) self.transportFactory( proto, chained_protocol, iconch.IConchUser(self.original), 80, 25) except Exception as e: print e oms_protocol = chained_protocol.terminalProtocol @defer.inlineCallbacks def spawn_command(): yield oms_protocol.spawn_commands(cmd) if oms_protocol.last_error: yield oms_protocol.spawn_command('last_error') proto.processEnded() spawn_command()
def manhole(settings: ManholeConfig, globals: Dict[str, Any]) -> Factory: """Starts a ssh listener with password authentication using the given username and password. Clients connecting to the ssh listener will find themselves in a colored python shell with the supplied globals. Args: username: The username ssh clients should auth with. password: The password ssh clients should auth with. globals: The variables to expose in the shell. Returns: A factory to pass to ``listenTCP`` """ username = settings.username password = settings.password.encode("ascii") priv_key = settings.priv_key if priv_key is None: priv_key = Key.fromString(PRIVATE_KEY) pub_key = settings.pub_key if pub_key is None: pub_key = Key.fromString(PUBLIC_KEY) checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(**{username: password}) rlm = manhole_ssh.TerminalRealm() # mypy ignored here because: # - can't deduce types of lambdas # - variable is Type[ServerProtocol], expr is Callable[[], ServerProtocol] rlm.chainedProtocolFactory = lambda: insults.ServerProtocol( # type: ignore[misc,assignment] SynapseManhole, dict(globals, __name__="__console__") ) factory = manhole_ssh.ConchFactory(portal.Portal(rlm, [checker])) # conch has the wrong type on these dicts (says bytes to bytes, # should be bytes to Keys judging by how it's used). factory.privateKeys[b"ssh-rsa"] = priv_key # type: ignore[assignment] factory.publicKeys[b"ssh-rsa"] = pub_key # type: ignore[assignment] return factory
def setUp(self): if not ssh: raise unittest.SkipTest( "Crypto requirements missing, can't run historic recvline tests over ssh" ) u, p = 'testuser', 'testpass' rlm = TerminalRealm() rlm.userFactory = TestUser rlm.chainedProtocolFactory = lambda: insultsServer ptl = portal.Portal( rlm, [checkers.InMemoryUsernamePasswordDatabaseDontUse(**{u: p})]) sshFactory = ConchFactory(ptl) sshFactory.serverProtocol = self.serverProtocol sshFactory.startFactory() recvlineServer = self.serverProtocol() insultsServer = insults.ServerProtocol(lambda: recvlineServer) sshServer = sshFactory.buildProtocol(None) clientTransport = LoopbackRelay(sshServer) recvlineClient = NotifyingExpectableBuffer() insultsClient = insults.ClientProtocol(lambda: recvlineClient) sshClient = TestTransport(lambda: insultsClient, (), {}, u, p, self.WIDTH, self.HEIGHT) serverTransport = LoopbackRelay(sshClient) sshClient.makeConnection(clientTransport) sshServer.makeConnection(serverTransport) self.recvlineClient = recvlineClient self.sshClient = sshClient self.sshServer = sshServer self.clientTransport = clientTransport self.serverTransport = serverTransport return recvlineClient.onConnection
def openShell(self, protocol): serverProtocol = insults.ServerProtocol(SSHServiceProtocol, self.avatar) serverProtocol.makeConnection(protocol) protocol.makeConnection(session.wrapProtocol(serverProtocol))
def makeProtocol(): return insults.ServerProtocol(manhole.ColoredManhole, namespace)
def chainProtocolFactory(): return insults.ServerProtocol(args['protocolFactory'], *args.get('protocolArgs', ()), **args.get('protocolKwArgs', {}))
def openShell(self, protocol): serverProtocol = insults.ServerProtocol(SSHProtocol, self, self.prompt, self.commands) serverProtocol.makeConnection(protocol) protocol.makeConnection(session.wrapProtocol(serverProtocol))
def do_python(): """Open a python interpreter. Use ^D (^Z on windows) to exit.""" protocol = insults.ServerProtocol(Manhole, self.namespace) self._switchTo(protocol)
def openShell(self, protocol): self.serverProtocol = insults.ServerProtocol(SSHDiSSOmniaGProtocol, self, self.api) self.serverProtocol.makeConnection(protocol) protocol.makeConnection(session.wrapProtocol(self.serverProtocol))
def chainedProtocolFactory(): return insults.ServerProtocol(manhole.Manhole, namespace)
def chainProtocolFactory(username=None): return insults.ServerProtocol( configdict["protocolFactory"], *configdict.get("protocolConfigdict", (username, )), **configdict.get("protocolKwArgs", {}), )
def chainProtocolFactory(): return insults.ServerProtocol(ColoredManhole, namespace)
def chainProtocolFactory(): return insults.ServerProtocol( ColoredManhole, dict(sketches=loaded_sketches, experiments=running_experiments))
def openShell(self, protocol): # <<< ? koja estefade mishe ? serverProtocol = insults.ServerProtocol(MiladSSHProtocol, self) serverProtocol.makeConnection(protocol) protocol.makeConnection(session.wrapProtocol(serverProtocol))
def chainProtocolFactory(username=None): return insults.ServerProtocol( configdict['protocolFactory'], *configdict.get('protocolConfigdict', (username,)), **configdict.get('protocolKwArgs', {}))
def makeProtocol(): namespace = makeNamespace() p = insults.ServerProtocol(manhole.ColoredManhole, namespace) return p
def openShell(self, protocol): server_protocol = insults.ServerProtocol(SwitchSSHShell, self, switch_core=self.switch_core) server_protocol.makeConnection(protocol) protocol.makeConnection(session.wrapProtocol(server_protocol))
def makeProtocol(): namespace = makeNamespace() p = insults.ServerProtocol(FriendlyManhole, namespace) return p
def __call__(self): return insults.ServerProtocol(manhole.ColoredManhole, self.namespace)
def openShell(self, protocol): serverProtocol = insults.ServerProtocol(SSHDemoProtocol, self) serverProtocol.makeConnection(protocol) protocol.makeConnection(session.wrapProtocol(serverProtocol))
def build_protocol(): p = insults.ServerProtocol(manhole.ColoredManhole, namespace) return p
def openShell(self, transport): honey_logging.console.info('Protocol being setup') self.transport = transport protocol = insults.ServerProtocol(HoneyProtocol, self) protocol.makeConnection(transport) transport.makeConnection(session.wrapProtocol(protocol))