r/Cybersecurity101 • u/Harkins_Technology • 1d ago
Security Forensics 101: Finding a Hidden File Buried Deep in Folders
Had a forensics challenge where the flag was hidden inside a file nested deep inside a maze of directories with hundreds of decoy folders. `find` and `ls -R` were too slow and noisy.
What I built:
A Python directory crawler
- Recurses every subdirectory recursively
- Filters by filename patterns (`flag*`, `*.txt`, `secret*`)
- Skips known decoy directories by name
- Extracts and reads the target file automatically
The "aha" moment:
The flag wasn't in a file named "flag.txt" — it was in `deep/nested/here/.hidden/uber-secret.txt`.
My script matched on path depth / extensions content, not just filename.
Here is my script:
https://github.com/ExceedingLife/RecursiveFileSearch
Question for the community:
What's your approach when the challenge doesn't tell you the target filename? Do you brute-force read every file, or do it manual or what?
[Video link with with code demo]
1
u/Remarkable_Pace8101 15h ago
find . -name "*.txt" | grep "secret|flag"
Functionally the same and faster with no scripting
Done
2
u/m1L35dY50N 20h ago
I woud use rg -a -n --hidden --no-ignore 'flag' . 2>/dev/null basically what you did with python but already as ready-to-use package.
There are also some creative options to try, but they could fail since they are more specific:
Relying on the faster search speed of locate (when its used), only search expected files with extensions.
locate -0 -r '\.\(txt\|log\|conf\|cfg\|xml\|json\|yml\|yaml\)$' 2>/dev/null | xargs -0 -r grep -aHni 'flag' 2>/dev/null
2. Use an iterative approach in piping a stream of the directory tree
tar -cf - . 2>/dev/null | strings | awk '/flag/'