Ejemplo n.º 1
0
	def test_spf_check_host(self):
		s = spf.SenderPolicyFramework('1.2.3.4', 'king-phisher.com')
		check_host_result = s.check_host()
		self.assertIsNotNone(check_host_result)
		self.assertEqual(check_host_result, 'fail')

		self.assertEqual(spf.check_host('1.2.3.4', 'king-phisher.com'), 'fail')
Ejemplo n.º 2
0
    def test_spf_check_host(self):
        s = spf.SenderPolicyFramework('1.2.3.4', 'king-phisher.com')
        check_host_result = s.check_host()
        self.assertIsNotNone(check_host_result)
        self.assertEqual(check_host_result, 'fail')

        self.assertEqual(spf.check_host('1.2.3.4', 'king-phisher.com'), 'fail')
Ejemplo n.º 3
0
    def test_spf_check_host(self):
        s = spf.SenderPolicyFramework("1.2.3.4", "king-phisher.com")
        check_host_result = s.check_host()
        self.assertIsNotNone(check_host_result)
        self.assertEqual(check_host_result, "fail")

        self.assertEqual(spf.check_host("1.2.3.4", "king-phisher.com"), "fail")
Ejemplo n.º 4
0
	def signal_send_precheck(self, mailer_tab):
		test_ip = mailer.guess_smtp_server_address(
			self.application.config['smtp_server'],
			(self.application.config['ssh_server'] if self.application.config['smtp_ssh_enable'] else None)
		)
		if not test_ip:
			self.logger.info('skipping dmarc policy check because the smtp server address could not be resolved')
			return True
		test_sender, test_domain = self.application.config['mailer.source_email_smtp'].split('@')
		self.logger.debug('checking the dmarc policy for domain: ' + test_domain)
		text_insert = mailer_tab.tabs['send_messages'].text_insert

		text_insert("Checking the DMARC policy of target domain '{0}'... ".format(test_domain))
		try:
			spf_result = spf.check_host(test_ip, test_domain, sender=test_sender)
		except spf.SPFError as error:
			text_insert("done, encountered exception: {0}.\n".format(error.__class__.__name__))
			return True

		try:
			dmarc_policy = DMARCPolicy.from_domain(test_domain)
		except DMARCNoRecordError:
			self.logger.debug('no dmarc policy found for domain: ' + test_domain)
			text_insert('done, no policy found.\n')
			return True
		except DMARCError as error:
			self.logger.warning('dmarc error: ' + error.message)
			text_insert("done, encountered exception: {0}.\n".format(error.__class__.__name__))
			return False
		text_insert('done.\n')
		self.logger.debug("dmarc policy set to {0!r} for domain: {1}".format(dmarc_policy.policy, test_domain))
		text_insert('Found DMARC policy:\n')
		text_insert('  Policy:  ' + dmarc_policy.policy + '\n')
		text_insert('  Percent: ' + dmarc_policy.get('pct') + '\n')
		if dmarc_policy.get('rua'):
			text_insert('  RUA URI: ' + dmarc_policy.get('rua') + '\n')
		if dmarc_policy.get('ruf'):
			text_insert('  RUF URI: ' + dmarc_policy.get('ruf') + '\n')

		if spf_result == constants.SPFResult.PASS:
			return True
		if dmarc_policy.policy == 'none' or dmarc_policy.get('pct') == '0':
			return True

		if dmarc_policy.policy == 'quarantine':
			message = 'The DMARC policy results in these messages being quarantined.'
		elif dmarc_policy.policy == 'reject':
			message = 'The DMARC policy results in these messages being rejected.'
		text_insert('WARNING: ' + message + '\n')
		ignore = gui_utilities.show_dialog_yes_no(
			'DMARC Policy Failure',
			self.application.get_active_window(),
			message + '\nContinue sending messages anyways?'
		)
		return ignore
Ejemplo n.º 5
0
	def signal_send_precheck(self, mailer_tab):
		test_ip = mailer.guess_smtp_server_address(
			self.application.config['smtp_server'],
			(self.application.config['ssh_server'] if self.application.config['smtp_ssh_enable'] else None)
		)
		if not test_ip:
			self.logger.info('skipping dmarc policy check because the smtp server address could not be resolved')
			return True
		test_sender, test_domain = self.application.config['mailer.source_email_smtp'].split('@')
		self.logger.debug('checking the dmarc policy for domain: ' + test_domain)
		text_insert = mailer_tab.tabs['send_messages'].text_insert

		text_insert("Checking the DMARC policy of target domain '{0}'... ".format(test_domain))
		try:
			spf_result = spf.check_host(test_ip, test_domain, sender=test_sender)
		except spf.SPFError as error:
			text_insert("done, encountered exception: {0}.\n".format(error.__class__.__name__))
			return True

		try:
			dmarc_policy = DMARCPolicy.from_domain(test_domain)
		except DMARCNoRecordError:
			self.logger.debug('no dmarc policy found for domain: ' + test_domain)
			text_insert('done, no policy found.\n')
			return True
		except DMARCError as error:
			self.logger.warning('dmarc error: ' + error.message)
			text_insert("done, encountered exception: {0}.\n".format(error.__class__.__name__))
			return False
		text_insert('done.\n')
		self.logger.debug("dmarc policy set to {0!r} for domain: {1}".format(dmarc_policy.policy, test_domain))
		text_insert('Found DMARC policy:\n')
		text_insert('  Policy:  ' + dmarc_policy.policy + '\n')
		text_insert('  Percent: ' + dmarc_policy.get('pct') + '\n')
		if dmarc_policy.get('rua'):
			text_insert('  RUA URI: ' + dmarc_policy.get('rua') + '\n')
		if dmarc_policy.get('ruf'):
			text_insert('  RUF URI: ' + dmarc_policy.get('ruf') + '\n')

		if spf_result == constants.SPFResult.PASS:
			return True
		if dmarc_policy.policy == 'none' or dmarc_policy.get('pct') == '0':
			return True

		if dmarc_policy.policy == 'quarantine':
			message = 'The DMARC policy results in these messages being quarantined.'
		elif dmarc_policy.policy == 'reject':
			message = 'The DMARC policy results in these messages being rejected.'
		text_insert('WARNING: ' + message + '\n')
		ignore = gui_utilities.show_dialog_yes_no(
			'DMARC Policy Failure',
			self.application.get_active_window(),
			message + '\nContinue sending messages anyways?'
		)
		return ignore
Ejemplo n.º 6
0
	def test_spf_nonexistent_domain(self):
		s = spf.SenderPolicyFramework('1.2.3.4', 'doesnotexist.king-phisher.com')
		self.assertIsNone(s.check_host())
		self.assertIsNone(spf.check_host('1.2.3.4', 'doesnotexist.king-phisher.com'))
Ejemplo n.º 7
0
 def test_spf_nonexistent_domain(self):
     s = spf.SenderPolicyFramework('1.2.3.4',
                                   'doesnotexist.king-phisher.com')
     self.assertIsNone(s.check_host())
     self.assertIsNone(
         spf.check_host('1.2.3.4', 'doesnotexist.king-phisher.com'))