<s> from twisted . words . xish import domish <EOL> from twisted . python import log <EOL> from wokkel . xmppim import AvailablePresence <EOL> from twisted . words . protocols . jabber . jid import JID <EOL> from wokkel import muc <EOL> import uuid <EOL> import json <EOL> class XMPPLoggerProtocol ( muc . MUCClient ) : <EOL> def __init__ ( self , rooms , server , nick ) : <EOL> muc . MUCClient . __init__ ( self ) <EOL> self . server = rooms . host <EOL> self . jrooms = rooms <EOL> self . _roomOccupantMap = { } <EOL> log . msg ( rooms . user ) <EOL> log . msg ( rooms . host ) <EOL> self . nick = nick <EOL> self . last = { } <EOL> self . activity = None <EOL> def connectionInitialized ( self ) : <EOL> """<STR_LIT>""" <EOL> self . join ( self . jrooms , self . nick ) ; <EOL> def joinedRoom ( self , room ) : <EOL> log . msg ( '<STR_LIT>' % room . name ) <EOL> def connectionMade ( self ) : <EOL> log . msg ( '<STR_LIT>' ) <EOL> self . send ( AvailablePresence ( ) ) <EOL> def connectionLost ( self , reason ) : <EOL> log . msg ( '<STR_LIT>' ) <EOL> def onMessage ( self , msg ) : <EOL> pass <EOL> def receivedGroupChat ( self , room , user , body ) : <EOL> pass <EOL> def receivedHistory ( self , room , user , body , dely , frm = None ) : <EOL> pass <EOL> from twisted . application import service <EOL> from twisted . words . protocols . jabber import jid <EOL> from wokkel . client import XMPPClient <EOL> from cowrie . core import dblog <EOL> from twisted . words . xish import domish <EOL> class DBLogger ( dblog . DBLogger ) : <EOL> def start ( self , cfg ) : <EOL> from random import choice <EOL> import string <EOL> server = cfg . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> user = cfg . get ( '<STR_LIT>' , '<STR_LIT:user>' ) <EOL> password = cfg . get ( '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> muc = cfg . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> channels = { } <EOL> for i in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> x = cfg . get ( '<STR_LIT>' , '<STR_LIT>' + i ) <EOL> if not x in channels : <EOL> channels [ x ] = [ ] <EOL> channels [ x ] . append ( i ) <EOL> resource = '<STR_LIT>' . join ( [ choice ( string . ascii_letters ) <EOL> for i in range ( <NUM_LIT:8> ) ] ) <EOL> jid = user + '<STR_LIT:/>' + resource <EOL> application = service . Application ( '<STR_LIT>' ) <EOL> self . run ( application , jid , password , JID ( None , [ muc , server , None ] ) , channels ) <EOL> def run ( self , application , jidstr , password , muc , channels , anon = True ) : <EOL> self . xmppclient = XMPPClient ( JID ( jidstr ) , password ) <EOL> if self . cfg . has_option ( '<STR_LIT>' , '<STR_LIT>' ) and self . cfg . get ( '<STR_LIT>' , '<STR_LIT>' ) in ( '<STR_LIT:1>' , '<STR_LIT:true>' , '<STR_LIT:yes>' ) : <EOL> self . xmppclient . logTraffic = True <EOL> ( user , host , resource ) = jid . parse ( jidstr ) <EOL> self . muc = XMPPLoggerProtocol ( <EOL> muc , channels . keys ( ) , user + '<STR_LIT:->' + resource ) <EOL> self . muc . setHandlerParent ( self . xmppclient ) <EOL> self . xmppclient . setServiceParent ( application ) <EOL> self . signals = { } <EOL> for channel in channels : <EOL> for signal in channels [ channel ] : <EOL> self . signals [ signal ] = channel <EOL> self . anonymous = True <EOL> self . xmppclient . startService ( ) <EOL> def broadcast ( self , msgtype , msg ) : <EOL> if msgtype in self . signals : <EOL> self . report ( msgtype , '<STR_LIT>' % <EOL> ( self . signals [ msgtype ] , self . muc . server ) , msg ) <EOL> def report ( self , msgtype , to , xmsg ) : <EOL> msg = { } <EOL> msg [ '<STR_LIT:type>' ] = msgtype <EOL> msg [ '<STR_LIT:message>' ] = xmsg <EOL> msgJson = json . dumps ( msg , indent = <NUM_LIT:5> ) <EOL> self . muc . groupChat ( self . muc . jrooms , msgJson ) <EOL> def createSession ( self , peerIP , peerPort , hostIP , hostPort ) : <EOL> session = uuid . uuid4 ( ) . hex <EOL> ses = { } <EOL> ses [ '<STR_LIT>' ] = session <EOL> ses [ '<STR_LIT>' ] = peerIP <EOL> ses [ '<STR_LIT>' ] = str ( peerPort ) <EOL> if self . anonymous == True : <EOL> ses [ '<STR_LIT>' ] = '<STR_LIT:127.0.0.1>' <EOL> else : <EOL> ses [ '<STR_LIT>' ] = hostIP <EOL> ses [ '<STR_LIT>' ] = str ( hostPort ) <EOL> self . broadcast ( '<STR_LIT>' , ses ) <EOL> return session <EOL> def handleTTYLogOpened ( self , session , args ) : <EOL> pass <EOL> def handleConnectionLost ( self , session , args ) : <EOL> ses = { } <EOL> ses [ '<STR_LIT>' ] = session <EOL> self . broadcast ( '<STR_LIT>' , ses ) <EOL> def handleLoginFailed ( self , session , args ) : <EOL> ses = { } <EOL> ses [ '<STR_LIT>' ] = session <EOL> ses [ '<STR_LIT:username>' ] = args [ '<STR_LIT:username>' ] <EOL> ses [ '<STR_LIT:password>' ] = args [ '<STR_LIT:password>' ] <EOL> self . broadcast ( '<STR_LIT>' , ses ) <EOL> def handleLoginSucceeded ( self , session , args ) : <EOL> ses = { } <EOL> ses [ '<STR_LIT>' ] = session <EOL> ses [ '<STR_LIT:username>' ] = args [ '<STR_LIT:username>' ] <EOL> ses [ '<STR_LIT:password>' ] = args [ '<STR_LIT:password>' ] <EOL> self . broadcast ( '<STR_LIT>' , ses ) <EOL> def handleCommand ( self , session , args ) : <EOL> ses = { } <EOL> ses [ '<STR_LIT>' ] = session <EOL> ses [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> ses [ '<STR_LIT:input>' ] = args [ '<STR_LIT:input>' ] <EOL> self . broadcast ( '<STR_LIT>' , ses ) <EOL> def handleUnknownCommand ( self , session , args ) : <EOL> ses = { } <EOL> ses [ '<STR_LIT>' ] = session <EOL> ses [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> ses [ '<STR_LIT:input>' ] = args [ '<STR_LIT:input>' ] <EOL> self . broadcast ( '<STR_LIT>' , ses ) <EOL> def handleInput ( self , session , args ) : <EOL> ses = { } <EOL> ses [ '<STR_LIT>' ] = session <EOL> ses [ '<STR_LIT>' ] = args [ '<STR_LIT>' ] <EOL> ses [ '<STR_LIT:input>' ] = args [ '<STR_LIT:input>' ] <EOL> self . broadcast ( '<STR_LIT:input>' , ses ) <EOL> def handleTerminalSize ( self , session , args ) : <EOL> pass <EOL> def handleClientVersion ( self , session , args ) : <EOL> ses = { } <EOL> ses [ '<STR_LIT>' ] = session <EOL> ses [ '<STR_LIT:version>' ] = args [ '<STR_LIT:version>' ] <EOL> self . broadcast ( '<STR_LIT>' , ses ) </s>
