Mining Attack Diagnosis (Read-Only)
Absolute Rules
- CRITICAL — MANDATORY EXECUTION: You MUST run the investigation via the entry script
scripts/mining_investigation.py. Do NOT hand-write bash/python, do NOT issue individual aliyun CLI calls, do NOT skip any step. If the script fails or times out, re-run it once before falling back — never abandon the 6-step SOP. The entry script internally invokes every Step 1–4 API (DescribeSuspEvents, DescribeAlarmEventDetail, DescribeSuspEventDetail, DescribeSecurityStatInfo, DescribeFieldStatistics, DescribeExposedInstanceList, DescribeVulList) regardless of intermediate results, and auto-retries transient ServiceUnavailable/Throttling/InternalError responses — so you must not pre-empt or short-circuit it with ad-hoc calls.
- ABSOLUTE PROHIBITION (read-only enforcement): Under NO circumstances may you generate, write, or execute any command/script calling a mutating API (
Update*/Delete*/Disable*/Modify*/Create*/Rotate*/Set*/Operate*) — e.g. OperateSuspiciousTargetBatch, ModifySecurityGroupRule, DeleteInstance. This includes scripts "for the user to run manually". If the user asks to quarantine/kill/isolate, only output the manual remediation workflow and declare this skill is read-only.
- MANDATORY OUTPUT FORMAT: When mining is confirmed, the report MUST start with the URGENT banner (see Report Output section); the Conclusion section MUST include the 4-phase remediation workflow verbatim. Partial output is forbidden.
- EXECUTION RULE FOR ERRORS: On any API error, log
[WARN] <error> to stderr and continue to the next step — never silently skip. On Forbidden/NoPermission, record the missing permission and continue. On empty results, set fields to N/A and proceed. On transient errors (ServiceUnavailable/Throttling/InternalError), the entry script retries automatically — do not conclude "service down" from a single failed call.
- INFORMATION COMPLETENESS (auto-fill first, ask second): When the user omits the account UID or region but the request intent is clear (e.g. only an API fragment like "describe susp"), do NOT stall asking for what can be derived — auto-derive the UID via
sts:GetCallerIdentity (the entry script does this when --account is omitted), use the default region cn-hangzhou, state the derivation explicitly in your reply and in the report metadata ("account auto-derived via STS"), then run the full investigation. Only ask a brief clarifying question when the request is too ambiguous to determine the product or investigation goal at all. Never fabricate findings in either path.
Overview
This skill implements a standard 6-step operating procedure for Alibaba Cloud
cryptomining (cryptojacking) detection and diagnosis. It detects mining alerts
via Security Center (SAS), extracts Indicators of Compromise (IOCs) from alert
detail, scopes the affected assets, detects the attack surface (exposed assets
- unpatched vulnerabilities) to hypothesize the intrusion entry, assesses risk,
and generates a prioritized handling/remediation report.
This skill is strictly read-only — it never performs containment,
quarantine, process termination, host isolation, or any handling/mutating
action. When mining is confirmed it prints a prominent URGENT banner telling
the operator to remediate manually.
6-Step Detection & Diagnosis SOP
Mining Attack Detection & Diagnosis — SAS Public API
|
v
+-----------------------------------------------+
| Step 1: Mining Alert Detection |
| Action: SAS DescribeSuspEvents |
| Filter: mining keywords (xmrig/mining-pool/...) |
| Output: mining alerts, affected assets, level |
+-----------------------------------------------+
|
v
+-----------------------------------------------+
| Step 2: Alert Detail & IOC Extraction |
| Action: DescribeAlarmEventDetail / |
| DescribeSuspEventDetail |
| Output: pool IPs/domains, sample MD5/SHA256, |
| malicious process/command indicators |
+-----------------------------------------------+
|
v
+-----------------------------------------------+
| Step 3: Affected Asset Scope |
| Group alerts by asset (uuid/name/IP) |
| + DescribeSecurityStatInfo / FieldStatistics |
| Output: blast radius, spread assessment |
+-----------------------------------------------+
|
v
+-----------------------------------------------+
| Step 4: Attack Surface Detection |
| Action: DescribeExposedInstanceList + |
| DescribeVulList (asap) |
| Output: likely intrusion entry vector |
+-----------------------------------------------+
|
v
+-----------------------------------------------+
| Step 5: Risk Assessment |
| Severity, handled status, spread, entry |
+-----------------------------------------------+
|
v
+-----------------------------------------------+
| Step 6: Handling & Remediation Report |
| IOC table + affected assets + attack surface |
| + P0-P3 prioritized remediation + conclusion |
| Read-only; URGENT banner if mining confirmed |
+-----------------------------------------------+
Intent Routing
| User Intent |
Action |
| Step 1: Detect mining alerts |
Read references/module1_alert_detection.md |
| Step 2: Extract IOCs from an alert |
Read references/module2_alert_detail_ioc.md |
| Step 3: Scope affected assets |
Read references/module3_affected_assets.md |
| Step 4: Detect attack surface / entry vector |
Read references/module4_attack_surface.md |
| Step 6: Remediation guidance |
Read references/module5_remediation_best_practices.md |
| Mining keyword / IOC reference |
Read references/mining_indicators.md |
| End-to-end runtime flow |
Read references/detection_flow.md |
Prerequisites
- aliyun CLI 3.x — required for API access:
brew install aliyun-cli # macOS; see https://help.aliyun.com/document_detail/121541.html
aliyun configure # stored in ~/.aliyun/config.json
- Credentials — read-only Security Center (SAS) permissions for the
Step 1–4 APIs listed in Absolute Rule #1. This skill is strictly read-only:
it needs no write/mutating permissions and never quarantines, isolates, or
terminates anything. Full permission list:
references/ram-policies.md.
- Python 3.9+ — standard library only, no external dependencies.
Authentication
Credentials are resolved automatically from the aliyun CLI profile
(~/.aliyun/config.json). The scripts never handle or print secrets.
# Run the investigation
python scripts/mining_investigation.py --account <UID>
# Select a specific profile
python scripts/mining_investigation.py --account <UID> --profile prod
CLI Options
All scripts support --help. Common parameters:
--account <UID> — Alibaba Cloud account UID (optional; auto-derived, report label only)
--days <N> — Lookback window in days (default 30)
--region <REGION> — Alibaba Cloud region (default: cn-hangzhou)
--format json|markdown — Report format
--output <path> — Output file (default: output/mining_report.md)
Additional pass-through options: --dealed Y|N|all, --profile <name>
(see references/detection_flow.md).
Observability
All API calls made by this skill include a User-Agent header for
platform-level tracing:
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-mining-attack-diagnosis/{session-id}
A session-id is a 32-character hex string auto-generated per invocation and
attached to every request in the same investigation run; it is logged to
stderr at the start of execution and included in the report metadata.
Report Output
MANDATORY OUTPUT FORMAT: The report MUST follow this structure exactly. When mining is confirmed, the URGENT banner MUST appear at the top. The Conclusion MUST include the full 4-phase remediation workflow (Phase 1: Preserve & Access → Phase 2: Eradicate & Isolate → Phase 3: Harden → Phase 4: Verify & Recover). Partial or truncated output is forbidden.
Step 6 produces a report with:
- Metadata & Severity — investigation time, account, window, overall severity
- URGENT banner — shown only when mining is confirmed (read-only reminder)
- Step 1 — Mining Alerts — table of matched alerts (level, event, asset, IP, keywords)
- Step 2 — IOC table — mining-pool IPs/domains, sample MD5/SHA256, process/command indicators
- Step 3 — Affected Assets — per-asset alert counts and event names
- Step 4 — Attack Surface — exposed asset count + unpatched vulnerability count
- Step 5 — Risk Analysis — findings (spread, connectivity, entry vector)
- Conclusion — Overview, Intrusion Path & Entry Vector, P0–P3 Remediation
No-Fabrication Rule
If Security Center returns no mining-matching alerts, report truthfully that no
mining compromise is indicated for the window. Never invent alerts, affected
assets, or IOCs to "complete" a conclusion, and do not print the URGENT banner
in that case.
Sensitive-Data Handling
- IOCs are preserved (never masked) — mining-pool IPs/domains, sample
hashes, and malicious process names carry forensic value and are needed for
containment.
- Account-scoped identifiers are masked — account UID and asset uuid are
masked in all output via
_cli.mask_sensitive(). Set MINING_NO_MASK=1 to
emit raw values.
- The AccessKey Secret / security token are used only for signing and are never
printed or logged.
Available Scripts
| Script |
Type |
Description |
scripts/mining_investigation.py |
Entry |
6-step detection & diagnosis orchestrator |
Standalone step scripts (scripts/query_*.py) and internal modules
(scripts/_cli.py, scripts/_constants.py) are invoked by the entry script;
do not run them directly.
Error Handling
On any error, log [WARN] <error> to stderr and continue to the next step
— never silently skip a step or abort the investigation. Transient errors
(ServiceUnavailable/Throttling/InternalError) are auto-retried by the
entry script; permission/parameter errors degrade gracefully with the failed
step recorded in the report. Full error table: see Absolute Rule #4 and
references/detection_flow.md.
1---
2name: alibabacloud-mining-attack-diagnosis
3description: |
4 Alibaba Cloud Security Center cryptomining (cryptojacking) diagnosis skill.
5 Use when the user reports or suspects a mining infection, receives a mining
6 alert, or asks for mining alert detection, IOC extraction (pool IPs,
7 malicious domains, sample hashes, malicious processes), affected-asset
8 scoping, attack-surface analysis, entry-vector analysis, risk assessment,
9 prioritized remediation reporting, cryptomining incident response, or
10 mining risk detection. Triggers: "mining", "cryptomining",
11 "cryptojacking", "coin mining", "coin-mining", "miner", "mining alert",
12 "mining alerts", "mining pool", "pool IPs", "malicious domains",
13 "sample hashes", "malicious processes", "mining IOC", "IOC extraction",
14 "mining alert detection", "affected-asset scoping",
15 "attack-surface analysis", "entry-vector analysis", "risk assessment",
16 "prioritized remediation reporting", "cryptomining incident response",
17 "mining risk detection", "xmrig", "kdevtmpfsi", "kinsing", "sysrv",
18 "minerd", "Security Center", "ECS high CPU mining"
19---
20
21# Mining Attack Diagnosis (Read-Only)
22
23## Absolute Rules
24
251. **CRITICAL — MANDATORY EXECUTION:** You **MUST** run the investigation via the entry script `scripts/mining_investigation.py`. Do **NOT** hand-write bash/python, do **NOT** issue individual `aliyun` CLI calls, do **NOT** skip any step. If the script fails or times out, **re-run it once** before falling back — never abandon the 6-step SOP. The entry script internally invokes **every** Step 1–4 API (`DescribeSuspEvents`, `DescribeAlarmEventDetail`, `DescribeSuspEventDetail`, `DescribeSecurityStatInfo`, `DescribeFieldStatistics`, `DescribeExposedInstanceList`, `DescribeVulList`) regardless of intermediate results, and auto-retries transient `ServiceUnavailable`/`Throttling`/`InternalError` responses — so you must **not** pre-empt or short-circuit it with ad-hoc calls.
262. **ABSOLUTE PROHIBITION (read-only enforcement):** Under **NO** circumstances may you generate, write, or execute any command/script calling a mutating API (`Update*`/`Delete*`/`Disable*`/`Modify*`/`Create*`/`Rotate*`/`Set*`/`Operate*`) — e.g. `OperateSuspiciousTargetBatch`, `ModifySecurityGroupRule`, `DeleteInstance`. This includes scripts "for the user to run manually". If the user asks to quarantine/kill/isolate, only output the manual remediation workflow and declare this skill is read-only.
273. **MANDATORY OUTPUT FORMAT:** When mining is confirmed, the report **MUST** start with the URGENT banner (see Report Output section); the Conclusion section **MUST** include the 4-phase remediation workflow verbatim. Partial output is forbidden.
284. **EXECUTION RULE FOR ERRORS:** On any API error, log `[WARN] <error>` to stderr and continue to the next step — never silently skip. On `Forbidden`/`NoPermission`, record the missing permission and continue. On empty results, set fields to N/A and proceed. On transient errors (`ServiceUnavailable`/`Throttling`/`InternalError`), the entry script retries automatically — do not conclude "service down" from a single failed call.
295. **INFORMATION COMPLETENESS (auto-fill first, ask second):** When the user omits the account UID or region but the request intent is clear (e.g. only an API fragment like "describe susp"), do **NOT** stall asking for what can be derived — auto-derive the UID via `sts:GetCallerIdentity` (the entry script does this when `--account` is omitted), use the default region `cn-hangzhou`, **state the derivation explicitly in your reply and in the report metadata** ("account auto-derived via STS"), then run the full investigation. Only ask a brief clarifying question when the request is too ambiguous to determine the product or investigation goal at all. Never fabricate findings in either path.
30
31## Overview
32
33This skill implements a standard 6-step operating procedure for Alibaba Cloud
34cryptomining (cryptojacking) detection and diagnosis. It detects mining alerts
35via Security Center (SAS), extracts Indicators of Compromise (IOCs) from alert
36detail, scopes the affected assets, detects the attack surface (exposed assets
37+ unpatched vulnerabilities) to hypothesize the intrusion entry, assesses risk,
38and generates a prioritized handling/remediation report.
39
40**This skill is strictly read-only — it never performs containment,
41quarantine, process termination, host isolation, or any handling/mutating
42action.** When mining is confirmed it prints a prominent URGENT banner telling
43the operator to remediate manually.
44
45## 6-Step Detection & Diagnosis SOP
46
47```
48Mining Attack Detection & Diagnosis — SAS Public API
49 |
50 v
51 +-----------------------------------------------+
52 | Step 1: Mining Alert Detection |
53 | Action: SAS DescribeSuspEvents |
54 | Filter: mining keywords (xmrig/mining-pool/...) |
55 | Output: mining alerts, affected assets, level |
56 +-----------------------------------------------+
57 |
58 v
59 +-----------------------------------------------+
60 | Step 2: Alert Detail & IOC Extraction |
61 | Action: DescribeAlarmEventDetail / |
62 | DescribeSuspEventDetail |
63 | Output: pool IPs/domains, sample MD5/SHA256, |
64 | malicious process/command indicators |
65 +-----------------------------------------------+
66 |
67 v
68 +-----------------------------------------------+
69 | Step 3: Affected Asset Scope |
70 | Group alerts by asset (uuid/name/IP) |
71 | + DescribeSecurityStatInfo / FieldStatistics |
72 | Output: blast radius, spread assessment |
73 +-----------------------------------------------+
74 |
75 v
76 +-----------------------------------------------+
77 | Step 4: Attack Surface Detection |
78 | Action: DescribeExposedInstanceList + |
79 | DescribeVulList (asap) |
80 | Output: likely intrusion entry vector |
81 +-----------------------------------------------+
82 |
83 v
84 +-----------------------------------------------+
85 | Step 5: Risk Assessment |
86 | Severity, handled status, spread, entry |
87 +-----------------------------------------------+
88 |
89 v
90 +-----------------------------------------------+
91 | Step 6: Handling & Remediation Report |
92 | IOC table + affected assets + attack surface |
93 | + P0-P3 prioritized remediation + conclusion |
94 | Read-only; URGENT banner if mining confirmed |
95 +-----------------------------------------------+
96```
97
98## Intent Routing
99
100| User Intent | Action |
101|-------------|--------|
102| Step 1: Detect mining alerts | Read [references/module1_alert_detection.md](references/module1_alert_detection.md) |
103| Step 2: Extract IOCs from an alert | Read [references/module2_alert_detail_ioc.md](references/module2_alert_detail_ioc.md) |
104| Step 3: Scope affected assets | Read [references/module3_affected_assets.md](references/module3_affected_assets.md) |
105| Step 4: Detect attack surface / entry vector | Read [references/module4_attack_surface.md](references/module4_attack_surface.md) |
106| Step 6: Remediation guidance | Read [references/module5_remediation_best_practices.md](references/module5_remediation_best_practices.md) |
107| Mining keyword / IOC reference | Read [references/mining_indicators.md](references/mining_indicators.md) |
108| End-to-end runtime flow | Read [references/detection_flow.md](references/detection_flow.md) |
109
110## Prerequisites
111
1121. **aliyun CLI 3.x** — required for API access:
113 ```bash
114 brew install aliyun-cli # macOS; see https://help.aliyun.com/document_detail/121541.html
115 aliyun configure # stored in ~/.aliyun/config.json
116 ```
1172. **Credentials** — read-only Security Center (SAS) permissions for the
118 Step 1–4 APIs listed in Absolute Rule #1. This skill is strictly read-only:
119 it needs no write/mutating permissions and never quarantines, isolates, or
120 terminates anything. Full permission list:
121 [references/ram-policies.md](references/ram-policies.md).
1223. **Python 3.9+** — standard library only, no external dependencies.
123
124## Authentication
125
126Credentials are resolved automatically from the aliyun CLI profile
127(`~/.aliyun/config.json`). The scripts never handle or print secrets.
128
129```bash
130# Run the investigation
131python scripts/mining_investigation.py --account <UID>
132
133# Select a specific profile
134python scripts/mining_investigation.py --account <UID> --profile prod
135```
136
137## CLI Options
138
139All scripts support `--help`. Common parameters:
140
141- `--account <UID>` — Alibaba Cloud account UID (optional; auto-derived, report label only)
142- `--days <N>` — Lookback window in days (default 30)
143- `--region <REGION>` — Alibaba Cloud region (default: cn-hangzhou)
144- `--format json|markdown` — Report format
145- `--output <path>` — Output file (default: `output/mining_report.md`)
146
147Additional pass-through options: `--dealed Y|N|all`, `--profile <name>`
148(see [references/detection_flow.md](references/detection_flow.md)).
149
150## Observability
151
152All API calls made by this skill include a `User-Agent` header for
153platform-level tracing:
154
155```
156--user-agent AlibabaCloud-Agent-Skills/alibabacloud-mining-attack-diagnosis/{session-id}
157```
158
159A `session-id` is a 32-character hex string auto-generated per invocation and
160attached to every request in the same investigation run; it is logged to
161stderr at the start of execution and included in the report metadata.
162
163## Report Output
164
165> **MANDATORY OUTPUT FORMAT:** The report **MUST** follow this structure exactly. When mining is confirmed, the URGENT banner **MUST** appear at the top. The Conclusion **MUST** include the full 4-phase remediation workflow (Phase 1: Preserve & Access → Phase 2: Eradicate & Isolate → Phase 3: Harden → Phase 4: Verify & Recover). Partial or truncated output is forbidden.
166
167Step 6 produces a report with:
168
1691. **Metadata & Severity** — investigation time, account, window, overall severity
1702. **URGENT banner** — shown only when mining is confirmed (read-only reminder)
1713. **Step 1 — Mining Alerts** — table of matched alerts (level, event, asset, IP, keywords)
1724. **Step 2 — IOC table** — mining-pool IPs/domains, sample MD5/SHA256, process/command indicators
1735. **Step 3 — Affected Assets** — per-asset alert counts and event names
1746. **Step 4 — Attack Surface** — exposed asset count + unpatched vulnerability count
1757. **Step 5 — Risk Analysis** — findings (spread, connectivity, entry vector)
1768. **Conclusion** — Overview, Intrusion Path & Entry Vector, P0–P3 Remediation
177
178## No-Fabrication Rule
179
180If Security Center returns no mining-matching alerts, report truthfully that no
181mining compromise is indicated for the window. Never invent alerts, affected
182assets, or IOCs to "complete" a conclusion, and do not print the URGENT banner
183in that case.
184
185## Sensitive-Data Handling
186
187- **IOCs are preserved (never masked)** — mining-pool IPs/domains, sample
188 hashes, and malicious process names carry forensic value and are needed for
189 containment.
190- **Account-scoped identifiers are masked** — account UID and asset uuid are
191 masked in all output via `_cli.mask_sensitive()`. Set `MINING_NO_MASK=1` to
192 emit raw values.
193- The AccessKey Secret / security token are used only for signing and are never
194 printed or logged.
195
196## Available Scripts
197
198| Script | Type | Description |
199|--------|------|-------------|
200| `scripts/mining_investigation.py` | Entry | 6-step detection & diagnosis orchestrator |
201
202Standalone step scripts (`scripts/query_*.py`) and internal modules
203(`scripts/_cli.py`, `scripts/_constants.py`) are invoked by the entry script;
204do not run them directly.
205
206## Error Handling
207
208On any error, log `[WARN] <error>` to stderr and **continue** to the next step
209— never silently skip a step or abort the investigation. Transient errors
210(`ServiceUnavailable`/`Throttling`/`InternalError`) are auto-retried by the
211entry script; permission/parameter errors degrade gracefully with the failed
212step recorded in the report. Full error table: see Absolute Rule #4 and
213[references/detection_flow.md](references/detection_flow.md).