On this page 19 sections
- What dir does
- Show all files
- Recursive enumeration
- Bare output
- Files only
- Search filenames for common CTF terms
- Why 2>nul is useful
- Search a specific user profile
- Interesting user directories
- Enumerate all user profiles
- Configuration file extensions
- Search several interesting extensions
- ProgramData
- AppData
- Web server files
- Windows Panther
- PowerShell history
- Search the entire drive as a fallback
- CTF workflow
What dir does
dir lists files and directories from Windows Command Prompt. During CTFs and authorised enumeration it is useful for quickly mapping a filesystem, locating unusual files and identifying configuration files before inspecting their contents.
dirShow all files
The /a option includes files with special attributes such as hidden and system files.
dir /adir /a:hdir /a:sRecursive enumeration
/s searches recursively through subdirectories. This is one of the most useful options during filesystem enumeration.
dir /sBare output
/b produces bare output containing only paths or filenames. It is much easier to pipe into other commands such as findstr.
dir /bdir /s /bFiles only
/a-d excludes directories and returns only files.
dir /s /b /a-dSearch filenames for common CTF terms
Before searching file contents, filename enumeration can reveal obvious artefacts such as flag.txt, proof.txt, user.txt or configuration backups.
dir /s /b *flag* 2>nuldir /s /b *user* 2>nuldir /s /b *proof* 2>nuldir /s /b *config* 2>nulWhy 2>nul is useful
Recursive searches often encounter directories that the current user cannot access. Redirecting STDERR to nul hides access-denied messages and keeps the output readable.
dir C:\ /s /b *flag* 2>nulSearch a specific user profile
Searching a user profile is usually faster and less noisy than immediately scanning the entire system drive.
dir "%USERPROFILE%" /s /b 2>nuldir "%USERPROFILE%\*flag*" /s /b 2>nulInteresting user directories
Desktop, Documents and Downloads are common locations for CTF artefacts, scripts, notes and configuration files.
dir "%USERPROFILE%\Desktop" /a /s /b 2>nuldir "%USERPROFILE%\Documents" /a /s /b 2>nuldir "%USERPROFILE%\Downloads" /a /s /b 2>nulEnumerate all user profiles
C:\Users reveals which local user profiles exist and can provide additional locations worth inspecting.
dir C:\Usersdir C:\Users /s /b /a-d 2>nulConfiguration file extensions
Configuration data is commonly stored in INI, CFG, CONF, CONFIG, XML, JSON, YAML and script files.
dir C:\Users\*.ini /s /b 2>nuldir C:\Users\*.config /s /b 2>nuldir C:\Users\*.xml /s /b 2>nuldir C:\Users\*.json /s /b 2>nulSearch several interesting extensions
A small FOR loop can enumerate several common configuration and script extensions without manually repeating every command. In interactive CMD use a single percent sign.
for %e in (txt ini cfg conf config xml json yml yaml ps1 bat cmd) do @dir C:\Users\*.%e /s /b 2>nulProgramData
C:\ProgramData stores application-wide configuration and data. In CTF environments it is often worth checking because installed applications may leave configuration, log or backup files here.
dir C:\ProgramData /a /s /b 2>nuldir C:\ProgramData\*.config /s /b 2>nuldir C:\ProgramData\*.xml /s /b 2>nulAppData
Applications frequently store per-user configuration in AppData. Both Roaming and Local can contain application settings, scripts, caches and configuration artefacts.
dir "%APPDATA%" /s /b 2>nuldir "%LOCALAPPDATA%" /s /b 2>nulWeb server files
On IIS systems the default web root is commonly C:\inetpub\wwwroot. Web application files can reveal configuration files, scripts and CTF artefacts.
dir C:\inetpub\wwwroot /a /s /b 2>nuldir C:\inetpub\wwwroot\web.config /s /b 2>nulWindows Panther
Windows setup information may remain under the Panther directories. In training environments these files can be useful enumeration targets.
dir C:\Windows\Panther /a /s /b 2>nuldir C:\Windows\Panther\*unattend* /s /b 2>nulPowerShell history
PowerShell command history can reveal commands previously executed by the current user. The default PSReadLine history commonly exists below the roaming AppData directory.
dir "%APPDATA%\Microsoft\Windows\PowerShell\PSReadLine" /a /s /b 2>nulSearch the entire drive as a fallback
A full recursive search can produce a large amount of output and should generally come after targeted enumeration.
dir C:\*flag* /s /b 2>nuldir C:\*.txt /s /b 2>nulCTF workflow
A practical workflow is to enumerate the current profile first, inspect application and web directories next, search interesting filenames and extensions, and only perform a full-drive recursive search if targeted searches do not reveal anything.
dir "%USERPROFILE%" /a /s /b 2>nuldir "%USERPROFILE%\*flag*" /s /b 2>nuldir C:\ProgramData /a /s /b 2>nuldir C:\*flag* /s /b 2>nul