Skip to content
Write-up Advanced

This Is How a Hacker Hacks: Part 3 — The Walls

The author describes a penetration test against an old CentOS document system where a webshell was already obtained, and recounts four failed attempts to escalate privileges or move laterally. Three dirtycow exploit variants failed on a textbook-vulnerable kernel, a full root filesystem silently broke remote writes, credential spraying across the LAN was rejected everywhere, and network segmentation limited reachability from the compromised host.

medium.com

Published on medium.com

Hacking

CypherNova1337, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

This is the third part of a series about a single penetration test. Parts 1 and 2 ended with a webshell on an 18-year-old document system. The client then asked whether root could be obtained, and this part covers the four walls the team hit while trying. The author's framing is deliberate: the failures are the curriculum, and each one changed the plan.

The box was a CentOS 6 host running kernel 2.6.32-642.x, last patched in 2016. The engagement also touched the surrounding LAN: MySQL servers, SSH-reachable historical hosts, an API gateway, a reverse proxy and a /23 of internal addresses.

From the original on medium.com

Setup

The starting position was a webshell on the document system, which gave remote command execution. From there the team had MySQL access and, later, the admin's original password hash recovered from nightly backups. No specific tool versions are given beyond the exploit variants described below; the static build was made on a modern toolchain and transported to the target's glibc 2.12.

Finding it

The kernel version, 2.6.32-642.x, sits squarely in the classic window for CVE-2016-5195, dirtycow, the copy-on-write race. The changelog did not contain the fix and the kernel was dated months before the fix landed. Every indicator said the exploit should work.

Exploitation

Step 1: dirtycow, three ways, zero wins

Three separate exploit implementations were tried, and all failed differently.

  1. The pthread variant, statically compiled, segfaulted on startup. Static glibc plus pthreads built on a modern toolchain does not take kindly to being moved onto glibc 2.12. Exit code 139, empty log.
  2. The single-process variant crashed in the race loop.
  3. The fork-based variant had a timing problem: the child's madvise loop of 500 million iterations finished before the parent's write loop got going. All writes returned EINVAL, so the race never lined up once.

The child loop was rewritten as an infinite loop and both processes were pinned to a single CPU with taskset, the canonical fix for a race that never wins. The result was still zero wins across dozens of runs and several hours.

The lesson drawn is that a vulnerable kernel version in a changelog is a hypothesis, not a fact. Backports are invisible, some vendors silently patch, and some kernels behave as patched for reasons nobody fully explains, such as transparent huge pages, KSM or memory layout luck. When three solid variants fail on a textbook-vulnerable kernel, the right move is a different vulnerability class rather than a fourth variant. That is what eventually produced root, in Part 4, through a userspace bug the box had no defence against.

Step 2: the ghost in the filesystem

Mid-engagement, remote commands started producing zero-byte files. Not errors: zero-byte files. A tee to a file produced an empty file, an echo with a redirect produced an empty file, and touch worked. Creating files worked; putting bytes into them did not.

This consumed two hours. The box was not yet owned, so dmesg was not available. The cause turned out to be that the root filesystem was 100% full. Every write failed with ENOSPC, and because PHP's system() swallows stderr, every error message vanished. The box looked like it was working while silently failing at everything.

Two lessons are drawn. First, silence is not success: when remote commands return no output, the first hypothesis should be that the output was thrown away, not that the command worked. Second, check disk space early. df -h is the first command on any new box, before exploits and before enumeration. A full filesystem explains a surprising number of otherwise unexplainable failures, including, later in the engagement, a storage array throwing I/O errors because the root volume it lived on was full.

The full filesystem was also a finding for the client, and not a small one: their backup server had been failing every write for an unknown length of time and nobody had noticed.

Step 3: one password, twelve guesses, zero progress

With a shell and MySQL access, the obvious next move was lateral: take the document system's credentials and spray them across the rest of the LAN. The result was a wall with a map on it.

  • A MySQL server on the network gateway rejected everything the team had.
  • Five more MySQL servers across the LAN rejected everything.
  • SSH to a half-dozen historical hosts was denied.
  • A backdoor account referenced in an admin's shell history, firefart, the default user created by the dirtycow proof-of-concept, existed in the history but rejected the default password. Whoever created it had changed the password or removed the account.

In parallel, a background crack of the admin's original password hash, recovered from the nightly backups, ran rockyou plus mutations and found nothing. The password was not a dictionary word.

The lesson is that credential reuse is the attacker's favourite assumption and is usually wrong, until it is not. Part 5 covers the moment it was not.

Step 4: the LAN is bigger than the map

From the webshell, the internal network revealed itself: a /23 full of hosts, an API gateway, and a reverse proxy that masked every external visitor. The team confirmed their own traffic appeared in the target's logs as the proxy's IP, a privacy-relevant detail for the client's own log forensics. Some hosts answered. The interesting ones, the registrar and the MIS systems, were unreachable from the owned box, firewalled away behind other segments.

The honest finding is that a single host is a foothold, not a map. A LAN pivot from one compromised box reaches only what that box can reach, and in a segmented network that is often less than you hope. Reachability was documented as a finding in itself: the flat segments that were reachable were exactly the ones that mattered.

Root cause

The walls here are not a single code defect. The dirtycow failures point to the gap between a kernel version string and the actual patch state of the binary: backports and silent vendor patches make the changelog an unreliable indicator. The zero-byte files came from a full root filesystem combined with PHP's system() discarding stderr, so failures were invisible to the operator. The credential spray failed because the password scheme did not rely on dictionary words. The pivot was limited by network segmentation: the interesting hosts were firewalled away behind other segments.

Impact

Each wall had a client-facing consequence. The full filesystem meant the client's backup server had been failing every write for an unknown period, which is a serious finding in its own right. The reverse proxy masked external visitors in the target's logs, which matters for the client's own log forensics. The reachability picture showed which flat segments were exposed from a single compromised host. The engagement did eventually reach root, but through a userspace bug rather than the kernel, and that is covered in Part 4.

Fix

No fixes are described in this part. The report notes that the full filesystem was reported to the client as a finding, and that the backup infrastructure was quietly broken. The remaining walls are presented as lessons for the tester rather than remediations for the target.

Variants to test

  1. Kernel version versus patch state. On any host with an old kernel, check the changelog and the build date, then try more than one exploit variant. A positive result is a working exploit; a negative result across several variants is a signal to change vulnerability class rather than write a fourth variant.
  2. Silent command failure. When remote commands return no output, run df -h and check stderr handling. A positive result is a full filesystem or a wrapper that discards stderr.
  3. Credential reuse. Spray recovered credentials across MySQL, SSH and other services on the LAN. A positive result is any service accepting a credential from another system.
  4. Backdoor accounts from tooling. Check shell history and account lists for default users created by public exploits, such as firefart. A positive result is an account that still exists and accepts its default password.
  5. Reachability mapping. From a single foothold, enumerate what the host can actually reach. A positive result is a flat segment containing systems that matter, reachable from the compromised box.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 15 min read.

What happened, in plain words

This is the third part of a series about one security test, carried out by a team of testers (often called penetration testers or ethical hackers) against a company's computer systems, with the company's permission. In parts 1 and 2 the team got a webshell onto a document management system: a small program placed on a server that lets the attacker run commands on it remotely, a bit like leaving a remote control inside someone's house. The system was 18 years old.

The client then asked the question that made this part worth writing: can you get root? Root is the all-powerful administrator account on a Linux machine. Whoever has root can do anything on that computer: read every file, install software, create or delete users. Getting from a normal, limited account to root is called privilege escalation, and it is usually the goal of an attacker who already has a foothold.

This part is not about the moment root was obtained. It is about the four walls the team ran into while trying. The author's point is that the failures are the lesson: each wall forced a change of plan, and the walls themselves turned out to be useful information about the client's systems.

The box was a server running CentOS 6, a Linux distribution (an operating system built on Linux), with kernel version 2.6.32-642.x. The kernel is the core of the operating system, the layer that talks to the hardware and enforces permissions. The machine had last been patched in 2016. Around it sat a LAN (local area network): the company's internal network of machines, including database servers, older hosts reachable over SSH, an API gateway, a reverse proxy and a block of internal addresses.

From the original on medium.com

The starting position

The team began with a webshell on the document system. A webshell gave them remote command execution on the server. That account is deliberately limited, because web servers are exposed to the internet and should not be able to do much damage if compromised. From there the team also had access to MySQL, a popular database system, and later recovered the administrator's original password hash from the nightly backups.

A hash is what you get when a password is passed through a one-way mathematical function. You cannot turn a hash back into the password by reversing the maths; you can only guess passwords, hash each guess and compare. That guessing process is called cracking, and it is why a stolen hash is dangerous but not instantly fatal.

No specific tool versions are given beyond the exploit variants described below. One detail matters: the static build was made on a modern toolchain and then moved onto the target's glibc 2.12. glibc is the standard C library on Linux, the shared code almost every program relies on. Building a program statically means bundling all its libraries inside the executable, so it should run anywhere; in practice, as we will see, that is not always true.

Finding the opening

The kernel version, 2.6.32-642.x, sits squarely in the classic window for CVE-2016-5195, better known as dirtycow. A CVE is a public catalogue number for a known vulnerability, so anyone can look up what it is and which versions are affected. Dirtycow is a copy-on-write race: a bug in how the kernel handles memory shared between processes, which lets a normal user overwrite files they should only be able to read, including files that lead to root.

A race condition is a bug that depends on timing: two things happening at once, and the attacker trying to slip in between them. Think of two people reaching for the same door handle at the same moment; if one is slightly faster, the other's hand lands on nothing. Dirtycow is that, in memory.

The changelog did not contain the fix, and the kernel was dated months before the fix landed. Every indicator said the exploit should work. An exploit is a program that turns a vulnerability into actual access.

Trying to break through

Step 1: dirtycow, three ways, zero wins

Three separate exploit implementations were tried, and all failed differently.

  1. The pthread variant, statically compiled, segfaulted on startup. Pthreads are the standard way a program runs several threads (parallel streams of work) at once. A segfault is a crash caused by the program touching memory it is not allowed to touch. Static glibc plus pthreads built on a modern toolchain does not take kindly to being moved onto glibc 2.12. Exit code 139, empty log. Exit code 139 is the shell's way of reporting a segfault, and the empty log meant there was nothing to read afterwards.
  2. The single-process variant crashed in the race loop. This one did not even use threads; it still died inside the part of the code that tries to win the race.
  3. The fork-based variant had a timing problem. Forking means a program copies itself into a second process, so one process can do one job while the other does another. Here the child's madvise loop of 500 million iterations finished before the parent's write loop got going. madvise is a system call that gives the kernel hints about how a block of memory will be used, and dirtycow exploits use it to set up the race. All writes returned EINVAL, an error meaning "invalid argument": the race never lined up once.

The child loop was rewritten as an infinite loop and both processes were pinned to a single CPU with taskset, the canonical fix for a race that never wins. Pinning means telling the operating system to run both processes on the same processor core, so they take turns in a predictable way instead of running truly in parallel on different cores. The result was still zero wins across dozens of runs and several hours.

The lesson drawn is that a vulnerable kernel version in a changelog is a hypothesis, not a fact. Backports are invisible: a backport is when a vendor takes a security fix written for a newer version of software and quietly applies it to an older version they still support. The version number does not change, so the changelog stops being a reliable guide. Some vendors silently patch, and some kernels behave as patched for reasons nobody fully explains, such as transparent huge pages (a memory optimisation that merges small memory pages into large ones), KSM (kernel same-page merging, which deduplicates identical memory pages to save space) or plain memory layout luck.

When three solid variants fail on a textbook-vulnerable kernel, the right move is a different vulnerability class rather than a fourth variant. That is what eventually produced root, in Part 4, through a userspace bug the box had no defence against. Userspace means ordinary programs, as opposed to the kernel: a bug in an ordinary program can be just as serious, and sometimes easier to exploit.

Step 2: the ghost in the filesystem

Mid-engagement, remote commands started producing zero-byte files. Not errors: zero-byte files. A tee to a file produced an empty file, an echo with a redirect produced an empty file, and touch worked. Creating files worked; putting bytes into them did not.

tee is a command that reads input and writes it both to the screen and to a file. echo prints text, and a redirect (>) sends that text into a file instead of the screen. touch creates an empty file or updates its timestamp, without writing any content. So the pattern was: making a file worked, filling it did not.

This consumed two hours. The box was not yet owned, so dmesg was not available. dmesg prints the kernel's own log of hardware and system messages, which often names the real problem; without root, the team could not read it. The cause turned out to be that the root filesystem was 100% full. The root filesystem is the main disk area where the operating system and its files live. Every write failed with ENOSPC, the error code for "no space left on device", and because PHP's system() swallows stderr, every error message vanished. system() is a PHP function that runs a shell command. stderr is the second of the two output channels every program has: stdout for normal output, stderr for errors. If a wrapper throws stderr away, errors become invisible. The box looked like it was working while silently failing at everything.

Two lessons are drawn. First, silence is not success: when remote commands return no output, the first hypothesis should be that the output was thrown away, not that the command worked. Second, check disk space early. df -h is the first command on any new box, before exploits and before enumeration. df reports free disk space, and -h makes it human-readable (sizes in MB and GB rather than raw blocks). A full filesystem explains a surprising number of otherwise unexplainable failures, including, later in the engagement, a storage array throwing I/O errors because the root volume it lived on was full. I/O errors are input/output errors: the system could not read or write data.

The full filesystem was also a finding for the client, and not a small one: their backup server had been failing every write for an unknown length of time and nobody had noticed. A backup server that silently writes nothing is worse than no backup server, because everyone believes the data is safe.

Step 3: one password, twelve guesses, zero progress

With a shell and MySQL access, the obvious next move was lateral movement: using credentials found on one machine to get into others on the same network. The team took the document system's credentials and sprayed them across the rest of the LAN. Password spraying means trying the same small set of passwords against many accounts or services, rather than many passwords against one account; it stays under lockout thresholds and catches people who reuse passwords. The result was a wall with a map on it.

  • A MySQL server on the network gateway rejected everything the team had. The gateway is the machine that connects the internal network to the outside world.
  • Five more MySQL servers across the LAN rejected everything.
  • SSH to a half-dozen historical hosts was denied. SSH is the standard way to log in to a Linux machine remotely, an encrypted command line over the network.
  • A backdoor account referenced in an admin's shell history, firefart, the default user created by the dirtycow proof-of-concept, existed in the history but rejected the default password. A proof-of-concept is a demonstration exploit published to show a vulnerability is real; this one creates a user called firefart with a known default password. Shell history is the file where a shell records the commands a user has typed. Whoever created the account had changed the password or removed it.

In parallel, a background crack of the admin's original password hash, recovered from the nightly backups, ran rockyou plus mutations and found nothing. Rockyou is a famous list of millions of real passwords leaked from a breach, and it is the first thing anyone tries when cracking a hash. Mutations means automatically varying each word: adding digits, changing case, appending a year. The password was not a dictionary word.

The lesson is that credential reuse (using the same password on several systems) is the attacker's favourite assumption and is usually wrong, until it is not. Part 5 covers the moment it was not.

Step 4: the LAN is bigger than the map

From the webshell, the internal network revealed itself: a /23 full of hosts, an API gateway, and a reverse proxy that masked every external visitor. A /23 is a way of writing a range of network addresses: it covers 512 addresses, roughly a medium-sized office network. An API gateway is the front door for program-to-program traffic: other systems talk to it, and it forwards their requests to the right internal service. A reverse proxy is a server that sits in front of the real websites and forwards visitors' requests to them, so the real servers only ever see the proxy's address.

The team confirmed their own traffic appeared in the target's logs as the proxy's IP, a privacy-relevant detail for the client's own log forensics. Log forensics means investigating what happened by reading log files; if every visitor looks like the proxy, the logs cannot tell one visitor from another. Some hosts answered. The interesting ones, the registrar and the MIS systems, were unreachable from the owned box, firewalled away behind other segments. A firewall is a filter that allows or blocks network traffic by rule, and segmentation means splitting a network into separate zones so that a machine in one zone cannot reach machines in another.

The honest finding is that a single host is a foothold, not a map. A pivot is using one compromised machine as a stepping stone to reach others; from one box you reach only what that box can reach, and in a segmented network that is often less than you hope. Reachability was documented as a finding in itself: the flat segments that were reachable were exactly the ones that mattered. A flat segment is a part of the network with no internal filtering, where every machine can talk to every other.

Why it happened

The walls here are not a single code defect. The dirtycow failures point to the gap between a kernel version string and the actual patch state of the binary: backports and silent vendor patches make the changelog an unreliable indicator. The zero-byte files came from a full root filesystem combined with PHP's system() discarding stderr, so failures were invisible to the operator. The credential spray failed because the password scheme did not rely on dictionary words. The pivot was limited by network segmentation: the interesting hosts were firewalled away behind other segments.

What it meant for the client

Each wall had a client-facing consequence. The full filesystem meant the client's backup server had been failing every write for an unknown period, which is a serious finding in its own right. The reverse proxy masked external visitors in the target's logs, which matters for the client's own log forensics. The reachability picture showed which flat segments were exposed from a single compromised host. The engagement did eventually reach root, but through a userspace bug rather than the kernel, and that is covered in Part 4.

What was fixed

No fixes are described in this part. The report notes that the full filesystem was reported to the client as a finding, and that the backup infrastructure was quietly broken. The remaining walls are presented as lessons for the tester rather than remediations for the target.

Things worth trying again

  1. Kernel version versus patch state. On any host with an old kernel, check the changelog and the build date, then try more than one exploit variant. A positive result is a working exploit; a negative result across several variants is a signal to change vulnerability class rather than write a fourth variant.
  2. Silent command failure. When remote commands return no output, run df -h and check stderr handling. A positive result is a full filesystem or a wrapper that discards stderr.
  3. Credential reuse. Spray recovered credentials across MySQL, SSH and other services on the LAN. A positive result is any service accepting a credential from another system.
  4. Backdoor accounts from tooling. Check shell history and account lists for default users created by public exploits, such as firefart. A positive result is an account that still exists and accepts its default password.
  5. Reachability mapping. From a single foothold, enumerate what the host can actually reach. A positive result is a flat segment containing systems that matter, reachable from the compromised box.

Glossary

  • API gateway: a server that sits in front of internal services and forwards program-to-program requests to the right one.
  • Backdoor account: a user account created secretly, often by an attacker or by an exploit, to allow later access.
  • Backport: a security fix written for a newer version of software and applied to an older version without changing its version number.
  • CentOS 6: an older Linux distribution, a complete operating system built on the Linux kernel.
  • Copy-on-write: a memory technique where data is shared until one process tries to change it, at which point a private copy is made; dirtycow abuses the timing of that copy.
  • Credential reuse: using the same username and password on more than one system.
  • CVE: a public catalogue number for a known vulnerability, so anyone can look up what it is and which versions are affected.
  • dirtycow: CVE-2016-5195, a Linux kernel race condition that lets a normal user overwrite files they should only be able to read.
  • dmesg: a command that prints the kernel's log of hardware and system messages.
  • ENOSPC: the error code meaning "no space left on device".
  • EINVAL: the error code meaning "invalid argument".
  • Enumeration: systematically listing what exists on a system or network, such as users, services and reachable hosts.
  • Exploit: a program or technique that turns a vulnerability into actual access.
  • Firewall: a filter that allows or blocks network traffic according to rules.
  • Flat segment: a part of a network with no internal filtering, where every machine can reach every other.
  • Fork: to copy a running program into a second process so the two can do different jobs.
  • glibc: the standard C library on Linux, shared code that almost every program relies on.
  • Hash: the one-way result of passing a password through a mathematical function; you cannot reverse it, only guess and compare.
  • I/O error: an input/output error, meaning the system could not read or write data.
  • Kernel: the core of the operating system, which talks to the hardware and enforces permissions.
  • KSM: kernel same-page merging, a memory optimisation that deduplicates identical memory pages.
  • LAN: local area network, a company's internal network of machines.
  • Lateral movement: using access on one machine to get into others on the same network.
  • madvise: a system call that gives the kernel hints about how a block of memory will be used.
  • MySQL: a popular database system.
  • Pivot: using one compromised machine as a stepping stone to reach others.
  • Privilege escalation: going from a limited account to a more powerful one, usually root.
  • Proof-of-concept: a demonstration exploit published to show a vulnerability is real.
  • pthread: the standard way a program runs several threads at once.
  • Race condition: a bug that depends on timing, where two things happening at once can be made to interleave in the attacker's favour.
  • Reverse proxy: a server in front of the real websites that forwards visitors' requests, so the real servers only see the proxy's address.
  • Rockyou: a famous list of millions of real passwords leaked from a breach, used as a starting wordlist when cracking hashes.
  • Root: the all-powerful administrator account on a Linux machine.
  • Root filesystem: the main disk area where the operating system and its files live.
  • Segfault: a crash caused by a program touching memory it is not allowed to touch.
  • Segmentation: splitting a network into separate zones so machines in one zone cannot reach machines in another.
  • Shell history: the file where a shell records the commands a user has typed.
  • Spraying: trying the same small set of passwords against many accounts or services, rather than many passwords against one.
  • SSH: the standard way to log in to a Linux machine remotely, an encrypted command line over the network.
  • stderr: the output channel every program has for error messages, separate from normal output.
  • taskset: a Linux command that pins a process to a chosen CPU core.
  • Transparent huge pages: a memory optimisation that merges small memory pages into large ones.
  • Userspace: ordinary programs, as opposed to the kernel.
  • Webshell: a small program placed on a server that lets an attacker run commands on it remotely.
  • /23: a way of writing a range of network addresses covering 512 addresses.

Similar reports

Same bug class and techniques, clearest first.