Skip to content
Access control Write-up Intermediate

Local Privilege Escalation in Keploy’s Self-Updater

Keploy's self-updater set the installed CLI binary to world-writable permissions after an update, so any local user could modify the executable. Because the agent is normally run with sudo, a later privileged invocation could execute attacker-controlled code as root.

ajithprabhu15 Follow

Published on medium.com

Bug Bounty

Ajith Prabhu, 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

Keploy records and replays API traffic. On native Linux it attaches eBPF hooks, so its agent runs with root privileges, and running Keploy with sudo is a normal part of its operation rather than an unusual edge case. The installed executable, typically /usr/local/bin/keploy, is therefore a program that may subsequently be executed as root, which makes its integrity security-relevant.

The feature at fault is Keploy's self-updater, the code path behind sudo keploy update. While reviewing Keploy's source code, Ajith Prabhu found that the updater left the installed CLI writable by every local user, creating a path for an unprivileged user to execute code with root privileges.

The issue was fixed in v3.6.109 and disclosed as GHSA-cmm2-f5q4-x436, rated High (CVSS 7.3). The advisory lists v2 releases and v3 releases before v3.6.109 as affected.

Setup

The work was a source code review of Keploy, followed by an in-tree Go test that exercised the update code path against a test executable and inspected the resulting file permissions. The attack scenario needs a local account and an opportunity to modify the binary before it is executed with elevated privileges; the author considers a shared Linux host where Keploy is used regularly a realistic setting.

Finding it

The updater lived in downloadAndUpdate, in pkg/service/tools/tools.go. It performed three relevant operations:

  1. Downloaded the release archive and extracted the executable to the fixed path /tmp/keploy, using os.Create.
  2. Renamed /tmp/keploy over the installed binary, typically /usr/local/bin/keploy.
  3. Set the installed binary's permissions:
Go
os.Chmod(path, 0777)

The third step was the immediate vulnerability. os.Chmod sets the requested permission bits directly, so the resulting executable was writable by every local user. In the vulnerable implementation the archive was not checked against a published checksum or signature; TLS was the primary protection for the download.

A second problem sat in the staging step: the updater used a fixed, shared path, /tmp/keploy. It created the file without exclusive creation semantics and could follow an existing symbolic link. Depending on the operating system and filesystem protections, this could expose the privileged update process to temporary-file and path-manipulation attacks. The author treats this as a secondary concern to the demonstrated permission flaw, since the consequences depend on the environment and require separate validation.

The fixed staging path also caused a reliability problem: if /tmp and the installation directory were on different filesystems, the rename could fail, because cross-filesystem renames are not supported.

Exploitation

Step 1: an administrator runs the updater

Bash
sudo keploy update

The updater downloads the release archive, extracts the executable to /tmp/keploy, renames it over the installed binary and then applies 0777 to the installed path.

Step 2: the installed binary becomes world-writable

The os.Chmod(path, 0777) call leaves the executable writable by every local user. The author confirmed this with an in-tree Go test that exercised the update code path against a test executable and inspected the resulting file permissions. The observed output was:

Text
installed binary mode after update: -rwxrwxrwx

Step 3: an unprivileged local user modifies the executable

With the binary world-writable, any local account can replace or alter its contents.

Step 4: a subsequent privileged invocation runs the modified binary

The next time an administrator runs Keploy with sudo, the modified binary executes, potentially running the attacker's code as root.

The attacker needs a local account and an opportunity to modify the binary before it is executed with elevated privileges. On a shared Linux host where Keploy is used regularly, the author considers that a realistic scenario.

On an existing installation, the current permissions can be inspected without invoking the updater:

Bash
stat -c '%A %a %n' "$(command -v keploy)"

The result shows the current file mode. It does not, by itself, establish whether the binary has been modified or whether every affected installation has the same permissions.

Root cause

The updater set the installed executable's mode to 0777 by pathname. os.Chmod applies the requested bits directly, so the file ended up writable by all local users, and the program that the updater installs is one that may later run as root. Nothing in the vulnerable implementation verified the downloaded archive against a published checksum or signature, so TLS was the primary protection for the download.

The staging design compounded this. A fixed, shared path under /tmp was created with os.Create, which does not use exclusive creation semantics and can follow an existing symbolic link, so the privileged update process could be exposed to temporary-file and path-manipulation attacks depending on the operating system and filesystem protections. The same fixed path could make the rename fail when /tmp and the installation directory were on different filesystems.

Impact

An unprivileged local user on a host where Keploy is installed can modify the installed executable after an administrator runs sudo keploy update, and have that code run as root the next time Keploy is invoked with elevated privileges. The precondition is a local account and a window in which to modify the binary before a privileged execution. The advisory rates the issue High (CVSS 7.3), and v2 releases and v3 releases before v3.6.109 are listed as affected.

Fix

The maintainers fixed the issue in PR #4729, released in Keploy v3.6.109. The revised updater makes several changes:

  • Pins the release: it downloads the asset for the specific release it announced, rather than relying on a moving latest reference.
  • Verifies the bytes: it hashes the download as it streams, caps the download at 256 MiB, and refuses the asset unless its SHA-256 digest matches the digest published by GitHub. A release without the expected digest is refused.
  • Stages safely: it downloads to a randomly named temporary file created with os.CreateTemp, then extracts the keploy executable into a randomly named file beside the installed binary.
  • Sets restrictive permissions: it sets the staged executable to 0755 through the open file handle, rather than applying 0777 by pathname.
  • Replaces atomically: it syncs the file and renames it over the installed binary on the same filesystem, also avoiding the earlier cross-filesystem rename failure.

Updating from an affected version does not necessarily repair the installed binary's permissions: the old updater can install v3.6.109 and then set its permissions to 0777 one last time. After updating, run:

Bash
sudo chmod 755 "$(command -v keploy)"

Alternatively, reinstall Keploy using the installation script. On a shared host where the binary was previously world-writable, consider that it may have been modified: correcting permissions alone does not establish the integrity of its contents, and reinstalling from a trusted source is the safer option.

Variants to test

  • Other self-updaters that chmod by pathname. Look for os.Chmod (or equivalent) applied to an installed executable after an update. A positive result is an installed binary whose mode includes write permission for group or others, such as -rwxrwxrwx, after running the updater.
  • Updaters that stage in a fixed shared path. Look for a hard-coded path under /tmp created without exclusive creation semantics. A positive result is the privileged updater following a pre-created symbolic link or reusing a file an unprivileged user controls.
  • Updaters that trust a moving latest reference. Check whether the updater resolves the release at download time rather than pinning the announced release. A positive result is the updater fetching an asset that differs from the release it reported.
  • Updaters without digest or signature verification. Check whether the downloaded archive is compared against a published checksum or signature. A positive result is an update that completes with a tampered or mismatched artifact.
  • Cross-filesystem staging. Run an updater whose staging directory and installation directory are on different filesystems. A positive result is a failed rename, which points to the same fixed-path staging design.
  • Upgrade paths from affected versions. Install an affected version, update to the fixed one, and inspect the resulting mode. A positive result is the fixed binary still left world-writable by the old updater, which is why the manual chmod 755 step matters.

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

Keploy is a free, open-source tool that software teams use to record the network traffic their programs send and receive, and then play it back later. Think of it like a tape recorder for conversations between a program and the servers it talks to. Developers use it to test their software without needing the real servers running.

On Linux, Keploy needs deep access to the operating system to do its recording. That means it has to run with the highest level of permission on the machine, the same level as the system administrator. In Linux terms, that level is called root. So people normally start Keploy with a command that begins with sudo, which is the standard way to say "run this as the administrator".

Keploy also has a feature that updates itself: you type sudo keploy update and it fetches a newer version and installs it. While reading Keploy's source code (the human-readable instructions that make up the program), a researcher named Ajith Prabhu noticed that this self-updater did something careless. After installing the new version, it changed the file's permissions so that every user on the machine could modify it.

That is a problem because the file being modified is the Keploy program itself, and that program is regularly run as root. If any ordinary user can rewrite it, they can put their own instructions inside it, and the next time an administrator runs Keploy, those instructions run with administrator power. This kind of attack, where a low-privilege user finds a way to gain high privileges, is called local privilege escalation.

The researcher reported it to the Keploy maintainers (the people who look after the project). They fixed it in version 3.6.109 and published a security advisory, GHSA-cmm2-f5q4-x436, rated High with a CVSS score of 7.3. The advisory lists version 2 releases and version 3 releases before 3.6.109 as affected.

Some background you need first

What Keploy does

Keploy records and replays API traffic. An API (Application Programming Interface) is the way one piece of software asks another for something: "give me the list of users", "save this order". The request and the answer travel over the network as text. Keploy sits in the middle, writes those conversations down, and can replay them later so a developer can test their program against realistic answers without needing the real service.

To capture that traffic on a normal Linux machine, Keploy uses a Linux feature called eBPF. You do not need the details; what matters is that eBPF hooks into the operating system at a very deep level, and using it requires root. So running Keploy with sudo is the normal way to use it, not an unusual setup.

Why the installed file matters

The installed program usually lives at /usr/local/bin/keploy. On Linux, files live in folders, and /usr/local/bin is a conventional folder for programs installed by an administrator. Because this particular program is started with sudo, it is a file that will later be executed with root power. Anything that can change that file can change what runs as root.

What file permissions are

Every file on Linux has a set of permissions that say who may read it, who may write to it (change it), and who may execute it (run it). They are usually shown as a string of letters and dashes, for example -rwxr-xr-x. The first character is the file type (- means a normal file). Then come three groups of three: the owner's permissions, the group's permissions, and everyone else's. r means read, w means write, x means execute, and - means that permission is not granted.

Permissions are also written as numbers. Each permission has a value: read is 4, write is 2, execute is 1. You add them up for each group. So 7 means read + write + execute (4+2+1), 5 means read + execute (4+1), and 0 means nothing. A mode of 0777 therefore means: owner can do everything, group can do everything, and everyone else can do everything, including writing to the file. A mode of 0755 means: owner can do everything, everyone else can read and execute but not write.

A useful everyday comparison: think of a shared kitchen. 0755 is like a recipe card pinned to the wall that everyone can read and follow, but only the person who pinned it can change it. 0777 is like leaving a blank card and a pen next to it, so any passer-by can rewrite the recipe before the cook uses it.

What a checksum and a signature are

A checksum (or hash) is a short fingerprint of a file's contents. Feed a file through a hashing function and you get a fixed-length string; change even one byte of the file and the fingerprint changes completely. If the publisher tells you the expected fingerprint, you can compute it yourself after downloading and compare. If they match, the file is almost certainly the one the publisher intended.

A signature goes further: the publisher uses a private cryptographic key to sign the file, and anyone with the matching public key can verify that the file really came from them and was not altered. A digest is another word for the output of a hash function.

TLS is the encryption that protects connections on the web, the padlock in your browser. It stops someone watching the network from reading or changing data in transit. It does not tell you whether the file you received is the file the publisher meant to send; it only protects the pipe.

What /tmp and symbolic links are

/tmp is a folder on Linux for temporary files. It is shared: every user on the machine can normally create files there. A symbolic link (or symlink) is a file that acts as a shortcut pointing at another file. If a program opens a symlink, it actually opens whatever the link points to. That is useful normally, but dangerous if a privileged program follows a link that an ordinary user planted.

How the researcher found it

The work was a source code review: reading the program's code looking for mistakes, rather than attacking a running system. The updater code lived in a function called downloadAndUpdate, in the file pkg/service/tools/tools.go. A function is a named block of code that does one job; here, the job is downloading and installing an update.

The function did three things that mattered:

  1. It downloaded the release archive (a compressed bundle containing the new version) and extracted the executable to a fixed path, /tmp/keploy, using a function called os.Create.
  2. It renamed /tmp/keploy over the installed binary, typically /usr/local/bin/keploy. Renaming over a file replaces it in one step.
  3. It set the installed binary's permissions with this line:
Go
os.Chmod(path, 0777)

Line by line: os.Chmod is a Go language function that changes a file's permissions. path is the location of the file to change, here the installed Keploy binary. 0777 is the new permission mode: read, write and execute for the owner, the group and everyone else. The leading 0 is a conventional prefix meaning the number is written in octal (base eight), which is how Linux permissions are usually expressed.

The third step was the immediate vulnerability. os.Chmod applies exactly the bits you ask for, so the resulting executable was writable by every local user on the machine. In this vulnerable version, the downloaded archive was not checked against a published checksum or signature; TLS was the main protection for the download.

There was a second problem in the staging step. The updater used a fixed, shared path, /tmp/keploy. It created the file without exclusive creation semantics, meaning it did not ask the operating system to fail if the file already existed. It could also follow an existing symbolic link. Depending on the operating system and filesystem protections, this could expose the privileged update process to temporary-file attacks and path-manipulation attacks. The researcher treats this as a secondary concern to the permission flaw, because the consequences depend on the environment and would need separate validation.

The fixed staging path also caused a reliability problem: if /tmp and the installation folder were on different filesystems (separate storage areas, for example separate disks or partitions), the rename could fail, because Linux does not support renaming a file across filesystems.

How the attack works, step by step

Step 1: an administrator runs the updater

Bash
sudo keploy update

Line by line: sudo means "run the following command with administrator (root) privileges". keploy is the program being run. update is the instruction telling Keploy to update itself. The updater downloads the release archive, extracts the executable to /tmp/keploy, renames it over the installed binary, and then applies 0777 to the installed path.

Why this step matters: the administrator is doing something completely normal. They are not making a mistake. The flaw is in what the program does afterwards.

Step 2: the installed binary becomes world-writable

The os.Chmod(path, 0777) call leaves the executable writable by every local user. The researcher confirmed this with a test written in Go, kept inside the project's own code tree (an in-tree test), which ran the update code against a test executable and then inspected the resulting file permissions. The observed output was:

Text
installed binary mode after update: -rwxrwxrwx

Line by line: installed binary mode after update: is just a label printed by the test. -rwxrwxrwx is the permission string. The leading - means it is a normal file. Then rwx for the owner, rwx for the group, and rwx for everyone else: read, write and execute for all three. The w in the last group is the problem: it means any user on the machine can change the file.

Why this step matters: it turns a suspicion into a demonstrated fact. The test shows the file really does end up world-writable after an update.

Step 3: an unprivileged local user modifies the executable

With the binary world-writable, any local account can replace or alter its contents. An unprivileged user is an ordinary account without administrator rights, the kind most people have on a shared machine.

Why this step matters: this is the moment the attacker gets their code into a file that will later be trusted.

Step 4: a subsequent privileged invocation runs the modified binary

The next time an administrator runs Keploy with sudo, the modified binary executes, potentially running the attacker's code as root.

Why this step matters: this is where the attacker's code gains administrator power. The attacker only needed to be able to write to a file that the administrator would later run.

The attacker needs a local account and an opportunity to modify the binary before it is executed with elevated privileges. On a shared Linux host where Keploy is used regularly, the researcher considers that a realistic scenario.

On an existing installation, you can check the current permissions without running the updater:

Bash
stat -c '%A %a %n' "$(command -v keploy)"

Line by line: stat is a Linux command that reports information about a file. -c tells it to print the result in a custom format. '%A %a %n' is that format: %A prints the permissions as letters (like -rwxr-xr-x), %a prints them as an octal number (like 755), and %n prints the file name. "$(command -v keploy)" runs the command command -v keploy, which finds the full path of the keploy program, and passes that path to stat. The quotes keep the path together as one argument even if it contains spaces.

The result shows the current file mode. It does not, by itself, establish whether the binary has been modified, or whether every affected installation has the same permissions.

The root cause

The updater set the installed executable's mode to 0777 by pathname. os.Chmod applies the requested bits directly, so the file ended up writable by all local users, and the program the updater installs is one that may later run as root. Nothing in the vulnerable version verified the downloaded archive against a published checksum or signature, so TLS was the main protection for the download.

The staging design made things worse. A fixed, shared path under /tmp was created with os.Create, which does not use exclusive creation and can follow an existing symbolic link, so the privileged update process could be exposed to temporary-file and path-manipulation attacks depending on the operating system and filesystem protections. The same fixed path could make the rename fail when /tmp and the installation folder were on different filesystems.

What the impact is

An unprivileged local user on a host where Keploy is installed can modify the installed executable after an administrator runs sudo keploy update, and have that code run as root the next time Keploy is invoked with elevated privileges. The precondition is a local account and a window in which to modify the binary before a privileged execution. The advisory rates the issue High (CVSS 7.3), and version 2 releases and version 3 releases before 3.6.109 are listed as affected.

CVSS stands for Common Vulnerability Scoring System. It is a standard way of scoring how serious a security flaw is, from 0 to 10. A score of 7.3 falls in the High band.

The fix

The maintainers fixed the issue in pull request #4729, released in Keploy v3.6.109. A pull request is a proposed change to a codebase that the maintainers review before accepting. The revised updater makes several changes:

  • Pins the release: it downloads the asset for the specific release it announced, rather than relying on a moving latest reference. A moving reference is a label like "latest" that points at whatever is newest at the moment; pinning means naming one exact version so the answer cannot change under you.
  • Verifies the bytes: it hashes the download as it streams, caps the download at 256 MiB, and refuses the asset unless its SHA-256 digest matches the digest published by GitHub. A release without the expected digest is refused. SHA-256 is a widely used hashing function. MiB means mebibytes, a unit of data size.
  • Stages safely: it downloads to a randomly named temporary file created with os.CreateTemp, then extracts the keploy executable into a randomly named file beside the installed binary. Random names make it much harder for an attacker to guess and pre-plant a file.
  • Sets restrictive permissions: it sets the staged executable to 0755 through the open file handle, rather than applying 0777 by pathname. 0755 means the owner can read, write and execute, while everyone else can only read and execute. Doing it through the open file handle means the program changes the permissions of the exact file it has open, not whatever happens to sit at a path at that moment.
  • Replaces atomically: it syncs the file and renames it over the installed binary on the same filesystem, also avoiding the earlier cross-filesystem rename failure. Atomic means the replacement happens in one indivisible step: there is no moment where the file is half-written.

One catch when upgrading

Updating from an affected version does not necessarily repair the installed binary's permissions. The old updater can install v3.6.109 and then set its permissions to 0777 one last time. After updating, run:

Bash
sudo chmod 755 "$(command -v keploy)"

Line by line: sudo runs the command as administrator, which is needed because changing permissions on a system program requires root. chmod is the Linux command that changes file permissions. 755 is the new mode: read, write and execute for the owner, read and execute for everyone else. "$(command -v keploy)" again finds the full path of the installed Keploy program and passes it to chmod.

Alternatively, reinstall Keploy using the installation script. On a shared host where the binary was previously world-writable, consider that it may have been modified: correcting permissions alone does not establish the integrity of its contents, and reinstalling from a trusted source is the safer option.

Similar things to look for elsewhere

These are patterns worth checking in other software that updates itself:

  • Other self-updaters that chmod by pathname. Look for os.Chmod (or the equivalent in another language) applied to an installed executable after an update. A positive result is an installed binary whose mode includes write permission for group or others, such as -rwxrwxrwx, after running the updater.
  • Updaters that stage in a fixed shared path. Look for a hard-coded path under /tmp created without exclusive creation. A positive result is the privileged updater following a pre-created symbolic link or reusing a file an unprivileged user controls.
  • Updaters that trust a moving latest reference. Check whether the updater resolves the release at download time rather than pinning the announced release. A positive result is the updater fetching an asset that differs from the release it reported.
  • Updaters without digest or signature verification. Check whether the downloaded archive is compared against a published checksum or signature. A positive result is an update that completes with a tampered or mismatched artifact.
  • Cross-filesystem staging. Run an updater whose staging folder and installation folder are on different filesystems. A positive result is a failed rename, which points to the same fixed-path staging design.
  • Upgrade paths from affected versions. Install an affected version, update to the fixed one, and inspect the resulting mode. A positive result is the fixed binary still left world-writable by the old updater, which is why the manual chmod 755 step matters.

Glossary

  • API: the way one piece of software asks another for something, such as "give me the list of users".
  • Atomic: happening in one indivisible step, with no moment where the result is half-finished.
  • Checksum: a short fingerprint computed from a file's contents, used to check the file has not changed.
  • chmod: the Linux command that changes a file's permissions.
  • CVSS: Common Vulnerability Scoring System, a standard 0 to 10 score for how serious a security flaw is.
  • Digest: the output of a hashing function; another word for checksum.
  • eBPF: a Linux feature that lets programs hook deep into the operating system; using it requires root.
  • Exclusive creation: asking the operating system to create a file only if it does not already exist, so an existing file cannot be silently reused.
  • Filesystem: the way storage is organised on a machine; separate disks or partitions are separate filesystems.
  • Function: a named block of code that performs one job.
  • Hash: see checksum.
  • In-tree test: a test kept inside the project's own code repository.
  • Local privilege escalation: an attack where an ordinary user on a machine finds a way to gain administrator-level power.
  • MiB: mebibyte, a unit of data size.
  • Moving reference: a label such as "latest" that points at whatever is newest at the time, so its meaning can change.
  • Octal: base-eight number notation, conventionally used to write Linux permissions.
  • Permissions: the rules on a file saying who may read it, write to it, and execute it.
  • Pull request: a proposed change to a codebase that maintainers review before accepting.
  • Root: the highest privilege level on Linux, the administrator account.
  • SHA-256: a widely used hashing function that produces a fingerprint of fixed length.
  • Signature: a cryptographic proof that a file came from a particular publisher and was not altered.
  • Source code review: reading a program's code looking for mistakes, rather than attacking a running system.
  • sudo: the Linux command that runs another command with administrator (root) privileges.
  • Symbolic link: a file that acts as a shortcut pointing at another file.
  • Temporary-file attack: an attack that abuses a predictable temporary file path, for example by planting a file or link there first.
  • TLS: the encryption that protects connections on the web, shown as the padlock in a browser.
  • Unprivileged user: an ordinary account without administrator rights.
  • World-writable: a file that every user on the machine is allowed to modify.

More by ajithprabhu15

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.