Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hak5
GitHub Repository: hak5/usbrubberducky-payloads
Path: blob/master/payloads/extensions/os_detect.txt
2968 views
1
EXTENSION OS_DETECTION
2
REM VERSION 1.1
3
REM AUTHOR: Korben
4
5
REM_BLOCK DOCUMENTATION
6
USB Rubber Ducky Host OS Detection
7
Generic OS detection at a high view is a moving target
8
results may vary greatly depending
9
on a combination of many variables:
10
- number of testing stages
11
- specific devices and versions tested against
12
- number of systems testing for (scope)
13
- detection techniques (passive/invisible/active/hybrid)
14
- overall speed
15
- overall accuracy
16
17
If all you require is windows vs <anything other os> detection, the
18
PASSIVE_WINDOWS_DETECT extension is recommended over this extension.
19
20
TARGET:
21
DEFAULT - Windows, Mac, Linux
22
ADVANCED_DETECTION - Windows, Mac, Linux, iOS, ChromeOS, Android
23
24
USAGE:
25
Uncomment the function call below to run this extension inline (here)
26
or call DETECT_OS() anywhere in your payload after the extension
27
Place this extension and the DETECT_OS() before
28
you would like to first reference $_OS to execute payload code conditionally
29
30
FEEDBACK:
31
As mentioned above, this a moving target (especially for mac systems)
32
Please report any issues identifying specific operating systems.
33
Your feedback will greatly help solidify the robustness of this extension
34
35
DEBUGGING:
36
SET DEBUGGING_OUTPUT DEFINE to TRUE, deploy on a target with text editor open for debug output
37
END_REM
38
39
REM CONFIGURATION:
40
REM For Debugging:
41
DEFINE #DEBUGGING_OUTPUT FALSE
42
DEFINE #ADVANCED_DETECTION FALSE
43
REM Timing fine tuning:
44
DEFINE #STARTUP_DELAY 1500
45
DEFINE #RESTART_WAIT 1000
46
DEFINE #CONNECT_WAIT 1000
47
DEFINE #OS_DETECT_MODE HID
48
DEFINE #OS_DETECT_VID VID_05AC
49
DEFINE #OS_DETECT_PID PID_021E
50
DEFINE #WINDOWS_HOST_REQUEST_COUNT 2
51
DEFINE #HOST_RESPONSE_TIMEOUT 1000
52
53
FUNCTION DETECT_OS()
54
$_HOST_CONFIGURATION_REQUEST_COUNT = 0
55
ATTACKMODE #OS_DETECT_MODE #OS_DETECT_VID #OS_DETECT_PID
56
DELAY #STARTUP_DELAY
57
SAVE_HOST_KEYBOARD_LOCK_STATE
58
59
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
60
IF_DEFINED_TRUE #ADVANCED_DETECTION
61
STRING ADVANCED OS DETECT
62
ELSE_DEFINED
63
STRING OS DETECT
64
END_IF_DEFINED
65
66
ENTER
67
STRING test caps
68
END_IF_DEFINED
69
70
IF ($_CAPSLOCK_ON == FALSE) THEN
71
LED_R
72
CAPSLOCK
73
DELAY #HOST_RESPONSE_TIMEOUT
74
END_IF
75
LED_OFF
76
77
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
78
ENTER
79
STRING test done
80
END_IF_DEFINED
81
82
IF $_RECEIVED_HOST_LOCK_LED_REPLY THEN
83
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
84
ENTER
85
STRING received led response
86
END_IF_DEFINED
87
LED_G
88
IF ($_HOST_CONFIGURATION_REQUEST_COUNT > #WINDOWS_HOST_REQUEST_COUNT) THEN
89
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
90
ENTER
91
STRING prediction: Windows
92
END_IF_DEFINED
93
$_OS = WINDOWS
94
ELSE
95
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
96
ENTER
97
STRING prediction: Linux
98
END_IF_DEFINED
99
$_OS = LINUX
100
END_IF
101
ELSE
102
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
103
ENTER
104
STRING no led response
105
ENTER
106
STRING prediciton: MacOS
107
END_IF_DEFINED
108
$_OS = MACOS
109
END_IF
110
111
IF_DEFINED_TRUE #ADVANCED_DETECTION
112
IF ( $_OS == LINUX ) THEN
113
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
114
ENTER
115
STRING soft reconnect
116
END_IF_DEFINED
117
ATTACKMODE OFF
118
DELAY #RESTART_WAIT
119
ATTACKMODE #OS_DETECT_MODE #OS_DETECT_VID #OS_DETECT_PID
120
DELAY #CONNECT_WAIT
121
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
122
ENTER
123
STRING reconnected
124
END_IF_DEFINED
125
IF ($_CAPSLOCK_ON == TRUE) THEN
126
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
127
ENTER
128
STRING caps led on
129
ENTER
130
STRING test numlock
131
END_IF_DEFINED
132
NUMLOCK
133
DELAY #HOST_RESPONSE_TIMEOUT
134
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
135
ENTER
136
STRING test done
137
END_IF_DEFINED
138
IF ($_NUMLOCK_ON == FALSE) THEN
139
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
140
ENTER
141
STRING no numlock led
142
ENTER
143
STRING prediciton: ChromeOS
144
END_IF_DEFINED
145
$_OS = CHROMEOS
146
ELSE
147
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
148
ENTER
149
STRING numlock led on
150
ENTER
151
STRING testing scrolllock
152
END_IF_DEFINED
153
SCROLLLOCK
154
DELAY #HOST_RESPONSE_TIMEOUT
155
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
156
ENTER
157
STRING test done
158
END_IF_DEFINED
159
IF ($_SCROLLLOCK_ON == TRUE) THEN
160
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
161
ENTER
162
STRING scrolllock led on
163
ENTER
164
STRING prediciton: Android
165
END_IF_DEFINED
166
$_OS = ANDROID
167
ELSE
168
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
169
ENTER
170
STRING no scrolllock reply
171
ENTER
172
STRING prediction: Linux
173
END_IF_DEFINED
174
$_OS = LINUX
175
END_IF
176
END_IF
177
END_IF
178
ELSE IF ($_OS == MACOS) THEN
179
IF ($_CAPSLOCK_ON == TRUE) THEN
180
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
181
ENTER
182
STRING caps led on
183
ENTER
184
STRING prediction: iOS
185
END_IF_DEFINED
186
$_OS = IOS
187
ELSE
188
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
189
ENTER
190
STRING no caps reply
191
ENTER
192
STRING prediction: MacOS
193
END_IF_DEFINED
194
$_OS = MACOS
195
END_IF
196
ELSE IF ($_OS == WINDOWS) THEN
197
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
198
ENTER
199
STRING Confident Windows Prediction
200
END_IF_DEFINED
201
$_OS = WINDOWS
202
END_IF
203
END_IF_DEFINED
204
205
RESTORE_HOST_KEYBOARD_LOCK_STATE
206
207
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
208
ENTER
209
STRING OS_DETECT complete
210
ENTER
211
END_IF_DEFINED
212
END_FUNCTION
213
214
REM Uncomment the function call below to run this extension inline (here)
215
REM or call DETECT_OS() anywhere in your payload after the extension
216
REM DETECT_OS()
217
END_EXTENSION
218
219