Back to skill

Security audit

Ubuntu Inspector

Security checks for vulnerabilities and agentic risk

Overview

This is a legitimate local Ubuntu inspection tool, but it asks users to run broad host checks with root access while writing sensitive reports insecurely under /tmp.

Install only if you are comfortable running a local system-inspection script and reviewing the generated report. Prefer running it without root first, avoid sharing the report publicly, and consider changing the script to use a private directory, mktemp, and 0600 permissions before running it on multi-user or production servers.

Vulnerability Patterns
  • Unauthorized Access and Privilege EscalationObtains permissions beyond the task's legitimate needs
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
Findings (2)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/inspect.sh:14
Finding
Predictable Temporary Report Path Permits Symlink-Based Privileged File Corruption<![CDATA[ ## Vulnerability Details **File Location**: `scripts/inspect.sh:14-16` **Vulnerability Type**: Predictable and unsafe temporary-file creation **Risk Level**: High ### Vulnerable Code ```bash # Output file REPORT_FILE="/tmp/ubuntu_inspection_$(date +%Y%m%d_%H%M%S).txt" echo "========================================" | tee -a "$REPORT_FILE" ``` The same report path is subsequently opened numerous times through `tee -a "$REPORT_FILE"`. ### Technical Analysis The script constructs its report filename from a timestamp with one-second precision and writes it directly into the shared `/tmp` directory. It does not use an atomic temporary-file creation mechanism such as `mktemp`, does not reject symbolic links, and does not verify the file's type or ownership before opening it. The documentation states that root privileges may be required for complete information. If the script is run as root, each `tee -a` invocation follows symbolic links and opens the link target with the script's elevated privileges. An unprivileged local attacker can predict or repeatedly generate candidate report names and place symbolic links at those paths. If a candidate matches the execution timestamp, the script appends its output to an attacker-selected file. The appended text is not fully attacker-controlled, so this is primarily a privileged file-corruption primitive rather than arbitrary file replacement. Nevertheless, corrupting security-sensitive configuration or structured system files can cause denial of service and may create escalation opportunities when combined with a suitable target and parser behavior. The use of append mode does not mitigate the issue because symbolic links are still followed when the target is opened. ### Attack Path 1. The attacker obtains local access to the host and monitors or predicts when an administrator will run the inspector. 2. The attacker calculates likely filenames such as `/tmp/ubuntu_inspection_20260912_143000.txt`. 3. Befo ...[truncated 1087 chars]
Remediation
<![CDATA[ ## Remediation Suggestions - Set a restrictive process umask before creating any report: ```bash umask 077 ``` - Atomically create the report with `mktemp` rather than deriving its name directly from the current time: ```bash REPORT_FILE="$(mktemp /tmp/ubuntu_inspection.XXXXXXXXXX)" ``` - Prefer a private temporary directory: ```bash REPORT_DIR="$(mktemp -d)" chmod 700 "$REPORT_DIR" REPORT_FILE="$REPORT_DIR/report.txt" ``` - Open a single trusted file descriptor once and direct all report output through it instead of repeatedly reopening the pathname. - Reject pre-existing files, symbolic links, and files not owned by the current user if a fixed location must be retained. - Avoid running the complete script as root. Isolate the small number of checks that require elevated access and grant only the minimum necessary permissions. - Add cleanup handling with `trap` if reports are intended to be temporary. ]]>

T05 · Unauthorized Access and Privilege Escalation

Warning
Location
scripts/inspect.sh:64
Finding
Sensitive Host Reconnaissance Data Is Written to an Insufficiently Protected Shared-Directory Report<![CDATA[ ## Vulnerability Details **File Location**: `scripts/inspect.sh:64-124` **Vulnerability Type**: Excessive privileged information collection and insecure report confidentiality **Risk Level**: Medium ### Vulnerable Code ```bash ip addr show | grep -E 'inet ' | grep -v '127.0.0.1' | awk '{print " " $2}' | tee -a "$REPORT_FILE" ss -tlnp | head -20 | tee -a "$REPORT_FILE" last -n 5 | tee -a "$REPORT_FILE" who | tee -a "$REPORT_FILE" ps aux --sort=-%mem | head -11 | tee -a "$REPORT_FILE" journalctl --priority=err --since "1 hour ago" --no-pager 2>/dev/null | head -10 | tee -a "$REPORT_FILE" || echo "Unable to read logs or no errors" | tee -a "$REPORT_FILE" lastb -n 10 2>/dev/null | tee -a "$REPORT_FILE" || echo "No records" | tee -a "$REPORT_FILE" ``` The report destination is defined separately at line 14: ```bash REPORT_FILE="/tmp/ubuntu_inspection_$(date +%Y%m%d_%H%M%S).txt" ``` ### Technical Analysis The script aggregates a substantial amount of security-relevant host information, including: - Interface addresses and routing information - Listening TCP ports and associated process information - Recent successful and failed login records - Currently logged-in users - Process command lines and memory usage - Recent system error logs - User and group statistics This collection is consistent with the documented inspection purpose, and the script does not transmit the information externally. However, the documentation recommends root execution for complete results, which may cause the report to contain information unavailable to ordinary local users. The collected information is written to a predictable file under the shared `/tmp` directory. The script does not set `umask 077`, explicitly create the report with mode `0600`, or place it in a private directory. Under a common `022` umask, a newly created report can be mode `0644`, making it readable by other local users. The exposure is especially significant for `ps aux`, `ss -tlnp`, `last`, `la ...[truncated 1672 chars]
Remediation
<![CDATA[ ## Remediation Suggestions - Set `umask 077` before report creation and explicitly enforce mode `0600`. - Store reports in a private directory owned by the invoking user instead of directly under shared `/tmp`. - Use `mktemp` for atomic and unpredictable report creation. - Run the script without root privileges by default. Clearly identify checks that require elevation and make them opt-in. - Separate general health metrics from sensitive security-audit data. - Add command-line options that allow users to omit login history, failed logins, process command lines, listening-process details, and journal entries. - Redact or minimize sensitive values, including remote addresses, usernames, process arguments, and potentially sensitive log content. - Apply a retention policy and securely remove reports after they are no longer needed. - Warn users that the report can contain security-sensitive host metadata and should not be shared without review. ]]>
Vulnerability Patterns
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
Findings (4)

Credential Access

High
Category
Privilege Escalation
Content
# 13. 安全相关
echo "【13. 安全信息】" | tee -a "$REPORT_FILE"
echo "系统用户数量: $(cat /etc/passwd | wc -l)" | tee -a "$REPORT_FILE"
echo "sudo 用户: $(grep -c 'sudo' /etc/group)" | tee -a "$REPORT_FILE"
echo "失败的登录尝试 (最近10次):" | tee -a "$REPORT_FILE"
lastb -n 10 2>/dev/null | tee -a "$REPORT_FILE" || echo "  无记录" | tee -a "$REPORT_FILE"
Confidence
60% confidence
Finding
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Missing User Warnings

Medium
Confidence
95% confidence
Finding
The script writes a detailed system inspection report to /tmp, a world-accessible shared directory on many systems, and the report contains sensitive host metadata such as hostname, IP addresses, listening ports, login records, users, and service state. Even if the script is intended for legitimate administration, storing this data in /tmp without restrictive permissions or an explicit warning can expose reconnaissance data to local users or other processes.

Sudo/Root Execution

Medium
Category
Privilege Escalation
Content
# 13. 安全相关
echo "【13. 安全信息】" | tee -a "$REPORT_FILE"
echo "系统用户数量: $(cat /etc/passwd | wc -l)" | tee -a "$REPORT_FILE"
echo "sudo 用户: $(grep -c 'sudo' /etc/group)" | tee -a "$REPORT_FILE"
echo "失败的登录尝试 (最近10次):" | tee -a "$REPORT_FILE"
lastb -n 10 2>/dev/null | tee -a "$REPORT_FILE" || echo "  无记录" | tee -a "$REPORT_FILE"
echo "" | tee -a "$REPORT_FILE"
Confidence
70% confidence
Finding
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Natural-Language Policy Violations

Low
Confidence
97% confidence
Finding
Most user-visible messages in the script are fixed in Chinese, which forces a specific language for output. The file does not provide any opt-in, configuration, or documented justification for restricting output to that locale.

Static analysis

No suspicious patterns detected.