diff --git a/README.md b/README.md index dcea9d5..b3ec78f 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@
+## What have I changed? -- By PoulDev +I added some commands to move the mouse pointer and clicking with it, I've also added some customer control commands like increasing the audio volume and more. + ## Quick Start Guide Install and have your USB Rubber Ducky working in less than 5 minutes. diff --git a/code.py b/code.py index 3d47f85..b879aed 100644 --- a/code.py +++ b/code.py @@ -8,7 +8,6 @@ import time -import digitalio from board import * import board from duckyinpython import * @@ -21,8 +20,6 @@ time.sleep(.5) def startWiFi(): - import ipaddress - # Get wifi details and more from a secrets.py file try: from secrets import secrets except ImportError: @@ -41,13 +38,6 @@ def startWiFi(): #supervisor.disable_autoreload() supervisor.runtime.autoreload = False -if(board.board_id == 'raspberry_pi_pico'): - led = pwmio.PWMOut(board.LED, frequency=5000, duty_cycle=0) -elif(board.board_id == 'raspberry_pi_pico_w'): - led = digitalio.DigitalInOut(board.LED) - led.switch_to_output() - - progStatus = False progStatus = getProgrammingStatus() print("progStatus", progStatus) @@ -69,14 +59,14 @@ async def main_loop(): button_task = asyncio.create_task(monitor_buttons(button1)) if(board.board_id == 'raspberry_pi_pico_w'): - pico_led_task = asyncio.create_task(blink_pico_w_led(led)) + pico_led_task = asyncio.create_task(blink_pico_w_led()) print("Starting Wifi") startWiFi() print("Starting Web Service") webservice_task = asyncio.create_task(startWebService()) await asyncio.gather(pico_led_task, button_task, webservice_task) else: - pico_led_task = asyncio.create_task(blink_pico_led(led)) + pico_led_task = asyncio.create_task(blink_pico_led()) await asyncio.gather(pico_led_task, button_task) asyncio.run(main_loop()) diff --git a/duckyinpython.py b/duckyinpython.py index a0a6087..d1d32e4 100644 --- a/duckyinpython.py +++ b/duckyinpython.py @@ -11,8 +11,12 @@ from board import * import pwmio import asyncio + import usb_hid from adafruit_hid.keyboard import Keyboard +from adafruit_hid.mouse import Mouse +from adafruit_hid.consumer_control import ConsumerControl +from adafruit_hid.consumer_control_code import ConsumerControlCode # comment out these lines for non_US keyboards from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS as KeyboardLayout @@ -47,6 +51,36 @@ 'F12': Keycode.F12, } + +kbd = Keyboard(usb_hid.devices) +layout = KeyboardLayout(kbd) + +mouse = Mouse(usb_hid.devices) +cc = ConsumerControl(usb_hid.devices) + +#init button +button1_pin = DigitalInOut(GP22) # defaults to input +button1_pin.pull = Pull.UP # turn on internal pull-up resistor +button1 = Debouncer(button1_pin) + +#init payload selection switch +payload1Pin = digitalio.DigitalInOut(GP4) +payload1Pin.switch_to_input(pull=digitalio.Pull.UP) +payload2Pin = digitalio.DigitalInOut(GP5) +payload2Pin.switch_to_input(pull=digitalio.Pull.UP) +payload3Pin = digitalio.DigitalInOut(GP10) +payload3Pin.switch_to_input(pull=digitalio.Pull.UP) +payload4Pin = digitalio.DigitalInOut(GP11) +payload4Pin.switch_to_input(pull=digitalio.Pull.UP) + +defaultDelay = 0 + +if(board.board_id == 'raspberry_pi_pico'): + led = pwmio.PWMOut(board.LED, frequency=5000, duty_cycle=0) +elif(board.board_id == 'raspberry_pi_pico_w'): + led = digitalio.DigitalInOut(board.LED) + led.switch_to_output() + def convertLine(line): newline = [] # print(line) @@ -75,53 +109,78 @@ def runScriptLine(line): def sendString(line): layout.write(line) +def parseMouseCommand(line): + if line.startswith('CLICK'): + if line[6:] == 'LEFT': + mouse.click(Mouse.LEFT_BUTTON) + elif line[6:] == 'RIGHT': + mouse.click(Mouse.RIGHT_BUTTON) + elif hasattr(Mouse, line[6:]): + mouse.click(getattr(Mouse, line[6:])) + + elif line.startswith('MOVE'): + x, y = line[5:].split(',') + x, y = int(x), int(y) + + mouse.move(x, y) + elif line.startswith('WHEEL'): + wheel = int(line[5:]) + mouse.move(wheel=wheel) + + elif line.startswith('PRESS'): + if line[6:] == 'LEFT': + mouse.press(Mouse.LEFT_BUTTON) + elif line[6:] == 'RIGHT': + mouse.press(Mouse.RIGHT_BUTTON) + elif hasattr(Mouse, line[6:]): + mouse.press(getattr(Mouse, line[6:])) + + elif line.startswith('RELEASE'): + if line[8:] == 'LEFT': + mouse.release(Mouse.LEFT_BUTTON) + elif line[8:] == 'RIGHT': + mouse.release(Mouse.RIGHT_BUTTON) + elif hasattr(Mouse, line[8:]): + mouse.release(getattr(Mouse, line[8:])) + def parseLine(line): global defaultDelay - if(line[0:3] == "REM"): - # ignore ducky script comments - pass - elif(line[0:5] == "DELAY"): + + if line.startswith("REM"): + pass # ignore ducky script comment + + elif line.startswith("DELAY"): time.sleep(float(line[6:])/1000) - elif(line[0:6] == "STRING"): + + elif line.startswith("STRING"): sendString(line[7:]) - elif(line[0:5] == "PRINT"): + + elif line.startswith("MOUSE"): + parseMouseCommand(line[6:]) + + elif line.startswith("CC"): + CC_KEY = line[3:] + if hasattr(ConsumerControlCode, CC_KEY): + cc.send(getattr(ConsumerControlCode, CC_KEY)) + + elif line.startswith("PRINT"): print("[SCRIPT]: " + line[6:]) - elif(line[0:6] == "IMPORT"): + + elif line.startswith("IMPORT"): runScript(line[7:]) - elif(line[0:13] == "DEFAULT_DELAY"): - defaultDelay = int(line[14:]) * 10 - elif(line[0:12] == "DEFAULTDELAY"): - defaultDelay = int(line[13:]) * 10 - elif(line[0:3] == "LED"): - if(led.value == True): - led.value = False - else: - led.value = True + + elif line.startswith("DEFAULT_DELAY"): + defaultDelay = int(line[14:]) + + elif line.startswith("DEFAULTDELAY"): + defaultDelay = int(line[13:]) + + elif line.startswith("LED"): + led.value = not led.value else: newScriptLine = convertLine(line) runScriptLine(newScriptLine) -kbd = Keyboard(usb_hid.devices) -layout = KeyboardLayout(kbd) - - - - -#init button -button1_pin = DigitalInOut(GP22) # defaults to input -button1_pin.pull = Pull.UP # turn on internal pull-up resistor -button1 = Debouncer(button1_pin) - -#init payload selection switch -payload1Pin = digitalio.DigitalInOut(GP4) -payload1Pin.switch_to_input(pull=digitalio.Pull.UP) -payload2Pin = digitalio.DigitalInOut(GP5) -payload2Pin.switch_to_input(pull=digitalio.Pull.UP) -payload3Pin = digitalio.DigitalInOut(GP10) -payload3Pin.switch_to_input(pull=digitalio.Pull.UP) -payload4Pin = digitalio.DigitalInOut(GP11) -payload4Pin.switch_to_input(pull=digitalio.Pull.UP) - def getProgrammingStatus(): # check GP0 for setup mode # see setup mode for instructions @@ -130,9 +189,6 @@ def getProgrammingStatus(): progStatus = not progStatusPin.value return(progStatus) - -defaultDelay = 0 - def runScript(file): global defaultDelay @@ -167,16 +223,16 @@ def selectPayload(): payload3State = not payload3Pin.value payload4State = not payload4Pin.value - if(payload1State == True): + if payload1State: payload = "payload.dd" - elif(payload2State == True): + elif payload2State: payload = "payload2.dd" - elif(payload3State == True): + elif payload3State: payload = "payload3.dd" - elif(payload4State == True): + elif payload4State: payload = "payload4.dd" else: @@ -186,14 +242,7 @@ def selectPayload(): return payload -async def blink_led(led): - print("Blink") - if(board.board_id == 'raspberry_pi_pico'): - blink_pico_led(led) - elif(board.board_id == 'raspberry_pi_pico_w'): - blink_pico_w_led(led) - -async def blink_pico_led(led): +async def blink_pico_led(): print("starting blink_pico_led") led_state = False while True: @@ -217,7 +266,7 @@ async def blink_pico_led(led): led_state = True await asyncio.sleep(0) -async def blink_pico_w_led(led): +async def blink_pico_w_led(): print("starting blink_pico_w_led") led_state = False while True: diff --git a/examples/consumerControl/README.md b/examples/consumerControl/README.md new file mode 100644 index 0000000..d27ab24 --- /dev/null +++ b/examples/consumerControl/README.md @@ -0,0 +1,16 @@ +# Consumer Control +Simulate a Consumer Control Device from the Raspberry Pi Pico + +## Avaible Commands: +``` +CC [ConsumerControlCode] +``` +Every ConsumerControlCode can be found [here](https://docs.circuitpython.org/projects/hid/en/latest/api.html#adafruit_hid.consumer_control_code.ConsumerControlCode) + +## Examples: +``` +CC BRIGHTNESS_INCREMENT +CC PLAY_PAUSE +CC MUTE +CC EJECT +``` diff --git a/examples/consumerControl/brightness.dd b/examples/consumerControl/brightness.dd new file mode 100644 index 0000000..1979a43 --- /dev/null +++ b/examples/consumerControl/brightness.dd @@ -0,0 +1,14 @@ +REM Make the monitor as dark as possible while the +REM payload is running, then set it to maximum brightness. + +REM The system needs a bit of time to adjust the brightness +DEFAULT_DELAY 200 + +CC BRIGHTNESS_DECREMENT +REPEAT 9 + +REM Payload Script Here +DELAY 2000 + +CC BRIGHTNESS_INCREMENT +REPEAT 9 diff --git a/examples/consumerControl/volume.dd b/examples/consumerControl/volume.dd new file mode 100644 index 0000000..aa9e72e --- /dev/null +++ b/examples/consumerControl/volume.dd @@ -0,0 +1,6 @@ +REM Max out the volume +REM Every time you press the button, the volume increases by 2, +REM so to make sure the volume is at its maximum, you need to press it 50 times. + +CC VOLUME_INCREMENT +REPEAT 49 diff --git a/examples/mouse/README.md b/examples/mouse/README.md new file mode 100644 index 0000000..7ada175 --- /dev/null +++ b/examples/mouse/README.md @@ -0,0 +1,21 @@ +# Mouse +Simulate a Mouse from the Raspberry Pi Pico + +## Avaible Commands: +``` +MOUSE CLICK LEFT/RIGHT +MOUSE MOVE x,y +MOUSE WHEEL x +MOUSE PRESS LEFT/RIGHT +MOUSE RELEASE LEFT/RIGHT +``` + +## Examples: +``` +MOUSE CLICK LEFT +MOUSE MOVE 200,-100 +MOUSE WHEEL 50 +MOUSE WHEEL -50 +MOUSE PRESS LEFT +MOUSE RELEASE LEFT +``` diff --git a/examples/mouse/click_and_movements.dd b/examples/mouse/click_and_movements.dd new file mode 100644 index 0000000..7a1c840 --- /dev/null +++ b/examples/mouse/click_and_movements.dd @@ -0,0 +1,8 @@ +REM Test mouse click and movement + +MOUSE CLICK RIGHT +DELAY 500 +MOUSE CLICK LEFT +MOUSE WHEEL 10 +DELAY 200 +MOUSE WHEEL -10 diff --git a/examples/mouse/hide_window.dd b/examples/mouse/hide_window.dd new file mode 100644 index 0000000..e69febf --- /dev/null +++ b/examples/mouse/hide_window.dd @@ -0,0 +1,14 @@ +REM Open the CMD and move it to the bottom of the screen +GUI r +DELAY 500 +STRING cmd +ENTER +DELAY 1000 +ALT SPACE +DELAY 100 +STRING s +DELAY 100 +DOWNARROW +DELAY 100 +MOUSE MOVE 0,1500 +ENTER \ No newline at end of file diff --git a/examples/mouse/select_text.dd b/examples/mouse/select_text.dd new file mode 100644 index 0000000..6902e06 --- /dev/null +++ b/examples/mouse/select_text.dd @@ -0,0 +1,6 @@ +REM Select something on the screen + +MOUSE PRESS LEFT +MOUSE MOVE 100,100 +MOUSE RELEASE LEFT + diff --git a/payload.dd b/payload.dd index 5f21333..1b6f53f 100644 --- a/payload.dd +++ b/payload.dd @@ -1,6 +1,8 @@ REM The next four lines open Notepad in Windows and type "Hello World!" + GUI r +DELAY 400 STRING notepad ENTER -DELAY 250 -STRING Hello World! \ No newline at end of file +DELAY 400 +STRING Hello World!