T09 · Insecure Skill Coding Practices
- Location
scripts/monitor.py:135- Finding
Unconditional Process Enumeration and Disclosure in JSON Output
- Content
View full analysis
Vulnerability Details
File Location:
scripts/monitor.py:135-168andscripts/monitor.py:238-241
Vulnerability Type: Sensitive process information exposure caused by excessive data collection
Risk Level: MediumVulnerable Code
python def get_top_processes(limit=5): """Get top processes by CPU usage.""" try: import subprocess result = subprocess.run( ['ps', 'aux', '--sort=-%cpu'], capture_output=True, text=True ) lines = result.stdout.strip().split('\n')[1:limit+1] processes = [] for line in lines: fields = line.split() if len(fields) >= 11: processes.append({ 'pid': fields[1], 'user': fields[0], 'cpu': float(fields[2]), 'mem': float(fields[3]), 'command': ' '.join(fields[10:]) }) return processes except: return [] def get_status(): """Get complete system status.""" return { 'cpu': get_cpu_usage(), 'memory': get_memory_usage(), 'disk': get_disk_usage(), 'network': get_network_stats(), 'uptime': get_uptime(), 'load': get_load_average(), 'processes': get_top_processes(5) }python status = get_status() if args.json: print(json.dumps(status, indent=2)) if not args.watch: breakTechnical Analysis
Every invocation calls
get_status(), which unconditionally invokesget_top_processes(5). That function executesps auxand collects process owners, process identifiers, CPU and memory utilization, and full command-line arguments.Metric-selection options such as
--cpu,--memory,--disk, and--networkdo not limit the information collected. Furthermore, JSON mode always serializes theprocessesfield, even when the caller did not request--processes.Process command l ...[truncated 1895 chars]
- Remediation
View remediation
Remediation Suggestions
- Collect process information only when explicitly requested through
--processes. - Build the result according to selected metrics rather than always calling
get_status(). - Omit the
processesproperty entirely when process reporting is not requested. - Avoid returning full command-line arguments by default. Prefer executable names or redact arguments that resemble secrets.
- Ensure JSON and human-readable modes enforce the same metric-selection policy.
- Document that process inspection can expose sensitive operational information.
- Run the monitor with the least-privileged account capable of reading the required metrics.
A safer implementation pattern is:
python status = {} if args.status or args.cpu: status['cpu'] = get_cpu_usage() if args.status or args.memory: status['memory'] = get_memory_usage() if args.status or args.disk: status['disk'] = get_disk_usage() if args.status or args.network: status['network'] = get_network_stats() if args.status: status['uptime'] = get_uptime() status['load'] = get_load_average() if args.processes: status['processes'] = get_top_processes(5)If aggregate
--statusoutput is intended to include process information, that behavior should be explicitly documented, while narrow metric options must not collect or emit it.- Collect process information only when explicitly requested through
