usbrubberducky-payloads/payloads/extensions/translate.txt

243 lines
7.5 KiB
Plaintext

EXTENSION TRANSLATE
REM VERSION 1.1
REM AUTHOR: Korben
REM_BLOCK DOCUMENTATION
This extension acts as a library or collection of helper functions
to work with converting variables in your payloads.
WHY:
Of the many ways to get information about the state of your payload
is by injecting static strings effectively as debugging prints
However, given the non-static nature of payloads using variables in
DuckyScript 3.0 - the ability to decode variables during payload
execution and print (inject) representations of their current state
can often be a critically helpful development and debugging tool.
Available Functions:
DEFAULT:
TRANSLATE_INT() - var to decimal string - set $INPUT prior to call
EXTENDED: (enabled using the #INCLUDE defines below):
TRANSLATE_HEX() - var to hexidecimal string - set $INPUT prior to call
TRANSLATE_BINARY() - var to binary string - set $INPUT prior to call
TRANSLATE_BOOL() - var to boolean string - set $INPUT prior to call
USAGE:
set $INPUT to desired var
call the correct translate_ function for the expected data type e.g.
VAR $myVar = 1234
$INPUT = $myVar
TRANSLATE_INT()
REM the above code will inject 1234
END_REM
REM CONFIGURATION:
DEFINE #INCLUDE_TRANSLATE_HEX FALSE
DEFINE #INCLUDE_TRANSLATE_BOOL FALSE
DEFINE #INCLUDE_TRANSLATE_BINARY FALSE
DEFINE #INCLUDE_SWAP_ENDIAN FALSE
REM Append ENTER after translation
VAR $AS_STRINGLN = TRUE
DEFINE #PRINT_INT 0
DEFINE #PRINT_HEX 1
VAR $DIGIT_PRINT_MODE = #PRINT_INT
VAR $D = 0
VAR $IN = 0
VAR $INPUT = 0
VAR $MOD = 0
VAR $P = FALSE
REM REQUIRED for INT/HEX - convert int to char
FUNCTION PRINTDIGIT()
IF ($D == 0) THEN
STRING 0
ELSE IF ($D == 1) THEN
STRING 1
ELSE IF ($D == 2) THEN
STRING 2
ELSE IF ($D == 3) THEN
STRING 3
ELSE IF ($D == 4) THEN
STRING 4
ELSE IF ($D == 5) THEN
STRING 5
ELSE IF ($D == 6) THEN
STRING 6
ELSE IF ($D == 7) THEN
STRING 7
ELSE IF ($D == 8) THEN
STRING 8
ELSE IF ($D == 9) THEN
STRING 9
IF_DEFINED_TRUE #INCLUDE_TRANSLATE_HEX
ELSE IF ($DIGIT_PRINT_MODE == #PRINT_HEX) THEN
IF ($D == 10) THEN
STRING A
ELSE IF ($D == 11) THEN
STRING B
ELSE IF ($D == 12) THEN
STRING C
ELSE IF ($D == 13) THEN
STRING D
ELSE IF ($D == 14) THEN
STRING E
ELSE IF ($D == 15) THEN
STRING F
END_IF
END_IF_DEFINED
ELSE
STRING ?
END_IF
END_FUNCTION
REM REQUIRED for INT/HEX- consumes a character / place from the input
FUNCTION CONSUME()
$D = 0
WHILE ($INPUT >= $MOD)
$D = ($D + 1)
$INPUT = ($INPUT - $MOD)
END_WHILE
IF (($D > 0) || ($P == TRUE)) THEN
$P = TRUE
PRINTDIGIT()
END_IF
END_FUNCTION
IF_DEFINED_TRUE #INCLUDE_SWAP_ENDIAN
REM ENDIAN SWAPPER helper, (useful for working with VID/PID)
FUNCTION SWAP_ENDIAN()
$INPUT = ((($INPUT >> 8) & 0x00FF) | (($INPUT << 8) & 0xFF00))
END_FUNCTION
END_IF_DEFINED
REM Translates a variable of presumed integer type and attempts to convert
REM and inject a DECIMAL string representation
FUNCTION TRANSLATE_INT()
$DIGIT_PRINT_MODE = #PRINT_INT
$P = FALSE
IF ( $INPUT >= 10000) THEN
$MOD = 10000
CONSUME()
END_IF
IF (($INPUT >= 1000) || ($P == TRUE)) THEN
$MOD = 1000
CONSUME()
END_IF
IF (($INPUT >= 100) || ($P == TRUE)) THEN
$MOD = 100
CONSUME()
END_IF
IF (($INPUT >= 10) || ($P == TRUE)) THEN
$MOD = 10
CONSUME()
END_IF()
$D = $INPUT
PRINTDIGIT()
IF $AS_STRINGLN THEN
ENTER
END_IF
END_FUNCTION
REM Translates a variable of presumed boolean type and attempts to convert
REM and inject a BOOLEAN string representation
REM TO ENABLE SET INCLUDE_TRANSLATE_BOOL to TRUE before compiling
IF_DEFINED_TRUE #INCLUDE_TRANSLATE_BOOL
FUNCTION TRANSLATE_BOOL()
IF $INPUT THEN
STRING TRUE
ELSE
STRING FALSE
END_IF
IF $AS_STRINGLN THEN
ENTER
END_IF
END_FUNCTION
END_IF_DEFINED
REM Translates a variable of presumed integer type and attempts to convert
REM and inject a HEX string representation
REM TO ENABLE SET INCLUDE_TRANSLATE_HEX to TRUE before compiling
IF_DEFINED_TRUE #INCLUDE_TRANSLATE_HEX
FUNCTION TRANSLATE_HEX()
$DIGIT_PRINT_MODE = #PRINT_HEX
VAR $chars = 0
VAR $d1 = 0
VAR $d2 = 0
VAR $d3 = 0
VAR $d4 = 0
WHILE ($INPUT > 0)
IF ($chars == 0) THEN
$d1 = ($INPUT % 16)
ELSE IF ($chars == 1) THEN
$d2 = ($INPUT % 16)
ELSE IF ($chars == 2) THEN
$d3 = ($INPUT % 16)
ELSE IF ($chars == 3) THEN
$d4 = ($INPUT % 16)
END_IF
$chars = ($chars + 1)
$INPUT = ($INPUT / 16)
END_WHILE
VAR $i = 0
STRING 0x
IF ($chars == 0) THEN
STRING 0x0000
ELSE IF ($chars == 1) THEN
STRING 000
$D = $d1
PRINTDIGIT()
ELSE IF ($chars == 2) THEN
STRING 00
$D = $d2
PRINTDIGIT()
$D = $d1
PRINTDIGIT()
ELSE IF ($chars == 3) THEN
STRING 0
$D = $d3
PRINTDIGIT()
$D = $d2
PRINTDIGIT()
$D = $d1
PRINTDIGIT()
ELSE IF ($chars == 4) THEN
STRING 0
$D = $d4
PRINTDIGIT()
$D = $d3
PRINTDIGIT()
$D = $d2
PRINTDIGIT()
$D = $d1
PRINTDIGIT()
END_IF
IF $AS_STRINGLN THEN
ENTER
END_IF
END_FUNCTION
END_IF_DEFINED
REM Translates a variable of presumed integer type and attempts to convert
REM and inject a BINARY string representation
REM TO ENABLE SET INCLUDE_TRANSLATE_BINARY to TRUE before compiling
IF_DEFINED_TRUE #INCLUDE_TRANSLATE_BINARY
FUNCTION TRANSLATE_BINARY()
VAR $I = 16
WHILE ( $I > 0 )
$I = ($I - 1)
IF (($INPUT & 0x8000) == 0 ) THEN
STRING 0
ELSE
STRING 1
END_IF
$INPUT = ($INPUT << 1)
END_WHILE
IF $AS_STRINGLN THEN
ENTER
END_IF
END_FUNCTION
END_IF_DEFINED
END_EXTENSION