2022-08-19 22:26:02 +00:00
|
|
|
EXTENSION OS_DETECTION
|
2023-03-14 22:19:57 +00:00
|
|
|
REM VERSION 1.1
|
|
|
|
REM AUTHOR: Korben
|
|
|
|
|
|
|
|
REM_BLOCK DOCUMENTATION
|
|
|
|
USB Rubber Ducky Host OS Detection
|
|
|
|
Generic OS detection at a high view is a moving target
|
|
|
|
results may vary greatly depending
|
|
|
|
on a combination of many variables:
|
|
|
|
- number of testing stages
|
|
|
|
- specific devices and versions tested against
|
|
|
|
- number of systems testing for (scope)
|
|
|
|
- detection techniques (passive/invisible/active/hybrid)
|
|
|
|
- overall speed
|
|
|
|
- overall accuracy
|
|
|
|
|
|
|
|
If all you require is windows vs <anything other os> detection, the
|
|
|
|
PASSIVE_WINDOWS_DETECT extension is recommended over this extension.
|
|
|
|
|
|
|
|
TARGET:
|
|
|
|
DEFAULT - Windows, Mac, Linux
|
|
|
|
ADVANCED_DETECTION - Windows, Mac, Linux, iOS, ChromeOS, Android
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
Uncomment the function call below to run this extension inline (here)
|
|
|
|
or call DETECT_OS() anywhere in your payload after the extension
|
|
|
|
Place this extension and the DETECT_OS() before
|
|
|
|
you would like to first reference $_OS to execute payload code conditionally
|
|
|
|
|
|
|
|
FEEDBACK:
|
|
|
|
As mentioned above, this a moving target (especially for mac systems)
|
|
|
|
Please report any issues identifying specific operating systems.
|
|
|
|
Your feedback will greatly help solidify the robustness of this extension
|
|
|
|
|
|
|
|
DEBUGGING:
|
|
|
|
SET DEBUGGING_OUTPUT DEFINE to TRUE, deploy on a target with text editor open for debug output
|
|
|
|
END_REM
|
2022-08-19 22:26:02 +00:00
|
|
|
|
2022-09-29 06:06:15 +00:00
|
|
|
REM CONFIGURATION:
|
2023-03-14 22:19:57 +00:00
|
|
|
REM For Debugging:
|
|
|
|
DEFINE #DEBUGGING_OUTPUT FALSE
|
|
|
|
DEFINE #ADVANCED_DETECTION FALSE
|
|
|
|
REM Timing fine tuning:
|
|
|
|
DEFINE #STARTUP_DELAY 1500
|
|
|
|
DEFINE #RESTART_WAIT 1000
|
|
|
|
DEFINE #CONNECT_WAIT 1000
|
|
|
|
DEFINE #OS_DETECT_MODE HID
|
|
|
|
DEFINE #OS_DETECT_VID VID_05AC
|
|
|
|
DEFINE #OS_DETECT_PID PID_021E
|
|
|
|
DEFINE #WINDOWS_HOST_REQUEST_COUNT 2
|
|
|
|
DEFINE #HOST_RESPONSE_TIMEOUT 1000
|
2022-08-19 22:26:02 +00:00
|
|
|
|
|
|
|
FUNCTION DETECT_OS()
|
2022-09-29 06:06:15 +00:00
|
|
|
$_HOST_CONFIGURATION_REQUEST_COUNT = 0
|
2023-03-14 22:19:57 +00:00
|
|
|
ATTACKMODE #OS_DETECT_MODE #OS_DETECT_VID #OS_DETECT_PID
|
|
|
|
DELAY #STARTUP_DELAY
|
2022-09-29 06:06:15 +00:00
|
|
|
SAVE_HOST_KEYBOARD_LOCK_STATE
|
|
|
|
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
|
|
|
IF_DEFINED_TRUE #ADVANCED_DETECTION
|
2022-09-29 06:06:15 +00:00
|
|
|
STRING ADVANCED OS DETECT
|
2023-03-14 22:19:57 +00:00
|
|
|
ELSE_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
STRING OS DETECT
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
|
|
|
|
ENTER
|
|
|
|
STRING test caps
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
|
|
|
|
IF ($_CAPSLOCK_ON == FALSE) THEN
|
|
|
|
LED_R
|
|
|
|
CAPSLOCK
|
2023-03-14 22:19:57 +00:00
|
|
|
DELAY #HOST_RESPONSE_TIMEOUT
|
2022-09-29 06:06:15 +00:00
|
|
|
END_IF
|
|
|
|
LED_OFF
|
|
|
|
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING test done
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
|
|
|
|
IF $_RECEIVED_HOST_LOCK_LED_REPLY THEN
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING received led response
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
LED_G
|
2023-03-14 22:19:57 +00:00
|
|
|
IF ($_HOST_CONFIGURATION_REQUEST_COUNT > #WINDOWS_HOST_REQUEST_COUNT) THEN
|
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING prediction: Windows
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
$_OS = WINDOWS
|
|
|
|
ELSE
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING prediction: Linux
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
$_OS = LINUX
|
|
|
|
END_IF
|
|
|
|
ELSE
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING no led response
|
|
|
|
ENTER
|
|
|
|
STRING prediciton: MacOS
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
$_OS = MACOS
|
|
|
|
END_IF
|
|
|
|
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #ADVANCED_DETECTION
|
2022-09-29 06:06:15 +00:00
|
|
|
IF ( $_OS == LINUX ) THEN
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING soft reconnect
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
ATTACKMODE OFF
|
2023-03-14 22:19:57 +00:00
|
|
|
DELAY #RESTART_WAIT
|
|
|
|
ATTACKMODE #OS_DETECT_MODE #OS_DETECT_VID #OS_DETECT_PID
|
|
|
|
DELAY #CONNECT_WAIT
|
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING reconnected
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
IF ($_CAPSLOCK_ON == TRUE) THEN
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING caps led on
|
|
|
|
ENTER
|
|
|
|
STRING test numlock
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
NUMLOCK
|
2023-03-14 22:19:57 +00:00
|
|
|
DELAY #HOST_RESPONSE_TIMEOUT
|
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING test done
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
IF ($_NUMLOCK_ON == FALSE) THEN
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING no numlock led
|
|
|
|
ENTER
|
|
|
|
STRING prediciton: ChromeOS
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
$_OS = CHROMEOS
|
|
|
|
ELSE
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING numlock led on
|
|
|
|
ENTER
|
|
|
|
STRING testing scrolllock
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
SCROLLLOCK
|
2023-03-14 22:19:57 +00:00
|
|
|
DELAY #HOST_RESPONSE_TIMEOUT
|
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING test done
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
IF ($_SCROLLLOCK_ON == TRUE) THEN
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING scrolllock led on
|
|
|
|
ENTER
|
|
|
|
STRING prediciton: Android
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
$_OS = ANDROID
|
|
|
|
ELSE
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING no scrolllock reply
|
|
|
|
ENTER
|
|
|
|
STRING prediction: Linux
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
$_OS = LINUX
|
|
|
|
END_IF
|
|
|
|
END_IF
|
|
|
|
END_IF
|
|
|
|
ELSE IF ($_OS == MACOS) THEN
|
|
|
|
IF ($_CAPSLOCK_ON == TRUE) THEN
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING caps led on
|
|
|
|
ENTER
|
|
|
|
STRING prediction: iOS
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
$_OS = IOS
|
|
|
|
ELSE
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING no caps reply
|
|
|
|
ENTER
|
|
|
|
STRING prediction: MacOS
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
$_OS = MACOS
|
|
|
|
END_IF
|
|
|
|
ELSE IF ($_OS == WINDOWS) THEN
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING Confident Windows Prediction
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
$_OS = WINDOWS
|
|
|
|
END_IF
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-09-29 06:06:15 +00:00
|
|
|
|
|
|
|
RESTORE_HOST_KEYBOARD_LOCK_STATE
|
|
|
|
|
2023-03-14 22:19:57 +00:00
|
|
|
IF_DEFINED_TRUE #DEBUGGING_OUTPUT
|
2022-09-29 06:06:15 +00:00
|
|
|
ENTER
|
|
|
|
STRING OS_DETECT complete
|
|
|
|
ENTER
|
2023-03-14 22:19:57 +00:00
|
|
|
END_IF_DEFINED
|
2022-08-19 22:26:02 +00:00
|
|
|
END_FUNCTION
|
2022-09-29 06:06:15 +00:00
|
|
|
|
2022-08-19 22:26:02 +00:00
|
|
|
REM Uncomment the function call below to run this extension inline (here)
|
|
|
|
REM or call DETECT_OS() anywhere in your payload after the extension
|
|
|
|
REM DETECT_OS()
|
2022-09-29 06:06:15 +00:00
|
|
|
END_EXTENSION
|