Skip to content

[Security] No PID/command tracking - cannot correlate requests to processes #128

Closed

Description

@Mossaka

Priority

P1 - High

Summary

AWF cannot correlate network requests to the specific commands or processes that made them. This significantly limits security auditing, incident response, and forensic capabilities.

Current Behavior

Squid logs show:

1703001234.567 172.30.0.20:45678 github.com 140.82.114.3:443 HTTP/1.1 CONNECT 200 TCP_TUNNEL:HIER_DIRECT github.com:443 "curl/7.88.1"

This shows the container IP (172.30.0.20), not which process inside the container made the request.

Security Impact

  • Cannot answer: "Which command made this request?"
  • Cannot identify: Which tool, script, or MCP server is making outbound connections
  • Incident response limited: If data exfiltration detected, cannot trace to specific process
  • Audit incomplete: Compliance requirements may mandate full request attribution

Proposed Solution

Implement PID Tracking via /proc filesystem

Approach:

  1. Read /proc/net/tcp to find socket inode for source port
  2. Scan /proc/[pid]/fd/ to find process owning the socket
  3. Read /proc/[pid]/cmdline for full command line
  4. Log correlation in structured format

Implementation sketch:

// src/pid-tracker.ts
export async function trackPidForPort(srcPort: number): Promise<{pid: number, cmdline: string}> {
  // Read /proc/net/tcp to find socket inode
  const tcpConnections = await readFile('/proc/net/tcp', 'utf-8');
  const inode = findInodeForPort(tcpConnections, srcPort);

  // Scan /proc/[pid]/fd/ to find process owning inode
  const pids = await readdir('/proc').filter(isNumeric);
  for (const pid of pids) {
    const fds = await readdir(`/proc/${pid}/fd`);
    for (const fd of fds) {
      const link = await readlink(`/proc/${pid}/fd/${fd}`);
      if (link.includes(`socket:[${inode}]`)) {
        const cmdline = await readFile(`/proc/${pid}/cmdline`, 'utf-8');
        return { pid: parseInt(pid), cmdline };
      }
    }
  }
  return { pid: -1, cmdline: 'unknown' };
}

Structured log output:

{
  "timestamp": "2024-01-01T00:00:00.000Z",
  "srcPort": 45678,
  "destDomain": "github.com",
  "destPort": 443,
  "pid": 12345,
  "cmdline": "curl https://github.com",
  "decision": "allowed"
}

Files to Create/Modify

  • New: src/pid-tracker.ts - PID correlation logic
  • New: containers/agent/pid-logger.sh - Shell-based alternative
  • Modify: src/docker-manager.ts - Integrate PID tracking
  • Modify: Squid log processing to include PID info

Testing

  • Verify PID tracking shows correct process info
  • Test with concurrent processes making requests
  • Verify command line captured correctly
  • Performance impact < 5% latency increase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions