GitHub Actions
在需要扫描的仓库中创建 .github/workflows/malware-scan.yml:
name: Malware scan
on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0'
permissions:
contents: read
security-events: write
jobs:
scan:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Scan for malware
id: amwscan
uses: marcocesarato/PHP-Antimalware-Scanner@master
with:
path: .
mode: lite
report-format: sarif
ignore-paths: '*/cache/*,*/logs/*'
- name: Upload SARIF report
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.amwscan.outputs.report-path }}
默认扫描使用 Lite 模式。AMWScan 发现安全问题时,作业会失败。即使扫描步骤失败,最后一步仍会把 SARIF 报告上传到 Security > Code scanning。
配置扫描
| 输入 | 默认值 | 用途 |
|---|---|---|
path | . | 要扫描的文件或目录。 |
mode | lite | 选择 full、lite、signatures、exploits 或 functions。 |
report-format | sarif | 写入 html、txt、json 或 sarif。 |
report-path | amwscan-report | 设置报告路径。 |
php-version | 8.3 | 选择 PHP 版本。 |
scan-archives | false | 扫描 ZIP 归档中的条目。 |
scan-all | false | 扫描文件时不按扩展名筛选。 |
ignore-paths | 空 | 排除以逗号分隔的路径或通配符模式。 |
disable-checksum | false | 禁用受支持平台的完整性检查。 |
disable-definitions-update | true | 跳过远程 Maltrail 定义更新。 |
fail-on-findings | true | 发现问题时返回代码 1。 |
该 Action 提供 exit-code 和 report-path 输出。设置 fail-on-findings: false 可收集结果而不让作业失败。扫描器或源错误仍会返回代码 2。
报告可能包含本地路径和代码片段。请仅向负责检查安全结果的人员开放归档访问权限,并限制保留时间。