Author Topic: Digispark prank keyboard driver  (Read 42164 times)

koenig

  • Newbie
  • *
  • Posts: 1
Digispark prank keyboard driver
« on: February 13, 2013, 12:52:02 am »

I backed the Kickstarter project Digispark a couple of months ago and yesterday I got all the goodies! Yum.

One of my plans, when I saw the Digispark and thought about the potential, was to make a prank keyboard driver - the Digispark is small and innocent and perfect for plugging into colleagues computers without their knowing.

So I wrote a small program that sleeps for six seconds and then picks a random number between 0 and 159. On 0-3 something happens otherwise it goes back to sleep, which means that there is a 1 in 40 chance of a prank.


I picked minimise all windows, minimise one window, turn the screen upside down and lock the computer as rather harmless, still interesting.


Here is the code
Code: [Select]
#include "DigiKeyboard.h"
void setup() {
}


void loop() {
 
 DigiKeyboard.update();
 DigiKeyboard.sendKeyStroke(0); //this is generally not necessary but with some older systems it seems to prevent missing the first character after a delay
 switch (random(160)) {
 case 0: // Minimize all windows
 DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT);
 break;
case 1: // Lock screen
 DigiKeyboard.sendKeyStroke(KEY_L, MOD_GUI_LEFT);
 break;
 
 case 2: // Minimize current window
 DigiKeyboard.sendKeyStroke(KEY_DOWN_ARROW, MOD_GUI_LEFT);
 break;
case 3: // Flip screen
 DigiKeyboard.sendKeyStroke(KEY_DOWN_ARROW, MOD_CONTROL_LEFT + MOD_ALT_LEFT);
 break;
default:
 break;
 }
 
 delay(6000);
}


I also had to make an addition to the DigiKeyboard.h file since it was lacking all but one arrow key:



Code: [Select]

#define KEY_UP_ARROW   0x52
#define KEY_DOWN_ARROW   0x51
#define KEY_LEFT_ARROW   0x50
#define KEY_RIGHT_ARROW   0x4F
« Last Edit: February 13, 2013, 04:56:31 am by koenig »

forsakenrider

  • Newbie
  • *
  • Posts: 26
Re: Digispark prank keyboard driver
« Reply #1 on: March 24, 2013, 08:22:10 pm »
I wonder if we can port some of irongeeks phukd libraries to digispark. would make for a nice minimalist pentesting tool!

forsakenrider

  • Newbie
  • *
  • Posts: 26
Re: Digispark prank keyboard driver
« Reply #2 on: March 26, 2013, 08:01:11 pm »
Heres a fun one, try it on a windows computer!

Code: [Select]
//Wallpaper Prank, modified by DW for use on the digispark

#include "DigiKeyboard.h"



void setup() {
  pinMode(1, OUTPUT); //LED on Model A
 
 
}


void loop() {
 
 
  DigiKeyboard.update();
  DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.delay(3000);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT); //minimize all windows
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_PrintScreen); //prntscr
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_F10, MOD_SHIFT_LEFT); //Open Menu
  DigiKeyboard.delay(200);
  DigiKeyboard.sendKeyStroke(KEY_V);
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_D);
  DigiKeyboard.delay(500); 
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(100);
  DigiKeyboard.println("mspaint");
  DigiKeyboard.delay(1200);
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_CONTROL_LEFT); //paste
  DigiKeyboard.delay(500); 
  DigiKeyboard.sendKeyStroke(KEY_S, MOD_CONTROL_LEFT); //save
  DigiKeyboard.delay(500); 
  DigiKeyboard.println("%userprofile%\\a.bmp"); //save in users folder
  DigiKeyboard.delay(500);
  DigiKeyboard.sendKeyStroke(KEY_F, MOD_ALT_LEFT); //file
  DigiKeyboard.delay(500);
  DigiKeyboard.sendKeyStroke(KEY_K); //set as desktop
  DigiKeyboard.delay(100); 
  DigiKeyboard.sendKeyStroke(KEY_T); //tile
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_F4, MOD_ALT_LEFT); //close paint
  DigiKeyboard.delay(300);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT | MOD_SHIFT_LEFT); //back to desktop as it was
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
 
}
« Last Edit: March 26, 2013, 09:01:57 pm by forsakenrider »

forsakenrider

  • Newbie
  • *
  • Posts: 26
Re: Digispark prank keyboard driver
« Reply #3 on: March 26, 2013, 09:39:16 pm »
Heres one to update facebook status. you need to add to DigiKeyboard.h:
Code: [Select]
#define KEY_Tab     43
then the code:

Code: [Select]
//  This will only work if the person is generally logged into facebook

#include "DigiKeyboard.h"

void setup() {
  // don't need to set anything up to use DigiKeyboard
}


void loop() {
 
  DigiKeyboard.sendKeyStroke(0);
 
  DigiKeyboard.delay(2000);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT); //minimize all windows
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(100);
  DigiKeyboard.println("https://m.facebook.com/");
  DigiKeyboard.delay(3000);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.println("hello world from the DigiSpark!");
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.sendKeyStroke(KEY_ENTER);
  DigiKeyboard.delay(50000);
}

PS- is there an easier way for the tabs?


« Last Edit: March 26, 2013, 09:41:39 pm by forsakenrider »

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Digispark prank keyboard driver
« Reply #4 on: March 26, 2013, 11:55:13 pm »
Sure is! DigiKeyboard.print("\t\t\t\t\t") types in six tabs!

forsakenrider

  • Newbie
  • *
  • Posts: 26
Re: Digispark prank keyboard driver
« Reply #5 on: March 27, 2013, 04:45:28 am »
Oh, whats easier!

Another question. For my first prank, can I make it save the file as a random number? I tried all sorts of things but I couldn't figure it out. The program doesn't work if there is already an "a.bmp" in the user's folder.



Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Digispark prank keyboard driver
« Reply #6 on: March 28, 2013, 12:40:38 am »

You could use psuedorandom numbers, but maybe it'd be better to just use an incrementing integer?


You can use the EEPROM library built in to arduino to store bytes in the internal memory, and could have some code in your setup which gets the number, increments it by one, saves it back, and later in your code you can use the incremented number.

forsakenrider

  • Newbie
  • *
  • Posts: 26
Re: Digispark prank keyboard driver
« Reply #7 on: March 28, 2013, 05:34:02 am »
Thanks for that info! there are so many different ways to go about this, wow.

I'm so glad I bought some digispark boards! I tried getting into arduino but found myself just copy and pasting everything. Now with the limited IO and memory its a lot easier to actually start understanding whats going on. What a great learning platform! I am having so much fun with these!

forsakenrider

  • Newbie
  • *
  • Posts: 26
Re: Digispark prank keyboard driver
« Reply #8 on: March 28, 2013, 08:13:31 pm »
Heres the final version of the desktop prank.

Now to write one that works on MAC...

Code: [Select]
//Wallpaper Prank, modified by DW for use on the digispark

#include "DigiKeyboard.h"
#include <EEPROM.h>

int a = 0;
int value;


void setup() {
  pinMode(1, OUTPUT); //LED on Model A
  value = EEPROM.read(a);
 
 
  value = value + 1;
  if (value > 100)
    value = 0;
 
 
  EEPROM.write(a, value);
 
 
 
}


void loop() {
 
 
 
  DigiKeyboard.update();
  DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.delay(2000);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT); //minimize all windows
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_PrintScreen); //printscreen
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_F10, MOD_SHIFT_LEFT); //Open Menu
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_V);
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_D);
  DigiKeyboard.delay(50); 
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(50);
  DigiKeyboard.println("mspaint");
  DigiKeyboard.delay(1200);
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_CONTROL_LEFT); //paste
  DigiKeyboard.delay(50); 
  DigiKeyboard.sendKeyStroke(KEY_S, MOD_CONTROL_LEFT); //save
  DigiKeyboard.delay(500);
 
 
  DigiKeyboard.print("%userprofile%\\"); //save in users folder
  DigiKeyboard.print(value); //number saved in eeprom + 1
  DigiKeyboard.println(".bmp");
 
 
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_F, MOD_ALT_LEFT); //file
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_K); //set as desktop
  DigiKeyboard.delay(100); 
  DigiKeyboard.sendKeyStroke(KEY_T); //tile
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_F4, MOD_ALT_LEFT); //close paint
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT | MOD_SHIFT_LEFT); //back to desktop as it was
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(100);
  DigiKeyboard.println("www.digistump.com"); //buy a digispark to get me back
 
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
 
}


Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Digispark prank keyboard driver
« Reply #9 on: March 28, 2013, 08:40:46 pm »
Here's a version for Mac:


Code: [Select]

//Wallpaper Prank, modified by DW for use on the digispark
#include "DigiKeyboard.h"

void setup() {
  pinMode(1, OUTPUT); //LED on Model A
}




void loop() {
  DigiKeyboard.update();
 
  // take screenshot in to clipboard
  DigiKeyboard.sendKeyStroke(KEY_3, MOD_GUI_LEFT | MOD_CONTROL_LEFT | MOD_SHIFT_LEFT);
  DigiKeyboard.delay(100); // 0.1s delay
  DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT);
  DigiKeyboard.delay(250);
  DigiKeyboard.println("Desktop & Screen Saver");
  DigiKeyboard.delay(2000);
  DigiKeyboard.print("\t"); // tab in to picture hole
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_GUI_LEFT);
  DigiKeyboard.delay(1000);
 
 
  DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT);
  DigiKeyboard.delay(1000);
  DigiKeyboard.println("Safari");
  DigiKeyboard.delay(4000);
  DigiKeyboard.sendKeyStroke(KEY_N, MOD_GUI_LEFT); // new window
  DigiKeyboard.sendKeyStroke(KEY_L, MOD_GUI_LEFT); // set focus to address bar
  DigiKeyboard.println("http://www.digistump.com/"); //buy a digispark to get me back
 
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
  while(true) { DigiKeyboard.update(); }
}


It doesn't need to mess around with files - it just copies in the wallpaper via the clipboard.

forsakenrider

  • Newbie
  • *
  • Posts: 26
Re: Digispark prank keyboard driver
« Reply #10 on: March 28, 2013, 09:04:30 pm »
Not bad, but that doesnt remove the icons after taking the printscreen.

Can we get to the command line from the spotlight? cuz if so I've found the command for hiding the icons. then after that set the desktop and voila!
Code: [Select]
defaults write com.apple.finder CreateDesktop -bool false

Code: [Select]
killall Finder

then just need to add a simple If statement, a switch or jumper and add the two codes and we have a windows and mac party pooper!

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Digispark prank keyboard driver
« Reply #11 on: March 28, 2013, 09:46:51 pm »
Installing system hacks in to the OS that don't have any GUI for reversing the mod steps beyond the realm of prank, in my view.


But if you want a command line, all you need to do is println "Terminal" in to spotlight and wait one second for it to open, then you can enter your commands

forsakenrider

  • Newbie
  • *
  • Posts: 26
Re: Digispark prank keyboard driver
« Reply #12 on: March 28, 2013, 09:58:30 pm »
very valid point. Heres your version plus my version and a jumper across pins 1 and 3 decides the OS:

Code: [Select]
//Wallpaper Prank, modified by DW for use on the digispark

#include "DigiKeyboard.h"
#include <EEPROM.h>

int a = 0;
int value;
int mac = 0;

void setup() {
  pinMode(0, OUTPUT);
  pinMode(2, INPUT);
  digitalWrite(0,HIGH);
 
  value = EEPROM.read(a);
 
 
  value = value + 1;
  if (value > 100)
    value = 0;
 
 
  EEPROM.write(a, value);
 
 
 
}


void loop() {
 
  mac = digitalRead(2);
 
  if (mac == HIGH) {
 
    DigiKeyboard.update();
 
  // take screenshot in to clipboard
  DigiKeyboard.sendKeyStroke(KEY_3, MOD_GUI_LEFT | MOD_CONTROL_LEFT | MOD_SHIFT_LEFT);
  DigiKeyboard.delay(100); // 0.1s delay
  DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT);
  DigiKeyboard.delay(250);
  DigiKeyboard.println("Desktop & Screen Saver");
  DigiKeyboard.delay(2000);
  DigiKeyboard.print("\t"); // tab in to picture hole
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_GUI_LEFT);
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT);
  DigiKeyboard.delay(1000);
  DigiKeyboard.println("Safari");
  DigiKeyboard.delay(4000);
  DigiKeyboard.sendKeyStroke(KEY_N, MOD_GUI_LEFT); // new window
  DigiKeyboard.sendKeyStroke(KEY_L, MOD_GUI_LEFT); // set focus to address bar
  DigiKeyboard.println("http://www.digistump.com/"); //buy a digispark to get me back
 
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
  while(true) { DigiKeyboard.update(); }
}


else{
 
   
  DigiKeyboard.update();
  DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.delay(2000);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT); //minimize all windows
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_PrintScreen); //printscreen
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_F10, MOD_SHIFT_LEFT); //Open Menu
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_V);
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_D);
  DigiKeyboard.delay(50); 
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(50);
  DigiKeyboard.println("mspaint");
  DigiKeyboard.delay(1200);
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_CONTROL_LEFT); //paste
  DigiKeyboard.delay(50); 
  DigiKeyboard.sendKeyStroke(KEY_S, MOD_CONTROL_LEFT); //save
  DigiKeyboard.delay(500);
 
 
  DigiKeyboard.print("%userprofile%\\"); //save in users folder
  DigiKeyboard.print(value); //number saved in eeprom + 1
  DigiKeyboard.println(".bmp");
 
 
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_F, MOD_ALT_LEFT); //file
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_K); //set as desktop
  DigiKeyboard.delay(100); 
  DigiKeyboard.sendKeyStroke(KEY_T); //tile
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_F4, MOD_ALT_LEFT); //close paint
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT | MOD_SHIFT_LEFT); //back to desktop as it was
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(100);
  DigiKeyboard.println("www.digistump.com"); //buy a digispark to get me back
 
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
}
}

I think it should work.
« Last Edit: March 28, 2013, 10:05:28 pm by forsakenrider »

willgonz

  • Newbie
  • *
  • Posts: 2
Re: Digispark prank keyboard driver
« Reply #13 on: October 01, 2013, 06:44:00 pm »
How can you send a Ctrl-Alt-Del?


technodoug

  • Newbie
  • *
  • Posts: 1
Re: Digispark prank keyboard driver
« Reply #14 on: October 17, 2013, 09:13:05 pm »
#define KEY_DELETE 76

DigiKeyboard.sendKeyStroke(KEY_DELETE, MOD_ALT_RIGHT | MOD_CONTROL_LEFT);