Welcome back! In our previous lesson, we built a conceptual model of a process's memory, outlining the distinct roles of the text, data, heap, and stack segments. We also had a brief introduction to the /proc/<pid>/maps file as a way to see this layout.
Today, we will move from concept to practice. This lesson is dedicated to mastering the use of the /proc filesystem as a powerful inspection tool. You will learn how to read and interpret a process's live memory map, which is the definitive ground truth for its structure. For anyone aiming to succeed in PWN challenges, understanding how to dissect a target's memory layout isn't just useful—it's the essential first step in planning your attack.
The /proc Filesystem: A Window into the Kernel
Before diving into memory maps, it's important to understand what the /proc directory is. It looks and acts like a normal directory, but it's not stored on your hard drive. It's a pseudo-filesystem, a special interface created by the Linux kernel in memory. It allows you to peer directly into the kernel's data structures and see live information about the system and its running processes.
Many of the command-line tools you use daily, like ps, top, and htop, are simply user-friendly frontends that parse information from /proc. The following video provides a concise overview of this concept.
Linux Sysadmin Basics -- 6.3 The /proc Filesystem
This clip from tutoriaLinux explains the purpose of the /proc filesystem and how it's organized by process ID (PID).
First, watch the introduction to understand what /proc is and how it relates to common system tools. Then, see how you can navigate into a specific process's directory using its Process ID.
As you just saw, each numbered directory within /proc corresponds to the PID of a running process. To explore a process, you first need its PID, which you can find easily with ps. For example, to find the PID of a running bash shell, you could use ps aux | grep bash. Once you have the PID, you can cd into /proc/<PID> and start exploring.
Inside, you'll find several important files that act as entry points into the process's state:
cmdline: The full command line that was used to start the process.environ: A list of the environment variables available to the process.cwd: A symbolic link to the process's current working directory.exe: A symbolic link to the on-disk executable file that the process is an instance of.maps: A detailed map of the process's virtual memory regions.mem: A virtual file representing the process's entire address space, allowing you to read its raw memory content (with appropriate permissions).
This next clip demonstrates how to access some of these files.
Linux Sysadmin Basics -- 6.3 The /proc Filesystem
Continuing with the same video, the instructor demonstrates inspecting a few key files inside a process's /proc directory.
Watch the segment from this point, where files like cmdline, cwd, and maps are examined using cat. This gives you a feel for the kind of raw information available.
Dissecting the Memory Map
The /proc/<pid>/maps file is the focus of our attention. It provides a complete, authoritative list of all the memory segments currently mapped into the process's virtual address space. Let's look at a detailed diagram of a Linux process's address space to have a reference map.

Now, let's learn to read the maps file, which describes this layout in text format. Each line in the file corresponds to a single contiguous memory region and has six columns. The following reading provides a clear, column-by-column breakdown.
Understanding Linux /proc/pid/maps or /proc/self/maps
This highly-rated answer on Stack Overflow provides an excellent and concise guide to the format of the /proc/$PID/maps file.
Read the first answer, starting from the field descriptions. Focus on understanding the meaning of each of the six columns: address, perms, offset, dev, inode, and pathname.
To summarize and reinforce what you just read:
address:start-endvirtual addresses of the region.perms: Permissions of the region. This is critical for exploitation.r= read,w= write,x= execute.p= private (copy-on-write),s= shared.
offset: The offset from the beginning of the file backing this mapping.dev: The major:minor device number where the file resides.inode: The inode number of the file on the device. An inode of0means this is an anonymous mapping, not backed by a specific file on disk.pathname: The path to the file being mapped. Special names like[heap],[stack], or[vdso]identify regions managed by the kernel.
Identifying Segments in Practice
With this knowledge, you can now parse the maps file of any process and identify the segments we discussed in the last lesson. Let's see how this works with a real-world example.
This DEV Community article does a great job of walking through a real /proc/<pid>/maps output for a bash process and interpreting it.
Start reading from the heading "Process Memory Map". The author breaks down a sample output, identifying the executable's own segments, shared libraries (.so files), and the special [stack] and [heap] regions. Pay close attention to how the pathname and perms columns are used to deduce the purpose of each memory region.
As the article demonstrates, you can identify regions by looking for key patterns:
- Text Segment: The
r-xpmapping of the main executable (e.g.,/bin/bash). - Data/BSS Segments: The
rw-pmapping of the main executable. - Heap: The region explicitly labeled
[heap]. This is the memory pool expanded by thebrksystem call. - Stack: The region labeled
[stack], typically located at a high memory address. - Shared Libraries: Mappings for files like
/lib/x86_64-linux-gnu/libc-2.21.so. Each library will have its own text (r-xp) and data (rw-p) segments. - Anonymous Mappings: Regions with no pathname, often created by
mmap()for large allocations. We'll see the importance of these in heap exploitation.
A Practical Exercise: Extracting the Heap
Now, let's put this knowledge to work. A common task in vulnerability analysis is to inspect the contents of a specific memory region. The /proc/<pid>/mem file gives us raw access, but to use it, we need to know exactly where to look. We can get that information from the maps file.
The same article you just read contains a brilliant practical exercise that automates this process. It shows you how to write a simple shell script to find the heap of a running process, dump its contents, and search for readable strings. This is a foundational technique for memory forensics and exploitation reconnaissance.
This is the final, most practical part of the DEV.to article.
Start reading from the section titled "Pulling Out the Heap". Follow the author's logic step-by-step: Identifying the heap's address range from the maps file. Using the dd command to read a specific portion of the /proc/<pid>/mem file. Automating the address calculation using grep, cut, and shell arithmetic. Piping the raw binary output to the strings utility to find interesting text. I highly recommend you open a terminal and try to replicate these commands on a process on your own system. This will solidify your understanding immensely.
This exercise beautifully ties everything together. You start with a PID, parse the maps file to find the address and size of the heap, and then use dd to surgically extract that memory region from the mem file for analysis. This is a microcosm of the workflow you'll use in many CTF challenges.
Conclusion
In this lesson, you've gained a practical and powerful tool for your arsenal. You now know how to use the /proc filesystem to look inside a running process and understand its memory structure with precision.
Key Takeaways:
- The
/procfilesystem is a virtual interface into live kernel data, not a collection of files on disk. - The
/proc/<pid>/mapsfile provides a complete layout of a process's virtual memory, with each line describing a region's address, permissions, and backing file. - By parsing the
pathnameandpermscolumns, you can identify the text, data, heap, stack, and shared library segments. - You can combine information from
mapswith read access to/proc/<pid>/memto programmatically inspect and extract the contents of specific memory regions.
So far, we have focused on the static state of a process—what its memory looks like at a given moment. In our next lesson, we will explore the dynamic side of process execution by examining syscalls, the fundamental mechanism a process uses to request services from the operating system kernel.