Extracting Data from Text Dumps: Base64 and Hex
CTF organizers hide flags in encodings, which directly correlates with real-world information security practices. The Deobfuscate/Decode Files or Information (T1140) technique , as classified by MITRE ATT&CK, describes the same scenario: attackers obfuscate data to evade detection, and analysts decode it.
Base64. String flag{hello_world}in Base64 it turns into ZmxhZ3toZWxsb193b3JsZH0=. It's impossible to recognize with the naked eye. Strategy: find all base64-like strings in the dump, decode them en masse, and look for the pattern in the decoded text.
grep -Eo '[A-Za-z0-9+/]{20,}={0,2}' dump.txt \
| base64 -d 2>/dev/null \
| grep -Eo 'flag\{[^}]+\}'
The first grep finds candidates - strings from the base64 alphabet of at least 20 characters in length with optional padding ( =). Threshold {20,}cuts off matches that are too short. base64 -ddecodes each line (errors are suppressed through 2>/dev/null). The second grep searches for the flag in the decoded text.
Hex encoding. Flag flag{abc} в hex — 666c61677b6162637d. Conveyor similar to: grep -Eo '[0-9a-fA-F]{20,}' dump.txt | xxd -r -p 2>/dev/null | grep -Eo 'flag\{[^}]+\}'. Utility xxd -r -pPerforms the reverse conversion from hex to ASCII.
ROT13. Classic substitution cipher. String flagafter ROT13 — synt. We search directly: grep -Eo 'synt\{[^}]+\}' dump.txt | tr 'A-Za-z' 'N-ZA-Mn-za-m'. Team trapplies the inverse ROT13 substitution (ROT13 is symmetric - applying it twice returns the original).
Extracting data from text dumps often requires a combination of multiple decodes. There are tasks involving double base64 (base64 of base64), hex-encoded base64, and other nested encodings—a kind of Russian doll. The approach is to build a pipeline of pipe symbols, passing the data through a chain of decoders.
CTF Grep Commands: A Practical Workflow from Dump to Flag
Theory without practice is empty. Let's look at the full workflow: a forensics category task, a file challenge.log800 MB in size.
file challenge.log
wc -l challenge.log
LC_ALL=C grep -Eom1 '[a-zA-Z0-9_]+\{[^}]+\}' challenge.log
grep -Eo '[A-Za-z0-9+/]{20,}={0,2}' challenge.log | head -20
grep -rEo 'flag\{[^}]+\}' ./extracted/ --include='*.txt'
grep -n -C 3 'подозрительная_строка' challenge.log
strings -n 6 challenge.log | grep -Eoi 'flag'
Step 1 - reconnaissance. filewill show the file type (ASCII text, UTF-8 Unicode text, data), wc -l— the number of lines. Two seconds, but you immediately understand the scale: text or binary, a thousand lines or two million.
Step 2 - Quick grep. Universal pattern with LC_ALL=C And -m1If the flag is open, the answer will appear in a split second. This step solves about half of the tasks. Seriously, half.
Step 3: Check encodings. Direct search yielded no results? Look for base64 blocks. head -20shows the first 20 candidates - we evaluate them visually to see if they look like base64 or if they are a random set of characters. Then we run them through base64 -dand look for a pattern.
Step 4 – Recursive search. If the task returned an archive with multiple files: grep -rEo 'flag\{[^}]+\}' ./extracted/. Option --include='*.txt'Limits the search to text files—grep doesn't waste time on images and binaries.
Step 5 - Context. Found a suspicious line but not sure? Flag -C 3will show three lines before and after the match, -nwill add line numbers. Then you can open the file exactly at the desired line: vim +номер challenge.log.
Step 6 - strings for binary inclusions If fileshowed datainstead of text, we first run it through strings.
This workflow covers approximately 70-80% of the jeopardy-CTF tasks in the misc, forensics, and crypto categories. Incidentally, picoCTF includes a "First Grep" task for beginners—it works exactly like this: given a file, find the line. picoCTF{...}one team.
awk and sed for CTF dumps: When grep fails
Grep works line by line—this is both its strength and its limitation. If a flag is split across multiple lines (hex dumps, multi-line logs), grep won't see it.
awk to extract fields. Let's say the log has the format timestamp | level | message, and the flag is hidden in the message field. Conveyor awk -F'|' '{print $3}' access.log | grep -Eo 'flag\{[^}]+\}'first through awkwill cut out the third field (separator) |), then grep will find the flag in it.
sed for preprocessing. Sometimes the organizers break the flag with spaces: f l a g { h e l l o }Remove spaces before searching: sed 's/ //g' dump.txt | grep -Eo 'flag\{[^}]+\}'Another option is to merge all the lines of the file into one: tr -d '\n' < dump.txt | grep -Eo 'flag\{[^}]+\}'. Team tr -d '\n'Removes line breaks. Be careful with large files—the entire line is loaded into memory.
pcregrep for multi-line search. pcregrepsupports the flag -M (multiline): pcregrep -Mo 'flag\{[^}]+\}' dump.txtThe only option without pre-gluing the lines is pcregrepwill automatically handle matches that cross a line boundary.
Connecting grep skills to real-world information security practice
Everything described above applies without modification outside of CTF. During an incident response, the analyst searches for indicators of compromise in logs using the same pipelines. The Credentials In Files (T1552.001) technique according to MITRE ATT&CK is literally grepping for patterns. password=, api_key=, secret=in the file system. Data from Local System (T1005) - collecting data from local files, the same recursive grep -rby directories. Shell History (T1552.003) - search for credentials leaks in .bash_history.
Team grep -rEi '(password|passwd|api_key|secret|token)=' /var/log/— a working tool for both CTF tasks and production server configuration audits. The only difference is the pattern: in CTFs, we look for flag{}, in life - data leaks.
CTF organizers hide flags in encodings, which directly correlates with real-world information security practices. The Deobfuscate/Decode Files or Information (T1140) technique , as classified by MITRE ATT&CK, describes the same scenario: attackers obfuscate data to evade detection, and analysts decode it.
Base64. String flag{hello_world}in Base64 it turns into ZmxhZ3toZWxsb193b3JsZH0=. It's impossible to recognize with the naked eye. Strategy: find all base64-like strings in the dump, decode them en masse, and look for the pattern in the decoded text.
grep -Eo '[A-Za-z0-9+/]{20,}={0,2}' dump.txt \
| base64 -d 2>/dev/null \
| grep -Eo 'flag\{[^}]+\}'
The first grep finds candidates - strings from the base64 alphabet of at least 20 characters in length with optional padding ( =). Threshold {20,}cuts off matches that are too short. base64 -ddecodes each line (errors are suppressed through 2>/dev/null). The second grep searches for the flag in the decoded text.
Hex encoding. Flag flag{abc} в hex — 666c61677b6162637d. Conveyor similar to: grep -Eo '[0-9a-fA-F]{20,}' dump.txt | xxd -r -p 2>/dev/null | grep -Eo 'flag\{[^}]+\}'. Utility xxd -r -pPerforms the reverse conversion from hex to ASCII.
ROT13. Classic substitution cipher. String flagafter ROT13 — synt. We search directly: grep -Eo 'synt\{[^}]+\}' dump.txt | tr 'A-Za-z' 'N-ZA-Mn-za-m'. Team trapplies the inverse ROT13 substitution (ROT13 is symmetric - applying it twice returns the original).
Extracting data from text dumps often requires a combination of multiple decodes. There are tasks involving double base64 (base64 of base64), hex-encoded base64, and other nested encodings—a kind of Russian doll. The approach is to build a pipeline of pipe symbols, passing the data through a chain of decoders.
CTF Grep Commands: A Practical Workflow from Dump to Flag
Theory without practice is empty. Let's look at the full workflow: a forensics category task, a file challenge.log800 MB in size.
file challenge.log
wc -l challenge.log
LC_ALL=C grep -Eom1 '[a-zA-Z0-9_]+\{[^}]+\}' challenge.log
grep -Eo '[A-Za-z0-9+/]{20,}={0,2}' challenge.log | head -20
grep -rEo 'flag\{[^}]+\}' ./extracted/ --include='*.txt'
grep -n -C 3 'подозрительная_строка' challenge.log
strings -n 6 challenge.log | grep -Eoi 'flag'
Step 1 - reconnaissance. filewill show the file type (ASCII text, UTF-8 Unicode text, data), wc -l— the number of lines. Two seconds, but you immediately understand the scale: text or binary, a thousand lines or two million.
Step 2 - Quick grep. Universal pattern with LC_ALL=C And -m1If the flag is open, the answer will appear in a split second. This step solves about half of the tasks. Seriously, half.
Step 3: Check encodings. Direct search yielded no results? Look for base64 blocks. head -20shows the first 20 candidates - we evaluate them visually to see if they look like base64 or if they are a random set of characters. Then we run them through base64 -dand look for a pattern.
Step 4 – Recursive search. If the task returned an archive with multiple files: grep -rEo 'flag\{[^}]+\}' ./extracted/. Option --include='*.txt'Limits the search to text files—grep doesn't waste time on images and binaries.
Step 5 - Context. Found a suspicious line but not sure? Flag -C 3will show three lines before and after the match, -nwill add line numbers. Then you can open the file exactly at the desired line: vim +номер challenge.log.
Step 6 - strings for binary inclusions If fileshowed datainstead of text, we first run it through strings.
This workflow covers approximately 70-80% of the jeopardy-CTF tasks in the misc, forensics, and crypto categories. Incidentally, picoCTF includes a "First Grep" task for beginners—it works exactly like this: given a file, find the line. picoCTF{...}one team.
awk and sed for CTF dumps: When grep fails
Grep works line by line—this is both its strength and its limitation. If a flag is split across multiple lines (hex dumps, multi-line logs), grep won't see it.
awk to extract fields. Let's say the log has the format timestamp | level | message, and the flag is hidden in the message field. Conveyor awk -F'|' '{print $3}' access.log | grep -Eo 'flag\{[^}]+\}'first through awkwill cut out the third field (separator) |), then grep will find the flag in it.
sed for preprocessing. Sometimes the organizers break the flag with spaces: f l a g { h e l l o }Remove spaces before searching: sed 's/ //g' dump.txt | grep -Eo 'flag\{[^}]+\}'Another option is to merge all the lines of the file into one: tr -d '\n' < dump.txt | grep -Eo 'flag\{[^}]+\}'. Team tr -d '\n'Removes line breaks. Be careful with large files—the entire line is loaded into memory.
pcregrep for multi-line search. pcregrepsupports the flag -M (multiline): pcregrep -Mo 'flag\{[^}]+\}' dump.txtThe only option without pre-gluing the lines is pcregrepwill automatically handle matches that cross a line boundary.
Connecting grep skills to real-world information security practice
Everything described above applies without modification outside of CTF. During an incident response, the analyst searches for indicators of compromise in logs using the same pipelines. The Credentials In Files (T1552.001) technique according to MITRE ATT&CK is literally grepping for patterns. password=, api_key=, secret=in the file system. Data from Local System (T1005) - collecting data from local files, the same recursive grep -rby directories. Shell History (T1552.003) - search for credentials leaks in .bash_history.
Team grep -rEi '(password|passwd|api_key|secret|token)=' /var/log/— a working tool for both CTF tasks and production server configuration audits. The only difference is the pattern: in CTFs, we look for flag{}, in life - data leaks.