Skip to content
Permalink
Browse files

Added more commands from DuckyScript

  • Loading branch information
kr0no committed Sep 10, 2016
1 parent e014b0f commit 3bbcdf1fe8c2f546f997d1786b2495bfef1b7187
Showing with 51 additions and 17 deletions.
  1. +45 −13 ducky2arduino.py
  2. +6 −4 helloworld_arduino.txt
@@ -9,35 +9,67 @@
input = sys.argv[1]
output = sys.argv[2]

data = '#include "HID-Project.h"\n\nvoid setup(){\n Keyboard.begin();\n delay(500);\n '

try:
input_file = open(input, "r")
except:
print('File ' +sys.argv[1]+ ' not found')
sys.exit()

sys.exit()
output_file = open(output, "w")

data = '#include "HID-Project.h"\n\nvoid setup() {\n Keyboard.begin();\n delay(500);\n\n // Payload\n '

for line in input_file:
cmd = line.split(' ', 1)
if cmd[0] == "REM":
data += ("// " + cmd[1].strip() + "\n ")
last_cmd = "// " + cmd[1].strip() + "\n "
data += last_cmd
elif cmd[0] == "DELAY":
data += ("delay(" + cmd[1].strip() + ");\n ")
last_cmd = "delay(" + cmd[1].strip() + ");\n "
data += last_cmd
elif cmd[0] == "STRING":
last_cmd = 'Keyboard.print("' + cmd[1].strip().replace('\"', '\\\"') + '");\n '
data += last_cmd
elif cmd[0] == "GUI":
data += ("Keyboard.press(KEY_LEFT_GUI);\n Keyboard.press(KEY_" + cmd[1].strip().upper() + ");\n Keyboard.releaseAll();\n ")
last_cmd = "Keyboard.press(KEY_LEFT_GUI);\n Keyboard.press(KEY_" + cmd[1].strip().upper() + ");\n Keyboard.releaseAll();\n "
data += last_cmd
elif cmd[0] == "MENU" or cmd[0] == "APP":
data += ("Keyboard.press(KEY_LEFT_SHIFT);\n Keyboard.press(KEY_F10);\n Keyboard.releaseAll();\n ")
last_cmd = "Keyboard.press(KEY_LEFT_SHIFT);\n Keyboard.press(KEY_F10);\n Keyboard.releaseAll();\n "
data += last_cmd
elif cmd[0] == "ALT":
data += ("Keyboard.press(KEY_LEFT_ALT);\n Keyboard.press(KEY_" + cmd[1].strip().upper() + ");\n Keyboard.releaseAll();\n ")
last_cmd = "Keyboard.press(KEY_LEFT_ALT);\n Keyboard.press(KEY_" + cmd[1].strip().upper() + ");\n Keyboard.releaseAll();\n "
data += last_cmd
elif cmd[0] == "CONTROL" or cmd[0] == "CTRL":
data += ("Keyboard.press(KEY_LEFT_CTRL);\n Keyboard.press(KEY_" + cmd[1].strip().upper() + ");\n Keyboard.releaseAll();\n ")
last_cmd = "Keyboard.press(KEY_LEFT_CTRL);\n Keyboard.press(KEY_" + cmd[1].strip().upper() + ");\n Keyboard.releaseAll();\n "
data += last_cmd
elif cmd[0].strip() == "ENTER":
data += ("Keyboard.write(KEY_ENTER);\n ")

data += '}\n\nvoid loop() {}\n'
last_cmd = "Keyboard.write(KEY_ENTER);\n "
data += last_cmd
elif cmd[0].strip() == "UP" or cmd[0].strip() == "UPARROW":
last_cmd = "Keyboard.write(KEY_UP); \n "
data += last_cmd
elif cmd[0].strip() == "DOWN" or cmd[0].strip() == "DOWNARROW":
last_cmd = "Keyboard.write(KEY_DOWN); \n "
data += last_cmd
elif cmd[0].strip() == "LEFT" or cmd[0].strip() == "LEFTARROW":
last_cmd = "Keyboard.write(KEY_LEFT); \n "
data += last_cmd
elif cmd[0].strip() == "RIGHT" or cmd[0].strip() == "RIGHTARROW":
last_cmd = "Keyboard.write(KEY_RIGHT); \n "
data += last_cmd
elif cmd[0].strip() == "SPACE":
last_cmd = "Keyboard.write(KEY_SPACE); \n "
data += last_cmd
elif cmd[0].strip() == "TAB":
last_cmd = "Keyboard.write(KEY_TAB); \n "
data += last_cmd
elif cmd[0].strip() == "HOME":
last_cmd = "Keyboard.write(KEY_HOME); \n "
data += last_cmd
elif cmd[0] == "REPEAT" or cmd[0] == "REPLAY":
last_cmd = "for (int i=0; i<" + cmd[1] + "; i++) {\n " + last_cmd + "}\n "
data += last_cmd

data += '}\n\nvoid loop() { }\n'
output_file.write(data)
print('Payload saved to ' + sys.argv[2])

@@ -1,19 +1,21 @@
#include "HID-Project.h"

void setup(){
void setup() {
Keyboard.begin();
delay(500);

// Payload
delay(3000);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(KEY_R);
Keyboard.releaseAll();
delay(500);
Keyboard.print('notepad');
Keyboard.print("notepad");
delay(500);
Keyboard.write(KEY_ENTER);
delay(750);
Keyboard.print('Hello World!!!');
Keyboard.print("Hello World!!!");
Keyboard.write(KEY_ENTER);
}

void loop() {}
void loop() { }

0 comments on commit 3bbcdf1

Please sign in to comment.
You can’t perform that action at this time.