This project provides an automated static analysis framework for files using [Strelka] (https://github.com/target/strelka) and URLs and multi-layer security heuristics. It queues file analysis tasks with Celery, stores results in a PostgreSQL database, and exposes FastAPI endpoints for uploading files, submitting URLs, and retrieving results.
- File Analysis: Scan uploaded files with Strelka, ClamAV, YARA, entropy checks, and IOC extraction.
- URL Analysis: Multi-layer URL inspection including structure, domain WHOIS/DNS, HTML content, and threat intelligence.
- Deduplication: Previously analyzed files return results immediately (based on SHA256).
- URL Deduplication: Previously analyzed URLs return results immediately (based on URL hash).
- Queued Analysis: Heavy files are processed asynchronously using Celery and RabbitMQ.
- Scoring Logic: Assigns a maliciousness score, verdict, and specific reasons based on analysis results.
- Explainable Verdicts: Every triggered indicator is returned with a human-readable explanation.
Before setting up the main application, you must install and configure Strelka and its dependencies.
Install necessary system tools and Docker:
sudo apt install -y wget git docker.io docker-compose-v2 golang jq
# Enable Docker and add current user to the docker group
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
# Note: You may need to log out and log back in for group changes to take effect.Clone the Strelka repository, start the backend containers, and build the oneshot client:
git clone [https://github.com/target/strelka.git](https://github.com/target/strelka.git)
cd strelka
# Start Strelka backend (Headless)
sudo docker compose -f build/docker-compose-no-build.yaml up -d
# Build the Go CLI tool
cd src/go/cmd/strelka-oneshot
go build -o strelka-oneshot
# Move the binary to your project root (adjust path as necessary)
mv strelka-oneshot ../../../../
cd ../../../../Verify Strelka is working by running a test scan:
./strelka-oneshot -f <file path> -l - | jq- Python: 3.12+
- Database: PostgreSQL 15+
- Message Broker: RabbitMQ
- Analysis Engine: Strelka (Headless/Dockerized)
Python Dependencies (listed in requirements.txt):
fastapiuvicornsqlalchemypsycopg2-binary(for PostgreSQL connection)celery[redis]pydanticpython-multipartrequestspython-dotenvpython-whois(WHOIS lookups for URL analysis)beautifulsoup4(HTML content parsing)dnspython(DNS record inspection)tldextract(TLD and domain extraction)validators(URL input validation)httpx(async HTTP client for fetching URLs)
git clone <repo-url>
cd static_analysis
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt-
Install PostgreSQL (Ubuntu):
sudo apt update sudo apt install postgresql postgresql-contrib -y sudo systemctl start postgresql sudo systemctl enable postgresql -
Log in as superuser:
sudo -u postgres psql
-
Create Database and User:
CREATE DATABASE analysis_db; CREATE USER strelka WITH PASSWORD 'password'; ALTER ROLE strelka SET client_encoding TO 'utf8'; ALTER ROLE strelka SET default_transaction_isolation TO 'read committed'; ALTER ROLE strelka SET timezone TO 'UTC'; GRANT ALL PRIVILEGES ON DATABASE analysis_db TO strelka;
-
Initialize Tables: Run the following Python snippet to create the tables using SQLAlchemy:
from db import engine, Base Base.metadata.create_all(bind=engine)
-
Install RabbitMQ:
sudo apt update sudo apt install rabbitmq-server sudo systemctl enable rabbitmq-server sudo systemctl start rabbitmq-server -
Start Celery Worker: Ensure your
tasksmodule is correctly imported to avoid "unregistered task" errors.celery -A celery_app.celery worker --loglevel=info
Start the FastAPI server:
uvicorn app:app --reload --port 8000Go to http http://127.0.0.1:8000/docs and see the endpoints.
Submit a file for static analysis via Strelka.
Example Response (Queued):
{
"message": "File queued for analysis",
"task_id": "4700f44b-bfa2-4fee-9b82-e8d2d71a54b3",
"sha256": "205064af53c802ca95a0f902096c0e1f2684081b73c3f6e4005a1af9f778c6aa"
}Retrieve the file analysis status and report.
Example Response (Success):
{
"task_id": "4700f44b-bfa2-4fee-9b82-e8d2d71a54b3",
"state": "SUCCESS",
"result": {
"score": 0,
"verdict": "benign",
"reasons": ["None"]
}
}Submit a URL for multi-layer security analysis. The analysis is performed synchronously and returns results immediately.
If the same URL was already analyzed before, the cached result is returned immediately from the database.
Request Body:
{
"url": "https://example.com"
}Analysis Pipeline:
- URL Structure Analysis — length, suspicious characters, IP-based URLs, shorteners, TLD, homograph detection
- Domain Intelligence — WHOIS age, registrar, hidden WHOIS, DNS records
- Content Analysis — hidden iframes, obfuscated JS, login forms, phishing keywords, redirect count
- Threat Intelligence — VirusTotal URL and domain lookups
- Risk Scoring — weighted aggregation with explainable verdict
Verdict Thresholds:
| Score | Verdict |
|---|---|
| < 30 | SAFE |
| 30 – 60 | SUSPICIOUS |
| > 60 | MALICIOUS |
Example Response:
{
"url": "http://paypa1-login.tk/verify",
"domain": "paypa1-login.tk",
"score": 85,
"verdict": "MALICIOUS",
"reasons": [
"Suspicious TLD: .tk",
"Possible homograph / look-alike of 'paypal'",
"URL does not use HTTPS",
"Very new domain (registered 5 days ago)",
"Page contains a login/password form (possible phishing)",
"Suspicious keywords: verify your account, urgent"
],
"final_url": "http://paypa1-login.tk/verify",
"http_status": 200,
"redirect_count": 0
}static_analysis/
│
├─ app.py # FastAPI application entry point
├─ file_routes.py # File analysis API endpoints
├─ url_routes.py # URL analysis API endpoint
├─ celery_app.py # Celery configuration
├─ tasks.py # Celery tasks definitions
├─ db.py # SQLAlchemy engine and session setup
├─ model.py # SQLAlchemy models (file + URL analysis results)
├─ utils.py # Shared helper functions (SHA256, VT, DNS, HTML parsing, etc.)
├─ file_scoring.py # File analysis scoring logic
├─ url_scoring.py # URL analysis scoring logic
├─ scoring.py # Compatibility exports for old imports
├─ uploads/ # Directory for temp storage of uploaded files
├─ requirements.txt # Project dependencies
└─ README.md # Documentation