def makeConsoleServerFactory (): from twisted.conch.insults import insults from twisted.conch.manhole import ColoredManhole from twisted.conch.manhole_ssh import ConchFactory, TerminalRealm from twisted.conch.ssh import keys from twisted.cred import checkers, portal shell_password = str(uuid.uuid1()).split("-")[0] # Note - using unsafe credentials checker. checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(octopus=shell_password) def chainProtocolFactory(): return insults.ServerProtocol( ColoredManhole, dict( sketches = loaded_sketches, experiments = running_experiments ) ) rlm = TerminalRealm() rlm.chainedProtocolFactory = chainProtocolFactory ptl = portal.Portal(rlm, [checker]) factory = ConchFactory(ptl) factory.publicKeys[b"ssh-rsa"] = keys.Key.fromFile(os.path.join(data_path, "ssh-keys", "ssh_host_rsa_key.pub")) factory.privateKeys[b"ssh-rsa"] = keys.Key.fromFile(os.path.join(data_path, "ssh-keys", "ssh_host_rsa_key")) print "Octopus SSH access credentials are octopus:%s\n\n" % shell_password return factory
def make_service(args): def chain_protocol_factory(): return insults.ServerProtocol( args['protocolFactory'], *args.get('protocolArgs', ()), **args.get('protocolKwArgs', {})) m = service.MultiService() # Telnet manhole if True: f = protocol.ServerFactory() f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol, insults.ServerProtocol, args['protocolFactory'], *args.get('protocolArgs', ()), **args.get('protocolKwArgs', {})) tsvc = internet.TCPServer(args['telnet'], f) # @UndefinedVariable tsvc.setServiceParent(m) # SSH manhole if False: checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(user="******") rlm = TerminalRealm() rlm.chainedProtocolFactory = chain_protocol_factory ptl = portal.Portal(rlm, [checker]) f = ConchFactory(ptl) csvc = internet.TCPServer(args['ssh'], f) # @UndefinedVariable csvc.setServiceParent(m) return m
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 __init__(self, namespace = None): """Generates the manhole, contstrained to the namespace...""" realm = TerminalRealm() realm.chainedProtocolFactory = \ lambda: insults.ServerProtocol(ColoredManhole, namespace) xportal = portal.Portal(realm) xportal.registerChecker(SSHRestrictedPKDB([getpass.getuser(),])) ConchFactory.__init__(self, xportal)
def makeFactory(namespace): checker = checkers.InMemoryUsernamePasswordDatabaseDontUse( username='******') def chainProtocolFactory(): return insults.ServerProtocol(ColoredManhole, namespace) rlm = TerminalRealm() rlm.chainedProtocolFactory = chainProtocolFactory ptl = portal.Portal(rlm, [checker]) return ConchFactory(ptl)
def makeManholeService(ns, options): from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse checker = InMemoryUsernamePasswordDatabaseDontUse(admin="admin") def chainProtocolFactory(): return insults.ServerProtocol(ColoredManhole, namespace=ns) rlm = TerminalRealm() rlm.chainedProtocolFactory = chainProtocolFactory ptl = portal.Portal(rlm, [checker]) f = ConchFactory(ptl) return internet.TCPServer(options['manhole-port'], f)
def make_service(args): checker = DjangoSuperuserCredChecker() def chainProtocolFactory(): return insults.ServerProtocol( args["protocol_factory"], *args.get("protocol_args", ()), **args.get("protocol_kwargs", {}) ) realm = TerminalRealm() realm.chainedProtocolFactory = chainProtocolFactory ptl = portal.Portal(realm, [checker]) f = ConchFactory(ptl) return internet.TCPServer(args["ssh_port"], f)
def make_manhole_server(self, port, username, password): from twisted.application.internet import TCPServer from twisted.cred.portal import Portal from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse from twisted.conch.manhole import ColoredManhole from twisted.conch.manhole_ssh import ConchFactory, TerminalRealm from twisted.conch.insults.insults import ServerProtocol rlm = TerminalRealm() rlm.chainedProtocolFactory = lambda: ServerProtocol(ColoredManhole, None) auth_checker = InMemoryUsernamePasswordDatabaseDontUse(**{username: password}) return TCPServer(port, ConchFactory(Portal(rlm, [auth_checker])))
def startService(self): def chainedProtocolFactory(): def getManhole(): return Manhole({"store": self.store}) protocol = insults.ServerProtocol(ColoredManhole) protocol.protocolFactory = getManhole return protocol checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(**{str(self.username): self.password}) realm = TerminalRealm() realm.chainedProtocolFactory = chainedProtocolFactory p = portal.Portal(realm, [checker]) strports.service(self.listen, ConchFactory(p)).setServiceParent(self.parent)
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 makeService(port, namespace): namespace.update({ 'refund_kick': refund_kick, 'filter_tables': filter_tables, 'filter_games': filter_games, 'pp': pp, 'namespace': namespace }) global poker_service poker_service = namespace['poker_service'] def chainProtocolFactory(): return insults.ServerProtocol( ColoredManhole, namespace ) realm = TerminalRealm() realm.chainedProtocolFactory = chainProtocolFactory manhole_portal = portal.Portal(realm, [AllowAnyAccess()]) factory = ConchFactory(manhole_portal) return internet.TCPServer(port, factory, interface="127.0.0.1")
def makeService(self, options): settings.loadConfig(options["file"]) svc = service.MultiService() checker = PublicKeyCredentialsChecker(pubAuthKeys) namespace = {"host": "67.23.43.147", "user": "******", "pw": "pkxmen0w", "provision": provision} sshRealm = TerminalRealm() sshRealm.chainedProtocolFactory = chainedProtocolFactory(namespace) sshPortal = portal.Portal(sshRealm, [checker]) sshFactory = ConchFactory(sshPortal) sshService = strports.service(str(settings.config["ssh"]["port"]), sshFactory) sshService.setServiceParent(svc) site = server.Site(web.getRoot(), logPath=settings.config["web"]["log"]) if int(settings.config["web"]["port"]) != 0: siteService = strports.service(settings.config["web"]["port"], site) siteService.setServiceParent(svc) if int(settings.config["web"]["sslport"]) != 0: key = settings.config["web"]["key"] cert = settings.config["web"]["cert"] port = int(settings.config["web"]["sslport"]) sslFactory = ChainedOpenSSLContextFactory(key, cert) sslServer = internet.SSLServer(port, site, sslFactory) sslServer.setServiceParent(svc) return svc
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 makeService(self, options): settings.loadConfig(options["file"]) svc = service.MultiService() checker = PublicKeyCredentialsChecker(pubAuthKeys) from shaft import supervisor s = supervisor.get() # We don't start by default since this will be triggered by web #s.startMinecraft(jar=settings.config["minecraft"]["jar"], # path=settings.config["minecraft"]["home"]) s.setServiceParent(svc) namespace = {"s": s, "log": log, "p": s.protocols} sshRealm = TerminalRealm() sshRealm.chainedProtocolFactory = chainedProtocolFactory(namespace) sshPortal = portal.Portal(sshRealm, [checker]) sshFactory = ConchFactory(sshPortal) sshService = strports.service(str(settings.config["ssh"]["port"]), sshFactory) sshService.setServiceParent(svc) site = server.Site(web.getRoot(), logPath=settings.config["web"]["log"]) if int(settings.config["web"]["port"]) != 0: siteService = strports.service(settings.config["web"]["port"], site) siteService.setServiceParent(svc) return svc
def makeService(self, options): settings.loadConfig(options["file"]) svc = service.MultiService() checker = PublicKeyCredentialsChecker(pubAuthKeys) from shaft import supervisor s = supervisor.get() # We don't start by default since this will be triggered by web #s.startMinecraft(jar=settings.config["minecraft"]["jar"], # path=settings.config["minecraft"]["home"]) s.setServiceParent(svc) namespace = {"s": s, "log": log, "p": s.protocols} sshRealm = TerminalRealm() sshRealm.chainedProtocolFactory = chainedProtocolFactory(namespace) sshPortal = portal.Portal(sshRealm, [checker]) sshFactory = ConchFactory(sshPortal) sshService = strports.service(str(settings.config["ssh"]["port"]), sshFactory) sshService.setServiceParent(svc) site = server.Site(web.getRoot(), logPath=settings.config["web"]["log"]) if int(settings.config["web"]["port"]) != 0: siteService = strports.service(settings.config["web"]["port"], site) siteService.setServiceParent(svc) return svc