Skip to content

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SentinelGraph MVP

Android Banking Trojan Detector — Reverse Engineering · Graph AI/ML · Swarm Intelligence · GenAI

Drag in an APK → get a risk score, verdict, AI-generated threat narrative, and full evidence breakdown in seconds.

Team Optional — IIIT Kottayam | CyberShield Hackathon 2026

All code is inside the sentinelgraph/ folder.


Four core pillars

Pillar What it means in SentinelGraph
Reverse Engineering Androguard disassembles the APK — extracts the function call graph (FCG), AndroidManifest, DEX bytecode, and all string constants without executing the app
Graph AI / ML The behaviour graph is fed into a 2-layer multi-head Graph Attention Network (GAT). Nodes are methods, permissions, APIs, components; edges are call/invocation relationships. The GAT learns which subgraphs are malicious.
Swarm Intelligence 4 specialised agents (Smali, Manifest, Network, Crypto) run in parallel (Round 1), publish typed signals to a shared AgentBus, then react to each other's findings in a targeted second pass (Round 2) — a deterministic swarm coordination protocol
Generative AI After analysis, a free-tier LLM (Llama 3 via OpenRouter or NVIDIA NIM) generates a concise 3–5 sentence threat intelligence narrative for SOC analysts, combining verdict, technique chain, and a recommended action

What it does

SentinelGraph reverse-engineers an Android APK, builds a behaviour graph from it, and runs a Graph Attention Network to decide if it is BENIGN, SUSPICIOUS, or MALICIOUS.

Every verdict comes with:

  • A 0–100 risk score
  • AI-generated threat intelligence summary (GenAI narrative, optional)
  • Flagged permissions and sensitive API call sites
  • Network / C2 indicators
  • Crypto and obfuscation findings
  • A plain-English evidence summary
  • Swarm signals from the 2-round agent coordination
  • Recommended SOC actions

Requirements

  • Python 3.10
  • Node.js 18+
  • uv — pip install uv

Setup

git clone https://github.com/nidheerakesh/Cybershield.git
cd Cybershield/sentinelgraph   # all code lives here

Backend

# Create venv with Python 3.10
uv venv --python 3.10 .venv
source .venv/bin/activate

# Install dependencies (CPU-only PyTorch)
uv pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu
uv pip install torch_geometric==2.5.3
uv pip install -r backend/requirements.txt

Frontend

cd frontend
npm install
cd ..

Running the system

cd sentinelgraph
bash start.sh

That's it. Both the API and the frontend start together.

Enabling GenAI threat summaries (optional)

The AI narrative card is powered by a free LLM via OpenRouter or NVIDIA NIM. It is fully optional — the rest of the system works without it.

# Inside sentinelgraph/
cp .env.example .env

Then open .env and set one of:

# Option 1 — OpenRouter (free tier, sign up at openrouter.ai)
OPENROUTER_API_KEY=sk-or-...

# Option 2 — NVIDIA NIM (free tier at build.nvidia.com)
NVIDIA_API_KEY=nvapi-...

Restart bash start.sh. After each APK analysis, a purple GenAI card appears at the top of the evidence panel with a 3–5 sentence threat narrative.

If neither key is set, the ai_threat_summary field is an empty string and the card is hidden — everything else works normally.

Starting SentinelGraph...

  API    →  http://localhost:8000
  UI     →  http://localhost:5173

  Press Ctrl+C to stop both.

Open http://localhost:5173 in your browser. Press Ctrl+C to stop everything.


Analysing an APK

  1. Open http://localhost:5173
  2. Drag and drop any .apk file into the upload zone (or click to browse)
  3. Wait 5–30 seconds depending on APK size
  4. The dashboard shows:
    • Circular risk gauge (0–100)
    • Colour-coded verdict badge (green = BENIGN, orange = SUSPICIOUS, red = MALICIOUS)
    • GenAI threat intelligence card (if API key is configured)
    • Circular risk gauge (0–100)
    • Colour-coded verdict badge (green = BENIGN, orange = SUSPICIOUS, red = MALICIOUS)
    • Evidence accordion: permissions, API calls, network indicators, crypto findings
    • Swarm signals panel (inter-agent findings from the 2-round analysis)
    • Recommended actions

Via API directly

curl -X POST http://localhost:8000/analyse \
  -F "file=@/path/to/sample.apk"

Retrieve a stored report:

curl http://localhost:8000/report/<report_id>

Health check:

curl http://localhost:8000/health
# {"status":"ok","model_loaded":false}

Training the GAT model (optional)

Without a trained model the system uses rule-based TTP scoring only (GAT posterior defaults to 0.5). Training improves accuracy significantly.

Step 1 — Get APKs

Put malware APKs in data/apks/malware/ and benign APKs in data/apks/benign/.

Quick option — clone a public malware dataset:

git clone https://github.com/ashishb/android-malware data/apks/malware_repo
find data/apks/malware_repo -name "*.apk" | xargs -I{} cp {} data/apks/malware/

For benign APKs, download any clean apps from APKMirror or F-Droid and place them in data/apks/benign/.

Step 2 — Preprocess APKs into graphs

source .venv/bin/activate
PYTHONPATH=. python -m backend.data.dataset \
    --malware-dir data/apks/malware/ \
    --benign-dir  data/apks/benign/ \
    --out-dir     data/processed/ \
    --workers 4

Each APK takes 5–30 seconds. Output is one .pt graph file per APK in data/processed/.

Step 3 — Train

PYTHONPATH=. python -m backend.model.train \
    --data-dir data/processed/ \
    --epochs 50

Prints ROC-AUC, F1 macro, and Precision@high-risk at the end.
Saves checkpoint to models/gat_checkpoint.pt.

Step 4 — Restart the API

The API loads the model on startup. Restart uvicorn after training:

PYTHONPATH=. uvicorn backend.api.main:app --reload --port 8000
# INFO: Model loaded from models/gat_checkpoint.pt

Project structure

sentinelgraph/
├── backend/
│   ├── ingestion/apk_parser.py      # Androguard: FCG + manifest + APIs
│   ├── agents/
│   │   ├── bus.py                   # Inter-agent signal bus (AgentBus)
│   │   ├── manifest_agent.py        # Permissions, components, accessibility
│   │   ├── smali_agent.py           # Sensitive APIs, opcodes, reflection
│   │   ├── network_agent.py         # URLs, IPs, C2 patterns, Tor
│   │   └── crypto_agent.py          # Ciphers, packers, string decryption
│   ├── coordinator/coordinator.py   # 2-round parallel dispatch + contradiction detection
│   ├── graph/
│   │   ├── builder.py               # NetworkX heterogeneous behaviour graph
│   │   ├── features.py              # 60-dim node feature vectors
│   │   └── converter.py             # NetworkX → PyTorch Geometric Data
│   ├── model/
│   │   ├── gat.py                   # 2-layer multi-head GAT
│   │   ├── train.py                 # Training script
│   │   └── metrics.py               # ROC-AUC, F1, Precision@high-risk
│   ├── genai/summarizer.py          # LLM threat narrative (OpenRouter / NVIDIA NIM)
│   ├── scoring/scorer.py            # R(s) = 100·σ(α·logit p + β·S)
│   ├── reporting/reporter.py        # JSON report generator
│   ├── data/
│   │   ├── sensitive_apis.py        # 29 curated high-risk Android APIs
│   │   └── dataset.py               # Batch APK preprocessor
│   └── api/main.py                  # FastAPI: POST /analyse, GET /report/{id}
├── frontend/
│   └── src/
│       ├── App.jsx
│       └── components/
│           ├── UploadAPK.jsx        # Drag-and-drop upload
│           ├── RiskDashboard.jsx    # SVG risk gauge + verdict badge
│           └── EvidencePanel.jsx    # Evidence accordion + swarm signals
├── models/                          # gat_checkpoint.pt saved here after training
├── .env.example                     # Template — copy to .env and add API key for GenAI
├── data/
│   ├── apks/malware/                # Input malware APKs
│   ├── apks/benign/                 # Input benign APKs
│   └── processed/                   # Preprocessed .pt graph files
└── scripts/setup_data.md           # Dataset acquisition guide

How the pipeline works

APK file
  ↓
[L0] Androguard — reverse-engineer: FCG, manifest, DEX, strings
  ↓
[L1] Coordinator — Round 1: dispatch 4 agents in parallel
  ↓
[L2] Agents run independently:
     ManifestAgent  → permissions, components, accessibility declarations
     SmaliAgent     → sensitive API call sites, opcode histogram, reflection
     NetworkAgent   → URLs, IPs, onion addresses, C2 patterns
     CryptoAgent    → ciphers, packers, string-decryption routines
  ↓
  AgentBus — agents publish typed signals (8 signal types)
  ↓
[L1] Coordinator — Round 2: agents react to each other's signals
     (e.g. CryptoAgent digs deeper when SmaliAgent found reflection)
  ↓
[L3] Behaviour Graph — heterogeneous NetworkX graph
     Nodes: Method, SensitiveAPI, Permission, Component, Endpoint
     Edges: CALLS, INVOKES, GUARDED_BY, DECLARES, REACHES
     → sensitive subgraph extracted (entry points → sensitive-API sinks)
  ↓
[L5] GAT — 2-layer multi-head Graph Attention Network
     → malicious posterior p(s)  (0.5 if no trained model)
  ↓
[L5] Risk Scorer — R(s) = 100 · σ(3.0 · logit p(s) + 2.0 · S(s))
     → BENIGN (R < 30) / SUSPICIOUS (30 ≤ R < 70) / MALICIOUS (R ≥ 70)
  ↓
[L6] Reporter — structured JSON report (verdict, risk_score, flagged_permissions,
     top_suspicious_apis, network_indicators, crypto_findings, swarm_signals, …)
  ↓
[L7] GenAI Summarizer — Llama 3 via OpenRouter / NVIDIA NIM
     → ai_threat_summary: "3–5 sentence SOC narrative"  (empty string if no key)
  ↓
React SOC Dashboard

API reference

Endpoint Method Description
/analyse POST Upload APK (multipart file field), returns full report JSON
/report/{id} GET Retrieve a previously analysed report by UUID
/health GET Returns {status, model_loaded}

Risk score interpretation

Score Verdict Action
0 – 29 BENIGN Archive, monitor
30 – 69 SUSPICIOUS Escalate to human analyst
70 – 100 MALICIOUS Block immediately, push IOCs

Tech stack

Layer Technology
Reverse engineering Androguard 4.1.1
Swarm coordination 4 static agents + AgentBus (8 signal types, 2 rounds)
Graph construction NetworkX 3.3
Graph ML PyTorch 2.3.1 + PyTorch Geometric 2.5.3
GenAI summarization OpenAI-compatible SDK → OpenRouter or NVIDIA NIM (Llama 3, free tier)
Backend FastAPI 0.111.0 + Uvicorn
Frontend React 18 + Vite
Package manager uv (Python 3.10)

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages