feat(security): run raw-socket tools via caps not sudo (drop GTFObins nmap root) - #1305
feat(security): run raw-socket tools via caps not sudo (drop GTFObins nmap root)#1305ocervell wants to merge 1 commit into
Conversation
… nmap root)
The prod worker image grants secator NOPASSWD sudo on nmap/arp-scan/arp, which
is a GTFObins root shell (sudo nmap --script=/tmp/x.nse -> root) reachable from
any shell injection in a worker. Add a security.privileged_mode config flag
('sudo' default, 'caps') that gates the sudo-prepend in Command.__init__, and
switch the full Alpine worker image to grant CAP_NET_RAW/CAP_NET_ADMIN via
setcap on the baked nmap/arp-scan/arp/naabu binaries instead of sudoers. The
lite image (installs tools at runtime, nothing baked to setcap) keeps the old
sudo grants as a deploy-time residual.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P5vSjfkBuGAAHdKxHS3ySm
|
Warning Review limit reached
Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
The prod worker Docker image (
.docker/Dockerfile.alpine) grants thesecatoruser
NOPASSWD: /usr/bin/nmap *(+arp-scan,arp) in/etc/sudoers. That'sa classic GTFObins root shell —
sudo nmap --script=/tmp/x.nse <target>executes arbitrary NSE Lua as root —so any shell-injection vulnerability reached inside a worker process escalates
straight to root.
Fix
Run the raw-socket tools (nmap, arp-scan, arp, naabu) via Linux file
capabilities (
CAP_NET_RAW/CAP_NET_ADMIN) instead ofsudo, gated by a newconfig flag so local/dev installs keep the simpler sudo path:
secator/config.py:Security.privileged_mode: str = 'sudo'—'sudo'(default, prepends
sudo) or'caps'(rely on setcap'd binaries). Overridablevia
SECATOR_SECURITY_PRIVILEGED_MODE.secator/runners/command.py: therequires_sudosudo-prepend (self.cmd/self.cmd_redacted) is now gated byCONFIG.security.privileged_mode != 'caps'..docker/Dockerfile.alpine(flavor-aware):NOPASSWDsudoers grant for nmap/arp-scan/arp.After tools are baked in,
setcap cap_net_raw,cap_net_admin+eipis appliedto the installed binaries (
/usr/bin/nmap,/usr/bin/arp-scan,/sbin/arp,/home/secator/.local/bin/naabu), andsecurity.privileged_modeis set tocapsfor thesecatoruser.to
setcap, so it keeps the oldNOPASSWDsudoers grants and defaultsudo mode. This is a known deploy-time residual; prod should prefer the
full image.
Test plan
tests/unit/test_command.py::TestCommandPrivilegedMode— withprivileged_mode = 'caps'arequires_sudocommand'sself.cmddoes NOTget
sudoprepended; with'sudo'(default) it does.2 passed.flake8clean on the changed Python files.not available in this environment) — full build happens on this PR's CI.
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01P5vSjfkBuGAAHdKxHS3ySm