National Cyber Warfare Foundation (NCWF)login

Inside 3snake: how it watches sshd and sudo for credential strings


0 user ratings
2026-10-20 07:28:32
milo
Red Team (CNA)
"Inside

3snake is a Linux post-exploitation research tool that uses ptrace and netlink proc events to extract password strings from newly spawned sshd and sudo processes during authorized assessments.








Toolblendin/3snake — C-based tracer that dumps credential-related strings from sshd and sudo authentication flows on rooted Linux hosts
CategoryLinux post-exploitation / process tracing utility
Primary UseDemonstrating on authorized, already-rooted targets how cleartext passwords transit read and write syscalls in sshd, sudo, su, ssh client, and passwd processes
Safe UseRestricted to penetration tests and red-team engagements with written authorization, lab environments, and defensive research into credential-exposure detection on Linux.
Telemetry NoteBecause it relies on ptrace attachment, defenders can spot it via auditd rules on ptrace syscalls, unexpected processes with CAP_SYS_PTRACE, and netlink proc connector listeners on the host.

blendin/3snake is a compact C utility written to answer a narrow but consequential question: on a Linux host where you already have root, how much credential material can you observe without modifying any binaries or loading a kernel module? The README is refreshingly candid about its scope — it targets rooted servers, reads memory from sshd and sudo system calls involved in password-based authentication, and, critically, never writes memory into the traced processes. That last property matters both operationally and forensically: the tool leaves the target binaries untouched, which is precisely why its author built it as an alternative to backdooring openssh or installing a kernel module.


The architecture is the interesting part for anyone studying Linux credential exposure. 3snake subscribes to the kernel's proc connector events over netlink sockets, which is how it learns about newly spawned processes in near real time. When a candidate process matching its tracer configuration appears — an sshd session, a sudo invocation — it spawns a dedicated tracer process and attaches via ptrace. From there it observes read and write system calls and extracts strings related to password authentication from the traced memory. This design gives it one tracer per target process rather than a monolithic loop, which keeps the monitoring logic isolated per credential event.


For operators evaluating detection coverage, the mechanism deserves attention. Nothing is patched, no LD_PRELOAD is involved, and no files belonging to OpenSSH or sudo are altered. The only host prerequisites the README lists are Linux, ptrace enabled, and the /proc filesystem mounted — the stock configuration of most distributions. That means an authorized assessment using 3snake exercises a detection surface that exists on effectively every Linux server: process-event monitoring via netlink and debugger attachment via ptrace, both of which are auditable behaviors rather than file-modification artifacts.


The build story is minimal and unremarkable in the best way. A single make in the repository root produces the binary, after which ./3snake -h shows options and a bare ./3snake runs the tracer attached to the current terminal. A daemonized mode exists via ./3snake -d with an -o flag directing output to a file such as /tmp/output_file.txt; the README notes that relative paths passed to -o resolve under the configured root directory when daemonized. That is the entire invocation surface — there is no network component, no persistence logic, and no obfuscation layer, which is consistent with its author describing it as a college-era project.


Configuration lives in src/config.h rather than in runtime flags, which tells you something about the tool's maturity and intended audience. Compile-time toggles include ROOT_DIR for the daemonized root directory, ENABLE_SSH for OpenSSH server password auth, ENABLE_SUDO for sudo password auth, ENABLE_SU (marked experimental) for su, ENABLE_SSH_CLIENT (also experimental) for outbound ssh client passwords, and ENABLE_PASSWD for capturing passwd password changes. The toggle granularity means an authorized engagement can scope collection narrowly — for example, enabling only ENABLE_SUDO to demonstrate sudo password hygiene — instead of blanket harvesting, and red teams should scope it that way deliberately.


The author's own framing in the README is a useful data point on intent. The stated motivation is dissatisfaction with the standard alternatives — backdooring openssh or installing a kernel module on target servers — both of which are heavier, riskier, and more detectable via file integrity monitoring. 3snake sits in a different spot on the trade-off curve: it is less invasive to the software supply chain of the host but more visible to syscall-level auditing, because ptrace attachment is a distinctive action that auditd and similar frameworks can be tuned to catch. For defenders, this asymmetry is the lesson: tools that avoid file tampering still require observable kernel interfaces.


Defensively, there are three concrete angles worth building detections around. First, ptrace attachment against security-sensitive binaries like sshd and sudo is abnormal on production hosts and can be alerted on directly. Second, subscribing to the netlink proc connector is itself a niche behavior — legitimate users are rare outside monitoring agents, so an unexpected listener deserves review. Third, unexpected processes holding CAP_SYS_PTRACE or running as root while spawning children per login event forms a recognizable process-tree pattern. None of these require signature coverage of 3snake itself, which is the right posture given how simple the tool is to recompile or rename.


The README's todo table reveals both completed capability and honest gaps. OpenSSH server password auth, sudo, su, and ssh client tracing are marked done, while regex-based string extraction from arbitrary processes is only partially there, and the wishlist includes making it easier to add new tracers, a Yubikey second-factor prompt idea for OpenSSH, and an output mode limited to usernames and passwords. The Yubikey item is telling — it hints at the author's awareness that the same observation point used to steal passwords could, in a hardened setup, be repurposed to demand a second factor from end users, turning the attack surface into a control.


Limitations are stated plainly and are worth repeating for anyone planning an authorized engagement around this tool: Linux only, ptrace must be permitted (relevant on hardened kernels and inside many containers), and /proc must be mounted. Containerized sshd deployments with dropped capabilities or seccomp filters blocking ptrace will blunt it, which is itself a validation of those hardening measures. Assessors should expect the tool to work on traditional VMs and bare metal and to fail informatively elsewhere.


As with any credential-capture tool, the governance burden sits with the operator. Capturing plaintext authentication strings on a system you are contractually permitted to test is a legitimate demonstration of post-compromise impact; doing it anywhere else is straightforwardly illegal. Engagements using 3snake should define scope in the rules of engagement, treat the output file as sensitive evidence, and purge it per the evidence-handling plan. The tool is licensed under MIT according to the repository, with the author's self-deprecating note about having written it in college — a fitting epilogue for a small, sharp utility that still illustrates a live lesson about Linux credential exposure.


In sum, 3snake earns its place in a study collection less for its code volume than for the clarity of its design: netlink proc events for discovery, per-process ptrace tracers for collection, compile-time toggles for scoping, and zero modification of target binaries. For red teams it is a lean way to demonstrate what root implies for credential visibility; for blue teams it is a checklist of exactly the kernel interfaces — ptrace, netlink connectors, CAP_SYS_PTRACE — that deserve standing detection rules. Both sides of an authorized engagement get something useful from understanding it.



Official project repository for blendin/3snake.

Download Tool

Educational analysis for authorized security professionals. Use only in controlled, authorized environments.






Source: OffensiveSec
Source Link: https://www.offsecblog.com/2026/10/inside-3snake-how-it-watches-sshd-and.html


Comments
new comment
Nobody has commented yet. Will you be the first?
 
Forum
Red Team (CNA)



Copyright 2012 through 2026 - National Cyber Warfare Foundation - All rights reserved worldwide.