コード例 #1
0
ファイル: CNBMMNmap.py プロジェクト: hackfestca/cnb
    def processCmd(self, oMsg):
        result = ''
        if len(oMsg.args) > 0:
            targetList = oMsg.args
            
            # Create temporary file
            oConfig = CNBConfig.getInstance()
            sLogDir = oConfig.get('global', 'log-dir')
            tmpFileName = sLogDir + self.NMAP_FILE + strftime("%Y-%m-%d_%H%M%S") + '.txt'
            fh = open(tmpFileName,"w")
            for h in targetList:
                fh.write(h + "\n")
            fh.close()
                
            cmd = copy(self.NMAP_CMD)
            cmd.append(tmpFileName)
            self.log.info(str(cmd))
            result = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]

            fh = open(tmpFileName,"a")
            fh.write('Command: ' + str(cmd))
            fh.write('User: ' + oMsg.username)
            fh.writelines(result)
            fh.close()
        else:
            result = "This cmd takes at least 1 arguments, check help"
        return result
コード例 #2
0
    def processCmd(self, oMsg):
        result = ''
        if len(oMsg.args) > 0:
            targetList = oMsg.args

            # Create temporary file
            oConfig = CNBConfig.getInstance()
            sLogDir = oConfig.get('global', 'log-dir')
            tmpFileName = sLogDir + self.NMAP_FILE + strftime(
                "%Y-%m-%d_%H%M%S") + '.txt'
            fh = open(tmpFileName, "w")
            for h in targetList:
                fh.write(h + "\n")
            fh.close()

            cmd = copy(self.NMAP_CMD)
            cmd.append(tmpFileName)
            self.log.info(str(cmd))
            result = subprocess.Popen(cmd,
                                      stdout=subprocess.PIPE).communicate()[0]

            fh = open(tmpFileName, "a")
            fh.write('Command: ' + str(cmd))
            fh.write('User: ' + oMsg.username)
            fh.writelines(result)
            fh.close()
        else:
            result = "This cmd takes at least 1 arguments, check help"
        return result
コード例 #3
0
ファイル: CNBMMFacts.py プロジェクト: OSSSP/cnb
 def __init__(self,log):
     CNBMatrixModule.__init__(self,log)
     oConfig = CNBConfig.getInstance()
     sRootDir = oConfig.get('global', 'fact-dir')
     
     for k in self.CHUCK_FACTS_FILES:
         self.log.info('Imported Chuck Quote file: ' + self.CHUCK_FACTS_FILES[k])
         fh = open(sRootDir + self.CHUCK_FACTS_FILES[k],"r")
         self._chuckFacts[k] = fh.readlines()
         fh.close()
コード例 #4
0
    def __init__(self,log):
        CNBMatrixModule.__init__(self,log)

        oConfig = CNBConfig.getInstance()
        sRootDir = oConfig.get('global', 'fact-dir')

        self.log.info('Imported Mother Quote file: ' + self.TAMERE_FACTS_FILE)
        fh = open(sRootDir + self.TAMERE_FACTS_FILE,"r")
        self._tamereFacts = fh.readlines()
        fh.close()
コード例 #5
0
ファイル: CNBMMSpy.py プロジェクト: hackfestca/cnb
 def _initDefaultRules(self):
     oConfig = CNBConfig.getInstance()
     if oConfig.has_option('spy', 'rules'):
         self.log.info('Importing default rules')
         aRules = oConfig.get('spy', 'rules')
         for r in aRules:
             aSrcDst = r.split('->')
             if len(aSrcDst) == 2:
                 aSrc = aSrcDst[0].split(';')
                 aDst = aSrcDst[1].split(';')
                 self.addRule(aSrc,aDst)
コード例 #6
0
ファイル: CNBMMCrack.py プロジェクト: OSSSP/cnb
    def processCmd(self, oMsg):
        result = ''
        if len(oMsg.args) > 1:
            hashType = oMsg.args[0].upper()
            stringList = oMsg.args[1::]

            # Create temporary file
            oConfig = CNBConfig.getInstance()
            sLogDir = oConfig.get('global', 'log-dir')
            tmpFileName = sLogDir + self.FIND_MY_HASH_FILE + strftime(
                "%Y-%m-%d_%H%M%S") + '.txt'
            if len(stringList) > 1:
                fh = open(tmpFileName, "w")
                for h in stringList:
                    fh.write(h + "\n")
                fh.close()
            else:
                fh = open(tmpFileName, "w")
                fh.write(stringList[0] + "\n")
                fh.close()

            sTpDir = oConfig.get('global', 'tp-dir')
            cmd = copy(self.FIND_MY_HASH_CMD)
            cmd[0] = sTpDir + cmd[0]
            cmd.insert(1, hashType)
            cmd.append(tmpFileName)
            self.log.info(str(cmd))

            # Telling the user that the hash will be cracked
            oConMgr = CNBManager.getInstance()
            oConMgr.sayCNB(oMsg.conId, oMsg.getSource(), self.MSG_CRACKING)

            # Process and reply
            result = subprocess.Popen(cmd,
                                      stdout=subprocess.PIPE).communicate()[0]

            # If the pass was cracked, remove some crap before sending results
            if self.MSG_CRACKED in result:
                result = result[result.find(self.MSG_CRACKED)::]
                fh = open(tmpFileName, "a")
                fh.write(result + "\n")
                fh.close()
        else:
            result = "This cmd takes at least 2 arguments, check help"
        return result
コード例 #7
0
 def save(self):
     oConfig = CNBConfig.getInstance()
     sFile = oConfig.get('global', 'log-dir') + self.TRIVIA_SAVE_FILE
     aObj = {'curQtId': self.curQtId,\
             'startDateTime': self.startDateTime,\
             'beginDateTime': self.beginDateTime,\
             'qtDateTime': self.qtDateTime,\
             'autoSave': self.autoSave,\
             #'_conId': self._conId,\
             #'_room': self._room,\
             '_state': self._state,\
             '_questions': self._questions,\
             '_results': self._results,\
             'timestamp': datetime.today(),\
            }
     self.log.info('Saving state to ' + sFile)
     pickle.dump(aObj, open(sFile, 'w'))
     return 'State was successfuly saved'
コード例 #8
0
ファイル: CNBMMTrivia.py プロジェクト: hackfestca/cnb
 def save(self):
     oConfig = CNBConfig.getInstance()
     sFile = oConfig.get('global', 'log-dir') + self.TRIVIA_SAVE_FILE
     aObj = {'curQtId': self.curQtId,\
             'startDateTime': self.startDateTime,\
             'beginDateTime': self.beginDateTime,\
             'qtDateTime': self.qtDateTime,\
             'autoSave': self.autoSave,\
             #'_conId': self._conId,\
             #'_room': self._room,\
             '_state': self._state,\
             '_questions': self._questions,\
             '_results': self._results,\
             'timestamp': datetime.today(),\
            }
     self.log.info('Saving state to ' + sFile)
     pickle.dump(aObj, open(sFile, 'w'))
     return 'State was successfuly saved'
コード例 #9
0
ファイル: CNBMMCrack.py プロジェクト: hackfestca/cnb
    def processCmd(self, oMsg):
        result = ''
        if len(oMsg.args) > 1:
            hashType = oMsg.args[0].upper()
            stringList = oMsg.args[1::]
            
            # Create temporary file
            oConfig = CNBConfig.getInstance()
            sLogDir = oConfig.get('global', 'log-dir')
            tmpFileName = sLogDir + self.FIND_MY_HASH_FILE + strftime("%Y-%m-%d_%H%M%S") + '.txt'
            if len(stringList) > 1:
                fh = open(tmpFileName,"w")
                for h in stringList:
                    fh.write(h + "\n")
                fh.close()
            else:
                fh = open(tmpFileName,"w")
                fh.write(stringList[0] + "\n")
                fh.close()
                
            sTpDir = oConfig.get('global', 'tp-dir')
            cmd = copy(self.FIND_MY_HASH_CMD)
            cmd[0] = sTpDir + cmd[0]
            cmd.insert(1, hashType)
            cmd.append(tmpFileName)
            self.log.info(str(cmd))

            # Telling the user that the hash will be cracked
            oConMgr = CNBManager.getInstance()
            oConMgr.sayCNB(oMsg.conId,oMsg.getSource(),self.MSG_CRACKING)

            # Process and reply
            result = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]

            # If the pass was cracked, remove some crap before sending results
            if self.MSG_CRACKED in result:
                result = result[result.find(self.MSG_CRACKED)::]
                fh = open(tmpFileName,"a")
                fh.write(result + "\n")
                fh.close()
        else:
            result = "This cmd takes at least 2 arguments, check help"
        return result
コード例 #10
0
    def load(self):
        oConfig = CNBConfig.getInstance()
        sFile = oConfig.get('global', 'log-dir') + self.TRIVIA_SAVE_FILE
        self.log.info('Loading state from ' + sFile)
        aObj = pickle.load(open(sFile, 'r'))

        timestamp = aObj['timestamp']
        self.curQtId = aObj['curQtId']
        self.startDateTime = aObj['startDateTime']
        #self.beginDateTime  = aObj['beginDateTime']
        self.beginDateTime = datetime.today()
        self.qtDateTime = aObj['qtDateTime'] + (datetime.today() - timestamp)
        self.autoSave = aObj['autoSave']
        #self._conId         = aObj['_conId']
        #self._room          = aObj['_room']
        self._state = aObj['_state']
        self._questions = aObj['_questions']
        self._results = aObj['_results']

        return 'State was successfuly loaded'
コード例 #11
0
ファイル: CNBMMTrivia.py プロジェクト: hackfestca/cnb
    def load(self):
        oConfig = CNBConfig.getInstance()
        sFile = oConfig.get('global', 'log-dir') + self.TRIVIA_SAVE_FILE
        self.log.info('Loading state from ' + sFile)
        aObj = pickle.load(open(sFile, 'r'))

        timestamp           = aObj['timestamp']
        self.curQtId        = aObj['curQtId']
        self.startDateTime  = aObj['startDateTime']
        #self.beginDateTime  = aObj['beginDateTime']
        self.beginDateTime  = datetime.today()
        self.qtDateTime     = aObj['qtDateTime'] + (datetime.today() - timestamp)
        self.autoSave       = aObj['autoSave']
        #self._conId         = aObj['_conId']
        #self._room          = aObj['_room']
        self._state         = aObj['_state']
        self._questions     = aObj['_questions']
        self._results       = aObj['_results']

        return 'State was successfuly loaded'
コード例 #12
0
    def __init__(self, conId, room, stime=None, load=None):
        Thread.__init__(self)
        oConfig = CNBConfig.getInstance()
        self.log = logging.getLogger(self.__class__.__name__)
        self._configLogs(oConfig)

        self._conId = conId
        self._room = room
        if stime:
            self.startDateTime = stime
            self.startAndWaitTrivia()
        else:
            self.startTrivia()

        sRootDir = oConfig.get('global', 'trivia-dir')
        self._importQts(sRootDir + self.TRIVIA_QUESTIONS_FILE)

        if load:
            self.load()

        self.start()
コード例 #13
0
ファイル: CNBMMTrivia.py プロジェクト: hackfestca/cnb
    def __init__(self,conId,room,stime=None,load=None):
        Thread.__init__(self)
        oConfig = CNBConfig.getInstance()
        self.log = logging.getLogger(self.__class__.__name__)
        self._configLogs(oConfig)
        
        self._conId = conId
        self._room = room
        if stime:
            self.startDateTime = stime
            self.startAndWaitTrivia()
        else:
            self.startTrivia()

        sRootDir = oConfig.get('global', 'trivia-dir')
        self._importQts(sRootDir + self.TRIVIA_QUESTIONS_FILE)

        if load:
            self.load()

        self.start()
コード例 #14
0
    def processCmd(self, oMsg):
        result = 'Missing arguments, check help'
        (args, err) = self.getParsedArgs(oMsg.args)

        globalConfig = CNBConfig.getInstance()
        oMgr = CNBManager.getInstance()
        instConfig = oMgr.getConfigCNB(oMsg.conId)
        if self._aGameInst.has_key(oMsg.conId):
            oGame = self._aGameInst[oMsg.conId]
        else:
            oGame = None

        if self._isAllowed(self._aLocalUsers, oMsg.username, oMsg.domain,
                           args):
            if err != '':
                result = err
            elif args.adm_start:
                if not oGame:
                    if not oMsg.isPrivate:
                        oGame = CNBMMTriviaGame(oMsg.conId, oMsg.room)
                        self._aGameInst[oMsg.conId] = oGame
                        result = 'Starting the trivia game'
                    else:
                        result = 'You must start trivia in a public room/chan'
                else:
                    result = 'Game already started'
            elif args.adm_starttime:
                if not oGame:
                    if not oMsg.isPrivate:
                        try:
                            f = '%Y-%m-%d_%H:%M'
                            v = ' '.join(args.adm_starttime)
                            d = datetime.strptime(v, f)
                            isValid = (
                                v == d.strftime(f)
                            )  # this makes sure the parsed date matches the original string
                        except ValueError:
                            isValid = False
                        if isValid:
                            oGame = CNBMMTriviaGame(oMsg.conId, oMsg.room, d)
                            self._aGameInst[oMsg.conId] = oGame
                            result = 'Game will start on ' + str(
                                args.adm_starttime)
                        else:
                            result = 'Bad date/time format'
                    else:
                        result = 'You must start trivia in a public room/chan'
                else:
                    result = 'Game already started'
            elif args.adm_stop:
                if oGame:
                    if not oMsg.isPrivate:
                        oGame.stopTrivia()
                        del oGame
                        oGame = None
                        self._aGameInst.pop(oMsg.conId)
                        result = 'Stopping...'
                    else:
                        result = 'You must stop trivia in a public room/chan'
                else:
                    result = 'Game not started yet'
            elif args.adm_next:
                if oGame:
                    oGame.chgQt()
                    result = ''
                else:
                    result = 'Game not started yet'
            elif args.adm_save:
                if oGame:
                    result = oGame.save()
                else:
                    result = 'Game not started yet'
            elif args.adm_load:
                if oGame:
                    result = oGame.load()
                else:
                    result = 'Game not started yet'
            elif args.adm_status:
                if oGame:
                    result = oGame.getStatus()
                else:
                    result = 'Game not started yet'
            elif args.adm_qinfo:
                if oGame:
                    if oMsg.isPrivate:
                        v = args.adm_qinfo[0]
                        result = oGame.getQuestionInfo(v)
                    else:
                        result = 'You must submit in private'
                else:
                    result = 'Game not started yet'
            elif args.answer:
                if oGame:
                    if oMsg.isPrivate:
                        v = ' '.join(args.answer)
                        result = oGame.submitAnswer(oMsg.username, v)
                        #result = oGame.submitAnswer(oMsg.username, args.answer)
                    else:
                        result = 'You must submit in private'
                else:
                    result = 'Game not started yet'
            elif args.question:
                if oGame:
                    result = oGame.getCurQtMsg()
                else:
                    result = 'Game not started yet'
            elif args.score:
                if oGame:
                    result = "Score: \n" + oGame.getResult()
                else:
                    result = 'Game not started yet'
            elif args.help:
                result = self.getUsage()
            else:
                result = self.getUsage()
        else:
            result = 'Unauthorized :)'

        return result
コード例 #15
0
ファイル: CNBMMTrivia.py プロジェクト: hackfestca/cnb
    def processCmd(self, oMsg):
        result = 'Missing arguments, check help'
        (args, err) = self.getParsedArgs(oMsg.args)

        globalConfig = CNBConfig.getInstance()
        oMgr = CNBManager.getInstance()
        instConfig = oMgr.getConfigCNB(oMsg.conId)
        if self._aGameInst.has_key(oMsg.conId):
            oGame = self._aGameInst[oMsg.conId]
        else:
            oGame = None
        
        if self._isAllowed(self._aLocalUsers, oMsg.username, oMsg.domain, args):    
            if err != '':
                result = err
            elif args.adm_start:
                if not oGame:
                    if not oMsg.isPrivate:
                        oGame = CNBMMTriviaGame(oMsg.conId,oMsg.room)
                        self._aGameInst[oMsg.conId] = oGame
                        result = 'Starting the trivia game'
                    else:
                        result = 'You must start trivia in a public room/chan'
                else:
                    result = 'Game already started'
            elif args.adm_starttime:
                if not oGame:
                    if not oMsg.isPrivate:
                        try:
                            f = '%Y-%m-%d_%H:%M'
                            v = ' '.join(args.adm_starttime)
                            d = datetime.strptime(v, f)
                            isValid = (v == d.strftime(f)) # this makes sure the parsed date matches the original string
                        except ValueError:
                            isValid = False
                        if isValid:
                            oGame = CNBMMTriviaGame(oMsg.conId,oMsg.room,d)
                            self._aGameInst[oMsg.conId] = oGame
                            result = 'Game will start on ' + str(args.adm_starttime)
                        else:
                            result = 'Bad date/time format'
                    else:
                        result = 'You must start trivia in a public room/chan'
                else:
                    result = 'Game already started'
            elif args.adm_stop: 
                if oGame:
                    if not oMsg.isPrivate:
                        oGame.stopTrivia()
                        del oGame
                        oGame = None
                        self._aGameInst.pop(oMsg.conId)
                        result = 'Stopping...'
                    else:
                        result = 'You must stop trivia in a public room/chan'
                else:
                    result = 'Game not started yet'
            elif args.adm_next:
                if oGame:
                    oGame.chgQt()
                    result = ''
                else:
                    result = 'Game not started yet'
            elif args.adm_save:
                if oGame:
                    result = oGame.save()
                else:
                    result = 'Game not started yet'
            elif args.adm_load:
                if oGame:
                    result = oGame.load()
                else:
                    result = 'Game not started yet'
            elif args.adm_status:
                if oGame:
                    result = oGame.getStatus()
                else:
                    result = 'Game not started yet'
            elif args.adm_qinfo:
                if oGame:
                    if oMsg.isPrivate:
                        v = args.adm_qinfo[0]
                        result = oGame.getQuestionInfo(v)
                    else:
                        result = 'You must submit in private'
                else:
                    result = 'Game not started yet'
            elif args.answer:
                if oGame: 
                    if oMsg.isPrivate:
                        v = ' '.join(args.answer)
                        result = oGame.submitAnswer(oMsg.username, v)
                        #result = oGame.submitAnswer(oMsg.username, args.answer)
                    else:
                        result = 'You must submit in private'
                else:
                    result = 'Game not started yet'
            elif args.question: 
                if oGame:
                    result = oGame.getCurQtMsg()
                else:
                    result = 'Game not started yet'
            elif args.score: 
                if oGame:
                    result = "Score: \n" + oGame.getResult()
                else:
                    result = 'Game not started yet'
            elif args.help:
                result = self.getUsage()
            else:
                result = self.getUsage()
        else:
            result = 'Unauthorized :)'

        return result