Get-keys.bat Apr 2026
setlocal ENABLEDELAYEDEXPANSION
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. get-keys.bat
@echo off REM get-keys.bat REM Recursively search for likely keys/tokens in files and generate a CSV report. REM Usage: REM get-keys.bat [root_path] [--extensions=ext1,ext2,...] [--exclude=pattern1;pattern2] [--mask] [--dry-run] REM Defaults: REM root_path = current directory REM extensions = txt,env,conf,config,json,js,py,java,xml,ini,yml,yaml,md,log REM exclude = .git;.venv;node_modules;venv REM mask = redact found values in report REM dry-run = do not write report (only console output) @echo off REM get-keys
:: -------------------------- :: 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 log REM exclude = .git
if "%DRY%"=="0" ( echo Report written to %OUTFILE% ) else ( echo Dry-run complete: no report written. )