> ## Documentation Index
> Fetch the complete documentation index at: https://docs.safedep.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Malware Analysis

> Detect malicious packages in your dependencies using SafeDep Cloud's advanced code analysis capabilities

<Note>Malware analysis is available for free with SafeDep Cloud. See [pricing](https://safedep.io/pricing) for details.</Note>

Analyze open source packages for malicious code using [Vet](https://github.com/safedep/vet) with SafeDep Cloud's hosted analysis service. The service scans package artifacts from public package registries.

## Supported Ecosystems

<CardGroup cols={3}>
  <Card title="npm" icon="node-js">
    JavaScript and TypeScript packages
  </Card>

  <Card title="PyPI" icon="python">
    Python packages and wheels
  </Card>

  <Card title="Go Modules" icon="golang">
    Go language modules
  </Card>

  <Card title="RubyGems" icon="gem">
    Ruby packages and gems
  </Card>

  <Card title="GitHub Actions" icon="github">
    GitHub Action workflows
  </Card>

  <Card title="VS Code Extensions" icon="visual-studio-code">
    Visual Studio Code extensions
  </Card>
</CardGroup>

## Requirements

<Steps>
  <Step title="Install Vet">
    You must have [Vet](https://github.com/safedep/vet) version `1.9.7` or above installed.
  </Step>

  <Step title="SafeDep Cloud Access">
    You must be onboarded to SafeDep Cloud with a Tenant Domain and API Key. See [SafeDep Cloud Quickstart](/governance/cloud/quickstart) for onboarding instructions.
  </Step>
</Steps>

## Repository Scanning

### Basic Malware Scanning

Enable malware analysis with the `--malware` flag:

```bash theme={null}
vet scan -D /path/to/code --malware
```

<Note>
  `vet` waits for a timeout period for malware analysis to complete. This works well for pull requests and CI/CD pipelines where the number of changed packages is small.
</Note>

### Timeout Configuration

Adjust analysis timeout for different scenarios:

```bash theme={null}
# Quick scan with shorter timeout
vet scan -D . --malware --malware-analysis-timeout 5m

# Thorough scan with longer timeout
vet scan -D . --malware --malware-analysis-timeout 15m
```

### Specific Manifest Scanning

Scan individual package manifest files:

```bash theme={null}
# npm projects
vet scan -M package-lock.json --malware

# Python projects
vet scan -M requirements.txt --malware

# Go projects
vet scan -M go.mod --malware

# Ruby projects
vet scan -M Gemfile.lock --malware
```

### PURL-Based Scanning

Scan specific packages using Package URLs:

```bash theme={null}
vet scan --purl pkg:npm/llm-oracle@1.0.2 --malware
```

<img src="https://mintcdn.com/safedep/A0tSXvZ_XcagO9QB/images/vet-malysis-llm-oracle.png?fit=max&auto=format&n=A0tSXvZ_XcagO9QB&q=85&s=d82d51432119f69fb9fb2636ef3dfe82" alt="Malware analysis results for llm-oracle package" width="1434" height="384" data-path="images/vet-malysis-llm-oracle.png" />

## Visual Studio Code Extensions

Scan locally installed VS Code extensions:

```bash theme={null}
vet scan --vsx --malware
```

<Warning>
  VS Code extension scanning is supported only for local developer machines, not in CI/CD environments.
</Warning>

## GitHub Actions Integration

### vet-action Cloud Mode

Enable malicious package protection in GitHub repositories using [vet-action](https://github.com/safedep/vet-action):

```yaml theme={null}
name: Malware Protection
on:
  pull_request:
    branches: [ main ]

jobs:
  malware-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Run malware analysis
        uses: safedep/vet-action@v1
        with:
          cloud: true
          cloud-key: ${{ secrets.SAFEDEP_CLOUD_API_KEY }}
          cloud-tenant: ${{ secrets.SAFEDEP_CLOUD_TENANT_DOMAIN }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

### Pull Request Integration

When enabled, Vet scans changed packages for malware and provides results directly in pull requests:

<img src="https://mintcdn.com/safedep/A0tSXvZ_XcagO9QB/images/vet-action-malysis-1.png?fit=max&auto=format&n=A0tSXvZ_XcagO9QB&q=85&s=65d9f9ce9240be1b2cc35b7c04871a2c" alt="vet malware analysis in GitHub PR" width="1854" height="1598" data-path="images/vet-action-malysis-1.png" />

Expand comments to view detailed package analysis results:

<img src="https://mintcdn.com/safedep/A0tSXvZ_XcagO9QB/images/vet-action-malysis-2.png?fit=max&auto=format&n=A0tSXvZ_XcagO9QB&q=85&s=19a909b404c9eaf7fb33e8f021714f60" alt="Detailed malware analysis results in PR" width="1682" height="850" data-path="images/vet-action-malysis-2.png" />

## Package Inspection

### Enable Experimental Feature

Package inspection is currently experimental. Enable it with:

```bash theme={null}
export VET_ENABLE_PACKAGE_INSPECT_COMMAND=true
```

### Inspect Single Packages

Perform detailed analysis of individual packages:

```bash theme={null}
vet inspect malware --purl pkg:npm/llm-oracle@1.0.2
```

<Note>
  Package analysis is performed asynchronously. Scanning usually takes a few minutes but may take longer depending on the analysis queue.
</Note>

### Analysis Results

On completion, Vet shows the analysis status and classification:

<img src="https://mintcdn.com/safedep/A0tSXvZ_XcagO9QB/images/llm-oracle-npm-malysis.png?fit=max&auto=format&n=A0tSXvZ_XcagO9QB&q=85&s=c244eb8c4bc08532020e8cb0fd757b22" alt="Malware scan result showing package classification" width="1550" height="626" data-path="images/llm-oracle-npm-malysis.png" />

### Export Results

Export analysis results as JSON:

```bash theme={null}
vet inspect malware \
  --purl pkg:npm/llm-oracle@1.0.2 \
  --report-json /tmp/analysis.json
```

## Understanding Results

### Classification Levels

* **SAFE**: No malicious behavior detected
* **SUSPICIOUS**: Potentially risky patterns identified
* **MALICIOUS**: Confirmed malicious behavior found

### Analysis Techniques

<AccordionGroup>
  <Accordion title="Static Analysis">
    * Code pattern analysis
    * Suspicious function detection
    * Obfuscation identification
  </Accordion>

  <Accordion title="Behavioral Analysis">
    * Network communication patterns
    * File system access patterns
    * Process execution analysis
  </Accordion>

  <Accordion title="Metadata Analysis">
    * Package metadata anomalies
    * Publisher reputation analysis
    * Distribution pattern analysis
  </Accordion>
</AccordionGroup>

## CI/CD Integration Examples

### GitLab CI

```yaml theme={null}
stages:
  - security

malware-scan:
  stage: security
  image: ghcr.io/safedep/vet:latest
  script:
    - vet scan -D . --malware --report-json malware-report.json
  artifacts:
    reports:
      security: malware-report.json
  variables:
    SAFEDEP_API_KEY: $SAFEDEP_API_KEY
    SAFEDEP_TENANT_ID: $SAFEDEP_TENANT_ID
```

### Jenkins Pipeline

```groovy theme={null}
pipeline {
    agent any
    
    environment {
        SAFEDEP_API_KEY = credentials('safedep-api-key')
        SAFEDEP_TENANT_ID = credentials('safedep-tenant-id')
    }
    
    stages {
        stage('Malware Scan') {
            steps {
                sh 'vet scan -D . --malware --report-json malware-results.json'
                archiveArtifacts artifacts: 'malware-results.json'
                publishTestResults testResultsPattern: 'malware-results.json'
            }
        }
    }
}
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Analysis times out frequently">
    * Increase the timeout with `--malware-analysis-timeout`
    * Scan smaller package sets
    * Check network connectivity to SafeDep Cloud
  </Accordion>

  <Accordion title="Authentication errors">
    * Verify your API key has malware analysis permissions
    * Check your tenant configuration
    * Ensure you are using Vet v1.9.7 or later
  </Accordion>

  <Accordion title="Legitimate packages are flagged">
    * Review the analysis details
    * Contact SafeDep support with the package details
    * Use exceptions management for temporary overrides
  </Accordion>
</AccordionGroup>

<CardGroup cols={2}>
  <Card title="vet-action Documentation" icon="github" href="https://github.com/safedep/vet-action?tab=readme-ov-file#cloud-mode">
    Complete GitHub Actions integration guide
  </Card>

  <Card title="SafeDep Cloud Setup" icon="cloud" href="/governance/cloud/quickstart">
    Get started with SafeDep Cloud for malware analysis
  </Card>

  <Card title="Package Inspection Guide" icon="magnifying-glass" href="https://github.com/safedep/vet#package-inspection">
    Learn more about experimental package inspection features
  </Card>

  <Card title="Report Issues" icon="bug" href="https://github.com/safedep/vet/issues">
    Report bugs or request features for malware analysis
  </Card>
</CardGroup>
