Ejemplo n.º 1
0
    def test_AUTH_LOGIN_reject(self):
        """ Makes sure the server rejects all invalid login attempts that use the LOGIN Authentication method.
        """
        def smtp_auth_login_reject():
            smtp_ = smtplib.SMTP('127.0.0.1',
                                 8888,
                                 local_hostname='localhost',
                                 timeout=15)
            smtp_.docmd('AUTH', 'LOGIN')
            smtp_.docmd(str(base64.b64encode(b'test'), 'utf-8'))
            code, _ = smtp_.docmd(str(base64.b64encode(b'test'), 'utf-8'))
            smtp_.quit()
            self.assertEqual(code, 535)

        options = {
            'enabled': 'True',
            'port': 0,
            'protocol_specific_data': {
                'banner': 'Test'
            },
            'users': {
                'someguy': 'test'
            }
        }

        smtp_cap = smtp.smtp(options, self.loop)

        server_coro = asyncio.start_server(smtp_cap.handle_session,
                                           '0.0.0.0',
                                           8888,
                                           loop=self.loop)
        self.server = self.loop.run_until_complete(server_coro)

        smtp_task = self.loop.run_in_executor(None, smtp_auth_login_reject)
        self.loop.run_until_complete(smtp_task)
Ejemplo n.º 2
0
    def test_connection(self):
        """ Tries to connect and run a EHLO command. Very basic test.
        """
        def smtp_connection():
            smtp_ = smtplib.SMTP('127.0.0.1',
                                 8888,
                                 local_hostname='localhost',
                                 timeout=15)
            smtp_.ehlo()
            smtp_.quit()

        # Use uncommon port so that we can run test even if the Honeypot is running.
        options = {
            'enabled': 'True',
            'port': 8888,
            'protocol_specific_data': {
                'banner': 'test'
            },
            'users': {
                'test': 'test'
            },
        }
        smtp_cap = smtp.smtp(options, self.loop)

        server_coro = asyncio.start_server(smtp_cap.handle_session,
                                           '0.0.0.0',
                                           8888,
                                           loop=self.loop)
        self.server = self.loop.run_until_complete(server_coro)

        smtp_task = self.loop.run_in_executor(None, smtp_connection)
        self.loop.run_until_complete(smtp_task)
Ejemplo n.º 3
0
    def test_AUTH_CRAM_MD5_reject(self):
        """ Makes sure the server rejects all invalid login attempts that use the
            CRAM-MD5 Authentication method.
        """

        options = {
            'enabled': 'True',
            'port': 0,
            'protocol_specific_data': {
                'banner': 'Test'
            },
            'users': {
                'someguy': 'test'
            }
        }
        cap = smtp.smtp(options)
        srv = StreamServer(('0.0.0.0', 0), cap.handle_session)
        srv.start()

        def encode_cram_md5(challenge, user, password):
            challenge = base64.decodestring(challenge)
            response = user + ' ' + hmac.HMAC(password, challenge).hexdigest()
            return base64.b64encode(response)

        smtp_ = smtplib.SMTP('127.0.0.1',
                             srv.server_port,
                             local_hostname='localhost',
                             timeout=15)
        _, resp = smtp_.docmd('AUTH', 'CRAM-MD5')
        code, resp = smtp_.docmd(encode_cram_md5(resp, 'test', 'test'))
        # For now, the server's going to return a 535 code.
        self.assertEqual(code, 535)
        srv.stop()
Ejemplo n.º 4
0
    def test_AUTH_CRAM_MD5_reject(self):
        """ Makes sure the server rejects all invalid login attempts that use the
            CRAM-MD5 Authentication method.
        """
        def encode_cram_md5(challenge, user, password):
            challenge = base64.decodebytes(challenge)
            response = user + b' ' + bytes(hmac.HMAC(password, challenge).hexdigest(), 'utf-8')
            return str(base64.b64encode(response), 'utf-8')

        def smtp_auth_cram_md5():
            smtp_ = smtplib.SMTP('127.0.0.1', 8888, local_hostname='localhost', timeout=15)
            _, resp = smtp_.docmd('AUTH', 'CRAM-MD5')
            code, resp = smtp_.docmd(encode_cram_md5(resp, b'test', b'test'))
            smtp_.quit()
            # For now, the server's going to return a 535 code.
            self.assertEqual(code, 535)

        options = {'enabled': 'True', 'port': 8888, 'protocol_specific_data': {'banner': 'Test'},
                   'users': {'someguy': 'test'}}
        smtp_cap = smtp.smtp(options, self.loop)

        server_coro = asyncio.start_server(smtp_cap.handle_session, '0.0.0.0', 8888, loop=self.loop)
        self.server = self.loop.run_until_complete(server_coro)

        smtp_task = self.loop.run_in_executor(None, smtp_auth_cram_md5)
        self.loop.run_until_complete(smtp_task)
Ejemplo n.º 5
0
    def test_connection(self):
        """ Tries to connect and run a EHLO command. Very basic test.
        """

        # Use uncommon port so that we can run test even if the Honeypot is running.
        options = {
            'enabled': 'True',
            'port': 0,
            'protocol_specific_data': {
                'banner': 'test'
            },
            'users': {
                'test': 'test'
            },
        }
        cap = smtp.smtp(options)
        srv = StreamServer(('0.0.0.0', 0), cap.handle_session)
        srv.start()

        smtp_ = smtplib.SMTP('127.0.0.1',
                             srv.server_port,
                             local_hostname='localhost',
                             timeout=15)
        smtp_.ehlo()
        smtp_.quit()
        srv.stop()
Ejemplo n.º 6
0
    def test_AUTH_LOGIN_reject(self):
        """ Makes sure the server rejects all invalid login attempts that use the LOGIN Authentication method.
        """

        options = {
            'enabled': 'True',
            'port': 0,
            'protocol_specific_data': {
                'banner': 'Test'
            },
            'users': {
                'someguy': 'test'
            }
        }

        cap = smtp.smtp(options)
        srv = StreamServer(('0.0.0.0', 0), cap.handle_session)
        srv.start()

        smtp_ = smtplib.SMTP('127.0.0.1',
                             srv.server_port,
                             local_hostname='localhost',
                             timeout=15)
        smtp_.docmd('AUTH', 'LOGIN')
        smtp_.docmd(base64.b64encode('test'))
        code, resp = smtp_.docmd(base64.b64encode('test'))
        self.assertEqual(code, 535)
        srv.stop()
Ejemplo n.º 7
0
    def test_AUTH_PLAIN_reject(self):
        """ Makes sure the server rejects all invalid login attempts that use the PLAIN Authentication method.
        """
        options = {'enabled': 'True', 'port': 0, 'protocol_specific_data': {'banner': 'Test'},
                   'users': {'someguy': 'test'}}

        cap = smtp.smtp(options)
        srv = StreamServer(('0.0.0.0', 0), cap.handle_session)
        srv.start()

        smtp_ = smtplib.SMTP('127.0.0.1', srv.server_port, local_hostname='localhost', timeout=15)
        arg = '\0%s\0%s' % ('test', 'test')
        code, resp = smtp_.docmd('AUTH', 'PLAIN ' + base64.b64encode(arg))
        self.assertEqual(code, 535)
        srv.stop()
Ejemplo n.º 8
0
    def test_connection(self):
        """ Tries to connect and run a EHLO command. Very basic test.
        """

        # Use uncommon port so that we can run test even if the Honeypot is running.
        options = {'enabled': 'True', 'port': 0, 'protocol_specific_data': {'banner': 'test'},
                   'users': {'test': 'test'},}
        cap = smtp.smtp(options)
        srv = StreamServer(('0.0.0.0', 0), cap.handle_session)
        srv.start()

        smtp_ = smtplib.SMTP('127.0.0.1', srv.server_port, local_hostname='localhost', timeout=15)
        smtp_.ehlo()
        smtp_.quit()
        srv.stop()
Ejemplo n.º 9
0
    def test_AUTH_CRAM_MD5_reject(self):
        """ Makes sure the server rejects all invalid login attempts that use the
            CRAM-MD5 Authentication method.
        """

        options = {'enabled': 'True', 'port': 0, 'protocol_specific_data': {'banner': 'Test'},
                   'users': {'someguy': 'test'}}
        cap = smtp.smtp(options)
        srv = StreamServer(('0.0.0.0', 0), cap.handle_session)
        srv.start()

        def encode_cram_md5(challenge, user, password):
            challenge = base64.decodestring(challenge)
            response = user + ' ' + hmac.HMAC(password, challenge).hexdigest()
            return base64.b64encode(response)

        smtp_ = smtplib.SMTP('127.0.0.1', srv.server_port, local_hostname='localhost', timeout=15)
        _, resp = smtp_.docmd('AUTH', 'CRAM-MD5')
        code, resp = smtp_.docmd(encode_cram_md5(resp, 'test', 'test'))
        # For now, the server's going to return a 535 code.
        self.assertEqual(code, 535)
        srv.stop()