From 391c4026042ed7434cbac9600210159f751990b6 Mon Sep 17 00:00:00 2001 From: Skickar <40251293+skickar@users.noreply.github.com> Date: Sat, 11 Dec 2021 01:02:16 -0700 Subject: [PATCH] Update duckyinpython.py --- duckyinpython.py | 108 ++++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 47 deletions(-) diff --git a/duckyinpython.py b/duckyinpython.py index 7b51baa..5084012 100644 --- a/duckyinpython.py +++ b/duckyinpython.py @@ -1,25 +1,54 @@ # License : GPLv2.0 # copyright (c) 2021 Dave Bailey # Author: Dave Bailey (dbisu, @daveisu) +# Nugget Fork: Kody Kinzie @skickar +# Now It Runs One Of 4 Payloads! import usb_hid from adafruit_hid.keyboard import Keyboard - +import board # comment out these lines for non_US keyboards from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS as KeyboardLayout from adafruit_hid.keycode import Keycode +from digitalio import DigitalInOut, Pull +from adafruit_debouncer import Debouncer +from board import * +import busio +import displayio +import adafruit_framebuf +import adafruit_displayio_sh1106 +import time + +## Screen setup and function to change image on the screen +displayio.release_displays() +WIDTH = 130 # Change these to the right size for your display! +HEIGHT = 64 +BORDER = 1 +i2c = busio.I2C(SCL, SDA) # Create the I2C interface. +display_bus = displayio.I2CDisplay(i2c, device_address=0x3c) +display = adafruit_displayio_sh1106.SH1106(display_bus, width=WIDTH, height=HEIGHT) # Create the SH1106 OLED class. + +def NugEyes(IMAGE): ## Make a function to put eyes on the screen + bitmap = displayio.OnDiskBitmap(IMAGE) # Setup the file as the bitmap data source + tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader) # Create a TileGrid to hold the bitmap + group = displayio.Group() # Create a Group to hold the TileGrid + group.append(tile_grid) # Add the TileGrid to the Group + display.show(group) # Add the Group to the Display + +NugEyes("/faces/menu.bmp") + +pins = (board.IO9, board.IO18, board.IO11, board.IO7) +buttons = [] # will hold list of Debouncer objects +for pin in pins: # set up each pin + tmp_pin = DigitalInOut(pin) # defaults to input + tmp_pin.pull = Pull.UP # turn on internal pull-up resistor + buttons.append( Debouncer(tmp_pin) ) # uncomment these lines for non_US keyboards # replace LANG with appropriate language #from keyboard_layout_win_LANG import KeyboardLayout #from keycode_win_LANG import Keycode -import time -import digitalio -from board import * -led = digitalio.DigitalInOut(LED) -led.direction = digitalio.Direction.OUTPUT - duckyCommands = { 'WINDOWS': Keycode.WINDOWS, 'GUI': Keycode.GUI, 'APP': Keycode.APPLICATION, 'MENU': Keycode.APPLICATION, 'SHIFT': Keycode.SHIFT, @@ -32,7 +61,6 @@ duckyCommands = { 'INSERT': Keycode.INSERT, 'NUMLOCK': Keycode.KEYPAD_NUMLOCK, 'PAGEUP': Keycode.PAGE_UP, 'PAGEDOWN': Keycode.PAGE_DOWN, 'PRINTSCREEN': Keycode.PRINT_SCREEN, 'ENTER': Keycode.ENTER, 'SCROLLLOCK': Keycode.SCROLL_LOCK, 'SPACE': Keycode.SPACE, 'TAB': Keycode.TAB, - 'BAKCKSPACE': Keycode.BACKSPACE, 'DELETE': Keycode.DELETE, 'A': Keycode.A, 'B': Keycode.B, 'C': Keycode.C, 'D': Keycode.D, 'E': Keycode.E, 'F': Keycode.F, 'G': Keycode.G, 'H': Keycode.H, 'I': Keycode.I, 'J': Keycode.J, 'K': Keycode.K, 'L': Keycode.L, 'M': Keycode.M, 'N': Keycode.N, 'O': Keycode.O, @@ -42,11 +70,11 @@ duckyCommands = { 'F4': Keycode.F4, 'F5': Keycode.F5, 'F6': Keycode.F6, 'F7': Keycode.F7, 'F8': Keycode.F8, 'F9': Keycode.F9, 'F10': Keycode.F10, 'F11': Keycode.F11, 'F12': Keycode.F12, - } + def convertLine(line): newline = [] - # print(line) + print(line) # loop on each key - the filter removes empty values for key in filter(None, line.split(" ")): key = key.upper() @@ -61,7 +89,7 @@ def convertLine(line): else: # if it's not a known key name, show the error for diagnosis print(f"Unknown key: <{key}>") - # print(newline) + print(newline) return newline def runScriptLine(line): @@ -81,42 +109,17 @@ def parseLine(line): time.sleep(float(line[6:])/1000) elif(line[0:6] == "STRING"): sendString(line[7:]) - elif(line[0:5] == "PRINT"): - print("[SCRIPT]: " + line[6:]) - elif(line[0:6] == "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 else: newScriptLine = convertLine(line) runScriptLine(newScriptLine) -kbd = Keyboard(usb_hid.devices) -layout = KeyboardLayout(kbd) - -# sleep at the start to allow the device to be recognized by the host computer -time.sleep(.5) - -# check GP0 for setup mode -# see setup mode for instructions -progStatus = False -progStatusPin = digitalio.DigitalInOut(GP0) -progStatusPin.switch_to_input(pull=digitalio.Pull.UP) -progStatus = not progStatusPin.value -defaultDelay = 0 - -def runScript(file): - global defaultDelay - - duckyScriptPath = file - f = open(duckyScriptPath,"r",encoding='utf-8') +def injectPayload(payloadNumber): + f = open(duckyScriptPath[payloadNumber],"r",encoding='utf-8') + print("Running payload.dd") previousLine = "" duckyScript = f.readlines() for line in duckyScript: @@ -130,12 +133,23 @@ def runScript(file): parseLine(line) previousLine = line time.sleep(float(defaultDelay)/1000) - -if(progStatus == False): - # not in setup mode, inject the payload - print("Running payload.dd") - runScript("payload.dd") - print("Done") -else: - print("Update your payload") + NugEyes("/faces/menu.bmp") + +kbd = Keyboard(usb_hid.devices) +layout = KeyboardLayout(kbd) +duckyScriptPath = ["payload1.dd", "payload2.dd", "payload3.dd", "payload4.dd"] + +# sleep at the start to allow the device to be recognized by the host computer +time.sleep(.5) +defaultDelay = 0 + +while True: + for i in range(len(buttons)): + buttons[i].update() + if buttons[i].fell: + print("button",i,"pressed!") + NugEyes("/faces/boingo.bmp") + injectPayload(i) + if buttons[i].rose: + print("button",i,"released!")