コード例 #1
0
    def start(self, one_shot=False):
        """
        Start simply loops indefinitely sleeping and pulling messages
        off for processing when they are available.

        If you give one_shot=True it will run once rather than do a big
        while loop with a sleep.
        """

        logging.info("Queue receiver started on queue dir %s" %
                     (self.queue_dir))
        logging.debug("Sleeping for %d seconds..." % self.sleep)

        exeSql = ShivaConfig.dbConnect(
        )  # Shiva - One time connection to mysqldb whenever lamson is started

        inq = queue.Queue(self.queue_dir)

        while True:
            keys = inq.keys()

            for key in keys:
                msg = inq.get(key)

                if msg:
                    logging.debug("Pulled message with key: %r off", key)
                    #self.process_message(msg)

                    # Shiva - Interupting normal flow execution of QueueReceiver here and calling our
                    # customized module ShivaTackleQueue to deal with mails retrieved from following queue:
                    # queuePath = '/root/Desktop/LamsonHoneyMail/MyMailServer/run/queue/new/'
                    # Send "key", which is actually the name of spam file in queue, and "msg", which is actually complete mail body, to ShivaTackleQueue
                    # Later "msg" needs to be passed to process_message function, which is done within our customized module itself
                    # "msg" is in MailRequest format
                    #ShivaTackleQueue.tackleQueue(key, msg)
                    ShivaTackleQueue.tackleQueue(key, msg, exeSql)

                    # Irrespective of mail relayed or not, it has to be cleared from queue. Hence, whether process_message executes or not,
                    # the control comes back to this point and ultimately spam gets removed from queue
                    logging.debug("Removed %r key from queue.\n\n", key)

                inq.remove(key)

            if one_shot:
                return
            else:
                time.sleep(self.sleep)
コード例 #2
0
ファイル: server.py プロジェクト: s4n7h0/shiva
    def start(self, one_shot=False):
        """
        Start simply loops indefinitely sleeping and pulling messages
        off for processing when they are available.

        If you give one_shot=True it will run once rather than do a big
        while loop with a sleep.
        """

        logging.info("Queue receiver started on queue dir %s" % (self.queue_dir))
        logging.debug("Sleeping for %d seconds..." % self.sleep)

        exeSql = ShivaConfig.dbConnect()  # Shiva - One time connection to mysqldb whenever lamson is started

        inq = queue.Queue(self.queue_dir)

        while True:
            keys = inq.keys()

            for key in keys:
                msg = inq.get(key)

                if msg:
                    logging.debug("Pulled message with key: %r off", key)
                    # self.process_message(msg)

                    # Shiva - Interupting normal flow execution of QueueReceiver here and calling our
                    # customized module ShivaTackleQueue to deal with mails retrieved from following queue:
                    # queuePath = '/root/Desktop/LamsonHoneyMail/MyMailServer/run/queue/new/'
                    # Send "key", which is actually the name of spam file in queue, and "msg", which is actually complete mail body, to ShivaTackleQueue
                    # Later "msg" needs to be passed to process_message function, which is done within our customized module itself
                    # "msg" is in MailRequest format
                    # ShivaTackleQueue.tackleQueue(key, msg)
                    ShivaTackleQueue.tackleQueue(key, msg, exeSql)

                    # Irrespective of mail relayed or not, it has to be cleared from queue. Hence, whether process_message executes or not,
                    # the control comes back to this point and ultimately spam gets removed from queue
                    logging.debug("Removed %r key from queue.\n\n", key)

                inq.remove(key)

            if one_shot:
                return
            else:
                time.sleep(self.sleep)
コード例 #3
0
ファイル: ShivaOldSpam.py プロジェクト: honeynet/shiva
	  exeSql.execute(counters1)
	  exeSql.execute(counters2)
	except mdb.Error, e:
	  logging.critical("[-] Error (ShivaOldSpam - counters) - %d: %s" % (e.args[0], e.args[1]))
	  ShivaConfig.errorHandling(key, msgMailRequest)
	  return None
	lastRelayed = "UPDATE relay SET relay.lastRelayed = '"+str(datetime.datetime.now())+"' WHERE relay.spam_id = '"+ str(mailFields['spam_id'])+"'"
    
	try:
	  exeSql.execute(lastRelayed)
	except mdb.Error, e:
	  logging.critical("[-] Error (ShivaOldSpam - lastRelayed) - %d: %s" % (e.args[0], e.args[1]))
	  ShivaConfig.errorHandling(key, msgMailRequest)
	  return None
	  
	ShivaTackleQueue.process_message(msgMailRequest)

      else:
	logging.critical("ShivaOldSpam - Quota full, not relaying")
    except:
      logging.critical("ShivaOldSpam - Error in counters")
      ShivaConfig.errorHandling(key, msgMailRequest)
      return None
  else:						# i,e. spam is old but wasn't relayed earlier - totalRelayedToday would have restricted it from getting relayed
    try:
      if totalRelayedToday[0] < ShivaConfig.relayCounter:
	logging.critical("ShivaOldSpam: Relaying old-spam - It didn't get chance earlier to get relayed")

	insertRelay = "INSERT INTO relay (`date`, `firstRelayed`, `lastRelayed`, `relayCounter`, `totalRelayed`, `spam_id`, `sensorID`) VALUES('"+str(mailFields['date'])+"', '"+str(mailFields['firstRelayed'])+"', '"+str(mailFields['lastRelayed'])+"', '1', '1', '"+str(mailFields['spam_id'])+"', '"+str(mailFields['sensorID'])+"')"
	
	try:
コード例 #4
0
        ShivaConfig.errorHandling(key, msgMailRequest)
        return None

    relayCounter = exeSql.fetchone()
    if relayCounter[0] < ShivaConfig.relayCounter:
        logging.critical(
            "ShivaNewSpam: Relaying spam - Relay count for the day has not reached its limit yet"
        )

        insertRelay = "INSERT INTO relay (`date`, `firstRelayed`, `lastRelayed`, `relayCounter`, `totalRelayed`, `spam_id`, `sensorID`) VALUES('" + str(
            mailFields['date']) + "', '" + str(
                mailFields['firstRelayed']) + "', '" + str(
                    mailFields['lastRelayed']) + "', '1', '1', '" + str(
                        mailFields['spam_id']) + "', '" + str(
                            mailFields['sensorID']) + "')"

        try:
            exeSql.execute(insertRelay)
        except mdb.Error, e:
            logging.critical(
                "[-] Error (ShivaNewSpam - insertRelay) - %d: %s" %
                (e.args[0], e.args[1]))
            ShivaConfig.errorHandling(key, msgMailRequest)
            return None

        ShivaTackleQueue.process_message(msgMailRequest)

    else:
        logging.critical(
            "ShivaNewSpam: Relay count for the day has reached - not relaying")