Beispiel #1
0
	def run(self):
		port = 25
		records = self.getInput('MXRecord')

		self.result.info('Starting hostname greeting test')
		testResult = []
		for row in records['mx_record']:
			host = row['host']
			ip = row['ip']
			type = row['connection_type']

			try:
				s = connect_to_host(ip, port, type, self)
			except Exception, e:
				self.result.warning('Failed to connect to mail server %s (%s)', (host, ip))
				continue

			try:
				s.send("HELO " + str(socket.getfqdn()) + "\n")
				data = s.recv(1024)

				regex = re.compile(r'^[0-9]*\s(.*?)\s')
				match = regex.match(data)
				if match:
					mailhost = match.group(1)

					ipv = get_ipv_type(mailhost)

					if len(ipv) < 2:
						if ip != ipv[2]:
							self.result.warning("IP of hostname (%s) in greeting message doesn't match mail server IP (%s)", (ip, ipv[2]))
					else:
						self.result.info('Valid hostname (%s) found in greeting message', mailhost)
						testResult.append(True)
				else:
					self.result.warning('Hostname is missing in greeting line:\n%s', data)
			except Exception, e:
				self.result.warning('Failed to resolve hostname (%s) in greeting message on %s', (mailhost, host))
Beispiel #2
0
	def run(self):
		records = self.getInput('MXRecord')

		self.result.info('Starting test')

		testResult = []
		for row in records['mx_record']:
			mxHost = row['host']
			mxType = row['connection_type']

			a = ipv_type_to_a_type(mxType)

			# Find A record for MX record
			arecord = get_arecord(mxHost, mxType)

			if not len(arecord):
				self.result.warning('Could not find %s record for MX record %s', (a, mxHost))
				continue

			# TODO: multiple here?
			arecordIP = arecord[0]
			arecordReverse = dns.reversename.from_address(arecordIP)
			arecordReverse = arecordReverse.to_text()

			# Find PTR record from reverse A record
			ptr = ''
			try:
				ptr = dns.resolver.query(arecordReverse, 'PTR')
				ptr = ptr.rrset[0]
				ptr = ptr.to_text()[0:-1]
			except:
				pass

			if ptr == '':
				self.result.warning('Could not find PTR record for %s', (arecordReverse))
				continue

			# TODO: multiple here?
			ptrHost = ptr

			# Resolve PTR
			resolvedIP = get_ipv_type(ptrHost, mxType)
			if len(resolvedIP) < 3:
				self.result.warning('Could not resolve PTR record %s', (ptrHost))
				continue

			if resolvedIP[2] == arecordIP:
				self.result.info('PTR record (%s) matches the %s record (%s)', \
						(ptrHost, a, arecordIP))
			else:
				testResult.append(arecordIP)
				self.result.warning('PTR record does not match the %s record (%s)', (a, arecordIP))

		code = Plugin.STATUS_OK
		if len(testResult) > 0:
			code = Plugin.STATUS_WARNING

		self.result.extra('more info ptr mx record', type='adv')

		self.result.info('Finished test')
		self.result.setTestStatus(code)
Beispiel #3
0
    def run(self):
        domain = self.getInput('domain')

        self.result.info('Starting MX record lookup against %s', (domain))
        dns = adns.init()
        mxRecords = dns.synchronous(domain, adns.rr.MX)
        records = []
        if (len(mxRecords[3]) >= 1):

            for i in mxRecords[3]:
                prio = str(i[0])
                host = i[1][0]
                ipv = get_ipv_type(host)
                if len(ipv) <= 2:
                    if self.logger:
                        self.logger.debug(
                            "Failed to find IPv type for host \"%s\"" % host)
                    continue
                if self.logger:
                    self.logger.debug("Host: %s, Prio: %s, IPv: %s" %
                                      (host, prio, ipv))

                records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
                  'connection_type': ipv[1]})
                self.result.info('Found host %s (%s), priority %s',
                                 (host, ipv[2], prio))
                if (ipv[1] == "INET6"):
                    ipv = get_ipv_type(host, "INET")
                    if (ipv[2] != None):
                        records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
                         'connection_type': ipv[1]})
                        self.result.info('Found host %s (%s), priority %s',
                                         (host, ipv[2], prio))
        else:
            prio = "-1"
            host = domain
            ipv = get_ipv_type(host)
            if len(ipv) != 0:
                records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
                 'connection_type': ipv[1]})
                self.result.info('Found host %s (%s), priority %s',
                                 (host, ipv[2], prio))
                if (ipv[1] == "INET6"):
                    ipv = get_ipv_type(host, "INET")
                    if (ipv[2] != None):
                        records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
                         'connection_type': ipv[1]})
                        self.result.info('Found no MX-record, using host %s (%s)', \
                          (host, ipv[2]))

        message = ""
        code = Plugin.STATUS_OK
        if len(records) == 0:
            message = 'No records found'
            code = Plugin.STATUS_ERROR
            self.result.error(message)
        elif len(records
                 ) == 1 and records[0]['prio'] == "-1" and self.isChild != 0:
            message = 'No MX-records found, using A/AAAA-record'
            code = Plugin.STATUS_OK
            self.result.info(message)
        elif len(records
                 ) == 1 and records[0]['prio'] == "-1" and self.isChild == 0:
            message = 'No MX-records found, using A/AAAA-record'
            code = Plugin.STATUS_WARNING
            self.result.warning(message)
        elif len(records) == 1 and records[0]['connection_type'] == "INET6" \
          and self.isChild == 0:
            message = 'Only IPv6 addresses found, this might cause delivery problems'
            code = Plugin.STATUS_WARNING
            self.result.warning(message)
        elif len(records) == 1 and self.isChild == 0:
            message = 'Only one record found, two or more is recommended'
            code = Plugin.STATUS_OK
            self.result.info(message)
        else:
            message = 'Multiple MX-records found'
            code = Plugin.STATUS_OK
            self.result.info(message)

        self.result.extra('more info mx record', type='adv')

        self.result.info('Finished MX record lookup against %s', (domain))

        # Output
        if len(records) == 0:
            self.result.setOutput(None)
        else:
            self.result.setOutput({'mx_record': records}, persist=True)

        self.result.setTestStatus(code)
Beispiel #4
0
	def run(self):
		domain = self.getInput('domain')

		self.result.info('Starting MX record lookup against %s', (domain))
		dns = adns.init()
		mxRecords = dns.synchronous(domain, adns.rr.MX)
		records = []
		if (len(mxRecords[3]) >= 1):

			for i in mxRecords[3]:
				prio = str(i[0])
				host = i[1][0]
				ipv = get_ipv_type(host)
				if len(ipv) <= 2:
					if self.logger:
						self.logger.debug("Failed to find IPv type for host \"%s\"" % host)
					continue
				if self.logger:
					self.logger.debug("Host: %s, Prio: %s, IPv: %s" % (host, prio, ipv))

				records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
						'connection_type': ipv[1]})
				self.result.info('Found host %s (%s), priority %s', (host, ipv[2], prio))
				if (ipv[1] == "INET6"):
					ipv = get_ipv_type(host, "INET")
					if (ipv[2] != None):
						records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
							'connection_type': ipv[1]})
						self.result.info('Found host %s (%s), priority %s', (host, ipv[2], prio))
		else:
			prio = "-1"
			host = domain
			ipv = get_ipv_type(host)
			if len(ipv) != 0:
				records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
					'connection_type': ipv[1]})
				self.result.info('Found host %s (%s), priority %s', (host, ipv[2], prio))
				if (ipv[1] == "INET6"):
					ipv = get_ipv_type(host, "INET")
					if (ipv[2] != None):
						records.append({'prio': prio, 'host': ipv[0], 'ip': ipv[2], \
							'connection_type': ipv[1]})
						self.result.info('Found no MX-record, using host %s (%s)', \
								(host, ipv[2]))

		message = ""
		code = Plugin.STATUS_OK
		if len(records) == 0:
			message = 'No records found'
			code = Plugin.STATUS_ERROR
			self.result.error(message)
		elif len(records) == 1 and records[0]['prio'] == "-1" and self.isChild != 0:
			message = 'No MX-records found, using A/AAAA-record'
			code = Plugin.STATUS_OK
			self.result.info(message)
		elif len(records) == 1 and records[0]['prio'] == "-1" and self.isChild == 0:
			message = 'No MX-records found, using A/AAAA-record'
			code = Plugin.STATUS_WARNING
			self.result.warning(message)
		elif len(records) == 1 and records[0]['connection_type'] == "INET6" \
				and self.isChild == 0:
			message = 'Only IPv6 addresses found, this might cause delivery problems'
			code = Plugin.STATUS_WARNING
			self.result.warning(message)
		elif len(records) == 1 and self.isChild == 0:
			message = 'Only one record found, two or more is recommended'
			code = Plugin.STATUS_OK
			self.result.info(message)
		else:
			message = 'Multiple MX-records found'
			code = Plugin.STATUS_OK
			self.result.info(message)

		self.result.extra('more info mx record', type='adv')

		self.result.info('Finished MX record lookup against %s', (domain))

		# Output
		if len(records) == 0:
			self.result.setOutput(None)
		else:
			self.result.setOutput({'mx_record': records}, persist=True)

		self.result.setTestStatus(code)
Beispiel #5
0
    def run(self):
        records = self.getInput('MXRecord')

        self.result.info('Starting test')

        testResult = []
        for row in records['mx_record']:
            mxHost = row['host']
            mxType = row['connection_type']

            a = ipv_type_to_a_type(mxType)

            # Find A record for MX record
            arecord = get_arecord(mxHost, mxType)

            if not len(arecord):
                self.result.warning(
                    'Could not find %s record for MX record %s', (a, mxHost))
                continue

            # TODO: multiple here?
            arecordIP = arecord[0]
            arecordReverse = dns.reversename.from_address(arecordIP)
            arecordReverse = arecordReverse.to_text()

            # Find PTR record from reverse A record
            ptr = ''
            try:
                ptr = dns.resolver.query(arecordReverse, 'PTR')
                ptr = ptr.rrset[0]
                ptr = ptr.to_text()[0:-1]
            except:
                pass

            if ptr == '':
                self.result.warning('Could not find PTR record for %s',
                                    (arecordReverse))
                continue

            # TODO: multiple here?
            ptrHost = ptr

            # Resolve PTR
            resolvedIP = get_ipv_type(ptrHost, mxType)
            if len(resolvedIP) < 3:
                self.result.warning('Could not resolve PTR record %s',
                                    (ptrHost))
                continue

            if resolvedIP[2] == arecordIP:
                self.result.info('PTR record (%s) matches the %s record (%s)', \
                  (ptrHost, a, arecordIP))
            else:
                testResult.append(arecordIP)
                self.result.warning(
                    'PTR record does not match the %s record (%s)',
                    (a, arecordIP))

        code = Plugin.STATUS_OK
        if len(testResult) > 0:
            code = Plugin.STATUS_WARNING

        self.result.extra('more info ptr mx record', type='adv')

        self.result.info('Finished test')
        self.result.setTestStatus(code)