
Rubber Ducky Ruby Library
Welcome to the rubber-ducky
Ruby library! This library provides an easy-to-use interface for encoding and decoding Rubber Ducky scripts into binary files and vice versa. Whether you're a beginner or a seasoned developer, this README will guide you through everything you need to know to get started and make the most of this library.
Table of Contents
Installation
To install the rubber-ducky
gem, simply add it to your Gemfile or install it directly using gem
:
gem install rubber-ducky
Alternatively, you can include it in your Gemfile
:
gem 'rubber-ducky'
Then, run bundle install
to install the gem.
Basic Usage
Let's start with the basics. The rubber-ducky
library allows you to encode and decode Rubber Ducky scripts. Here’s how to use it:
Encoding a Script
To encode a Rubber Ducky script, you'll first need a script written in a plain text file. Let's assume you have a file named payload.txt
with the following content:
DELAY 500
GUI r
DELAY 500
STRING cmd
CTRL-SHIFT ENTER
DELAY 1000
ALT y
DELAY 500
STRING netsh advfirewall set allprofiles state off
ENTER
To encode this script into a binary file, use the following code:
require 'rubber-ducky'
Rubber::Ducky.encode('payload.txt', output: 'inject.bin', language: 'us')
This will generate a binary file named inject.bin
that can be used with a Rubber Ducky USB device.
Decoding a Binary File
Decoding a binary file back to its script form is just as easy. Assuming you have a binary file named inject.bin
, you can decode it like this:
require 'rubber-ducky'
decoded_script = Rubber::Ducky.decode('inject.bin', output: 'payload-decode.txt', language: 'us')
puts "Decoded content:"
puts decoded_script
This will output the decoded script to the console and save it to payload-decode.txt
.
Advanced Usage
Now that you're familiar with the basics, let's dive into some advanced features.
Customizing Encoding and Decoding
You can customize the encoding and decoding processes by directly manipulating the content before encoding or after decoding. For example:
require 'rubber-ducky'
script = File.read('payload.txt')
script.gsub!('500', '1000')
Rubber::Ducky.encode(script, output: 'inject.bin', language: 'us')
decoded_script = Rubber::Ducky.decode('inject.bin')
puts decoded_script
Working with Different Languages
The library supports multiple keyboard layouts. You can specify the language using the language
option. For example, to encode a script using the German keyboard layout:
Rubber::Ducky.encode('payload.txt', output: 'inject.bin', language: 'de')
Similarly, to decode a file encoded with the German layout:
decoded_script = Rubber::Ducky.decode('inject.bin', language: 'de')
Professional Tips and Tricks
For advanced users, here are some tips to make the most of the rubber-ducky
library.
Integrating with Other Tools
You can easily integrate this library with other Ruby tools and frameworks. For example, you can use it in a Rails application to generate payloads on the fly:
class PayloadsController < ApplicationController
def create
script = params[:script]
file_path = Rails.root.join('tmp', 'inject.bin')
Rubber::Ducky.encode(script, output: file_path, language: 'us')
send_file file_path, type: 'application/octet-stream', filename: 'inject.bin'
end
end
Error Handling
The library is designed to be robust, but you should still handle potential errors gracefully:
begin
Rubber::Ducky.encode('payload.txt', output: 'inject.bin', language: 'us')
rescue StandardError => e
puts "An error occurred during encoding: #{e.message}"
end
Best Practices
- Test your payloads: Always test your payloads in a safe environment before deploying them.
- Use version control: Keep your scripts under version control to track changes and collaborate with others.
- Stay updated: Keep the library and your Ruby version up to date to avoid compatibility issues.
Contributing
We welcome contributions! If you'd like to contribute to this project, please fork the repository and submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Whether you're automating tasks with a Rubber Ducky or exploring new ways to interact with devices, the rubber-ducky
Ruby library offers a powerful and flexible toolset to get the job done. Happy coding!
rubber-ducky
rubber-ducky