Get-keys.bat

set "OUTFILE=%CD%\get-keys_report_%DT%.csv"

:: Normalize paths and build exclude list for findstr set "EXCLUDE_FILTER=" for %%E in (%EXCLUDE:;= %) do ( if defined EXCLUDE_FILTER (set "EXCLUDE_FILTER=!EXCLUDE_FILTER!|%%E") else set "EXCLUDE_FILTER=%%E" ) get-keys.bat

:: -------------------------- :: Helper: mask value (simple) :: -------------------------- :mask_value REM Input: %1 value, Output: masked in MASKED_VALUE variable setlocal ENABLEDELAYEDEXPANSION set "VAL=%~1" if "%MASK%"=="1" ( set "LEN=0" for /l %%i in (0,1,200) do ( if "!VAL:~%%i,1!"=="" goto :gotlen ) :gotlen set /a KEEP=4 set /a LBOUND=KEEP if %LEN% LSS %KEEP% set "KEEP=1" REM show first KEEP chars and mask the rest with * set "PREFIX=!VAL:~0,%KEEP%!" set "MASKED_SUFFIX=" for /l %%i in (1,1,60) do set "MASKED_SUFFIX=!MASKED_SUFFIX!*" set "MASKED_VALUE=!PREFIX!!MASKED_SUFFIX!" ) else ( set "MASKED_VALUE=%VAL%" ) endlocal & set "MASKED_VALUE=%MASKED_VALUE%" goto :eof set "OUTFILE=%CD%\get-keys_report_%DT%

Below is a thorough, extensible Windows batch script named get-keys.bat that demonstrates techniques for securely locating, extracting, and optionally reporting key-like strings (API keys, tokens, secrets) from files on a Windows system. This is intended for legitimate use only — e.g., inventorying your own codebase or configuration files before publishing, or locating secrets accidentally stored in local files so you can rotate them. Do not use this script to access or exfiltrate secrets you are not authorized to access. if "%DRY%"=="0" ( echo Report written to %OUTFILE%

if "%DRY%"=="0" ( echo Report written to %OUTFILE% ) else ( echo Dry-run complete: no report written. )

:: -------------------------- :: Main scan loop :: -------------------------- pushd "%ROOT%" 2>nul || (echo Cannot access %ROOT% & exit /b 1)

:: Convert extensions list into a findstr include filter set "EXT_FILTER=" for %%E in (%EXTS:,= %) do ( if defined EXT_FILTER (set "EXT_FILTER=!EXT_FILTER! *.%%E") else set "EXT_FILTER=*.%%E" )