Back to skill

Security audit

Empirecms7.5 Php8 Upgrade

Security checks for vulnerabilities and agentic risk

Overview

The skill mostly matches its PHP 8 migration purpose, but needs Review because it can rewrite many CMS files and includes unsafe SQL rewrite examples plus hardcoded deployment details.

Install only for an EmpireCMS 7.5 PHP 8 migration after making restorable file and database backups. Do not let an agent apply the SQL examples as written; require casting or prepared statements for IDs and class IDs, and review the hardcoded 127.0.2.100/J:\Vhosts notes as environment-specific material rather than generic instructions.

Vulnerability Patterns
  • 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
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Error
Location
SKILL.md:456
Finding

Unsafe SQL Interpolation Recommended by PHP 8 Migration Templates

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, lines 456-493; additional concrete examples appear at lines 796, 820, 847, and 1126
Vulnerability Type: SQL injection through direct interpolation of unvalidated values
Risk Level: High

The Skill recommends inserting array values directly into SQL statements as part of its PHP 8 compatibility migration procedure.

php
// Recommended numeric-field syntax
$empire->query("select ... where classid={$r['classid']} and id={$r['id']}");
$empire->query("update ... set classid={$add['classid']}");

// Recommended INSERT syntax
$empire->query(
    "insert into {$dbtbpre}enewsztinfo(ztid,cid,classid,id,newstime,mid,isgood) " .
    "values('$ztid','$zcid',{$r['classid']},{$r['id']},{$r['newstime']},'$mid','0');"
);

Additional concrete migration examples use the same unsafe pattern:

php
$finfor = $empire->fetch1(
    "select " . ReturnSqlFtextF($mid) .
    " from {$dbtbpre}ecms_" . $tbname . "_data_" . $r['stb'] .
    " where id={$r['id']} limit 1"
);

$empire->query(
    "update {$dbtbpre}ecms_" . $tbname .
    " set onclick=onclick+1 where id={$add['id']} limit 1"
);

$next_r = $empire->fetch1(
    "select isurl,titleurl,classid,id,title from {$dbtbpre}ecms_" .
    $class_r[$add['classid']]['tbname'] .
    " FORCE INDEX (idx_classid_id_asc) where id>{$add['id']} " .
    "and classid={$add['classid']} order by id limit 1"
);

Technical Analysis

The migration correctly identifies that unquoted PHP array keys are incompatible with PHP 8, but its proposed SQL repair directly interpolates values such as $r['id'], $r['classid'], $r['newstime'], and $add['id'] without parameter binding, integer conversion, or explicit validation.

Curly-brace interpolation only resolves PHP string parsing. It does not provide SQL escaping or establish that a value is numeric. If any interpolated value is derived from an HTTP request, i ...[truncated 2246 chars]

Remediation
View remediation

Remediation Suggestions

  1. Replace the documented direct-interpolation pattern with prepared statements and bound parameters wherever the database abstraction layer supports them.
php
$stmt = $database->prepare(
    'SELECT ... WHERE classid = :classid AND id = :id'
);
$stmt->execute([
    ':classid' => (int) $r['classid'],
    ':id'      => (int) $r['id'],
]);
  1. If the legacy EmpireCMS database API cannot use prepared statements, validate and cast every numeric value before constructing the query:
php
$id = (int) ($r['id'] ?? 0);
$classid = (int) ($r['classid'] ?? 0);

$empire->query(
    "select ... where classid=$classid and id=$id"
);
  1. Validate identifiers against their expected domain. Reject missing, negative, zero, or out-of-range values where they are not valid:
php
$id = filter_var($r['id'] ?? null, FILTER_VALIDATE_INT, [
    'options' => ['min_range' => 1],
]);

if ($id === false) {
    throw new InvalidArgumentException('Invalid content identifier');
}
  1. Continue to quote and escape string fields according to the database driver's rules, preferably through bound parameters. Do not treat curly-brace interpolation as an escaping mechanism.

  2. For dynamic table names such as $tbname or $r['stb'], use a strict allowlist because table identifiers generally cannot be protected using ordinary value placeholders:

php
if (!in_array($tbname, $allowedTableNames, true)) {
    throw new InvalidArgumentException('Invalid table name');
}
  1. Update every similar example in SKILL.md, including the concrete examples around lines 796, 820, 847, and 1126, so Agents are not given conflicting secure and insecure guidance.

  2. Add a mandatory migration verification step that traces the source of every SQL value and performs security tests using malformed numeric input. Review the final code with static analysis and application-level SQL injection testing.

...[truncated 215 chars]

Vulnerability Patterns
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • YARA SignaturesMalware Match, Webshell Match, Cryptominer Match
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
Findings (5)

YARA rule 'php_webshell_obfuscated': Obfuscated PHP webshell — eval(base64_decode/gzinflate/str_rot13) [webshells]

Critical
Category
YARA Match
Confidence
80% confidence
Finding

YARA rule matched a known webshell pattern (PHP, Python, JSP, or ASPX webshell).

Content

Scanner excerpt · SKILL.md (reported line 215)May include surrounding context.

100版 while(list($key,$value)=each($tmp)) // ... 处理逻辑

// 101版 - 注释掉each,改用foreach // while(list($key,$value)=each($tmp)) foreach($tmp as $key=>$value) // ... 处理逻辑保持不变

text

---

### SendEmail.inc.php preg_replace /e 问题

两个版本都存在此问题(原版也未完全修复)。需手动替换:

**第1244行**:

```php
//  修改前
$encoded = preg_replace("/([\001-\010\013\014\016-\037\075\177-\377])/e",
    'sprintf("=%02X", ord("\\1"))', $encoded);

//  修改后
$encoded = preg_replace_callback(
    "/([\001-\010\013\014\016-\037\075\177-\377])/",
    function($m) { return '=' . sprintf('%02X', ord($m[1])); },
    $encoded
);

第1247行:同理替换


100版独有目录与文件检查清单

以下目录/文件是 100版独有或二次开发重命名的,需独立检查,不能直接参考 101版:

| 目录/文件 | 状态 | 检查重点

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The manifest description and the document body are entirely in Chinese and frame the skill's invocation and execution in that language, but nowhere state that the skill is limited to Chinese-speaking users or offer an opt-in language choice. Under the policy, a skill that forces a specific language without user choice is a natural-language policy violation unless the locale restriction is explicitly justified.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

Although the manifest presents the skill as a general EmpireCMS PHP 8 upgrade helper, the body is tailored to a specific deployment and references concrete hosts, directory structures, and known file states. This mismatch increases the risk of unintentional disclosure because consumers may invoke it assuming generic behavior while it reveals sensitive details from a real environment.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The skill embeds environment-specific intelligence such as internal host identifiers, deployment comparison targets, and project-state details that go beyond a generic PHP 8 upgrade guide. This can leak sensitive infrastructure context to users of the skill and may facilitate lateral reconnaissance or targeted follow-on attacks if the skill is exposed outside the intended environment.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Low
Category
Not specified by scanner
Confidence
86% confidence
Finding

The skill states that it cannot act without a user-provided project path, yet later includes pre-known backup and host-specific project details. This inconsistency suggests the skill contains latent environment knowledge, which weakens operator trust boundaries and can expose internal pathing and asset locations unnecessarily.

Content

No source excerpt is available for this finding.