Volatile Cyber Defense: A self-destructing security middleware for Python web applications
Project description
vcd-python
Volatile Cyber Defense (VCD) の Python 実装です。攻撃を検知したらプロセスが即座に証拠を保全して自壊し、クリーンな状態で回復するセキュリティミドルウェアです。
論文: DOI: 10.5281/zenodo.19648507
インストール
pip install vcd-python
Flask と使用する場合:
pip install vcd-python[flask]
クイックスタート
from flask import Flask
from vcd import VCDMiddleware
app = Flask(__name__)
@app.route("/")
def index():
return "Hello, World!"
# デフォルト:検知 → 証拠保全のみ(自壊・ブロックなし)
app.wsgi_app = VCDMiddleware(app.wsgi_app)
自壊を有効化する場合(本番推奨):
app.wsgi_app = VCDMiddleware(
app.wsgi_app,
self_destruct=True,
forensics_path="/var/vcd/forensics.jsonl",
)
⚠️ 警告
self_destruct=True を設定すると、攻撃検知時にプロセスが os._exit(1) で即時終了します。
supervisord・systemd・Kubernetes 等の自動再起動機構が必須です。
詳細は SECURITY.md を参照してください。
VCD の動作フロー
このプロダクトのコアは 証拠保全 と 自壊 です。
攻撃リクエスト
↓
検知(XSS・SQLi 等)
↓
証拠書き出し(forensics.jsonl へ) ← コア
↓
自壊(os._exit(1)) ← コア
↓
supervisord 等による自動再起動
IP ブロック機能(オプション)
デフォルトでは無効です。block=True を指定すると、攻撃元 IP を記録し、再起動後も同一 IP を 403 で遮断します。
app.wsgi_app = VCDMiddleware(
app.wsgi_app,
self_destruct=True,
forensics_path="/var/vcd/forensics.jsonl",
block=True,
blocklist_path="/var/vcd/blocklist.txt",
)
(再起動後)
↓
ブロックリスト読み込み → 同一 IP を 403 で遮断
設定オプション
| パラメータ | デフォルト | 説明 |
|---|---|---|
detectors |
[XSSDetector(), SQLiDetector()] |
使用する検知器のリスト |
self_destruct |
False |
自壊の有効化 |
forensics_path |
/var/vcd/forensics.jsonl |
証拠ファイルのパス |
block |
False |
IP ブロック機能の有効化 |
blocklist_path |
/var/vcd/blocklist.txt |
ブロックリストのパス(block=True 時に使用) |
on_detect |
None |
検知時のコールバック関数 |
カスタム検知器
from vcd import VCDMiddleware
from vcd.detector import BaseDetector
class MyDetector(BaseDetector):
def detect(self, request):
if "malicious" in request.get_data(as_text=True):
return True, "custom pattern detected"
return False, ""
app.wsgi_app = VCDMiddleware(
app.wsgi_app,
detectors=[MyDetector()],
self_destruct=True,
)
ライセンス
MIT License — 詳細は LICENSE を参照してください。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vcd_python-0.1.0.tar.gz.
File metadata
- Download URL: vcd_python-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9284bd355fcb0c5bff0b8ca6086f68de5267e35be0495ad6639afb64b6c68b75
|
|
| MD5 |
6d9e9b4fb9924c84857aa925dd661c66
|
|
| BLAKE2b-256 |
02a08cd6778f438b95769995e5fb9690ba44c89315ac7927b688c0e78b3a52f1
|
File details
Details for the file vcd_python-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vcd_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dd542e8a7c783cc1be817b525324bd999ffe588ea59cd8f1d9635a1b278ff54
|
|
| MD5 |
52bcfee1514837fd8c4942b42c7e3c2f
|
|
| BLAKE2b-256 |
28ac670f131e32002dce5684a788f62f7e7f3b812201ed0cd07f46a66a068db1
|