On this page 24 sections
- What findstr does
- Case-insensitive searching
- Show line numbers
- Recursive search
- Skip binary files
- Recommended CTF combination
- Search for an exact string
- Search several strings at once
- Search configuration files
- Search configuration keywords
- Search assignment-style values
- Search XML configuration
- Search JSON and YAML
- Search scripts
- Search only filenames containing matches
- Search the current user profile
- Search ProgramData
- Search IIS web applications
- PowerShell history
- Search Windows Panther files
- Pipe dir output into findstr
- Filename search versus content search
- Targeted search before full filesystem search
- findstr limitations
What findstr does
findstr searches text inside files. It is the native Windows CMD equivalent of a basic grep workflow and is extremely useful when analysing configuration files, scripts, logs and CTF artefacts.
findstr "flag" file.txtCase-insensitive searching
/i ignores uppercase and lowercase differences. This is useful when the exact capitalisation of a value is unknown.
findstr /i "flag" file.txtShow line numbers
/n shows the line number where each match was found.
findstr /in "flag" file.txtRecursive search
/s searches matching files in the current directory and every subdirectory.
findstr /si "flag" *.*Skip binary files
/p skips files containing non-printable characters. This reduces noise when recursively searching large directory trees.
findstr /sip "flag" *.*Recommended CTF combination
Combining /s, /p, /i and /n gives recursive searching, skips many binary files, ignores case and displays line numbers.
findstr /spin "flag" *.* 2>nulSearch for an exact string
/c treats the supplied text as a single search string. It is especially useful when searching strings containing spaces or specific flag prefixes.
findstr /spin /c:"flag{" *.* 2>nulfindstr /spin /c:"CTF{" *.* 2>nulSearch several strings at once
Multiple /c options allow several interesting values to be searched in a single command.
findstr /spin /c:"flag{" /c:"CTF{" /c:"proof" /c:"user.txt" *.* 2>nulSearch configuration files
Instead of scanning every file type, restricting findstr to common configuration extensions is faster and produces cleaner output.
findstr /spin /c:"flag{" *.ini *.cfg *.conf *.config *.xml *.json *.yml *.yaml 2>nulSearch configuration keywords
Configuration files frequently contain key-value pairs. In CTF environments useful search terms include password, secret, token, key and connection strings.
findstr /spin /c:"password" /c:"passwd" /c:"secret" /c:"token" /c:"api_key" *.ini *.cfg *.config *.xml *.json *.yml *.yaml 2>nulSearch assignment-style values
Searching for assignment syntax can reduce matches from documentation or comments.
findstr /spin /c:"password=" /c:"passwd=" /c:"secret=" /c:"token=" /c:"key=" *.ini *.cfg *.conf *.config 2>nulSearch XML configuration
Windows and .NET applications frequently use XML-based configuration files.
findstr /spin /c:"password" *.xml *.config 2>nulfindstr /spin /c:"connectionString" *.config *.xml 2>nulSearch JSON and YAML
Modern applications commonly store configuration in JSON or YAML files.
findstr /spin /c:"password" /c:"secret" /c:"token" *.json *.yml *.yaml 2>nulSearch scripts
Batch and PowerShell scripts can reveal application paths, usernames, scheduled operations and other useful CTF context.
findstr /spin /c:"flag{" /c:"password" /c:"token" *.ps1 2>nulfindstr /spin /c:"flag{" /c:"password" *.bat *.cmd 2>nulSearch only filenames containing matches
/m prints only the names of files containing matching text. This is useful for reducing output before manually inspecting interesting files.
findstr /sim /c:"flag{" *.* 2>nulfindstr /sim /c:"password" *.ini *.cfg *.config *.xml 2>nulSearch the current user profile
Changing into the user profile before recursively searching keeps the scope manageable.
cd /d "%USERPROFILE%"findstr /spin /c:"flag{" *.* 2>nulSearch ProgramData
ProgramData is a useful application configuration location on Windows.
cd /d C:\ProgramDatafindstr /spin /c:"flag{" /c:"password" /c:"secret" /c:"token" *.ini *.cfg *.config *.xml *.json 2>nulSearch IIS web applications
On Windows web servers, web.config and application files under inetpub are useful targets during authorised lab enumeration.
cd /d C:\inetpub\wwwrootfindstr /spin /c:"flag{" /c:"password" /c:"connectionString" *.* 2>nulPowerShell history
PowerShell history is plain text and can be searched directly when it exists and permissions allow access.
findstr /i /n /c:"password" /c:"token" /c:"flag" "%APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt" 2>nulSearch Windows Panther files
Windows installation and deployment configuration can exist under C:\Windows\Panther. In training environments these files are worth reviewing separately.
findstr /spin /c:"password" /c:"username" C:\Windows\Panther\*.xml 2>nulPipe dir output into findstr
dir and findstr also work together when the goal is to filter filenames and paths rather than file contents.
dir C:\Users /s /b /a-d 2>nul | findstr /i "flag proof password config backup"Filename search versus content search
Piping dir into findstr searches the path or filename itself. Running findstr directly against files searches their contents. Understanding this difference avoids confusion during enumeration.
dir /s /b 2>nul | findstr /i "flag"findstr /spin /c:"flag{" *.* 2>nulTargeted search before full filesystem search
Searching an entire C: drive recursively can be slow and noisy. Start with user profiles, ProgramData, web roots and known application directories before expanding the scope.
cd /d "%USERPROFILE%" && findstr /spin /c:"flag{" *.* 2>nulcd /d C:\ProgramData && findstr /spin /c:"flag{" *.txt *.ini *.cfg *.config *.xml *.json 2>nulfindstr limitations
findstr is useful but its regular-expression engine is much more limited than grep, ripgrep or PowerShell Select-String. It may also behave poorly with binary files, Unicode encodings and very long lines. Use it primarily as a fast native Windows search tool.