Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  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: LeXeL : lexelEZ[at]gmail[dot]com\n\n"""
  42. print "*"*80
  43. print tit
  44. print "*"*80
  45. def sender(self):
  46. log_ip = "log"
  47. ftp = FTP(self.ftp_server)
  48. ftp.login(user=self.ftp_user,passwd=self.ftp_pass)
  49. arc = str(self.archivos)
  50. arc = arc.replace("['", "")
  51. arc = arc.replace("']", "")
  52. for dic in self.archivosLogs:
  53.  
  54. print ">>>>>>> %s" %(dic)
  55. f = open (dic ,"rb")
  56. ftp.cwd("/log")
  57. ftp.storbinary('STOR '+arc,f)
  58. self.mover()
  59. self.correo()
  60. self.archivosLogs.remove(dic)
  61. self.archivos.remove(arc)
  62.  
  63.  
  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.  
  90. def info(self):
  91. now = datetime.datetime.now()
  92. now =str(now)
  93. d = ""
  94. for dic in self.archivosLogs:
  95. d += "We have found a Log file in: %s\n" %(dic)
  96. a = "The log file have been moved to %s" %(self.directorio2move)
  97. return """Your local Time is :%s\n %s \n %s """ %(now,d,a)
  98.  
  99. def correo(self):
  100. if self.SMTPTF == True:
  101. smtp = smtplib.SMTP('smtp.gmail.com',25)
  102. smtp.ehlo()
  103. smtp.starttls()
  104. smtp.ehlo()
  105. smtp.login(self.smtp_user,self.smtp_pass)
  106. mensaje = MIMEText(self.info())
  107. mensaje['From']=self.smtp_user
  108. mensaje['To']=self.TUEMAIL
  109. mensaje['Subject']="Se ha Encontrado un Log File en tu systema"
  110. smtp.sendmail(self.smtp_user,self.TUEMAIL,mensaje.as_string())
  111.  
  112.  
  113. def conecter(self):
  114. self.titulo()
  115. fserver = self.ftp_server
  116. fuser=self.ftp_user
  117. fpass=self.ftp_pass
  118. sserver=self.smtp_server
  119. suser=self.smtp_user
  120. spass=self.smtp_pass
  121. try:
  122. ftp = FTP(fserver)
  123. ftp.login(user=fuser,passwd=fpass)
  124. except BaseException, e:
  125.  
  126. print '\n [-] Error: %s ' %(e)
  127. else:
  128. print "
  129. [*]Sucessfuly conencted to: %s" %(fserver)
  130. if "log" in ftp.nlst():
  131. print "[+] Found a Log file on the FTP server"
  132. if "log" not in ftp.nlst():
  133. print "[+] Creating a Log directory on the FTP server"
  134. ftp.mkd("/log")
  135.  
  136.  
  137. try:
  138. smtp = smtplib.SMTP(sserver,25)
  139. smtp.ehlo()
  140. smtp.starttls()
  141. smtp.ehlo()
  142. smtp.login(suser,spass)
  143. except BaseException, e:
  144. print '\n [-] Error: %s ' %(e)
  145. self.SMTPTF = False
  146. else:
  147. print "
  148. [*]Sucessfuly conencted to: %s" %(sserver)
  149. self.SMTPTF = True
  150.  
  151.  
  152.  
  153. def buscador(self):
  154.  
  155. try:
  156. path_to_search = raw_input("Please enter the path to scan: ")
  157. timetowait = input("Please enter the time to sleep in seconds: ")
  158. print "The Program Just start Please wait"
  159. print "Found:"
  160. except KeyboardInterrupt, IOError:
  161. print "[-] An Error occured \n Quiting!"
  162. sys.exit(1)
  163. while True:
  164. now = datetime.datetime.now()
  165. for root, dirs, files in walk(path_to_search):
  166. for archivo in files:
  167. (shortname, extension) = path.splitext(archivo)
  168.  
  169. if extension=='.log':
  170. formato = shortname+" | "+str(now)
  171. archivo2 = formato+extension
  172. self.archivosLogs.append(path.join(root, archivo))
  173. self.archivos.append(archivo2)
  174. self.sender()
  175. time.sleep(timetowait)
  176.  
  177.  
  178.  
  179. if __name__ == '__main__':
  180. Log = Log_finder()
  181. Log.conecter()
  182. Log.buscador()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement