Skip to content

Commit

Permalink
Add Programming switch (dbisu#4)
Browse files Browse the repository at this point in the history
* Add support for programming switch

* Update README.md documentation
  • Loading branch information
dbisu authored Aug 21, 2021
1 parent 45b302a commit 68ac3b1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ $ cp duckyinpython.py /<path to media device>/code.py
Copy your Ducky Scipt file as payload.dd

$ cp <duckyscriptfile> /path to media device>/payload.dd

# NEW: added support for a programming switch.
Tie pin 0 (GPIO0) to pin 3 (GND) to not automatically run payloads.
Easiest way to do this is to add a jumper wire between those pins.
![jumper wire](pics/jumper.png)
50 changes: 32 additions & 18 deletions duckyinpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
import time
import digitalio
from board import *

duckyCommands = ["WINDOWS", "GUI", "APP", "MENU", "SHIFT", "ALT", "CONTROL", "CTRL", "DOWNARROW", "DOWN",
"LEFTARROW", "LEFT", "RIGHTARROW", "RIGHT", "UPARROW", "UP", "BREAK", "PAUSE", "CAPSLOCK", "DELETE", "END",
Expand Down Expand Up @@ -63,22 +65,34 @@ def parseLine(line):
#sleep a the start to allow the device to be recognized by the host computer
time.sleep(.5)

defaultDelay = 0
duckyScriptPath = "payload.dd"
f = open(duckyScriptPath,"r",encoding='utf-8')
print("Running payload.dd")
previousLine = ""
duckyScript = f.readlines()
for line in duckyScript:
line = line.rstrip()
if(line[0:6] == "REPEAT"):
for i in range(int(line[7:])):
#repeat the last command
parseLine(previousLine)
time.sleep(float(defaultDelay)/1000)
else:
parseLine(line)
previousLine = line
time.sleep(float(defaultDelay)/1000)

print("Done...")
# check GPIO0 for program switch
# easiest way to implement is to run a jumper from pin 0 (GPIO0) to pin3 (GND)
progStatus = False
progStatusPin = digitalio.DigitalInOut(GP0)
progStatusPin.switch_to_input(pull=digitalio.Pull.UP)
progStatus = progStatusPin.value

if(progStatus == True):
#not in programming state, run script file
defaultDelay = 0
duckyScriptPath = "payload.dd"
f = open(duckyScriptPath,"r",encoding='utf-8')
print("Running payload.dd")
previousLine = ""
duckyScript = f.readlines()
for line in duckyScript:
line = line.rstrip()
if(line[0:6] == "REPEAT"):
for i in range(int(line[7:])):
#repeat the last command
parseLine(previousLine)
time.sleep(float(defaultDelay)/1000)
else:
parseLine(line)
previousLine = line
time.sleep(float(defaultDelay)/1000)

print("Done...")
else:
print("Update new payload file")
Binary file added pics/jumper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 68ac3b1

Please sign in to comment.