SHARE
TWEET

Untitled

a guest Jun 15th, 2017 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. __author__="Diego Rodriguez"
  2. __date__ ="$08/16/2010 09:53:59 PM$"
  3. from os import path, walk
  4. from ftplib import FTP
  5. import smtplib
  6. import mimetypes
  7. from email.MIMEText import MIMEText
  8. import socket
  9. import sys
  10. import time
  11. import datetime
  12. import shutil
  13. import os
  14. class Log_finder(object):
  15.     def __init__(self):
  16.   self.ftp_server=""#FTP server
  17.   self.ftp_user=""#FTP user
  18.   self.ftp_pass=""#FTP pass
  19.   self.smtp_server="smtp.gmail.com"#SMTP server (irecomend gmail ;))
  20.   self.smtp_user=""#SMTP user
  21.   self.smtp_pass=""# SMTP password
  22.   self.directorio2move="/Mysecretlogfolder"# directory where logs files will be moved
  23.   self.TUEMAIL = ""# your email
  24.   self.archivosLogs=[]
  25.   self.archivos=[]
  26.     def titulo(self):
  27.           tit = """ \n
  28. \t  ________  __                  __  __                          
  29. \t /        |/  |                /  |/  |                          
  30. \t $$$$$$$$/ $$/  _______    ____$$ |$$ |        ______    ______  
  31. \t $$ |__    /  |/       \ /    $$ |$$ |       /      \ /      \
  32. \t $$    |   $$ |$$$$$$$  |/$$$$$$$ |$$ |      /$$$$$$  |/$$$$$$  |
  33. \t $$$$$/    $$ |$$ |  $$ |$$ |  $$ |$$ |      $$ |  $$ |$$ |  $$ |
  34. \t $$ |      $$ |$$ |  $$ |$$ \__$$ |$$ |_____ $$ \__$$ |$$ \__$$ |
  35. \t $$ |      $$ |$$ |  $$ |$$    $$ |$$       |$$    $$/ $$    $$ |
  36. \t $$/       $$/ $$/   $$/  $$$$$$$/ $$$$$$$$/  $$$$$$/   $$$$$$$ |
  37. \t                                                       /  \__$$ |
  38. \t                                                       $$    $$/
  39. \t                                                        $$$$$$/
  40.  
  41. \tHerramienta Creada por: Oscar Diaz y Diego Rodriguez\n\n"""
  42.  
  43. \tHerramienta Creada por: LeXeL : lexelEZ[at]gmail[dot]com\n\n"""
  44.  print "*"*80
  45.  print tit
  46.  print "*"*80
  47.    def sender(self):
  48.  log_ip = "log"
  49.  ftp = FTP(self.ftp_server)
  50.  ftp.login(user=self.ftp_user,passwd=self.ftp_pass)
  51.  arc = str(self.archivos)
  52.  arc = arc.replace("['", "")
  53.  arc = arc.replace("']", "")
  54.  for dic in self.archivosLogs:
  55.  
  56.    print ">> %s" %(dic)
  57.    f = open (dic ,"rb")
  58.    ftp.cwd("/log")
  59.    ftp.storbinary('STOR '+arc,f)
  60.    self.mover()
  61.    self.correo()
  62.    self.archivosLogs.remove(dic)
  63.    self.archivos.remove(arc)
  64.  
  65.    def mover(self):
  66.  if "Mysecretlogfolder" in os.listdir("/"):
  67.    for dirc in self.archivosLogs:
  68.    try:
  69.    shutil.move(dirc,self.directorio2move)
  70.  
  71.    except:
  72.    print "There was an Error\nPlease check this:"
  73.    print "\t[-]The directory %s" %(self.directorio2move)
  74.    print "\t[-]check if the file already exist's"
  75.    sys.exit(1)
  76.  elif "Mysecretlogfolder" not in os.listdir("/"):
  77.    os.system("mkdir %s" %(self.directorio2move))
  78.    for dirc in self.archivosLogs:
  79.    try:
  80.    shutil.move(dirc,self.directorio2move)
  81.    except:
  82.    print "There was an Error\nPlease check this:"
  83.    print "\t[-]The directory %s" %(self.directorio2move)
  84.    print "\t[-]check if the file already exist's"
  85.    sys.exit(1)
  86.  else:
  87.    print "[-] Could't create the directory!"
  88.  
  89.    def info(self):
  90.  now = datetime.datetime.now()
  91.  now =str(now)
  92.  d = ""
  93.  for dic in self.archivosLogs:
  94.    d += "We have found a Log file in: %s\n" %(dic)
  95.    a =  "The log file have been moved to %s" %(self.directorio2move)
  96.  return """Your local Time is :%s\n %s \n %s  """  %(now,d,a)
  97.  
  98.    def correo(self):
  99.  if self.SMTPTF == True:
  100.    smtp = smtplib.SMTP('smtp.gmail.com',25)
  101.    smtp.ehlo()
  102.    smtp.starttls()
  103.    smtp.ehlo()
  104.    smtp.login(self.smtp_user,self.smtp_pass)
  105.    mensaje = MIMEText(self.info())
  106.    mensaje['From']=self.smtp_user
  107.    mensaje['To']=self.TUEMAIL
  108.    mensaje['Subject']="Se ha Encontrado un Log File en tu systema"
  109.    smtp.sendmail(self.smtp_user,self.TUEMAIL,mensaje.as_string())
  110.  
  111.    def conecter(self):
  112.  self.titulo()
  113.  fserver = self.ftp_server
  114.  fuser=self.ftp_user
  115.  fpass=self.ftp_pass
  116.  sserver=self.smtp_server
  117.  suser=self.smtp_user
  118.  spass=self.smtp_pass
  119.  try:
  120.    ftp = FTP(fserver)
  121.    ftp.login(user=fuser,passwd=fpass)
  122.  except BaseException, e:
  123.  
  124.    print '\n [-] Error: %s ' %(e)
  125.  else:
  126.    print "[*]Sucessfuly conencted to: %s" %(fserver)
  127.  if "log" in ftp.nlst():
  128.    print "[+] Found a Log file on the FTP server"
  129.  if "log" not in ftp.nlst():
  130.    print "[+] Creating a Log directory on the FTP server"
  131.    ftp.mkd("/log")
  132.  
  133.  try:
  134.    smtp = smtplib.SMTP(sserver,25)
  135.    smtp.ehlo()
  136.    smtp.starttls()
  137.    smtp.ehlo()
  138.    smtp.login(suser,spass)
  139.  except BaseException, e:
  140.    print '\n [-] Error: %s ' %(e)
  141.    self.SMTPTF = False
  142.  else:
  143.    print "[*]Sucessfuly conencted to: %s" %(sserver)
  144.    self.SMTPTF = True
  145.  
  146.    def buscador(self):
  147.  
  148.  try:
  149.    path_to_search = raw_input("Please enter the path to scan: ")
  150.    timetowait = input("Please enter the time to sleep in seconds: ")
  151.    print "The Program Just start Please wait"
  152.    print "Found:"
  153.  except KeyboardInterrupt, IOError:
  154.    print "[-] An Error occured \n Quiting!"
  155.    sys.exit(1)
  156.  while True:
  157.    now = datetime.datetime.now()
  158.    for root, dirs, files in walk(path_to_search):
  159.    for archivo in files:
  160.    (shortname, extension) = path.splitext(archivo)  
  161.  
  162.    if extension=='.log':
  163.    formato = shortname+" | "+str(now)
  164.    archivo2 = formato+extension
  165.    self.archivosLogs.append(path.join(root, archivo))
  166.    self.archivos.append(archivo2)
  167.    self.sender()
  168.    time.sleep(timetowait)
  169.  
  170. if __name__ == '__main__':
  171.    Log = Log_finder()
  172.    Log.conecter()
  173.    Log.buscador()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top