The find utility is a directory searcher designed to locate files based on incredibly specific criteria like permissions, ownership, modification dates, and file types. In the context of offensive security, it is arguably the most dangerous reconnaissance tool available on a Linux system. Once you gain initial access to a machine, this utility allows you to hunt for misconfigured permissions, hardcoded passwords in hidden files, and vulnerable binaries that can be abused for privilege escalation. Because it is installed on virtually every Unix-like operating system by default, it is the perfect tool for "living off the land" without needing to upload custom enumeration scripts that might trigger an antivirus alert.
The Core Syntax
Unlike tools that just parse text, find crawls the actual filesystem hierarchy. The basic syntax always follows a specific structure: you call the utility, specify the directory path where you want the search to begin, and then pass your filtering arguments.
If you do not specify a path, it defaults to your current working directory. If you specify /, it will search the entire filesystem starting from the root directory.
Searching by Name and Type
The absolute basics begin with the -name flag. This allows you to search for exact file names or use wildcards to hunt for specific extensions like database backups or configuration files. If you are unsure of the capitalization, the -iname flag performs the exact same search but ignores case sensitivity entirely.
When crawling a massive filesystem, searching by name alone will return a messy mix of directories, symbolic links, and raw files. You tighten the search using the -type flag. You will primarily use it to filter for standard files using f, or directories using d.
Command:
Result:
Operational Security and Depth Control
When crawling a root filesystem, you can easily cause a server to hang or alert defenders by recursively traversing massive network shares or infinite virtual file systems. The -maxdepth flag is crucial for operational security. By setting a maximum directory depth, you force the utility to only search a few folders deep before stopping.
Command:
Result:
Hunting by Time and Size
The -mmin and -mtime flags allow you to search based on file modification time. This is invaluable during an engagement when you want to see exactly what configuration files a system administrator modified in the last 60 minutes, or what logs were altered just before you compromised the machine.
Command:
Result:
The -size flag helps you hunt for hidden loot. By filtering for files larger than a specific megabyte threshold, you can easily uncover forgotten database dumps, old virtual machine images, or uncompressed backup archives left behind by lazy administrators.
Command:
Result:
Discovering SUID Binaries via Permissions
The -perm flag is the holy grail for privilege escalation. It allows you to search for files with specific permission bits set.
By searching for files with the 4000 permission bit, you can locate SUID binaries. These are special executables that run with the privileges of the file owner (usually root) regardless of which user executes them. We push standard errors to /dev/null to keep our terminal clean from permission denied warnings.
Command:
Result:
Weaponizing the Exec Flag
The -exec flag allows you to execute a secondary command on every single file the search returns.
If you discover that the find binary itself has SUID permissions, or if your compromised user is allowed to run it via sudo, you can abuse this flag to break out of the search utility entirely and spawn a privileged shell. The command executes /bin/sh and the -quit argument ensures it stops after spawning the first shell, rather than spawning a new shell for every file it finds.
Command:
Result:
Conclusion
The ability to navigate and filter a filesystem natively is what separates script kiddies from advanced operators. By mastering basic syntax like -name and -type, and chaining them with advanced filters like -mmin, -size, and -perm, you can map out a target's internal structure and locate the exact misconfigurations needed to elevate your privileges.
Follow and keep in touch as we continue exploring command-line mastery in our next post.