Jump to content

[Version 1] Rubber Ducky Libraries


NFG

Recommended Posts

I started playing with my Teensy in the Arduino software a couple of days ago and realized that the arduino software is just a bunch of cpp code in libraries, cores, and examples files. This gave me an idea. Why don’t we try to make a set of standard libraries for the rubber ducky? This would help everyone stop reinventing the same code for every project. Does this sound like a good idea?

To help show how easy this is I’ve posted my conversion of haxwithaxe/Irongeek sample code. Just make the files listed below under the (Arduino folder)\libraries\RubberDucky and (Arduino folder)\libraries\RubberDucky\examples folders. Then when you open the Arduino software there is a RubberDucky option in the examples menu.

(Arduino folder)\libraries\RubberDucky\KeyPress.h

/*
 KeyPress.h - Library for sending single a Key press.
 Created by NFG, 5 7, 2010.
 Released into the public domain.
*/

#ifndef KeyPress_h
#define KeyPress_h

#include "WProgram.h"

    void KeyPress(int _SomeKey);
    void KeyCombo(int _ModKey,int _SomeKey);

#endif

(Arduino folder)\libraries\RubberDucky\KeyPress.cpp

/*
 KeyPress.cpp - Library for sending single a Key press.
 Created by NFG, 5 7, 2010.
 Released into the public domain.
 */

#include "WProgram.h"
#include "KeyPress.h"

void KeyPress(int _SomeKey) {
  Keyboard.set_key1(_SomeKey); // set some key
  Keyboard.send_now(); // "press" some key
  // clear some key
  Keyboard.set_key1(0);
  Keyboard.send_now();
}

void KeyCombo(int _ModKey,int _SomeKey) {
  Keyboard.set_modifier(_ModKey); //set one or more modifier keys
  Keyboard.set_key1(_SomeKey); // set regular key
  Keyboard.send_now(); // send strokes
  // clear keys
  Keyboard.set_modifier(0); // prep release of control keys
  Keyboard.set_key1(0); // have to do this to keep it from hitting key multiple times.
  Keyboard.send_now();
}

(Arduino folder)\libraries\RubberDucky\Windows.h

/*
 Windows.h - Library for Common wondows keyboard shortcuts.
 Created by NFG, 5 7, 2010.
 Released into the public domain.
 */

#ifndef Windows_h
#define Windows_h

#include "WProgram.h"
#include "KeyPress.h"

namespace Windows {
    void Command(char *_SomeCommand);
    void Help(void);
    void Start(void);
    void Switch(void);
    void Quit(void);
    void Lock(void);
    void MinAll(void);
    void Explorer(void);
    void Copy(void);
    void Cut(void);
    void Paste(void);
    void SelAll(void);
};

#endif

(Arduino folder)\libraries\RubberDucky\Windows.cpp

/*
 Windows.cpp - Library for Common wondows keyboard shortcuts.
 Created by NFG, 5 7, 2010.
 Released into the public domain.
*/

#include "WProgram.h"
#include "Windows.h"
#include "KeyPress.h"

namespace Windows
{
  void Command(char *_SomeCommand)
  {
    KeyCombo(MODIFIERKEY_GUI,KEY_R); // open run dialog
    delay(1500); // wait for it to open
    Keyboard.print(_SomeCommand); // enter some command
    KeyPress(KEY_ENTER); // exec some command
  }
  void Help(void)
    { 
      KeyPress(KEY_F1); // Display Help 
    }
  void Start(void)
    {
       KeyCombo(MODIFIERKEY_GUI,0); // Display Start Menu 
    }
  void Switch(void)
    {
      KeyCombo(MODIFIERKEY_ALT,KEY_TAB); // open run dialog 
    }
  void Quit(void)
    {
      KeyCombo(MODIFIERKEY_ALT,KEY_F4); // open run dialog 
    }
  void Lock(void)
    {
      KeyCombo(MODIFIERKEY_GUI,KEY_L); // open run dialog 
    }
  void MinAll(void)
    {
      KeyCombo(MODIFIERKEY_GUI,KEY_M); // open run dialog 
    }
  void Explorer(void)
    {
      KeyCombo(MODIFIERKEY_GUI,KEY_E); // open run dialog
    }
  void Copy(void)
    {
      KeyCombo(MODIFIERKEY_CTRL,KEY_C); // open run dialog 
    }
  void Cut(void)
    {
      KeyCombo(MODIFIERKEY_CTRL,KEY_X); // open run dialog 
    }
  void Paste(void)
    {
      KeyCombo(MODIFIERKEY_CTRL,KEY_V); // open run dialog 
    }
  void SelAll(void)
    {
      KeyCombo(MODIFIERKEY_CTRL,KEY_A); // open run dialog
    }
}

(Arduino folder)\libraries\RubberDucky\keywords.txt

#######################################
# Syntax Coloring Map For Test
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

Windows	KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

KeyPress	KEYWORD2
KeyCombo	KEYWORD2
Command	KEYWORD2
Help	KEYWORD2
Start	KEYWORD2
Switch	KEYWORD2
Quit	KEYWORD2
Lock	KEYWORD2
MinAll	KEYWORD2
Explorer	KEYWORD2
Copy	KEYWORD2
Cut	KEYWORD2
Paste	KEYWORD2
SelAll	KEYWORD2

(Arduino folder)\libraries\RubberDucky\examples\Windows_example\Windows_example.pde

#include <KeyPress.h>
#include <Windows.h>

/* The following Library was haxwithaxe and Omidenchin(aka Omi)) code to do simple keyboard functions with the Teensy converted to a Library format.

NOTE: The original code is Irongeek's (with many additions and subtractions by haxwithaxe and Omidenchin(aka Omi))
       haxwithaxe has removed the DIPSwitch code because he doesn't have a dipswitch to play with, but it can be just as easily put back in and used to
       select the payload. It is strongly recommended that you go to Irongeek's site and not only look at his code but watch the accompanying video right
       above the code example

Original Source: http://www.irongeek.com/i.php?page=securit...eystroke-dongle
Also see his updated source with some of my stuff in it.

To learn more about Teensyduino see:
http://www.pjrc.com/teensy/teensyduino.html
Look in arduino-xxxx\hardware\teensy\cores\tensy_hid\usb_api.h for key definitions
Edit arduino-xxxx\hardware\teensy\cores\tensy_hid\usb_private.h to change USB Vendor and Product ID

To learn more about keyboard shortcuts
Apple: http://support.apple.com/kb/ht1343
Windows: http://support.microsoft.com/kb/126449
Gnome/KDE: http://www.novell.com/coolsolutions/tip/2289.html
Please add more to this list if you can think of any window managers that have default keyboard shortcuts
*/

int ledPin = 11; // LED connected to digital pin 11 for teensy2 and pin 6 for teensy2++
// The setup() method runs once, when the sketch starts
void setup() {
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);

}

// the loop() method runs over and over again,
// as long as the Arduino has power
void loop() {
  delay(1000); // wait for host to listen
  digitalWrite(ledPin, HIGH); // set the LED on

  Windows::Command("notepad.exe");
  delay(1000);
  Keyboard.print("Rubber Ducky was here!!! }:)");
  delay(1000);
  Windows::SelAll();
  delay(1000);
  KeyPress(KEY_BACKSPACE);
  delay(1000);
  Windows::Quit(); 

  digitalWrite(ledPin, LOW); // set the LED off
  delay(1500); //keeps commands from being sent one after the other too fast
}

Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...