예제 #1
0
    def connectionMade(self):
        if (self.transport.getHost().port == config.smtpPort):
            self.name = config.smtpName
        elif (self.transport.getHost().port == config.smtpsPort):
            self.name = config.smtpsName
        else:
            log.err("Please check SMTP/SMTPS port configuration!")
            self.name = "SMTP/SMTPS"

        self.setTimeout(self.timeoutPreAuth)

        log.info(self.name + " established connection to " +
                 str(self.transport.getPeer().host) + ":" +
                 str(self.transport.getPeer().port))

        # add connection to dictionary
        self.factory.clients[self] = (str(self.transport.getPeer().host) +
                                      ":" + str(self.transport.getPeer().port))

        # protocol state
        self.state["connected"] = True
        self.peerOfAttacker = self.transport.getPeer().host

        response = "220 Service ready ESMTP\r\n"
        self.transport.write(response.encode("UTF-8"))
예제 #2
0
    def connectionMade(self):
        if (self.transport.getHost().port == config.imapPort):
            self.name = config.imapName
        elif (self.transport.getHost().port == config.imapsPort):
            self.name = config.imapsName
        else:
            log.err("Please check IMAP/IMAPS port configuration!")
            self.name = "IMAP/IMAPS"

        self.setTimeout(self.timeoutPreAuth)
        log.info(self.name + " established connection to " +
                 str(self.transport.getPeer().host) + ":" +
                 str(self.transport.getPeer().port))

        # add connection to dictionary
        self.factory.clients[self] = (str(self.transport.getPeer().host) +
                                      ":" + str(self.transport.getPeer().port))

        # protocol state
        self.state["connected"] = True
        self.stateRFC = IMAPState.NotAuth
        self.peerOfAttacker = self.transport.getPeer().host

        # server hello
        response = "* OK IMAP4rev1 Service Ready\r\n"
        self.transport.write(response.encode("UTF-8"))
예제 #3
0
 def stopService(self):
     self._stop = True
     self._transport.stopListening()
     try:
         self._transport.connectionLost("Force close/cleanup due to next service scheduling")
     except AttributeError:
         log.err("HTTPService connectionLost wirft AttributeError!")
예제 #4
0
def save():
    try:
        file = open(dbfilePath, 'w')
        file.write(json.dumps(lastLoginTime))
        file.close()
    except:
        # e.g. insufficient write permissions, io error etc.
        log.err("Failed to write lastLoginTime to file \"" + str(dbfilePath) +
                "\"")
예제 #5
0
 def lookupChannel(self, channelType, windowSize, maxPacket, data):
     klass = self.channelLookup.get(channelType, None)
     if not klass:
         log.err("Channel {} requested but not found!".format(
             channelType.decode()))
     else:
         return klass(remoteWindow=windowSize,
                      remoteMaxPacket=maxPacket,
                      data=data,
                      avatar=self)
예제 #6
0
def restore():
    global lastLoginTime
    try:
        file = open(dbfilePath, 'r')
    except FileNotFoundError:
        pass
    else:
        try:
            lastLoginTime = json.loads(file.read())
        except:
            # e.g. damaged json encoding
            log.err("Failed to load lastLoginTime from existing file \"" +
                    str(dbfilePath) + "\"")
예제 #7
0
    def writeToDatabase(self, user, pw, services):

        if type(user) is bytes:
            user = user.decode()
        if type(pw) is bytes:
            pw = pw.decode()

        try:
            with open(self.filepath, "a") as file:
                log.info("Begin Honeytoken creation: {} : {}".format(
                    user, pw))  #TODO make this a proper log type
                file.write("\n" + services + self.sep + user + self.sep + pw +
                           self.sep)
        except Exception as e:
            log.err("Honeytoken DB write exception: {}".format(e))
예제 #8
0
    def stopService(self):
        """
        Closes all open ports and stops the Service
        """
        if not self._stop:
            for key, _ in self._transport.items():
                self._transport[key].stopListening()
                try:
                    self._transport[key].connectionLost(
                        "Force close/cleanup due to next service scheduling")
                except AttributeError:
                    l.err("ListenService connectionLost wirft AttributeError!",
                          key)

        self._stop = True
        self._active = False
예제 #9
0
    def stopOnPort(self, port):
        """
        Stop service on a specific port.
        :param port: the port where the service should stop listening
        """

        if port in self._transport and self._active:
            self._transport[port].stopListening()
            try:
                self._transport[port].connectionLost(
                    "Force close/cleanup due to next service scheduling")
            except AttributeError:
                l.err("ListenService connectionLost wirft AttributeError!",
                      port)
            self._transport.pop(port, None)
            # Dict is Empty
            if self._transport == False:
                self._stop = True
예제 #10
0
    def startService(self):
        """
        Start service on all ports defined in config.py. 
        Ignores ports where it can't listen.
        :return:
        """
        try:
            self._stop = False
            for port in self._port:
                try:
                    self._transport[port] = reactor.listenTCP(
                        port, self._fService)
                except CannotListenError:
                    pass

            self._active = True

        except Exception as e:
            l.err(e)
            self._stop = True
예제 #11
0
    def __init__(self):
        """
        Opens a RAW socket which is able to monitor all TCP/IP Traffic within the machine.
        Root priv. are needed!
        """
        super(TCPFlagSniffer, self).__init__()
        self._name = config.tcpFlagSnifferName
        self.synConnections = dict([])

        self.reInstanceThreads()

        self.synConnectionsLock = threading.Lock()
        self.rootStatus = True

        try:
            self.rSock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
        except socket.error:
            log.info("RAW Socket could not be created. You are root?")
            log.err("TCPFlagSniffer wird nicht ordnungsgemäß ausgeführt werden!")
            self.rootStatus = False
예제 #12
0
    def connectionMade(self):
        if (self.transport.getHost().port == config.pop3Port):
            self.name = config.pop3Name
        elif (self.transport.getHost().port == config.pop3sPort):
            self.name = config.pop3sName
        else:
            log.err("Please check POP3/POP3S port configuration!")
            self.name = "POP3/POP3S"

        self.setTimeout(self.timeoutPreAuth)

        log.info(self.name+" established connection to "+str(self.transport.getPeer().host)+":"+str(self.transport.getPeer().port))

        # add connection to dictionary
        self.factory.clients[self] = (str(self.transport.getPeer().host) + ":" + str(self.transport.getPeer().port))
        
        # protocol state
        self.state["connected"] = True
        self.peerOfAttacker = self.transport.getPeer().host

        # TODO: modify server name
        response = "+OK example.com POP3 server\r\n"
        self.transport.write(response.encode("UTF-8"))