def test_login(self): """Tests if the SMTP bait can login to the SMTP capability""" options = { 'enabled': 'True', 'port': 0, 'protocol_specific_data': { 'banner': 'Test' }, 'users': { 'test': 'test' } } cap = honeypot_smtp.smtp(options, self.work_dir) srv = StreamServer(('0.0.0.0', 0), cap.handle_session) srv.start() bee_info = { 'timing': 'regular', 'username': '******', 'password': '******', 'port': srv.server_port, 'server': '127.0.0.1', 'local_hostname': 'testhost', 'honeypot_id': '1234' } beesessions = {} BaitSession.client_id = 'f51171df-c8f6-4af4-86c0-f4e163cf69e8' current_bait = bee_smtp.Smtp(bee_info) current_bait.connect() current_bait.login(bee_info['username'], bee_info['password']) srv.stop()
def test_login(self): """Tests if the SMTP bait can login to the SMTP capability""" sessions = {} options = {'enabled': 'True', 'port': 0, 'protocol_specific_data': {'banner': 'Test'}, 'users': {'test': 'test'}} cap = hive_smtp.smtp(sessions, options, self.work_dir) srv = StreamServer(('0.0.0.0', 0), cap.handle_session) srv.start() bee_info = { 'timing': 'regular', 'username': '******', 'password': '******', 'port': srv.server_port, 'server': '127.0.0.1', 'local_hostname': 'testhost', 'honeypot_id': '1234' } beesessions = {} BaitSession.client_id = 'f51171df-c8f6-4af4-86c0-f4e163cf69e8' current_bait = bee_smtp.smtp(beesessions, bee_info) current_bait.connect() current_bait.login(bee_info['username'], bee_info['password']) srv.stop()
def test_login(self): """Tests if the SMTP bee can send emails to the SMTP capability""" sessions = {} users = {'test': BaitUser('test', 'test')} authenticator = Authenticator(users) Session.authenticator = authenticator cap = hive_smtp.smtp(sessions, {'enabled': 'True', 'port': 0, 'banner': 'Test'}, users, self.work_dir) srv = StreamServer(('0.0.0.0', 0), cap.handle_session) srv.start() bee_info = { 'timing': 'regular', 'username': '******', 'password': '******', 'port': srv.server_port, 'server': '127.0.0.1', 'local_hostname': 'testhost' } beesessions = {} BaitSession.client_id = 'f51171df-c8f6-4af4-86c0-f4e163cf69e8' current_bee = bee_smtp.smtp(beesessions, bee_info) current_bee.connect() current_bee.login(bee_info['username'], bee_info['password']) result = current_bee.client.sendmail('*****@*****.**', '*****@*****.**', 'Just testing the SMTP bee') self.assertEquals(result, {}) srv.stop()
def test_connection(self): """ Tries to connect and run a EHLO command. Very basic test. """ sessions = {} # 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(sessions, options, self.work_dir) 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()
def test_retrieve(self): """ Tests if a mail can be properly retrieved from the mail corpus """ sessions = {} users = {'test': BaitUser('test', 'test')} authenticator = Authenticator(users) Session.authenticator = authenticator cap = hive_smtp.smtp(sessions, {'enabled': 'True', 'port': 0, 'banner': 'Test'}, users, self.work_dir) srv = StreamServer(('0.0.0.0', 0), cap.handle_session) srv.start() gevent.sleep() bee_info = { 'timing': 'regular', 'username': '******', 'password': '******', 'port': srv.server_port, 'server': '127.0.0.1', 'local_hostname': 'testhost' } beesessions = {} BaitSession.client_id = 'f51171df-c8f6-4af4-86c0-f4e163cf69e8' current_bee = bee_smtp.smtp(beesessions, bee_info) from_addr, to_addr, mail_body = current_bee.get_one_mail() self.assertGreater(len(from_addr), 0) self.assertGreater(len(to_addr), 0) self.assertGreater(len(mail_body), 0)
def test_AUTH_CRAM_MD5_reject(self): """ Makes sure the server rejects all login attempts that use the CRAM-MD5 Authentication method. """ sessions = {} users = {} #provide valid login/pass to authenticator authenticator = Authenticator(users) Session.authenticator = authenticator options = {'enabled': 'True', 'port': 0, 'banner': 'Test'} cap = smtp.smtp(sessions, options, users, self.work_dir) 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()
def test_AUTH_CRAM_MD5_reject(self): """ Makes sure the server rejects all invalid login attempts that use the CRAM-MD5 Authentication method. """ sessions = {} options = { 'enabled': 'True', 'port': 0, 'protocol_specific_data': { 'banner': 'Test' }, 'users': { 'someguy': 'test' } } cap = smtp.smtp(sessions, options, self.work_dir) 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()
def test_AUTH_PLAIN_reject(self): """ Makes sure the server rejects all invalid login attempts that use the PLAIN Authentication method. """ sessions = {} options = { 'enabled': 'True', 'port': 0, 'protocol_specific_data': { 'banner': 'Test' }, 'users': { 'someguy': 'test' } } cap = smtp.smtp(sessions, options, self.work_dir) 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()
def test_AUTH_LOGIN(self): """ Makes sure the server accepts valid login attempts that use the LOGIN Authentication method. """ sessions = {} options = { 'enabled': 'True', 'port': 0, 'protocol_specific_data': { 'banner': 'Test' }, 'users': { 'test': 'test' } } cap = smtp.smtp(sessions, options, self.work_dir) 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, 235) srv.stop()
def test_retrieve(self): """ Tests if a mail can be properly retrieved from the mail corpus """ options = {'enabled': 'True', 'port': 0, 'protocol_specific_data': {'banner': 'Test'}, 'users': {'test': 'test'}} cap = honeypot_smtp.smtp(options, self.work_dir) srv = StreamServer(('0.0.0.0', 0), cap.handle_session) srv.start() gevent.sleep() bait_info = { 'timing': 'regular', 'username': '******', 'password': '******', 'port': srv.server_port, 'server': '127.0.0.1', 'local_hostname': 'testhost' } BaitSession.client_id = 'f51171df-c8f6-4af4-86c0-f4e163cf69e8' current_bee = bee_smtp.Smtp(bait_info) from_addr, to_addr, mail_body = current_bee.get_one_mail() self.assertGreater(len(from_addr), 0) self.assertGreater(len(to_addr), 0) self.assertGreater(len(mail_body), 0)
def test_retrieve(self): """ Tests if a mail can be properly retrieved from the mail corpus """ options = { 'enabled': 'True', 'port': 0, 'protocol_specific_data': { 'banner': 'Test' }, 'users': { 'test': 'test' } } cap = honeypot_smtp.smtp(options, self.work_dir) srv = StreamServer(('0.0.0.0', 0), cap.handle_session) srv.start() gevent.sleep() bait_info = { 'timing': 'regular', 'username': '******', 'password': '******', 'port': srv.server_port, 'server': '127.0.0.1', 'local_hostname': 'testhost' } BaitSession.client_id = 'f51171df-c8f6-4af4-86c0-f4e163cf69e8' current_bee = bee_smtp.Smtp(bait_info) from_addr, to_addr, mail_body = current_bee.get_one_mail() self.assertGreater(len(from_addr), 0) self.assertGreater(len(to_addr), 0) self.assertGreater(len(mail_body), 0)
def test_login(self): """Tests if the SMTP bait can send emails to the SMTP capability""" options = {'enabled': 'True', 'port': 0, 'protocol_specific_data': {'banner': 'Test'}, 'users': {'test': 'test'}} cap = honeypot_smtp.smtp(options, self.work_dir) srv = StreamServer(('0.0.0.0', 0), cap.handle_session) srv.start() bee_info = { 'timing': 'regular', 'username': '******', 'password': '******', 'port': srv.server_port, 'server': '127.0.0.1', 'local_hostname': 'testhost' } beesessions = {} BaitSession.client_id = 'f51171df-c8f6-4af4-86c0-f4e163cf69e8' current_bee = bee_smtp.Smtp(bee_info) current_bee.connect() current_bee.login(bee_info['username'], bee_info['password']) result = current_bee.client.sendmail('*****@*****.**', '*****@*****.**', 'Just testing the SMTP bait') self.assertEquals(result, {}) srv.stop()
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, self.work_dir) 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()
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, self.work_dir) 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()
def test_AUTH_LOGIN(self): """ Makes sure the server accepts valid login attempts that use the LOGIN Authentication method. """ options = {'enabled': 'True', 'port': 0, 'protocol_specific_data': {'banner': 'Test'}, 'users': {'test': 'test'}} cap = smtp.smtp(options, self.work_dir) srv = StreamServer(('0.0.0.0', 0), cap.handle_session) srv.start() smtp_client = smtplib.SMTP('127.0.0.1', srv.server_port, local_hostname='localhost', timeout=15) smtp_client.docmd('AUTH', 'LOGIN') smtp_client.docmd(base64.b64encode('test')) code, resp = smtp_client.docmd(base64.b64encode('test')) self.assertEqual(code, 235) srv.stop()
def test_AUTH_PLAIN_reject(self): """ Makes sure the server rejects all login attempts that use the PLAIN Authentication method. """ sessions = {} users = {} #provide valid login/pass to authenticator authenticator = Authenticator(users) Session.authenticator = authenticator options = {'enabled': 'True', 'port': 0, 'banner': 'Test'} cap = smtp.smtp(sessions, options, users, self.work_dir) 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()
def test_connection(self): """ Tries to connect and run a EHLO command. Very basic test. """ users = {'test': BaitUser('test', 'test')} #provide valid login/pass to authenticator authenticator = Authenticator(users) Session.authenticator = authenticator sessions = {} # Use uncommon port so that we can run test even if the Honeypot is running. options = {'enabled': 'True', 'port': 0, 'banner': 'Test'} cap = smtp.smtp(sessions, options, users, self.work_dir) 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()
def test_AUTH_CRAM_MD5(self): """ Makes sure the server accepts valid login attempts that use the CRAM-MD5 Authentication method. """ options = {'enabled': 'True', 'port': 0, 'protocol_specific_data': {'banner': 'Test'}, 'users': {'test': 'test'}} cap = smtp.smtp(options, self.work_dir) 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, 235) srv.stop()
def test_login(self): """Tests if the SMTP bait can send emails to the SMTP capability""" sessions = {} options = { 'enabled': 'True', 'port': 0, 'protocol_specific_data': { 'banner': 'Test' }, 'users': { 'test': 'test' } } cap = hive_smtp.smtp(sessions, options, self.work_dir) srv = StreamServer(('0.0.0.0', 0), cap.handle_session) srv.start() bee_info = { 'timing': 'regular', 'username': '******', 'password': '******', 'port': srv.server_port, 'server': '127.0.0.1', 'local_hostname': 'testhost' } beesessions = {} BaitSession.client_id = 'f51171df-c8f6-4af4-86c0-f4e163cf69e8' current_bee = bee_smtp.smtp(beesessions, bee_info) current_bee.connect() current_bee.login(bee_info['username'], bee_info['password']) result = current_bee.client.sendmail('*****@*****.**', '*****@*****.**', 'Just testing the SMTP bait') self.assertEquals(result, {}) srv.stop()