abhinav-mittal33/bling-blue-team

GitHub: abhinav-mittal33/bling-blue-team

一个用于银行交易后取证欺诈检测的混合流水线系统,结合规则、图谱和机器学习来识别可疑资金流向并生成证据。

Stars: 0 | Forks: 0

# 🔵 BLING 蓝队 ### 取证欺诈检测引擎 — 印度联合银行 [![Python](https://img.shields.io/badge/Python-3.11-3776AB?style=flat-square&logo=python&logoColor=white)](https://python.org) [![FastAPI](https://img.shields.io/badge/FastAPI-0.111-009688?style=flat-square&logo=fastapi&logoColor=white)](https://fastapi.tiangolo.com) [![XGBoost](https://img.shields.io/badge/XGBoost-2.x-FF6600?style=flat-square)](https://xgboost.readthedocs.io) [![PostgreSQL](https://img.shields.io/badge/PostgreSQL-15-336791?style=flat-square&logo=postgresql&logoColor=white)](https://postgresql.org) [![Redis](https://img.shields.io/badge/Redis-7.x-DC382D?style=flat-square&logo=redis&logoColor=white)](https://redis.io) [![测试](https://img.shields.io/badge/Tests-23%20passing-brightgreen?style=flat-square)](tests/)
## 这是什么 交易后取证欺诈检测引擎。资金已经转移。此系统对每一笔已结算的交易进行评分,在发现可疑情况时重建资金流向,并将带有 SHAP 解释的证据包连同 STR 报告草稿提交给人类调查人员。 ## 架构 ### 三级检测流水线 ``` flowchart TD A[Graph Engine\nPOST /api/v1/score] --> B{Tier 1\nFast Rules\n5ms} B -->|78pct FAST_CLEAN| C[PASS\nscore=0.05] B -->|22pct UNCERTAIN\nor SUSPICIOUS| D{Tier 2\nHard Graph Gates\n15ms} D -->|Gate fires| E[REVIEW\nscore=1.0] D -->|UNCERTAIN clear| F[LOG\nscore=0.10] D -->|SUSPICIOUS clear| G{Tier 3\nXGBoost\n30ms} G --> H[Indian Context\nAdjustment] H --> I{Threshold} I -->|lt 0.30| J[PASS] I -->|0.30-0.49| K[LOG] I -->|0.50-0.74| L[REVIEW] I -->|ge 0.75| M[HIGH_RISK] L --> N[Alert Created\nCelery: Fund Trail] M --> N E --> N N --> O[GET /alerts/id\nEvidence Package] O --> P[Investigator\nPOST /feedback] P -->|Confirmed fraud| Q[Blockchain + Red Team] P -->|False positive| R[River FTRL\nOnline Update] style A fill:#1a73e8,color:#fff style M fill:#d93025,color:#fff style N fill:#e8710a,color:#fff style C fill:#1e8e3e,color:#fff ``` ### 静态新颖性传感器(隔离森林) ``` flowchart LR A[Every transaction\nafter scoring] --> B{Isolation Forest\n17 structural features} B -->|score ge -0.20\nnormal| C[No action] B -->|score lt -0.20\nanomalous| D[novelty_queue\nDev review] D --> E{Fingerprint\n10+ times\nin 7 days?} E -->|Yes| F[Red Team\nEscalation] E -->|No| G[Batch triage] style D fill:#e8710a,color:#fff style F fill:#d93025,color:#fff ``` ## 5 个硬性图谱门控(第二级) 门控触发时 `score=1.0` 或直接放行。没有部分分数。基于印度储备银行 FATF 层叠检测指南。 | 门控 | 检测目标 | 关键信号 | |------|---------|-----------| | **循环** | 循环资金流向 A→B→C→A(2-8 跳) | `cycle_membership` — 每晚批处理 | | **汇集** | 资金积累无合法流出 | `sink_score = retention × inflow_concentration` | | **二分图** | 7+ 发送方 → 1 收集方(密度 >0.7) | `bipartite_score` | | **现金骤子汇集** | 收款 → ATM 提现 → 数字静默 | 仅 PostgreSQL — 无需设备 ID | | **商户终端** | 通过 POS 终端进行的往返交易 | `merchant_terminal_id` 关联 | 门控触发后,**会按顺序运行 5 个合法性过滤器** — 内部/资金部 → KYC 关系 → 薪资预付 → 所有商户 → 金额 <70%。如果都无法解释:复审,记录门控名称。绝不静默处理。 ## XGBoost 集成模型(第三级) **310,000 个训练样本** — 100K 合成印度原型 + 200K BAF NeurIPS 2022 + 10K 银行风险数据集 | 指标 | 值 | |--------|-------| | AUCPR | 0.69 | | 欺诈平均分 | 0.787 | | 正常平均分 | 0.160 | | `scale_pos_weight` | ~49× (类别比) | 共 59 个特征:35 个图特征(每晚预计算并存入 Redis) + 24 个实时表格特征。
完整 59 特征列表 **图结构 — Redis,每晚更新(35 个特征)** | 特征 | 测量内容 | |---------|---------| | `pagerank_fraud_seeded` | 与已确认欺诈节点的接近度 | | `betweenness_centrality` | 社区间的桥梁? | | `clustering_coefficient` | 邻域连通性 | | `degree_centrality` | 相对于图规模的连接数 | | `community_id` | Louvain 社区 | | `community_fraud_ratio` | 社区中标记为欺诈的百分比 | | `shortest_path_to_fraud` | 到欺诈节点的最小跳数 | | `cycle_membership` | 属于检测到的循环的一部分? | | `sink_score` | 资金流入 vs 流出 | | `bipartite_score` | 多对一扇入密度 | | `fan_out_ratio` | 出度 / 入度 | | `temporal_acceleration` | 交易频率趋势 | | `cash_mule_sink_score` | 收款 + 提现 + 休眠复合得分 | | `bridge_node_probability` | 桥接干净和脏钱? | | `dormancy_reactivation_flag` | 休眠后突然活跃 | | `account_age_days` | 开户天数 | | `kyc_completeness_score` | KYC 文件完整度 0-1 | | `txn_count_30d / 90d / all` | 按窗口计数 | | `avg_txn_amount_30d` | 最近 30 天平均金额 | | `distinct_counterparties_30d` | 最近 30 天唯一收款方 | | `channel_entropy` | 支付渠道多样性 | | `night_txn_ratio` | 晚 10 点至早 5 点的交易比例 | | `weekend_txn_ratio` | 周末交易比例 | | `return_ratio` | 收到后立即转出的比例 | | `amount_zscore` | 与历史记录的偏差 | | `counterparty_novelty` | 新收款方比例 | | `hour_deviation` | 与典型交易小时的偏差 | | `channel_switch` | 该账户的不寻常渠道 | | `amount_series_score` | 低于阈值的结构化信号 | | `burst_score` | 相对于基线的速度峰值 | | `velocity_ratio` | 当前速率 / 历史平均 | | `dormancy_break` | 距上次活动的天数 | | `geography_switch` | 新位置 vs 历史 | **实时表格 — 在评分时计算(24 个特征)** `txn_amount` · `txn_amount_log` · `txn_amount_rounded` · `channel_upi/imps/rtgs/neft` · `hour_of_day` · `day_of_week` · `is_weekend` · `is_night` · `is_festival_period` · `amount_vs_threshold_50000/100000/1000000` · `payee_vpa_age_days` · `txn_count_last_1h/24h/7d` · `txn_volume_last_1h/24h` · `distinct_payees_24h` · `payee_in_alert_log` · `payee_shared_alert_count`
### 印度情境调整(XGBoost 后乘数) | 场景 | 乘数 | 原因 | |----------|-----------|-----| | 节日期间(排灯节/胡里节/开斋节/九夜节) | ×0.70 | 家庭礼物转账合法激增 | | 零工账户 | ×0.85 | 不规则收入模拟速度峰值 | | 老年人(>60)+ 夜间交易 | ×1.50 | 数字逮捕骗局针对夜间活动的老年人 | | 老年人 + 收款方 VPA <7 天 | ×1.30 | 新 VPA + 老年人 = 强诈骗信号 | | Jan Dhan 账户 + 首次数字支付 | ×0.65 | 首次数字用户按定义就显得异常 | | 农村地区 + 跨邦地理切换 | ×0.75 | 季节性迁移是正常的 | ## 16 种欺诈原型 | 原型 | 描述 | 测试得分 | |-----------|-------------|-----------| | `structuring` | 多笔交易刚好低于 ₹50K/₹1L/₹10L 阈值 | 0.867 | | `romance_scam` | 向新 VPA 的转账金额逐步升级 | 0.845 | | `pig_butchering` | 先小额建立信任,然后大额退出 | 0.833 | | `merchant_terminal` | 通过 POS 终端的往返交易 | 0.813 | | `cash_in_mule` | 现金存款 → 数字交易 → ATM 取现 | 0.813 | | `otp_fraud` | 多次失败尝试 → 收到 OTP 后成功 | 0.803 | | `digital_arrest` | 老年人 + 夜间 + 大额 + 新 VPA | 0.802 | | `investment_fraud` | 高回报承诺 + 加密货币入口 | 0.807 | | `account_takeover` | 设备更换 + 交易速度异常 + 新收款方 | 0.799 | | `low_slow_mule` | 45 天预热后凌晨 2 点突发 1.8L | 0.798 | | `cycle_round_trip` | 循环流动 — 第二级门控捕获 | 0.794 | | `salary_mule` | 合法薪资转入,立即转出 | 0.768 | | `rapid_layering` | 4+ 跳,金额递减,<20 分钟 | 0.759 | | `sim_swap` | 设备更换 + 立即进行高额 UPI 交易 | 0.745 | | `ghost_node_cash` | ATM 取现 + 18 小时后在另一城市存款 | 0.706 | | `bipartite_mule` | 7+ 发送方 → 1 收集方,密度 0.85 | 0.698 | ## 隔离森林 — 新颖模式传感器 隔离森林在 **每笔交易评分后静默运行**。欺诈分数永不改变。 **存在的原因:** XGBoost 捕捉已知模式。对手会迭代。隔离森林监控结构异常,这些异常与任何合法账户都不匹配——在有人为此编写门控之前,捕捉新的规避技术。 **仅使用 17 个结构特征** — 排除时间和金额特征(夜猫子和养老金领取者不应被标记为新颖)。 ### 开发者工作流 ``` # 查看待处理的新颖标志 curl "http://localhost:8000/api/v1/novelty/queue" \ -H "X-API-Key: $INTERNAL_API_KEY" # 仅限升级的模式(相同指纹出现 10 次以上) curl "http://localhost:8000/api/v1/novelty/queue?escalation_only=true" \ -H "X-API-Key: $INTERNAL_API_KEY" # 确认为新的欺诈模式 — 然后为其编写一个网关 curl -X PATCH "http://localhost:8000/api/v1/novelty/42/review" \ -H "X-API-Key: $INTERNAL_API_KEY" \ -H "Content-Type: application/json" \ -d '{"status":"REVIEWED_NEW_FRAUD","developer_notes":"SIM swap variant — write gate"}' ``` ## API 参考 ### 提交 /api/v1/score 认证:`GRAPH_ENGINE_API_KEY` · 速率限制:1000 次/分钟 ``` // Request { "transaction_id": "TXN_001", "account_id": "ACC123456789", "amount": "500000.00", "channel": "UPI", "timestamp": "2026-05-17T02:14:00Z", "payee_vpa": "recipient@upi", "payee_vpa_created_at": "2026-05-15T10:00:00Z" } // Response { "transaction_id": "TXN_001", "score": 0.9654, "action": "HIGH_RISK", "gate_fired": null, "alert_id": "a1b2c3d4-...", "processing_ms": 47 } ``` ### 获取 /api/v1/alerts/{alert_id} 认证:`INVESTIGATOR_API_KEY` — 资金流向 + SHAP 值 + STR 草稿(156 个 FINnet 字段) ### 提交 /api/v1/feedback 认证:`INVESTIGATOR_API_KEY` — 触发区块链密封 + 红队 DNA + River FTRL 更新 ## 如何运行 ``` # 基础设施 docker-compose up -d # 环境设置 cp .env.example .env # fill credentials # 数据库 python scripts/init_db.py alembic upgrade head # 训练模型 python ml/train.py # XGBoost (~2 min) python ml/train_isolation_forest.py # Isolation Forest (~30 sec) # 初始化 Redis 和演示数据 python scripts/seed_redis.py python scripts/generate_test_data.py && python scripts/load_sample_data.py # 启动 API uvicorn app.main:app --reload --port 8000 # 验证 curl http://localhost:8000/health # {"status": "ok"} pytest tests/ -v # 23 passing ``` ## 数据库 | 表 | 用途 | 可变? | |-------|---------|---------| | `accounts` | 来自核心银行的 KYC 数据 | 蓝队只读 | | `transactions` | 已结算的交易记录 | 仅追加 | | `fraud_scores` | 评分结果 + SHAP + 特征向量 | 追加 | | `alerts` | 当分数 ≥ REVIEW 时创建 | 调查员更新 | | `feedback_log` | 调查员决策 | 仅追加 | | `graph_features_cache` | 每晚预计算的图特征 | 每晚更新 | | `model_audit` | **不可变** RBI PMLA §12 审计跟踪 | 仅 INSERT(数据库强制) | | `novelty_queue` | 隔离森林发现,供开发者使用 | 开发者更新 | **Redis 键:** | 键 | 用途 | TTL | |-----|---------|-----| | `vel:1h:{account}` | 速度计数器,1 小时 | 3600 秒 | | `vel:24h:{account}` | 速度计数器,24 小时 | 86400 秒 | | `feat:{account}` | 35 个预计算的图特征 | 26 小时 | | `novelty:fp:{fp}` | 新颖性指纹出现次数 | 7 天 | ## 技术栈 | 层级 | 技术 | |-------|-----------| | API | FastAPI 0.111 + Uvicorn | | ML 评分 | XGBoost 2.x + SHAP 0.44 | | 在线学习 | River 0.21 FTRL | | 新颖性检测 | scikit-learn IsolationForest | | 主数据库 | PostgreSQL 15 | | 图数据库 | Neo4j Community 5.x(只读) | | 缓存 | Redis 7.x | | 异步任务 | Celery | | 调度器 | APScheduler 3.x | | 可观测性 | structlog + Prometheus | | 部署 | Docker + Docker Compose | ## 安全性 | 关注点 | 实现方式 | |---------|---------------| | 认证 | 按调用者的 X-API-Key,路由级 | | 速率限制 | 1000 次/分钟(POST /score,slowapi) | | SQL 注入 | 仅使用参数化查询 | | 日志中的 PII | `sha256(SALT + account_id)[:12]` | | 密钥 | 仅 `.env` 文件 | | 审计完整性 | 数据库触发器阻止对 `model_audit` 的 UPDATE/DELETE | | 输入验证 | 每个边界层使用 Pydantic v2 | ## 文件结构 ``` app/ ├── api/v1/ score.py · alert.py · feedback.py · novelty.py · health.py ├── detection/ pipeline.py · tier1/ · tier2/ (5 gates) · tier3/ · context/ · novelty/ ├── evidence/ trail_builder.py (Celery) · str_generator.py ├── graph/ neo4j_client.py · queries/ · precompute/nightly_batch.py ├── integrations/ blockchain_client.py · red_team_client.py └── utils/ redis_client.py · audit_logger.py · metrics.py ml/ ├── train.py XGBoost (310K rows, 16 archetypes) ├── train_isolation_forest.py IF (legit-only, 17 features) ├── baf_graph_bridge.py BAF NeurIPS 2022 → graph schema └── deepesh_bridge.py Banking risk dataset → graph schema alembic/versions/ ├── 001_initial_schema.py 7 core tables └── 002_add_novelty_queue.py novelty_queue table tests/ ├── test_integration/test_fraud_scenarios.py 8 fraud scenarios (all pass) └── test_novelty/test_isolation_forest.py 15 novelty + separation tests ``` ## 队友集成 | 队友 | 方向 | 内容 | |---------|-----------|------| | 图引擎 | → 蓝队 | 每笔已结算交易 POST /api/v1/score | | 图引擎 | → Neo4j | 构建实时图 — 蓝队只读 | | 调查员仪表板 | → 蓝队 | GET /alerts/{id} · POST /feedback | | 区块链 | ← 蓝队 | 在确认欺诈时密封证据 | | 红队 | ← 蓝队 | 基于反馈和新颖性升级的欺诈 DNA |
BLING 黑客松 · 蓝队 · 印度联合银行
结合图谱智能的交易后取证欺诈检测
标签:Apex, AV绕过, Celery任务队列, FastAPI, Isolation Forest, PostgreSQL, Python, Redis, River FTRL, SHAP可解释性, STR报告, XGBoost, 三层管道, 交易后分析, 人工智能, 区块链, 图门控, 在线学习, 异常检测, 快速规则, 搜索引擎查询, 无后门, 机器学习, 欺诈检测, 法证分析, 测试用例, 用户模式Hook绕过, 证据管理, 请求拦截, 资金追踪, 逆向工具, 金融安全, 金融犯罪, 银行业务, 风险评分