Path: blob/master/payloads/extensions/translate.txt
2968 views
EXTENSION TRANSLATE1REM VERSION 1.12REM AUTHOR: Korben34REM_BLOCK DOCUMENTATION5This extension acts as a library or collection of helper functions6to work with converting variables in your payloads.7WHY:8Of the many ways to get information about the state of your payload9is by injecting static strings effectively as debugging prints10However, given the non-static nature of payloads using variables in11DuckyScript 3.0 - the ability to decode variables during payload12execution and print (inject) representations of their current state13can often be a critically helpful development and debugging tool.1415Available Functions:16DEFAULT:17TRANSLATE_INT() - var to decimal string - set $INPUT prior to call18EXTENDED: (enabled using the #INCLUDE defines below):19TRANSLATE_HEX() - var to hexidecimal string - set $INPUT prior to call20TRANSLATE_BINARY() - var to binary string - set $INPUT prior to call21TRANSLATE_BOOL() - var to boolean string - set $INPUT prior to call2223USAGE:24set $INPUT to desired var25call the correct translate_ function for the expected data type e.g.26VAR $myVar = 123427$INPUT = $myVar28TRANSLATE_INT()29REM the above code will inject 123430END_REM3132REM CONFIGURATION:33DEFINE #INCLUDE_TRANSLATE_HEX FALSE34DEFINE #INCLUDE_TRANSLATE_BOOL FALSE35DEFINE #INCLUDE_TRANSLATE_BINARY FALSE36DEFINE #INCLUDE_SWAP_ENDIAN FALSE3738REM Append ENTER after translation39VAR $AS_STRINGLN = TRUE4041DEFINE #PRINT_INT 042DEFINE #PRINT_HEX 143VAR $DIGIT_PRINT_MODE = #PRINT_INT44VAR $D = 045VAR $IN = 046VAR $INPUT = 047VAR $MOD = 048VAR $P = FALSE4950REM REQUIRED for INT/HEX - convert int to char51FUNCTION PRINTDIGIT()52IF ($D == 0) THEN53STRING 054ELSE IF ($D == 1) THEN55STRING 156ELSE IF ($D == 2) THEN57STRING 258ELSE IF ($D == 3) THEN59STRING 360ELSE IF ($D == 4) THEN61STRING 462ELSE IF ($D == 5) THEN63STRING 564ELSE IF ($D == 6) THEN65STRING 666ELSE IF ($D == 7) THEN67STRING 768ELSE IF ($D == 8) THEN69STRING 870ELSE IF ($D == 9) THEN71STRING 972IF_DEFINED_TRUE #INCLUDE_TRANSLATE_HEX73ELSE IF ($DIGIT_PRINT_MODE == #PRINT_HEX) THEN74IF ($D == 10) THEN75STRING A76ELSE IF ($D == 11) THEN77STRING B78ELSE IF ($D == 12) THEN79STRING C80ELSE IF ($D == 13) THEN81STRING D82ELSE IF ($D == 14) THEN83STRING E84ELSE IF ($D == 15) THEN85STRING F86END_IF87END_IF_DEFINED88ELSE89STRING ?90END_IF91END_FUNCTION9293REM REQUIRED for INT/HEX- consumes a character / place from the input94FUNCTION CONSUME()95$D = 096WHILE ($INPUT >= $MOD)97$D = ($D + 1)98$INPUT = ($INPUT - $MOD)99END_WHILE100IF (($D > 0) || ($P == TRUE)) THEN101$P = TRUE102PRINTDIGIT()103END_IF104END_FUNCTION105106IF_DEFINED_TRUE #INCLUDE_SWAP_ENDIAN107REM ENDIAN SWAPPER helper, (useful for working with VID/PID)108FUNCTION SWAP_ENDIAN()109$INPUT = ((($INPUT >> 8) & 0x00FF) | (($INPUT << 8) & 0xFF00))110END_FUNCTION111END_IF_DEFINED112113114REM Translates a variable of presumed integer type and attempts to convert115REM and inject a DECIMAL string representation116FUNCTION TRANSLATE_INT()117$DIGIT_PRINT_MODE = #PRINT_INT118$P = FALSE119IF ( $INPUT >= 10000) THEN120$MOD = 10000121CONSUME()122END_IF123IF (($INPUT >= 1000) || ($P == TRUE)) THEN124$MOD = 1000125CONSUME()126END_IF127IF (($INPUT >= 100) || ($P == TRUE)) THEN128$MOD = 100129CONSUME()130END_IF131IF (($INPUT >= 10) || ($P == TRUE)) THEN132$MOD = 10133CONSUME()134END_IF()135$D = $INPUT136PRINTDIGIT()137IF $AS_STRINGLN THEN138ENTER139END_IF140END_FUNCTION141142REM Translates a variable of presumed boolean type and attempts to convert143REM and inject a BOOLEAN string representation144REM TO ENABLE SET INCLUDE_TRANSLATE_BOOL to TRUE before compiling145IF_DEFINED_TRUE #INCLUDE_TRANSLATE_BOOL146FUNCTION TRANSLATE_BOOL()147IF $INPUT THEN148STRING TRUE149ELSE150STRING FALSE151END_IF152IF $AS_STRINGLN THEN153ENTER154END_IF155END_FUNCTION156END_IF_DEFINED157158REM Translates a variable of presumed integer type and attempts to convert159REM and inject a HEX string representation160REM TO ENABLE SET INCLUDE_TRANSLATE_HEX to TRUE before compiling161IF_DEFINED_TRUE #INCLUDE_TRANSLATE_HEX162FUNCTION TRANSLATE_HEX()163$DIGIT_PRINT_MODE = #PRINT_HEX164VAR $chars = 0165VAR $d1 = 0166VAR $d2 = 0167VAR $d3 = 0168VAR $d4 = 0169WHILE ($INPUT > 0)170IF ($chars == 0) THEN171$d1 = ($INPUT % 16)172ELSE IF ($chars == 1) THEN173$d2 = ($INPUT % 16)174ELSE IF ($chars == 2) THEN175$d3 = ($INPUT % 16)176ELSE IF ($chars == 3) THEN177$d4 = ($INPUT % 16)178END_IF179$chars = ($chars + 1)180$INPUT = ($INPUT / 16)181END_WHILE182VAR $i = 0183STRING 0x184IF ($chars == 0) THEN185STRING 0x0000186ELSE IF ($chars == 1) THEN187STRING 000188$D = $d1189PRINTDIGIT()190ELSE IF ($chars == 2) THEN191STRING 00192$D = $d2193PRINTDIGIT()194$D = $d1195PRINTDIGIT()196ELSE IF ($chars == 3) THEN197STRING 0198$D = $d3199PRINTDIGIT()200$D = $d2201PRINTDIGIT()202$D = $d1203PRINTDIGIT()204ELSE IF ($chars == 4) THEN205STRING 0206$D = $d4207PRINTDIGIT()208$D = $d3209PRINTDIGIT()210$D = $d2211PRINTDIGIT()212$D = $d1213PRINTDIGIT()214END_IF215IF $AS_STRINGLN THEN216ENTER217END_IF218END_FUNCTION219END_IF_DEFINED220221REM Translates a variable of presumed integer type and attempts to convert222REM and inject a BINARY string representation223REM TO ENABLE SET INCLUDE_TRANSLATE_BINARY to TRUE before compiling224IF_DEFINED_TRUE #INCLUDE_TRANSLATE_BINARY225FUNCTION TRANSLATE_BINARY()226VAR $I = 16227WHILE ( $I > 0 )228$I = ($I - 1)229IF (($INPUT & 0x8000) == 0 ) THEN230STRING 0231ELSE232STRING 1233END_IF234$INPUT = ($INPUT << 1)235END_WHILE236IF $AS_STRINGLN THEN237ENTER238END_IF239END_FUNCTION240END_IF_DEFINED241END_EXTENSION242243244