def makeService(self, options): """ Make services to handle push event notifications. """ # check confguration file is specified and exists if not options["config"]: raise ValueError( 'Configuration file not specified (try to check --help option)' ) cfgFileName = options["config"] if not os.path.isfile(cfgFileName): raise ValueError('Configuration file not found:', cfgFileName) # read configuration file cfg = ConfigParser() cfg.read(cfgFileName) # create Twisted application application = service.Application("gitlab-webhook-xmpp") serviceCollection = service.IServiceCollection(application) # create XMPP client client = XMPPClient(JID(cfg.get('xmpp', 'jid')), cfg.get('xmpp', 'password')) # client.logTraffic = True client.setServiceParent(application) # join to all MUC rooms nickname = cfg.get('xmpp', 'nickname') if cfg.has_option( 'xmpp', 'nickname') else DEFAULT_NICKNAME notifications = cfg.items('notifications') for room, repositoryMasks in notifications: mucHandler = MUCHandler(JID(room), nickname, repositoryMasks.split(',')) mucHandler.setHandlerParent(client) self.mucHandlers.append(mucHandler) templateLoader = None if cfg.has_option('message', 'template'): templateFullName = cfg.get('message', 'template') templatePath, self.templateName = os.path.split(templateFullName) templateLoader = FileSystemLoader(templatePath) else: self.templateName = DEFAULT_TEMPLATE_NAME templateLoader = PackageLoader('xmpp_webhook', 'templates') self.templateEnvironment = Environment(loader=templateLoader, extensions=['jinja2.ext.i18n']) self.templateEnvironment.install_null_translations( ) # use i18n to pluralize only # create web hook handler rootHttpResource = Resource() rootHttpResource.putChild('', WebHookHandler(self)) site = server.Site(rootHttpResource) httpPort = cfg.getint('http', 'port') if cfg.has_option( 'http', 'port') else DEFAULT_HTTP_PORT httpServer = internet.TCPServer(httpPort, site) httpServer.setServiceParent(serviceCollection) return serviceCollection
def makeService(self, options): with open(options.config, "r") as config_file: config = json.load(config_file) root = resource.Resource() root.putChild('jsMath', static.File(config["global"]["jsmath"])) bot = service.MultiService() xmppclient = XMPPClient(JID(config["global"]["jid"]), config["global"]["password"]) xmppclient.logTraffic = options['verbose'] xmppclient.setServiceParent(bot) xmppclient.dbpool = DatabaseRunner(config["global"]["database"]) xmppclient.rooms = dict() xmlrpc_port = config["global"].get("xml-rpc-port", None) if xmlrpc_port is not None: xmlrpcinterface = XMLRPCInterface(xmppclient) rpc = internet.TCPServer(xmlrpc_port, server.Site(xmlrpcinterface)) rpc.setName('XML-RPC') rpc.setServiceParent(bot) for muc_config in config["mucs"]: room_jid = JID(muc_config["jid"]) mucbot = KITBot(room_jid, muc_config.get("password", None), config["global"]["logpath"]) mucbot.setHandlerParent(xmppclient) if "xml-rpc-id" in muc_config: xmppclient.rooms[muc_config["xml-rpc-id"]] = mucbot # Log resource portal = Portal( LogViewRealm(os.path.join(config["global"]['logpath'], room_jid.user + '.log')), [strcred.makeChecker(muc_config["log-auth"])] ) credential_factory = DigestCredentialFactory('md5', 'Hello Kitty!') auth_resource = HTTPAuthSessionWrapper(portal, [credential_factory]) root.putChild(room_jid.user, auth_resource) httpd_log_view = internet.TCPServer(config["global"]["http-port"], server.Site(root)) httpd_log_view.setServiceParent(bot) # REPL over SSH def makeREPLProtocol(): namespace = dict(bot=xmppclient) return insults.ServerProtocol(manhole.ColoredManhole, namespace) repl_realm = manhole_ssh.TerminalRealm() repl_realm.chainedProtocolFactory = makeREPLProtocol repl_checker = checkers.SSHPublicKeyDatabase() repl_portal = Portal(repl_realm, [repl_checker]) repl_factory = manhole_ssh.ConchFactory(repl_portal) repl = internet.TCPServer(config["global"]["ssh-port"], repl_factory) repl.setServiceParent(bot) return bot
def connect(self): application = service.Application("gbot") xmppclient = XMPPClient(jid.internJID(self.username), self.password) xmppclient.logTraffic = False self.protocol = GBotProtocol() self.protocol.bot = self self.protocol.setHandlerParent(xmppclient) xmppclient.setServiceParent(application) return application
def connect(self): application = service.Application('UniblabXMPP') xmppclient = XMPPClient(jid.internJID(self.xmpp_user), self.xmpp_pass) self.client=UniblabXMPPProtocol() self.client.transport = self self.client.setHandlerParent(xmppclient) xmppclient.setServiceParent(application) xmppclient.startService()
def setupConnection(self): xmppclient = XMPPClient(self.jid, self.password, self.jabber_server) xmppclient.logTraffic = False xmppbot = XMPPCassBot(self, self.state['nickname']) xmppbot.conference_server = self.conference_server xmppbot.setHandlerParent(xmppclient) xmppclient.setServiceParent(self) self.xmppbot = xmppbot self.xmppclient = xmppclient
class botService(service.MultiService): """ xmpp botService """ name = "xmppClient" def __init__(self, root, parent): self.root = root self.parent = parent self.logger = logging.getLogger("xmppClient") self.config = self.root.getServiceNamed('config') self.config.set("enabled", False, "main", network="xmpp") service.MultiService.__init__(self) self.protocol = None try: self.myjid = self.config.get("jid", "", "main.xmppClient") password = self.config.get("password", "", "main.xmppClient") if not (self.myjid and password): self.logger.warn("please set main.xmppClient.jid "+\ "and main.xmppClient.password") return self.client = XMPPClient(jid.internJID(self.myjid + "/otfbot"), password) self.client.logTraffic = False self.protocol = Bot(root, self) self.messageProtocol = myMessageProtocol(self.protocol) self.messageProtocol.setHandlerParent(self.client) self.presenceClientProtocol = myPresenceClientProtocol( self.protocol) self.presenceClientProtocol.setHandlerParent(self.client) self.rosterClientProtocol = myRosterClientProtocol(self.protocol) self.rosterClientProtocol.setHandlerParent(self.client) self.protocol.messageProtocol = self.messageProtocol self.protocol.rosterClientProtocol = self.rosterClientProtocol self.protocol.presenceClientProtocol = self.presenceClientProtocol self.client.setServiceParent(self) except Exception as e: self.logger.error(e) def startService(self): try: service.MultiService.startService(self) except Exception as e: self.logerror(self.logger, "xmppClient", e) def serviceOnline(self, servicename): if self.protocol: self.protocol.serviceOnline(servicename) else: self.logger.warn("I have no protocol and i want to cry")
def makeService(self, options): """ Make services to handle push event notifications. """ # check confguration file is specified and exists if not options["config"]: raise ValueError('Configuration file not specified (try to check --help option)') cfgFileName = options["config"]; if not os.path.isfile(cfgFileName): raise ValueError('Configuration file not found:', cfgFileName) # read configuration file cfg = ConfigParser() cfg.read(cfgFileName) # create Twisted application application = service.Application("gitlab-webhook-xmpp") serviceCollection = service.IServiceCollection(application) # create XMPP client client = XMPPClient(JID(cfg.get('xmpp', 'jid')), cfg.get('xmpp', 'password')) # client.logTraffic = True client.setServiceParent(application) # join to all MUC rooms nickname = cfg.get('xmpp', 'nickname') if cfg.has_option('xmpp', 'nickname') else DEFAULT_NICKNAME notifications = cfg.items('notifications') for room, repositoryMasks in notifications: mucHandler = MUCHandler(JID(room), nickname, repositoryMasks.split(',')) mucHandler.setHandlerParent(client) self.mucHandlers.append(mucHandler) templateLoader = None if cfg.has_option('message', 'template'): templateFullName = cfg.get('message', 'template') templatePath, self.templateName = os.path.split(templateFullName) templateLoader = FileSystemLoader(templatePath) else: self.templateName = DEFAULT_TEMPLATE_NAME templateLoader = PackageLoader('xmpp_webhook', 'templates') self.templateEnvironment = Environment(loader=templateLoader, extensions=['jinja2.ext.i18n']) self.templateEnvironment.install_null_translations() # use i18n to pluralize only # create web hook handler rootHttpResource = Resource() rootHttpResource.putChild('', WebHookHandler(self)) site = server.Site(rootHttpResource) httpPort = cfg.getint('http', 'port') if cfg.has_option('http', 'port') else DEFAULT_HTTP_PORT httpServer = internet.TCPServer(httpPort, site) httpServer.setServiceParent(serviceCollection) return serviceCollection
def __init__(self, myjid, mysecret): application = service.Application("Xmpp XiVO CTI") xmppclient = XMPPClient(jid.internJID(myjid), mysecret) xmppclient.setServiceParent(application) xmppclient.startService() xmppclient.logTraffic = DEBUG self.factory = xmppProtocol() self.factory.setHandlerParent(xmppclient) self.pubsub_factory = ctiPubSubClient(CONFIG["xmpp"]["jid"]) self.pubsub_factory.setHandlerParent(xmppclient)
class Output(cowrie.core.output.Output): def __init__(self): cowrie.core.output.Output.__init__(self) def start(self): from random import choice import string server = CONFIG.get('output_xmpp', 'server') user = CONFIG.get('output_xmpp', 'user') password = CONFIG.get('output_xmpp', 'password') muc = CONFIG.get('output_xmpp', 'muc') resource = ''.join([choice(string.ascii_letters) for i in range(8)]) jid = user + '/' + resource application = service.Application('honeypot') self.run(application, jid, password, JID(None, [muc, server, None]), server) def run(self, application, jidstr, password, muc, server): self.xmppclient = XMPPClient(JID(jidstr), password) if CONFIG.has_option('output_xmpp', 'debug') and \ CONFIG.getboolean('output_xmpp', 'debug') is True: self.xmppclient.logTraffic = True # DEBUG HERE (user, host, resource) = jid.parse(jidstr) self.muc = XMPPLoggerProtocol( muc, server, user + '-' + resource) self.muc.setHandlerParent(self.xmppclient) self.xmppclient.setServiceParent(application) self.anonymous = True self.xmppclient.startService() def write(self, logentry): for i in list(logentry.keys()): # Remove twisted 15 legacy keys if i.startswith('log_'): del logentry[i] elif i == "time": del logentry[i] msgJson = json.dumps(logentry, indent=5) self.muc.groupChat(self.muc.jrooms, msgJson) def stop(self): self.xmppclient.stopService()
def initIrcJabberRelay(application): manager = RelayManager() # Configure IRC ircfactory = IrcBotFactory(manager, cfg["ircchannel"], cfg["ircnick"], manager.sendJabber) # point = TCP4ClientEndpoint(reactor, 'irc.freenode.net', 6667) # d = point.connect(ircfactory) # d.addCallback(gotProtocol) connector = internet.TCPClient(cfg["ircserver"], cfg["ircport"], ircfactory) connector.setServiceParent(application) # Configure Jabber xmppclient = XMPPClient(jid.internJID(cfg["jabberjid"]), cfg["jabberpass"]) jabberbot = JabberBot(manager, cfg["jabberserver"], cfg["jabberchannel"], cfg["jabbernick"], manager.sendIRC) xmppclient.logTraffic = False jabberbot.setHandlerParent(xmppclient) xmppclient.setServiceParent(application) manager.setJabber(jabberbot)
def makeService(cls, config): """ Setup the necessary network services for the application server. """ if(conf.get('suppress-deprecation-warnings')): warnings.filterwarnings('ignore', r'.*', DeprecationWarning) master_service = service.MultiService() xmpp_client = XMPPClient(jid.internJID(conf.get('jid')), conf.get('secret')) xmpp_client.setName("xmpp-client") xmpp_client.setServiceParent(master_service) bot = xmpp.BotProtocol() bot.setHandlerParent(xmpp_client) for room in conf.get('join-rooms'): print 'creating room client for %s' % room muc_client = xmpp.MUCBotClient(*room) muc_client.setHandlerParent(xmpp_client) return master_service
class Output(cowrie.core.output.Output): """ xmpp output """ def start(self): server = CowrieConfig.get("output_xmpp", "server") user = CowrieConfig.get("output_xmpp", "user") password = CowrieConfig.get("output_xmpp", "password") muc = CowrieConfig.get("output_xmpp", "muc") resource = "".join([choice(string.ascii_letters) for i in range(8)]) jid = user + "/" + resource application = service.Application("honeypot") self.run(application, jid, password, JID(None, [muc, server, None]), server) def run(self, application, jidstr, password, muc, server): self.xmppclient = XMPPClient(JID(jidstr), password) if CowrieConfig.getboolean("output_xmpp", "debug", fallback=False): self.xmppclient.logTraffic = True (user, host, resource) = jid.parse(jidstr) self.muc = XMPPLoggerProtocol(muc, server, user + "-" + resource) self.muc.setHandlerParent(self.xmppclient) self.xmppclient.setServiceParent(application) self.anonymous = True self.xmppclient.startService() def write(self, logentry): for i in list(logentry.keys()): # Remove twisted 15 legacy keys if i.startswith("log_"): del logentry[i] elif i == "time": del logentry[i] msgJson = json.dumps(logentry, indent=5) self.muc.groupChat(self.muc.jrooms, msgJson) def stop(self): self.xmppclient.stopService()
class botService(service.MultiService): """ xmpp botService """ name = "xmppClient" def __init__(self, root, parent): self.root = root self.parent = parent self.logger = logging.getLogger("xmppClient") self.config = self.root.getServiceNamed('config') self.config.set("enabled", False, "main", network="xmpp") service.MultiService.__init__(self) self.protocol=None try: self.myjid=self.config.get("jid", "", "main.xmppClient") password=self.config.get("password", "", "main.xmppClient") if not (self.myjid and password): self.logger.warn("please set main.xmppClient.jid "+\ "and main.xmppClient.password") return self.client = XMPPClient(jid.internJID(self.myjid+"/otfbot"), password) self.client.logTraffic = False self.protocol=Bot(root, self) self.messageProtocol=myMessageProtocol(self.protocol) self.messageProtocol.setHandlerParent(self.client) self.presenceClientProtocol=myPresenceClientProtocol(self.protocol) self.presenceClientProtocol.setHandlerParent(self.client) self.rosterClientProtocol=myRosterClientProtocol(self.protocol) self.rosterClientProtocol.setHandlerParent(self.client) self.protocol.messageProtocol=self.messageProtocol self.protocol.rosterClientProtocol=self.rosterClientProtocol self.protocol.presenceClientProtocol=self.presenceClientProtocol self.client.setServiceParent(self) except Exception, e: self.logger.error(e)
output = (self.PACKET.get_packet(packet_id), None) # Return status. return output def abort_job(self, vm_jid, job_id): """ Terminate a job. """ self.__send__(self.abort_job_packet(vm_jid, job_id)) def terminate_vm(self, vm_jid): """ Terminate a VM. """ self.__send__(packet) # Misc. if __name__ == "__main__": FARM_JID = raw_input("Farm JID: ") MY_JID = raw_input("My JID: ") PASSWORD = raw_input("My password: "******"TestVillein") test_villein = villein(MY_JID, PASSWORD, FARM_JID) xmpp_client = XMPPClient(test_villein.JID, PASSWORD) xmpp_client.logTraffic = False test_villein.setHandlerParent(xmpp_client) xmpp_client.setServiceParent(app)
class DBLogger(dblog.DBLogger): def start(self, cfg): from random import choice import string server = cfg.get('database_xmpp', 'server') user = cfg.get('database_xmpp', 'user') password = cfg.get('database_xmpp', 'password') muc = cfg.get('database_xmpp', 'muc') channels = {} for i in ('createsession', 'connectionlost', 'loginfailed', 'loginsucceeded', 'command', 'clientversion'): x = cfg.get('database_xmpp', 'signal_' + i) if not x in channels: channels[x] = [] channels[x].append(i) resource = ''.join([choice(string.ascii_letters) for i in range(8)]) jid = user + '/' + resource application = service.Application('honeypot') self.run(application, jid, password, muc, channels) def run(self, application, jidstr, password, muc, channels, anon=True): self.xmppclient = XMPPClient(jid.JID(jidstr), password) if self.cfg.has_option('database_xmpp', 'debug') and \ self.cfg.get('database_xmpp', 'debug') in ('1', 'true', 'yes'): self.xmppclient.logTraffic = True # DEBUG HERE (user, host, resource) = jid.parse(jidstr) self.muc = XMPPLoggerProtocol(muc, channels.keys(), user + '-' + resource) self.muc.setHandlerParent(self.xmppclient) self.xmppclient.setServiceParent(application) self.signals = {} for channel in channels: for signal in channels[channel]: self.signals[signal] = channel self.anonymous = True self.xmppclient.startService() def broadcast(self, msgtype, msg): if msgtype in self.signals: self.report(msgtype, '%s@%s' % (self.signals[msgtype], self.muc.server), msg) def report(self, msgtype, to, xmsg): body = domish.Element((None, 'body')) body.addContent('\n') msg = domish.Element( ('http://github.com/micheloosterhof/cowrie', 'cowrie')) msg['type'] = msgtype msg.addChild(xmsg) body.addChild(msg) self.muc.groupChat(jid.JID(to), body) # We have to return an unique ID def createSession(self, peerIP, peerPort, hostIP, hostPort): session = uuid.uuid4().hex ses = domish.Element((None, 'session')) ses['session'] = session ses['remote_host'] = peerIP ses['remote_port'] = str(peerPort) if self.anonymous == True: ses['local_host'] = '127.0.0.1' else: ses['local_host'] = hostIP ses['local_port'] = str(hostPort) self.broadcast('createsession', ses) return session def handleTTYLogOpened(self, session, args): pass def handleConnectionLost(self, session, args): ses = domish.Element((None, 'session')) ses['session'] = session self.broadcast('connectionlost', ses) def handleLoginFailed(self, session, args): ses = domish.Element((None, 'credentials')) ses['session'] = session ses['username'] = args['username'] ses['password'] = args['password'] self.broadcast('loginfailed', ses) def handleLoginSucceeded(self, session, args): ses = domish.Element((None, 'credentials')) ses['session'] = session ses['username'] = args['username'] ses['password'] = args['password'] self.broadcast('loginsucceeded', ses) def handleCommand(self, session, args): ses = domish.Element((None, 'command')) ses['session'] = session ses['command'] = 'known' ses.addContent(args['input']) self.broadcast('command', ses) def handleUnknownCommand(self, session, args): ses = domish.Element((None, 'command')) ses['session'] = session ses['command'] = 'unknown' ses.addContent(args['input']) self.broadcast('command', ses) def handleInput(self, session, args): ses = domish.Element((None, 'input')) ses['session'] = session ses['realm'] = args['realm'] ses.addContent(args['input']) self.broadcast('input', ses) def handleTerminalSize(self, session, args): pass def handleClientVersion(self, session, args): ses = domish.Element((None, 'version')) ses['session'] = session ses['version'] = args['version'] self.broadcast('clientversion', ses)
class DBLogger(dblog.DBLogger): def start(self, cfg): from random import choice import string server = cfg.get('database_xmpp', 'server') user = cfg.get('database_xmpp', 'user') password = cfg.get('database_xmpp', 'password') muc = cfg.get('database_xmpp', 'muc') channels = {} for i in ('createsession', 'connectionlost', 'loginfailed', 'loginsucceeded', 'command', 'clientversion'): x = cfg.get('database_xmpp', 'signal_' + i) if not x in channels: channels[x] = [] channels[x].append(i) resource = ''.join([choice(string.ascii_letters) for i in range(8)]) jid = user + '/' + resource application = service.Application('honeypot') self.run(application, jid, password, JID(None,[muc,server,None]), channels) def run(self, application, jidstr, password, muc, channels, anon=True): self.xmppclient = XMPPClient(JID(jidstr), password) if self.cfg.has_option('database_xmpp', 'debug') and \ self.cfg.get('database_xmpp', 'debug') in ('1', 'true', 'yes'): self.xmppclient.logTraffic = True # DEBUG HERE (user, host, resource) = jid.parse(jidstr) self.muc = XMPPLoggerProtocol( muc, channels.keys(), user + '-' + resource) self.muc.setHandlerParent(self.xmppclient) self.xmppclient.setServiceParent(application) self.signals = {} for channel in channels: for signal in channels[channel]: self.signals[signal] = channel self.anonymous = True self.xmppclient.startService() def broadcast(self, msgtype, msg): if msgtype in self.signals: self.report(msgtype, '%s@%s' % (self.signals[msgtype], self.muc.server) , msg) def report(self, msgtype, to, xmsg): msg = {} msg['type'] = msgtype msg['message'] = xmsg msgJson = json.dumps(msg,indent=5) self.muc.groupChat(self.muc.jrooms, msgJson) # We have to return an unique ID def createSession(self, peerIP, peerPort, hostIP, hostPort): session = uuid.uuid4().hex ses = {} ses['session'] = session ses['remote_host'] = peerIP ses['remote_port'] = str(peerPort) if self.anonymous == True: ses['local_host'] = '127.0.0.1' else: ses['local_host'] = hostIP ses['local_port'] = str(hostPort) self.broadcast('createsession', ses) return session def handleTTYLogOpened(self, session, args): pass def handleConnectionLost(self, session, args): ses = {} ses['session'] = session self.broadcast('connectionlost', ses) def handleLoginFailed(self, session, args): ses = {} ses['session'] = session ses['username'] = args['username'] ses['password'] = args['password'] self.broadcast('loginfailed', ses) def handleLoginSucceeded(self, session, args): ses = {} ses['session'] = session ses['username'] = args['username'] ses['password'] = args['password'] self.broadcast('loginsucceeded', ses) def handleCommand(self, session, args): ses = {} ses['session'] = session ses['command'] = 'known' ses['input'] = args['input'] self.broadcast('command', ses) def handleUnknownCommand(self, session, args): ses = {} ses['session'] = session ses['command'] = 'unknown' ses['input'] = args['input'] self.broadcast('command', ses) def handleInput(self, session, args): ses = {} ses['session'] = session ses['realm'] = args['realm'] ses['input'] = args['input'] self.broadcast('input', ses) def handleTerminalSize(self, session, args): pass def handleClientVersion(self, session, args): ses = {} ses['session'] = session ses['version'] = args['version'] self.broadcast('clientversion', ses)
# Configuration parameters config = ConfigParser.RawConfigParser() config.read('bot.conf') myJID = JID(config.get('Connection', 'my_jid')) roomJID = JID(config.get('Connection', 'room_jid')) roomPassword = config.get('Connection', 'room_password') my_nick = config.get('Connection', 'my_nick') my_secret = config.get('Connection', 'my_secret') rt_url = config.get('RT', 'url') rt_display_url = config.get('RT','display_url') rt_user = config.get('RT', 'user') rt_pwd = config.get('RT', 'pwd') rt_default_queue = config.get('RT','default_queue') LOG_TRAFFIC = False #LOG_TRAFFIC = True # Set up the Twisted application application = service.Application("MUC Client") client = XMPPClient(myJID, my_secret) client.logTraffic = LOG_TRAFFIC client.setServiceParent(application) mucHandler = RTBot(roomJID, my_nick, rt_url, rt_user, rt_pwd, roomPassword, rt_display_url, output_format) mucHandler.setHandlerParent(client)
def makeService(self, options): # create Twisted application application = service.Application(TAP_NAME) serviceCollection = service.IServiceCollection(application) # check confguration file is specified and exists if not options["config"]: raise ValueError('Configuration file not specified (try to check --help option)') cfgFileName = options["config"]; if not os.path.isfile(cfgFileName): raise ConfigurationError('Configuration file not found:', cfgFileName) # read configuration file cfg = ConfigParser() with codecs.open(cfgFileName, 'r', encoding='utf-8') as f: cfg.readfp(f) # get Google login and password from configuration if not cfg.has_option('account', 'login') or not cfg.has_option('account', 'password'): raise ConfigurationError('Google account login and password must be specified ' 'in configuration file [account] section') self.googleLogin = cfg.get('account', 'login') self.googlePassword = cfg.get('account', 'password') self.googleDeveloperId = cfg.get('account', 'developer_id') \ if cfg.has_option('account', 'developer_id') else None # get ANDROID_ID from configuration if not cfg.has_option('account', 'android_id'): raise ConfigurationError('ANDROID_ID must be specified in configuration file [account] section') self.androidId = cfg.get('account', 'android_id') # get apps to monitor reviews apps = cfg.items('apps') if not apps: raise ConfigurationError('No apps to monitor reviews defined ' 'in configuration file [apps] section') for appId, appName in apps: self.apps.append(Application(appId, appName)) # open database dbFilename = cfg.get('db', 'filename') if cfg.has_option('db', 'filename') else DEFAULT_DB_FILENAME self.dbpool = adbapi.ConnectionPool("sqlite3", dbFilename, check_same_thread=False) # create XMPP client client = XMPPClient(JID(cfg.get('xmpp', 'jid')), cfg.get('xmpp', 'password')) # client.logTraffic = True client.setServiceParent(application) # join to all MUC rooms nickname = cfg.get('xmpp', 'nickname') if cfg.has_option('xmpp', 'nickname') else DEFAULT_NICKNAME notifications = cfg.items('chats') for chat, appIdPatterns in notifications: mucNotifier = MUCNotifier(JID(chat), nickname, appIdPatterns.split(',')) mucNotifier.setHandlerParent(client) self.mucNotifiers.append(mucNotifier) self.pollPeriod = humanfriendly.parse_timespan(cfg.get('poll', 'period')) \ if cfg.has_option('poll', 'period') else DEFAULT_POLL_PERIOD self.pollDelay = humanfriendly.parse_timespan(cfg.get('poll', 'delay')) \ if cfg.has_option('poll', 'delay') else DEFAULT_POLL_DELAY self.langs = [lang.strip() for lang in cfg.get('poll', 'lang').split(',')] \ if cfg.has_option('poll', 'lang') else [ DEFAULT_LANG ] templateLoader = None if cfg.has_option('notification', 'template'): templateFullName = cfg.get('notification', 'template') templatePath, self.templateName = os.path.split(templateFullName) templateLoader = FileSystemLoader(templatePath) else: self.templateName = DEFAULT_TEMPLATE_NAME templateLoader = PackageLoader('reviewnotify', 'templates') self.templateEnvironment = Environment(loader=templateLoader, extensions=['jinja2.ext.i18n']) localeDir = pkg_resources.resource_filename('reviewnotify', 'locales') locale = None if cfg.has_option('i18n', 'locale'): locale = cfg.get('i18n', 'locale') translations = babel.support.Translations.load(dirname=localeDir, locales=locale) self.templateEnvironment.install_gettext_translations(translations) self.templateEnvironment.filters['datetime'] = format_datetime self.templateEnvironment.filters['review_url'] = review_url reactor.callLater(3.0, self.run) # TODO make initial delay configurable return serviceCollection
self.__send__(packet) output = (self.PACKET.get_packet(packet_id), None) # Return status. return output def abort_job(self, vm_jid, job_id): """ Terminate a job. """ self.__send__(self.abort_job_packet(vm_jid, job_id)) def terminate_vm(self, vm_jid): """ Terminate a VM. """ self.__send__(packet) # Misc. if __name__ == "__main__": FARM_JID = raw_input("Farm JID: ") MY_JID = raw_input("My JID: ") PASSWORD = raw_input("My password: "******"TestVillein") test_villein = villein(MY_JID, PASSWORD, FARM_JID) xmpp_client = XMPPClient(test_villein.JID, PASSWORD) xmpp_client.logTraffic = False test_villein.setHandlerParent(xmpp_client) xmpp_client.setServiceParent(app)
class DBLogger(dblog.DBLogger): def start(self): from random import choice import string server = CONFIG.get('database_xmpp', 'server') user = CONFIG.get('database_xmpp', 'user') password = CONFIG.get('database_xmpp', 'password') muc = CONFIG.get('database_xmpp', 'muc') channels = {} for i in ('createsession', 'connectionlost', 'loginfailed', 'loginsucceeded', 'command', 'clientversion'): x = CONFIG.get('database_xmpp', 'signal_' + i) if x not in channels: channels[x] = [] channels[x].append(i) resource = ''.join([choice(string.ascii_letters) for i in range(8)]) jid = user + '/' + resource application = service.Application('honeypot') self.run(application, jid, password, JID(None, [muc, server, None]), channels) def run(self, application, jidstr, password, muc, channels, anon=True): self.xmppclient = XMPPClient(JID(jidstr), password) if CONFIG.has_option('database_xmpp', 'debug') and CONFIG.getboolean( 'database_xmpp', 'debug'): self.xmppclient.logTraffic = True # DEBUG HERE (user, host, resource) = jid.parse(jidstr) self.muc = XMPPLoggerProtocol(muc, list(channels.keys()), user + '-' + resource) self.muc.setHandlerParent(self.xmppclient) self.xmppclient.setServiceParent(application) self.signals = {} for channel in channels: for signal in channels[channel]: self.signals[signal] = channel self.anonymous = True self.xmppclient.startService() def broadcast(self, msgtype, msg): if msgtype in self.signals: self.report(msgtype, '{}@{}'.format(self.signals[msgtype], self.muc.server), msg) def report(self, msgtype, to, xmsg): msg = {} msg['type'] = msgtype msg['message'] = xmsg msgJson = json.dumps(msg, indent=5) self.muc.groupChat(self.muc.jrooms, msgJson) # We have to return an unique ID def createSession(self, peerIP, peerPort, hostIP, hostPort): session = uuid.uuid4().hex ses = {} ses['session'] = session ses['remote_host'] = peerIP ses['remote_port'] = str(peerPort) if self.anonymous: ses['local_host'] = '127.0.0.1' else: ses['local_host'] = hostIP ses['local_port'] = str(hostPort) self.broadcast('createsession', ses) return session def handleTTYLogOpened(self, session, args): pass def handleConnectionLost(self, session, args): ses = {} ses['session'] = session self.broadcast('connectionlost', ses) def handleLoginFailed(self, session, args): ses = {} ses['session'] = session ses['username'] = args['username'] ses['password'] = args['password'] self.broadcast('loginfailed', ses) def handleLoginSucceeded(self, session, args): ses = {} ses['session'] = session ses['username'] = args['username'] ses['password'] = args['password'] self.broadcast('loginsucceeded', ses) def handleCommand(self, session, args): ses = {} ses['session'] = session ses['command'] = 'known' ses['input'] = args['input'] self.broadcast('command', ses) def handleUnknownCommand(self, session, args): ses = {} ses['session'] = session ses['command'] = 'unknown' ses['input'] = args['input'] self.broadcast('command', ses) def handleInput(self, session, args): ses = {} ses['session'] = session ses['realm'] = args['realm'] ses['input'] = args['input'] self.broadcast('input', ses) def handleTerminalSize(self, session, args): pass def handleClientVersion(self, session, args): ses = {} ses['session'] = session ses['version'] = args['version'] self.broadcast('clientversion', ses)