Exemplo n.º 1
0
	def __init__(self):
		Ether2Any.__init__(self, tap=Conf.get('tunnelEthernet', True))
		
		handlerConf = Conf.get('handler', {'allowFrom': None, 'allowTo': None})
		self.mailHandler = NetMailHandler(self.dev, **handlerConf)
		self.mailTo = Conf.get('mailTo', None)
		self.mailFrom = Conf.get('mailFrom', None)
		
		self.smtpConf = Conf.get('smtp')
		smtpd = Conf.get("smtpd", {'enabled': False})
		if smtpd['enabled']:
			self.smtpd = SMTPServerThread(smtpd['listen'], self.mailHandler)
		else:
			self.smtpd = None
		
		imapConf = Conf.get("imap", {'enabled': False})
		if imapConf['enabled']:
			self.imap = SimpleIMAPClient(imapConf, self.mailTo, self.mailHandler)
		else:
			self.imap = None
		
		self.generator = SpamGenerator()
		
		network = Conf.get('network', {'mtu': 1400})
		self.dev.ifconfig(**network)
Exemplo n.º 2
0
class NetMailHandler():
	devWriteMutex = threading.Lock()
	""" Parse, decode and write incoming mails to output. """
	def __init__(self, dev, allowFrom, allowTo):
		self.dev = dev
		self.allowFrom = allowFrom
		self.allowTo = allowTo
		self.generator = SpamGenerator()
	
	def receiveMail(self, mailfrom, mailto, data):
		# FIXME: mailfrom can be None
		mail = email.email.message_from_string(data)
		
		# try to harvest text/plain part of mail
		if mail.get_content_type() == "text/plain":
			self._handleText(mail.get_payload())
		elif mail.get_content_type() == "multipart/alternative":
			for msg in mail.get_payload():
				if msg.get_content_type() == "text/plain":
					self.handleText(msg.get_payload())
		elif self.allowFrom == None and self.allowTo == None:
			self._handleText(data)
		else:
			pass
	
	def _handleText(self, text):
		data = None
		# FIXME: Where do these "\n " or 0a 20 come from?
		#        Seem to occure only when smtplib sends (long) mails to smtpd
		text = text.replace("\n ", "")
		try:
			#tmpTime = time.time()
			data = self.generator.decode(text)
			#print "DECODE", time.time() - tmpTime
		except DecodingException, e:
			print "Error: Could not decode text! See error below"
			print " < ----------- 8< ----------- > "
			print e
			print " < ----------- 8< ----------- > "
		if data:
			self.devWriteMutex.acquire()
			self.dev.write(data)
			self.devWriteMutex.release()
Exemplo n.º 3
0
	def __init__(self, dev, allowFrom, allowTo):
		self.dev = dev
		self.allowFrom = allowFrom
		self.allowTo = allowTo
		self.generator = SpamGenerator()
Exemplo n.º 4
0
class MailTunnel(Ether2Any):
	def __init__(self):
		Ether2Any.__init__(self, tap=Conf.get('tunnelEthernet', True))
		
		handlerConf = Conf.get('handler', {'allowFrom': None, 'allowTo': None})
		self.mailHandler = NetMailHandler(self.dev, **handlerConf)
		self.mailTo = Conf.get('mailTo', None)
		self.mailFrom = Conf.get('mailFrom', None)
		
		self.smtpConf = Conf.get('smtp')
		smtpd = Conf.get("smtpd", {'enabled': False})
		if smtpd['enabled']:
			self.smtpd = SMTPServerThread(smtpd['listen'], self.mailHandler)
		else:
			self.smtpd = None
		
		imapConf = Conf.get("imap", {'enabled': False})
		if imapConf['enabled']:
			self.imap = SimpleIMAPClient(imapConf, self.mailTo, self.mailHandler)
		else:
			self.imap = None
		
		self.generator = SpamGenerator()
		
		network = Conf.get('network', {'mtu': 1400})
		self.dev.ifconfig(**network)
	
	def connectSMTP(self):
		if self.smtpConf['crypto'] == ENCRYPTION_SSL:
			self.smtp = smtplib.SMTP_SSL(self.smtpConf['server'], 465)
		else:
			self.smtp = smtplib.SMTP(self.smtpConf['server'])
		
		if self.smtpConf['crypto'] == ENCRYPTION_STARTTLS:
			self.smtp.starttls()
		
		if self.smtpConf['authentication']:
			self.smtp.login(self.smtpConf['user'], self.smtpConf['password'])
	
	def sendMail(self, fromAddr, toAddrs, subject, msg):
		e = MIMEText(msg)
		e['Subject'] = subject
		e['From'] = fromAddr
		e['To'] = ",\n".join(toAddrs)
		t = time.time()
		try:
			self.smtp.sendmail(fromAddr, toAddrs, e.as_string())
			#print "Mail took %fs" % (time.time()-t)
		except smtplib.SMTPServerDisconnected:
			self.connectSMTP()
			self.smtp.sendmail(fromAddr, toAddrs, e.as_string())
			print "Mail+reconnect took %fs" % (time.time()-t)
	
	def getRandomSubject(self):
		return random.choice([
			"Get laid TODAY!", "This is your chance", "Hello",
			"Business proposal", "Your ad on 2 million websites",
			"Make Money Online", "Assistance needed", "You WON!",
			"Stop wasting time - buy viagra!", "She is waiting for you...",
			"He is waiting for you...", "Your IP addres was logged!",
			"Never be short again!", "Have your own traffic generator!",
			"Credit report FRAUD ALERT", "It's time for you"])
	
	def sendToNet(self, packet):
		data = self.generator.encode(packet)
		self.sendMail(self.mailFrom, [self.mailTo], self.getRandomSubject(), data) 
	
	def sendToDev(self, socket):
		pass
	
	def run(self):
		# start threads / connections
		self.connectSMTP()
		
		if self.imap:
			self.imap.start()

		if self.smtpd:
			self.smtpd.start()
		
		# call super method
		Ether2Any.run(self)