Back to skill

Security audit

Alibaba Cloud Compute SWAS Open

Security checks for vulnerabilities and agentic risk

Overview

This cloud administration skill is mostly purpose-aligned, but it needs review because its SSH repair script can grant persistent root access and builds privileged remote commands unsafely.

Install only if you are comfortable giving the skill Alibaba Cloud administrative authority. Use least-privilege RAM credentials, avoid the SSH repair helper unless you have reviewed and constrained it, do not run it with untrusted parameters or key files, and prefer a non-root, audited, reversible access-recovery workflow.

Vulnerability Patterns
  • Unauthorized Access and Privilege EscalationObtains permissions beyond the task's legitimate needs
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • 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
Findings (3)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/fix_ssh_access.py:38
Finding

Remote Command Injection Through Unsafely Interpolated SSH Parameters

Content
View full analysis

Vulnerability Details

File Location: scripts/fix_ssh_access.py:38-80
Vulnerability Type: Shell command injection
Risk Level: High

The build_script function inserts the user-controlled --user and --port arguments and the contents of the --pubkey file directly into a Bash script. The resulting script is submitted to Alibaba Cloud SWAS Cloud Assistant for privileged execution on the selected instance.

python
def build_script(pub_key: str, user: str, port: str | None) -> str:
    port_block = ""
    if port:
        port_block = f"""
if ! grep -q '^Port' $SSHD_CONFIG; then
  echo 'Port {port}' >> $SSHD_CONFIG
else
  sed -i 's/^Port.*/Port {port}/' $SSHD_CONFIG
fi
"""

    return f"""#!/bin/bash
set -e
USER_NAME="{user}"
HOME_DIR=$(getent passwd "$USER_NAME" | cut -d: -f6)
if [ -z "$HOME_DIR" ]; then
  echo "User $USER_NAME not found"
  exit 1
fi

mkdir -p "$HOME_DIR/.ssh"
chmod 700 "$HOME_DIR/.ssh"
if ! grep -qF '{pub_key}' "$HOME_DIR/.ssh/authorized_keys" 2>/dev/null; then
  echo '{pub_key}' >> "$HOME_DIR/.ssh/authorized_keys"
fi
chmod 600 "$HOME_DIR/.ssh/authorized_keys"
chown -R "$USER_NAME":"$USER_NAME" "$HOME_DIR/.ssh"

SSHD_CONFIG=/etc/ssh/sshd_config
if ! grep -q '^PermitRootLogin' $SSHD_CONFIG; then
  echo 'PermitRootLogin yes' >> $SSHD_CONFIG
else
  sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' $SSHD_CONFIG
fi
if ! grep -q '^PubkeyAuthentication' $SSHD_CONFIG; then
  echo 'PubkeyAuthentication yes' >> $SSHD_CONFIG
else
  sed -i 's/^PubkeyAuthentication.*/PubkeyAuthentication yes/' $SSHD_CONFIG
fi
{port_block}

Technical Analysis

Python f-string interpolation does not provide shell escaping. Each input is inserted into a different shell quoting context:

  • user is placed inside double quotes and can escape that context with an embedded double quote.
  • port is placed inside single-quoted echo and sed arguments and c ...[truncated 1655 chars]
Remediation
View remediation

Remediation Suggestions

  1. Validate --user against a restrictive Linux username expression and additionally confirm that the account exists.
  2. Parse --port as an integer through argparse, require a value from 1 through 65535, and render only the normalized integer.
  3. Parse and validate the public key with a suitable SSH-key library. Permit only recognized public-key algorithms and reject embedded line breaks, shell metacharacters, malformed base64, and trailing data that is not an approved comment.
  4. Do not construct executable shell source from raw values. Transfer data through safely encoded input, such as base64-decoded data passed as positional arguments or files, and apply robust shell quoting when unavoidable.
  5. Avoid placing user input inside sed programs. Use a configuration-management library or a fixed script whose arguments are passed separately from its source.
  6. Add tests covering quotes, command substitutions, line breaks, shell separators, option-like values, malformed keys, and out-of-range ports.
  7. Require explicit confirmation before sending a privileged remote command and log the target region and instance without logging sensitive key material.

T05 · Unauthorized Access and Privilege Escalation

Error
Location
scripts/fix_ssh_access.py:67
Finding

SSH Repair Unconditionally Enables Direct Root Login

Content
View full analysis

Vulnerability Details

File Location: scripts/fix_ssh_access.py:67-71, 99-102
Vulnerability Type: Excessive privilege and insecure SSH configuration
Risk Level: High

The script defaults to installing the supplied key for root and unconditionally rewrites the SSH daemon configuration to allow direct root login, even when the caller selects a non-root user.

python
if ! grep -q '^PermitRootLogin' $SSHD_CONFIG; then
  echo 'PermitRootLogin yes' >> $SSHD_CONFIG
else
  sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' $SSHD_CONFIG
fi
python
parser = argparse.ArgumentParser()
parser.add_argument("--region", required=True)
parser.add_argument("--instance-id", required=True)
parser.add_argument("--user", default="root")
parser.add_argument("--port", help="Set SSH port in sshd_config")
parser.add_argument("--pubkey", default="~/.ssh/id_ed25519.pub")

After making the change, the script immediately restarts the SSH service:

bash
if systemctl list-unit-files | grep -q '^ssh\.service'; then
  systemctl restart ssh
elif systemctl list-unit-files | grep -q '^sshd\.service'; then
  systemctl restart sshd
elif command -v service >/dev/null 2>&1; then
  service ssh restart || service sshd restart

Technical Analysis

Restoring key-based SSH access does not require globally enabling direct root login. The behavior exceeds minimum privilege because:

  • The default target account is root.
  • PermitRootLogin yes is applied regardless of the account selected through --user.
  • The value permits direct root login using every authentication mechanism otherwise enabled by the server, rather than limiting root to public-key authentication.
  • The script does not back up sshd_config, validate it with sshd -t, preserve a rollback mechanism, or verify that a restrictive firewall policy exists before restarting the service.
  • Existing organization-specific restrictions ...[truncated 1513 chars]
Remediation
View remediation

Remediation Suggestions

  1. Default --user to a non-root administrative account and require an explicit confirmation flag before modifying root access.
  2. Do not alter PermitRootLogin when repairing access for a non-root account.
  3. If root key access is explicitly required, use PermitRootLogin prohibit-password rather than yes, subject to the operating system's supported syntax and the user's confirmed policy.
  4. Preserve existing hardened settings unless the caller explicitly requests a narrowly defined change.
  5. Create a protected backup of sshd_config before modification and restore it automatically if validation or restart fails.
  6. Run sshd -t -f /etc/ssh/sshd_config before restarting the service.
  7. Verify the new key and account permissions before changing daemon policy.
  8. Use an atomic configuration update and maintain an out-of-band recovery channel while applying SSH changes.
  9. Recommend source-IP-restricted firewall rules and short-lived or centrally managed keys.
  10. Record the intended account and configuration changes for audit purposes without recording private credentials.

T08 · Insecure Dependencies

Warning
Location
SKILL.md:31
Finding

Alibaba Cloud SDK Dependencies Are Installed Without Version or Integrity Pinning

Content
View full analysis

Vulnerability Details

File Location: SKILL.md:31-36
Vulnerability Type: Unpinned third-party dependencies
Risk Level: Medium

The installation instructions retrieve the latest available releases of security-sensitive cloud SDK packages without a lock file, exact versions, or package hashes.

bash
python3 -m venv .venv
. .venv/bin/activate
python -m pip install alibabacloud_swas_open20200601 alibabacloud_tea_openapi alibabacloud_credentials

Technical Analysis

These packages execute in a process that can access Alibaba Cloud access keys and security tokens. Installing unconstrained versions means the reviewed Skill does not determine the code that will ultimately execute. A future compromised release, compromised dependency, or incompatible update could run during installation or import with access to cloud credentials and management permissions.

The package names are consistent with the declared Alibaba Cloud SDK workflow, and the audit found no evidence that they are intentionally malicious or typosquatted. The risk arises from absent reproducibility and integrity controls rather than from a confirmed malicious package.

Attack Path

  1. An operator follows the documented setup instructions.
  2. pip resolves the newest package versions and their transitive dependencies from the configured package index.
  3. A compromised, malicious, or unexpectedly incompatible release is selected because no reviewed version or hash is enforced.
  4. Package installation or later module import executes the selected code.
  5. That code runs in the same environment as Alibaba Cloud credentials and can access the cloud APIs available to the operator.

Impact Assessment

A compromised dependency could steal Alibaba Cloud credentials, enumerate SWAS infrastructure, execute commands on instances, alter firewall rules, modify keys, stop or reset systems, or perform other operations permitted to the configured RA ...[truncated 113 chars]

Remediation
View remediation

Remediation Suggestions

  1. Pin every direct dependency to an exact reviewed version.
  2. Generate a lock file containing all transitive dependencies.
  3. Require cryptographic hashes during installation, for example through a hash-locked requirements file.
  4. Configure an explicitly trusted package index or an internally controlled package mirror.
  5. Review dependency release notes and security advisories before updating.
  6. Automate vulnerability and provenance scanning in continuous integration.
  7. Continue using an isolated virtual environment and grant the runtime cloud identity only the permissions needed for the requested operation.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • YARA SignaturesMalware Match, Webshell Match, Cryptominer Match
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
Findings (16)

Credential Access

High
Category
Privilege Escalation
Confidence
94% confidence
Finding

This script creates or modifies a user's authorized_keys file on a remote instance, which directly grants persistent shell access to whoever controls the injected public key. In a management skill that can target cloud instances end-to-end, this is highly security-sensitive because misuse or parameter injection can become unauthorized access across managed hosts.

Content

Scanner excerpt · scripts/fix_ssh_access.py (reported line 59)May include surrounding context.

python
mkdir -p "$HOME_DIR/.ssh"
chmod 700 "$HOME_DIR/.ssh"
if ! grep -qF '{pub_key}' "$HOME_DIR/.ssh/authorized_keys" 2>/dev/null; then
  echo '{pub_key}' >> "$HOME_DIR/.ssh/authorized_keys"
fi
chmod 600 "$HOME_DIR/.ssh/authorized_keys"

Credential Access

High
Category
Privilege Escalation
Confidence
98% confidence
Finding

Appending a supplied public key into authorized_keys grants durable login capability and is effectively an access-provisioning primitive. In the SWAS remote-command context, that capability is especially dangerous because a caller can establish access without interactive review on the target system.

Content

Scanner excerpt · scripts/fix_ssh_access.py (reported line 60)May include surrounding context.

python
mkdir -p "$HOME_DIR/.ssh"
chmod 700 "$HOME_DIR/.ssh"
if ! grep -qF '{pub_key}' "$HOME_DIR/.ssh/authorized_keys" 2>/dev/null; then
  echo '{pub_key}' >> "$HOME_DIR/.ssh/authorized_keys"
fi
chmod 600 "$HOME_DIR/.ssh/authorized_keys"
chown -R "$USER_NAME":"$USER_NAME" "$HOME_DIR/.ssh"

YARA rule 'backdoor_persistence': Backdoor persistence with malicious payloads (shell commands, SSH key injection, hidden root users) [malware]

High
Category
YARA Match
Confidence
96% confidence
Finding

The YARA hit is substantively valid: the script injects an SSH key into authorized_keys and also enables root/public-key login, which are common persistence and backdoor techniques when abused. Although the apparent intent is administrative repair, the behavior is inherently dual-use and particularly dangerous in a cloud management skill capable of remote execution on instances.

Content

Scanner excerpt · scripts/fix_ssh_access.py (reported line 60)May include surrounding context.

python
t {port}' >> $SSHD_CONFIG
else
  sed -i 's/^Port.*/Port {port}/' $SSHD_CONFIG
fi
"""

    return f"""#!/bin/bash
set -e
USER_NAME="{user}"
HOME_DIR=$(getent passwd "$USER_NAME" | cut -d: -f6)
if [ -z "$HOME_DIR" ]; then
  echo "User $USER_NAME not found"
  exit 1
fi

mkdir -p "$HOME_DIR/.ssh"
chmod 700 "$HOME_DIR/.ssh"
if ! grep -qF '{pub_key}' "$HOME_DIR/.ssh/authorized_keys" 2>/dev/null; then
  echo '{pub_key}' >> "$HOME_DIR/.ssh/authorized_keys"
fi
chmod 600 "$HOME_DIR/.ssh/authorized_keys"
chown -R "$USER_NAME":"$USER_NAME" "$HOME_DIR/.ssh"

SSHD_CONFIG=/etc/ssh/sshd_config
if ! grep -q '^PermitRootLogin' $SSHD_CONFIG; then
  echo 'PermitRootLogin yes' >> $SSHD_CONFIG
else
  sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' $SSHD_CONFIG
fi
if ! grep -q '^PubkeyAuthentication' $SSHD_CONFIG; then
  echo 'PubkeyAuthentication yes' >> $SSHD_CONFIG
else
  sed -i 's/^PubkeyAuthentication.*/PubkeyAuthentication yes/' $SSHD_CONFIG
fi
{port_block}

if systemctl list-unit-files | grep -q '^

Credential Access

High
Category
Privilege Escalation
Confidence
91% confidence
Finding

Manipulating authorized_keys permissions is part of enabling the newly added credential, so in context it contributes to completing a persistent access path on the remote host. The risk is not the chmod itself but that it operationalizes unauthorized or poorly governed credential installation.

Content

Scanner excerpt · scripts/fix_ssh_access.py (reported line 62)May include surrounding context.

python
if ! grep -qF '{pub_key}' "$HOME_DIR/.ssh/authorized_keys" 2>/dev/null; then
  echo '{pub_key}' >> "$HOME_DIR/.ssh/authorized_keys"
fi
chmod 600 "$HOME_DIR/.ssh/authorized_keys"
chown -R "$USER_NAME":"$USER_NAME" "$HOME_DIR/.ssh"

SSHD_CONFIG=/etc/ssh/sshd_config

Credential Access

High
Category
Privilege Escalation
Confidence
90% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · scripts/fix_ssh_access.py (reported line 101)May include surrounding context.

python
parser.add_argument("--instance-id", required=True)
    parser.add_argument("--user", default="root")
    parser.add_argument("--port", help="Set SSH port in sshd_config")
    parser.add_argument("--pubkey", default="~/.ssh/id_ed25519.pub")
    args = parser.parse_args()

    pubkey_path = os.path.expanduser(args.pubkey)

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
95% confidence
Finding

The skill clearly enables access to environment variables, shell execution, and file read/write workflows, but it does not declare an explicit tool scope or permissions boundary. In a cloud-management skill that can invoke commands and use credentials from environment variables, this ambiguity increases the risk of unintended credential access, overly broad execution, or misuse of local system capabilities beyond what a caller expects.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
89% confidence
Finding

The skill advertises command execution, instance lifecycle changes, firewall updates, disk/image operations, and database actions, but it does not prominently warn that these actions can disrupt services, alter security posture, or destroy data. Because the skill is specifically designed for production cloud resource management, lack of an explicit impact warning makes accidental destructive use more likely and increases operational risk.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

This markdown file documents operations such as ResetSystem, DeleteSnapshot(s), ResetDisk, DeleteCustomImage(s), RunCommand, StartTerminalSession, AllocatePublicConnection, and password resets, but it contains no warning about potential data loss, remote command execution, exposure, or irreversible changes. Under the markdown-specific SQP-2 criteria, a skill description should disclose behaviors that could affect user data, privacy, or system integrity.

Content

No source excerpt is available for this finding.

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
80% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · scripts/fix_ssh_access.py (reported line 58)May include surrounding context.

python
fi

mkdir -p "$HOME_DIR/.ssh"
chmod 700 "$HOME_DIR/.ssh"
if ! grep -qF '{pub_key}' "$HOME_DIR/.ssh/authorized_keys" 2>/dev/null; then
  echo '{pub_key}' >> "$HOME_DIR/.ssh/authorized_keys"
fi

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
80% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · scripts/fix_ssh_access.py (reported line 62)May include surrounding context.

python
if ! grep -qF '{pub_key}' "$HOME_DIR/.ssh/authorized_keys" 2>/dev/null; then
  echo '{pub_key}' >> "$HOME_DIR/.ssh/authorized_keys"
fi
chmod 600 "$HOME_DIR/.ssh/authorized_keys"
chown -R "$USER_NAME":"$USER_NAME" "$HOME_DIR/.ssh"

SSHD_CONFIG=/etc/ssh/sshd_config

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
89% confidence
Finding

The code builds and sends a shell script that writes to authorized_keys, modifies /etc/ssh/sshd_config, and restarts the SSH service on the target instance. Although the module docstring describes the behavior, there is no runtime confirmation or user-facing warning before executing these potentially disruptive remote changes.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The script invokes SWAS RunCommand to execute a shell script on a remote instance, which is a safety-relevant operation affecting system state and access. The file contains no confirmation prompt, warning print/log, or explanatory comment beyond the brief module docstring, so users are not explicitly informed that remote command execution will occur.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

This markdown file is entirely written in Chinese and does not indicate that the language choice is optional or tied to a documented region-specific requirement. Under the policy rule for language or locale constraints, this can be considered a natural-language policy violation because users are not offered a language/locale choice or opt-in.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Low
Category
Not specified by scanner
Confidence
82% confidence
Finding

The file-level docstring says the script summarizes SWAS instances by plan, but the implementation also directly sources access credentials from environment variables to authenticate API calls. While API access is expected for cloud inventory, explicit credential harvesting is a broader capability than the narrow 'summarize' description of this script itself implies.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
88% confidence
Finding

This Python code accesses sensitive credential environment variables to authenticate with Alibaba Cloud, but the file contains no print/log message, confirmation, or explanatory warning beyond the brief module docstring. Under the code-file SQP-2 criteria, sensitive credential access should have some visible disclosure unless clearly covered elsewhere.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
84% confidence
Finding

This code accepts a user-supplied output path and writes results to it directly, but provides no confirmation prompt, warning message, or explanatory comment about the file write behavior. Because file writes are safety-relevant operations under this rule, the lack of disclosure is a quality/safety issue even though the write is part of normal execution.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.