strings command
strings
Purpose
The strings command is used to extract and display readable text (ASCII or Unicode strings) from binary files, such as executables, object files, or core dumps.
It’s very useful to:
-
Find hidden text or messages inside compiled programs or data files
-
Inspect binaries for debugging or reverse engineering
-
Check what libraries, error messages, or paths a binary uses
🧩 Basic Syntax
If used without options, strings prints all readable text sequences of 4 or more characters found in the file.
🧪 Example 1: Using strings on an Executable
Suppose you have a compiled C program:
Now run:
Example Output:
🧩 Explanation:
-
It shows text strings inside the binary file.
-
You can see library names (
libc.so.6), system paths, and even your program’s output string ("Hello, world!").
🧪 Example 2: Using strings on Any File
You can also run it on a non-text file:
This will display readable text within the image file, such as:
-
File metadata
-
Author name
-
Software used to create the image
🧩 Example 3: Searching for Specific Strings
Combine strings with grep to find specific text patterns.
This filters and shows only lines containing the word “error”.
🧩 Example 4: Minimum String Length
By default, strings prints sequences of 4 or more characters.
You can change this with the -n option:
This will print only strings 6 characters or longer.
🧩 Example 5: Show Offset of Each String
This prints the byte offset (in decimal) where each string occurs in the file.
Example output:
Here, the numbers represent the positions in the binary file where each string starts.
🧩 Example 6: Reading from Standard Input
You can pipe data into strings:
🧾 Useful Options Summary
| Option | Description |
|---|---|
-a | Scan the entire file (default) |
-n <number> | Minimum string length (default = 4) |
-t <format> | Print offset (format: d=decimal, o=octal, x=hex) |
-e <encoding> | Specify character encoding (e.g., s=single-byte, l=16-bit little-endian) |
-f | Print the filename before each string (useful with multiple files) |
🧠Summary
-
It demonstrates how executables and binary files still contain human-readable data.
-
Helps students see the difference between source code and compiled output.
-
Useful for understanding binary inspection, debugging, and security basics.
-
Builds a foundation for reverse engineering concepts later in the course.
🧪 Simple Lab Exercise
Task:
-
Write a C program that prints a message and compile it:
-
Use the
stringscommand: -
Observe how your program’s message appears inside the compiled binary.
Comments
Post a Comment