Ejemplo n.º 1
0
Archivo: xmpp.py Proyecto: nutim/cowrie
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
class StatusBotService(service.Service):
    def __init__(self):
        self.client = XMPPClient(JID(config.JABBER_CLIENT_USER),
                                 config.JABBER_CLIENT_PASS,
                                 config.JABBER_CLIENT_HOST)
        self.presenceFetcher = PresenceFetcher()
        self.presenceFetcher.setHandlerParent(self.client)
        self.tweeter = Tweeter()
        self.loopingCall = LoopingCall(self.makeRequest)

    def startService(self):
        service.Service.startService(self)
        self.client.startService()
        self.loopingCall.start(config.REFRESH_INTERVAL_SECS)

    def stopService(self):
        service.Service.stopService(self)
        self.loopingCall.stop()
        self.client.stopService()

    def makeRequest(self):
        d = self.presenceFetcher.doProbe(config.JABBER_TARGET)
        d.addCallbacks(self._sendTweet, log.err)
        return d

    def _sendTweet(self, statuses):
        if not statuses:
            log.msg("No statuses received")
            return succeed(None)
        else:
            d = self.tweeter.tweet(statuses[0])
            d.addCallback(self._receiveTweetResponse)
            return d

    def _receiveTweetResponse(self, result):
        code, body = result
        # 403 is probably a duplicate tweet
        if code == 200:
            decoded = json.loads(body)
            log.msg("Tweeted new status: " + decoded['text'])
        elif code == 403:
            log.msg("Duplicate tweet, ignoring")
        else:
            log.err("Error tweeting {}: {}".format(code, body))
Ejemplo n.º 4
0
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()