Ejemplo n.º 1
0
	def run(self):
		records = self.getInput('MXRecord')
		port = 25
		# Get settings
		max_connection_time = int(self.pluginConfig.get('connection_warning_length'))

		self.result.info('Starting connection test')

		if len(records['mx_record']) <= 0:
			self.result.error('Test could not be executed')

		results = []
		slowConnections = 0
		failedConnections = 0
		out = {'connection_time': []}
		statusCounts = {Plugin.STATUS_OK: 0, Plugin.STATUS_WARNING: 0, Plugin.STATUS_ERROR: 0}
		for ip in records['mx_record']:
			prio = ip['prio']
			host = ip['host']
			type = ip['connection_type']
			ip = ip['ip']

			code = Plugin.STATUS_OK
			error = ""
			end = None
			try:
				#s.settimeout(20.0)
				#c = s.connect( (ip, 25) )
				#s.close()
				start = end = 0
				try:
					start = tt.time()
					s = connect_to_host(ip, port, type, self)
					end = tt.time()
				except Exception, e:
					self.result.warning('Failed to connect to mail server %s (%s)', (host, ip))
					continue

				ftime = end - start
				time = "%0.6f" % (ftime)

				out['connection_time'].append({'time': time, 'host': host, 'ip': ip})
				s.recv(1024)
			except socket.error, e:
				self.logger.debug('Host: %s (%s), Connection plugin error: %s' \
						% (host, ip, e))

				failedConnections += 1
				code = Plugin.STATUS_WARNING
				if e[0] == 101:
					error = "network unreachable"
				elif e[0] == 111:
					error = "connection refused"
				elif e[0] == 110 or e[0] == 'timed out' or e == 'timed out':
					error = "connection timed out"
				else:
					error = "unable to connect"
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
    def run(self):
        records = self.getInput('MXRecord')
        port = 25
        # Get settings
        max_connection_time = int(
            self.pluginConfig.get('connection_warning_length'))

        self.result.info('Starting connection test')

        if len(records['mx_record']) <= 0:
            self.result.error('Test could not be executed')

        results = []
        slowConnections = 0
        failedConnections = 0
        out = {'connection_time': []}
        statusCounts = {
            Plugin.STATUS_OK: 0,
            Plugin.STATUS_WARNING: 0,
            Plugin.STATUS_ERROR: 0
        }
        for ip in records['mx_record']:
            prio = ip['prio']
            host = ip['host']
            type = ip['connection_type']
            ip = ip['ip']

            code = Plugin.STATUS_OK
            error = ""
            end = None
            try:
                #s.settimeout(20.0)
                #c = s.connect( (ip, 25) )
                #s.close()
                start = end = 0
                try:
                    start = tt.time()
                    s = connect_to_host(ip, port, type, self)
                    end = tt.time()
                except Exception, e:
                    self.result.warning(
                        'Failed to connect to mail server %s (%s)', (host, ip))
                    continue

                ftime = end - start
                time = "%0.6f" % (ftime)

                out['connection_time'].append({
                    'time': time,
                    'host': host,
                    'ip': ip
                })
                s.recv(1024)
            except socket.error, e:
                self.logger.debug('Host: %s (%s), Connection plugin error: %s' \
                  % (host, ip, e))

                failedConnections += 1
                code = Plugin.STATUS_WARNING
                if e[0] == 101:
                    error = "network unreachable"
                elif e[0] == 111:
                    error = "connection refused"
                elif e[0] == 110 or e[0] == 'timed out' or e == 'timed out':
                    error = "connection timed out"
                else:
                    error = "unable to connect"
Ejemplo n.º 4
0
	def run(self):
		domain = self.getInput('domain')
		email = self.getInput('email')
		records = self.getInput('MXRecord')
		port = 25

		self.result.info('Started user scanning 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:
				self.result.warning('Failed to connect to mail server %s (%s)', (host, ip))
				testResult.append(True)
				continue

			# Random email used in test
			rnd = ''
			rnd = ''.join(random.sample(string.ascii_lowercase + string.digits, 12))
			rnd += '@' + domain

			fqdn = socket.getfqdn()
			conversation = [
				[
					'HELO %s\r\n' % fqdn,
					'VRFY %s\r\n' % email,
					'VRFY %s\r\n' % rnd
				],
				[
					'250.*',
					'25[0-2].*',
					'25[1-2].*|55[0,4].*',
				],
				[
					'252.*'
				]
			]

			# Scan for users
			testlog = ''
			error = False
			counter252 = 0
			for i in range(len(conversation[0])):
				send = conversation[0][i]
				recv = conversation[1][i]

				testlog = ''
				if i == 0:
					data = s.recv(1024)
					testlog += "<<< %s" % data

					if not re.search('220.*', data):
						self.result.info('%s', testlog)
						self.result.warning("No standard greeting on %s (%s)", (host, ip))
						testResult.append(True)
						continue

				s.send(send)
				testlog += ">>> %s" % send

				data = ''
				try:
					data = s.recv(1024)
				except socket.timeout:
					self.result.warning('Connection timed out')
					error = True
					break

				testlog += "<<< %s" % data
				self.result.info('%s', testlog)

				if not re.search(recv, data):
					error = True
					break

				if re.search(conversation[2][0], data):
					counter252 += 1

			testResult.append(error)

			if counter252 == 2:
				self.result.goldstar("%s (%s) answering \"252\" which is good for avoiding spam, see http://cr.yp.to/smtp/vrfy.html for more information.", (host, ip))

			if error:
				self.result.warning("User scanning %s (%s) failed\n%s", (host,ip,testlog))
			else:
				self.result.info('User scanning %s (%s) completed', (host,ip))


		self.result.extra('more info user scanning', type='adv')

		self.result.info('Finished user scanning test')

		code = Plugin.STATUS_OK
		if True in testResult:
			code = Plugin.STATUS_WARNING

		self.result.setTestStatus(code)
Ejemplo n.º 5
0
    def run(self):
        port = 25

        # Get default input that all plugins receive (domain, name and testId)
        domain = self.getInput('domain')
        email = self.getInput('email')

        # Get the output from the MXRecord-plugin
        records = self.getInput('MXRecord')

        self.result.info('Started user scanning 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))
                testResult.append(True)
                continue

            # Create a random email used in the test
            rnd = ''
            rnd = ''.join(
                random.sample(string.ascii_lowercase + string.digits, 12))
            rnd += '@' + domain

            fqdn = socket.getfqdn()
            # Conversation with email server divided in three parts: [ What to send ], [ what answers to excpect ], [ what answers is classed as errors ].
            conversation = [[
                'HELO %s\r\n' % fqdn,
                'VRFY %s\r\n' % email,
                'VRFY %s\r\n' % rnd
            ], [
                '250.*',
                '25[0-2].*',
                '25[1-2].*|55[0,4].*',
            ], ['252.*']]

            # Run conversation
            testlog = ''
            error = False
            counter252 = 0
            for i in range(len(conversation[0])):
                send = conversation[0][i]
                recv = conversation[1][i]

                testlog = ''
                # Is this the first iteraction with the server?
                if i == 0:
                    data = s.recv(1024)
                    testlog += "<<< %s" % data

                    # Make sure we get a 220 greeting message
                    if not re.search('220.*', data):
                        self.result.info('%s', testlog)
                        self.result.warning("No standard greeting on %s (%s)",
                                            (host, ip))
                        testResult.append(True)
                        continue

                # Send data to the server
                s.send(send)
                testlog += ">>> %s" % send

                # Get the answer from the server
                data = s.recv(1024)
                testlog += "<<< %s" % data
                self.result.info('%s', testlog)

                # if the reply isn't expected proceed with next server
                if not re.search(recv, data):
                    error = True
                    break

                # Set count number of 252 entries for server
                if re.search(conversation[2][0], data):
                    counter252 += 1

            testResult.append(error)

            # if the server responds 252 on both set a goldstar
            if counter252 == 2:
                # Add a gold star to the test with a message explaining the reason behind it
                self.result.goldstar(
                    "%s (%s) answering \"252\" which is good for avoiding spam, see http://cr.yp.to/smtp/vrfy.html for more information.",
                    (host, ip))

            if error:
                self.result.warning("User scanning %s (%s) failed\n%s",
                                    (host, ip, testlog))
            else:
                self.result.info('User scanning %s (%s) completed', (host, ip))
Ejemplo n.º 6
0
	def run(self):
		domain = self.getInput('domain')
		email = self.getInput('email')
		records = self.getInput('MXRecord')
		port = 25

		self.result.info('Started user scanning test')

		testResult = []
		mx_counter252 = 0
		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:
				self.result.warning('Failed to connect to mail server %s (%s)', (host, ip))
				testResult.append(True)
				continue

			# Random email used in test
			rnd = ''
			rnd = ''.join(random.sample(string.ascii_lowercase + string.digits, 12))
			rnd += '@' + domain

			fqdn = socket.getfqdn()
			conversation = [
				[
					'HELO %s\r\n' % fqdn,
					'VRFY %s\r\n' % email,
					'VRFY %s\r\n' % rnd
				],
				[
					'250.*',
					'25[0-2].*',
					'25[1-2].*|55[0,4].*',
				],
				[
					'252.*'
				]
			]

			# Scan for users
			testlog = ''
			error = False
			counter252 = 0
			for i in range(len(conversation[0])):
				send = conversation[0][i]
				recv = conversation[1][i]

				testlog = ''
				if i == 0:
					data = s.recv(1024)
					testlog += "<<< %s" % data

					if not re.search('220.*', data):
						self.result.info('%s', testlog)
						self.result.warning("No standard greeting on %s (%s)", (host, ip))
						testResult.append(True)
						continue

				s.send(send)
				testlog += ">>> %s" % send

				data = ''
				try:
					data = s.recv(1024)
				except socket.timeout:
					self.result.warning('Connection timed out')
					error = True
					break

				testlog += "<<< %s" % data
				self.result.info('%s', testlog)

				if not re.search(recv, data):
					error = True
					break

				if re.search(conversation[2][0], data):
					counter252 += 1

			testResult.append(error)

			if counter252 == 2:
				mx_counter252 += 1

			if error:
				self.result.warning("User scanning %s (%s) failed\n%s", (host,ip,testlog))
			else:
				self.result.info('User scanning %s (%s) completed', (host,ip))

		if mx_counter252 > 0:
			self.result.goldstar('At least one MX host answers "252" which is good for avoiding spam, see http://cr.yp.to/smtp/vrfy.html for more information.')

		self.result.extra('more info user scanning', type='adv')

		self.result.info('Finished user scanning test')

		code = Plugin.STATUS_OK
		if True in testResult:
			code = Plugin.STATUS_WARNING

		self.result.setTestStatus(code)
Ejemplo n.º 7
0
	def run(self):
		port = 25

		# Get default input that all plugins receive (domain, name and testId)
		domain = self.getInput('domain')
		email = self.getInput('email')

		# Get the output from the MXRecord-plugin	
		records = self.getInput('MXRecord')

		self.result.info('Started user scanning 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))
				testResult.append(True)
				continue

			# Create a random email used in the test
			rnd = ''
			rnd = ''.join(random.sample(string.ascii_lowercase + string.digits, 12))
			rnd += '@' + domain
			
			fqdn = socket.getfqdn()
			# Conversation with email server divided in three parts: [ What to send ], [ what answers to excpect ], [ what answers is classed as errors ].
			conversation = [
				[
					'HELO %s\r\n' % fqdn,
					'VRFY %s\r\n' % email,
					'VRFY %s\r\n' % rnd
				],
				[
					'250.*',
					'25[0-2].*',
					'25[1-2].*|55[0,4].*',
				],
				[
					'252.*'
				]
			]

			# Run conversation
			testlog = ''
			error = False
			counter252 = 0
			for i in range(len(conversation[0])):
				send = conversation[0][i]
				recv = conversation[1][i]
			
				testlog = ''
				# Is this the first iteraction with the server?
				if i == 0:
					data = s.recv(1024)
					testlog += "<<< %s" % data
					
					# Make sure we get a 220 greeting message	
					if not re.search('220.*', data):
						self.result.info('%s', testlog)
						self.result.warning("No standard greeting on %s (%s)", (host,ip))
						testResult.append(True)
						continue
				
				# Send data to the server
				s.send(send)
				testlog += ">>> %s" % send

				# Get the answer from the server
				data = s.recv(1024)
				testlog += "<<< %s" % data
				self.result.info('%s', testlog)

				# if the reply isn't expected proceed with next server
				if not re.search(recv, data):
					error = True
					break

				# Set count number of 252 entries for server
				if re.search(conversation[2][0], data):
					counter252 += 1

			testResult.append(error)

			# if the server responds 252 on both set a goldstar
			if counter252 == 2:
				# Add a gold star to the test with a message explaining the reason behind it
				self.result.goldstar("%s (%s) answering \"252\" which is good for avoiding spam, see http://cr.yp.to/smtp/vrfy.html for more information.", (host, ip))

			if error:
				self.result.warning("User scanning %s (%s) failed\n%s", (host,ip,testlog))
			else:
				self.result.info('User scanning %s (%s) completed', (host,ip))