Two Linux kernel APIs from 1999 that fix credential theft in ssh-agent, gpg-agent, and every Unix socket daemon

Posted by GroundbreakingStay27@reddit | linux | View on Reddit | 17 comments

Built a credential broker for AI agents and found that ssh-agent, gpg-agent, and every UDS-based credential tool trusts the same boundary: the Unix UID. The assumption "if theyre running as you youve already lost" breaks when AI agents execute arbitrary code as your UID by design.

## The Exploit

SO_PEERCRED records who called `connect()` but fds survive `fork()`+`exec()`. Attacker connects, forks, child execs the legit binary, parent sends on inherited fd. Daemon hashes the childs binary — matches. Token issued to the attacker.

Tried eight mitigations. All failed because attacker controls exec timing.

## The Fix

  1. SCM_CREDENTIALS** (Linux 2.2, 1999) — kernel verified sender PID on every message, not just connection. Fork attack: sender != connector, rejected.

  2. Process-bound tokens** — token tied to attesting PID. Stolen token from different PID, rejected.

\~50 lines total. Two attack surfaces closed.

## What We Built With It

The tool (Hermetic) does somthing no other credential manager does — it lets AI agents USE your API keys without ever HAVING them. Four modes:

-Brokered:***daemon makes the HTTPS call, agent gets response only

- Transient:** credential in isolated child process, destroyed on exit

- MCP Proxy:** sits between IDE and any MCP server, injects credentials, scans every response for leakage, pins tool definitions against supply chain tampering

- Direct:* prints to human terminal only, passphrase required

The agent never touches the credential in any mode. Its not a secret manager that returns secrets — its a broker that uses them on your behalf.

Whitepaper with full exploit chain + 8 failed mitigations: https://hermeticsys.com

Source: https://github.com/hermetic-sys/Hermetic

The vulnerabilty class affects any daemon using SO_PEERCRED for auth. Happy to discuss.