<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
<!-- NERF is a trademark of defconxt. -->
---
name: performing-ghidra-scripting
description: >-
  Develop and execute Ghidra scripts in Java and Python to automate reverse engineering tasks, custom analysis, and vulnerability pattern detection.
domain: cybersecurity
subdomain: reverse-engineering
tags:
  - ghidra
  - scripting
  - automation
  - java
  - python
version: "1.0"
author: defconxt
license: AGPL-3.0
metadata:
  mitre-attack: ["T1027"]
  cwe: ["CWE-506"]
  tools: ["Ghidra", "ghidra-bridge", "pyhidra", "Ghidrathon"]
---

# Performing Ghidra Scripting

## Overview

Develop and execute Ghidra scripts in Java and Python to automate reverse engineering tasks, custom analysis, and vulnerability pattern detection.

## Prerequisites

| Tool / Requirement | Details |
|---|---|
| `Ghidra` | Security tooling |
| `ghidra-bridge` | Security tooling |
| `pyhidra` | Security tooling |
| `Ghidrathon` | Security tooling |
| Isolated lab environment for testing | Environment requirement |
| Authorization and signed Rules of Engagement (RoE) | Environment requirement |
| Relevant target samples or systems acquired through authorized channels | Environment requirement |

## Quick Reference

```python
# Ghidra Python script (run inside Ghidra)
from ghidra.program.model.symbol import SourceType

# List all functions
fm = currentProgram.getFunctionManager()
for func in fm.getFunctions(True):
    print(f"{func.getName()} @ {func.getEntryPoint()}")

# Find cross-references to function
refs = getReferencesTo(toAddr(0x00401000))
for ref in refs:
    print(f"  XRef from: {ref.getFromAddress()}")
```

## Workflow

### Step 1: Preparation and Reconnaissance

```bash
# Identify target and gather initial intelligence
file ./target_sample
ghidra --version 2>/dev/null || echo "Install Ghidra"

# Set up working directory
mkdir -p /tmp/performing-ghidra-scripting/{output,logs,artifacts}
```

### Step 2: Primary Analysis

```bash
# Execute primary analysis with Ghidra
# Refer to Quick Reference above for detailed commands
echo "[*] Running Performing Ghidra Scripting with Ghidra..."

# Log all operations
script -q /tmp/performing-ghidra-scripting/logs/session.log
```

### Step 3: Deep Investigation

```bash
# Apply ghidra-bridge for secondary analysis
echo "[*] Deep investigation with ghidra-bridge..."

# Cross-reference findings
diff /tmp/performing-ghidra-scripting/output/primary.json /tmp/performing-ghidra-scripting/output/secondary.json
```

### Step 4: Documentation and Reporting

```bash
# Generate structured findings report
cat <<'EOF' > /tmp/performing-ghidra-scripting/output/report.json
{
  "technique": "performing-ghidra-scripting",
  "domain": "reverse-engineering",
  "tools_used": ["Ghidra", "ghidra-bridge"],
  "findings": [],
  "recommendations": []
}
EOF
```

## Detection

```yaml
title: Ghidra Scripting Detection
id: e1271e54-70a2-4822-ac61-529ca24b1f98
status: experimental
description: Detects suspicious activity related to performing ghidra scripting techniques in reverse engineering context
logsource:
  category: process_creation
  product: windows
detection:
  selection:
    CommandLine: "*performing*ghidra*"
  condition: selection
level: medium
tags:
  - attack.t1027
  - attack.defense_evasion
falsepositives:
  - Malware analysis sandbox performing automated binary inspection
```


**Detection Opportunities**

| Indicator | Source | Detection Logic |
|---|---|---|
| Ghidra Scripting Detection | windows/process_creation | Sigma rule (medium) |
| ATT&CK Coverage | MITRE ATT&CK | T1027 |

## Verification

- [ ] Environment and tools verified and operational
- [ ] Target samples acquired through authorized channels
- [ ] Primary analysis completed with findings documented
- [ ] Secondary validation performed with independent tooling
- [ ] All artifacts preserved in structured output directory
- [ ] Detection opportunities documented for blue team

## References

- [MITRE ATT&CK T1027](https://attack.mitre.org/techniques/T1027) — Related technique
- [Ghidra Documentation](https://ghidra.org/) — Primary tooling
- [ghidra-bridge Reference](https://ghidra-bridge.org/) — Secondary tooling
